display units in web demo

This commit is contained in:
Stefano D'Angelo 2024-01-20 11:25:44 +01:00
parent 4269699af4
commit 86875466cc

View File

@ -63,6 +63,33 @@ function unmap(index, value) {
return p.map == "logarithmic" ? Math.log(value / p.minimum) / (2.0 * Math.log(Math.sqrt(p.maximum * p.minimum) / Math.abs(p.minimum))) : (value - p.minimum) / (p.maximum - p.minimum);
}
var units = {
"bar": "bars",
"beat": "beats",
"bpm": "BPM",
"cent": "ct",
"cm": "cm",
"coef": "",
"db": "dB",
"degree": "deg",
"frame": "frames",
"hz": "Hz",
"inch": "\"",
"khz": "kHz",
"km": "km",
"m": "m",
"mhz": "MHz",
"midiNote": "MIDI note",
"mile": "mi",
"min": "mins",
"mm": "mm",
"ms": "ms",
"oct": "octaves",
"pc": "%",
"s": "s",
"semitone12TET": "semi"
};
var initState = 0; // 0 = not inited, 1 = in progress, 2 = inited
window.addEventListener("load", function (e) {
@ -96,7 +123,8 @@ window.addEventListener("load", function (e) {
var value = document.createElement("span");
value.setAttribute("id", "v" + i);
value.innerText = parameters[i].defaultValue;
var u = parameters[i].unit;
value.innerText = parameters[i].defaultValue + (u in units ? " " + units[u] : "");
var range = document.createElement("input");
range.setAttribute("type", "range");
@ -121,7 +149,8 @@ window.addEventListener("load", function (e) {
var p = node.parameters.get(parameters[index].name);
var val = map(index, e.target.value);
p.setValueAtTime(val, 0);
v.innerText = val;
var u = parameters[index].unit;
v.innerText = val + (u in units ? " " + units[u] : "");
});
}