minor fixing

This commit is contained in:
Paolo Marrone 2024-07-05 16:18:17 +02:00
parent acf92dd51d
commit f366841c2c
3 changed files with 134 additions and 132 deletions

View File

@ -97,12 +97,12 @@ struct templateApp: App {
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ContentView() ContentView()
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in .onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
audioPause() audioPause()
} }
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
audioResume() audioResume()
} }
} }
} }
} }

View File

@ -21,10 +21,11 @@
--> -->
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>{{=it.product.name}}</title> <title>{{=it.product.name}}</title>
<script type="text/javascript"> <script type="text/javascript">
function request(data) { function request(data) {
return window.webkit.messageHandlers.listener.postMessage(data); return window.webkit.messageHandlers.listener.postMessage(data);
} }
@ -75,125 +76,126 @@ var outParamInterval;
window.onload = async function () { window.onload = async function () {
topButtonElem = document.getElementById("topButton"); topButtonElem = document.getElementById("topButton");
var paramsElem = document.getElementById("params"); var paramsElem = document.getElementById("params");
for (var i = 0; i < data.buses.length; i++) for (var i = 0; i < data.buses.length; i++) {
if (data.buses[i].type == "audio" && data.buses[i].direction == "input") { if (data.buses[i].type == "audio" && data.buses[i].direction == "input") {
hasAudioPermission = !await needAudioPermission(); hasAudioPermission = !await needAudioPermission();
break; break;
} }
}
topButtonElem.value = hasAudioPermission ? "START" : "INIT"; topButtonElem.value = hasAudioPermission ? "START" : "INIT";
topButtonElem.addEventListener("click", async function () { topButtonElem.addEventListener("click", async function () {
if (hasAudioPermission) { if (hasAudioPermission) {
if (audioStarted) { if (audioStarted) {
clearInterval(outParamInterval); clearInterval(outParamInterval);
await audioStop(); await audioStop();
paramsElem.innerHTML = ""; paramsElem.innerHTML = "";
topButtonElem.value = "START"; topButtonElem.value = "START";
audioStarted = false; audioStarted = false;
} else { } else {
if (await audioStart()) { if (await audioStart()) {
for (var i = 0; i < data.parameters.length; i++) { for (var i = 0; i < data.parameters.length; i++) {
var div = document.createElement("div"); var div = document.createElement("div");
var label = document.createElement("label"); var label = document.createElement("label");
label.setAttribute("for", "p" + i); label.setAttribute("for", "p" + i);
label.innerText = data.parameters[i].name; label.innerText = data.parameters[i].name;
var range = document.createElement("input"); var range = document.createElement("input");
range.classList.add("range"); range.classList.add("range");
range.setAttribute("type", "range"); range.setAttribute("type", "range");
range.setAttribute("id", "p" + i); range.setAttribute("id", "p" + i);
range.setAttribute("name", "p" + i); range.setAttribute("name", "p" + i);
if (data.parameters[i].isBypass || data.parameters[i].toggled) { if (data.parameters[i].isBypass || data.parameters[i].toggled) {
range.setAttribute("min", 0); range.setAttribute("min", 0);
range.setAttribute("max", 1); range.setAttribute("max", 1);
range.setAttribute("step", 1); range.setAttribute("step", 1);
} else { } else {
range.setAttribute("min", 0); range.setAttribute("min", 0);
range.setAttribute("max", 1); range.setAttribute("max", 1);
range.setAttribute("step", data.parameters[i].integer ? 1 / (data.parameters[i].maximum - data.parameters[i].minimum) : "any"); range.setAttribute("step", data.parameters[i].integer ? 1 / (data.parameters[i].maximum - data.parameters[i].minimum) : "any");
} }
range.value = unmap(i, data.parameters[i].defaultValue); range.value = unmap(i, data.parameters[i].defaultValue);
if (data.parameters[i].direction == "output") if (data.parameters[i].direction == "output")
range.setAttribute("readonly", "true"); range.setAttribute("readonly", "true");
else { else {
let index = i; let index = i;
range.addEventListener("input", range.addEventListener("input",
async function (ev) { async function (ev) {
await setParameter(index, map(index, parseFloat(ev.target.value))); await setParameter(index, map(index, parseFloat(ev.target.value)));
}); });
} }
div.appendChild(label); div.appendChild(label);
div.appendChild(document.createElement("br")); div.appendChild(document.createElement("br"));
div.appendChild(range); div.appendChild(range);
paramsElem.appendChild(div); paramsElem.appendChild(div);
} }
outParamInterval = setInterval( outParamInterval = setInterval(
async function () { async function () {
for (var i = 0; i < data.parameters.length; i++) for (var i = 0; i < data.parameters.length; i++)
if (data.parameters[i].direction == "output") { if (data.parameters[i].direction == "output") {
document.getElementById("p" + i).value = unmap(i, await getParameter(i)); document.getElementById("p" + i).value = unmap(i, await getParameter(i));
} }
}, 50); }, 50);
topButtonElem.value = "STOP"; topButtonElem.value = "STOP";
audioStarted = true; audioStarted = true;
} else } else
alert("Could not start audio"); alert("Could not start audio");
} }
} else { } else {
await requestAudioPermission(); await requestAudioPermission();
var interval = setInterval( var interval = setInterval(
async function () { async function () {
if (!await needAudioPermission()) { if (!await needAudioPermission()) {
gotAudioPermission(); gotAudioPermission();
clearInterval(interval); clearInterval(interval);
} }
}, 50); }, 50);
} }
}); });
}; };
function gotAudioPermission() { function gotAudioPermission() {
hasAudioPermission = true; hasAudioPermission = true;
topButtonElem.value = "START"; topButtonElem.value = "START";
} }
</script> </script>
<style> <style>
* { * {
margin: 0; margin: 0;
padding: 0; padding: 0;
user-select: none; user-select: none;
} }
body { body {
margin: 1em; margin: 1em;
} }
#topButton { #topButton {
width: 100%; width: 100%;
border: 0; border: 0;
background-color: #04aa6d; background-color: #04aa6d;
color: white; color: white;
padding: 0.5em; padding: 0.5em;
text-align: center; text-align: center;
margin-bottom: 1em; margin-bottom: 1em;
padding: 1em; padding: 1em;
} }
.range { .range {
width: 90%; width: 90%;
} }
</style> </style>
</head> </head>
<body> <body>
<input id="topButton" type="button"> <input id="topButton" type="button">
<div id="params"></div> <div id="params"></div>
</body> </body>
</html> </html>

View File

@ -109,16 +109,16 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
if (mutex.try_lock()) { if (mutex.try_lock()) {
# if PARAMETERS_N > 0 # if PARAMETERS_N > 0
for (size_t i = 0; i < PARAMETERS_N; i++) { for (size_t i = 0; i < PARAMETERS_N; i++) {
if (param_data[i].out) { if (param_data[i].out) {
# ifdef PARAM_OUT_CPU_INDEX # ifdef PARAM_OUT_CPU_INDEX
if (i == PARAM_OUT_CPU_INDEX) { if (i == PARAM_OUT_CPU_INDEX) {
param_values_prev[i] = param_values[i] = cpu_meter; param_values_prev[i] = param_values[i] = cpu_meter;
continue; continue;
} }
# endif # endif
param_values_prev[i] = param_values[i] = plugin_get_parameter(&instance, i); param_values_prev[i] = param_values[i] = plugin_get_parameter(&instance, i);
} }
else if (param_values_prev[i] != param_values[i]) { else if (param_values_prev[i] != param_values[i]) {
plugin_set_parameter(&instance, i, param_values[i]); plugin_set_parameter(&instance, i, param_values[i]);
param_values_prev[i] = param_values[i]; param_values_prev[i] = param_values[i];
} }
@ -178,10 +178,10 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
#endif #endif
#ifdef PARAM_OUT_CPU_INDEX #ifdef PARAM_OUT_CPU_INDEX
const unsigned long long processTimeEnd = fatica_time_process(); const unsigned long long processTimeEnd = fatica_time_process();
const unsigned long long processTime100n = processTimeEnd - processTimeStart; const unsigned long long processTime100n = processTimeEnd - processTimeStart;
const double processTimeS = ((double) processTime100n) * 1.0e-7; const double processTimeS = ((double) processTime100n) * 1.0e-7;
cpu_meter = cpu_meter * 0.9f + ((float) (processTimeS * sample_rate)) * 0.1f; cpu_meter = cpu_meter * 0.9f + ((float) (processTimeS * sample_rate)) * 0.1f;
#endif #endif
} }
@ -301,7 +301,7 @@ char audioStart() {
#endif #endif
plugin_set_sample_rate(&instance, (float)device.sampleRate); plugin_set_sample_rate(&instance, (float)device.sampleRate);
sample_rate = (float)device.sampleRate; sample_rate = (float)device.sampleRate;
size_t req = plugin_mem_req(&instance); size_t req = plugin_mem_req(&instance);
if (req != 0) { if (req != 0) {