diff --git a/src/cambiare/index.mjs b/src/cambiare/index.mjs index 8c640dc7..7f0bac27 100644 --- a/src/cambiare/index.mjs +++ b/src/cambiare/index.mjs @@ -41,6 +41,20 @@ let mountElement = function (root, children) { root.appendChild(e); }); }; +let classOff = function (target, classes) { + classes.forEach((e) => { + if (target.classList.contains(e)) { + target.classList.remove(e); + }; + }); +}; +let classOn = function (target, classes) { + classes.forEach((e) => { + if (!target.classList.contains(e)) { + target.classList.add(e); + }; + }); +}; let Cambiare = class extends RootDisplay { #maxPoly = 0; @@ -88,6 +102,23 @@ let Cambiare = class extends RootDisplay { setClockSource(clockSource) { this.#clockSource = clockSource; }; + setMode(mode) { + let upThis = this; + classOff(upThis.#canvas, [`cambiare-mode-gm`, `cambiare-mode-xg`, `cambiare-mode-gs`, `cambiare-mode-ns5r`, `cambiare-mode-05rw`, `cambiare-mode-x5d`, `cambiare-mode-k11`, `cambiare-mode-sg`, `cambiare-mode-g2`, `cambiare-mode-mt32`, `cambiare-mode-sd`, `cambiare-mode-krs`, `cambiare-mode-s90es`, `cambiare-mode-motif`]); + if (mode != "?") { + classOn(upThis.#canvas, [`cambiare-mode-${mode}`]); + }; + }; + setPort(port) { + let upThis = this; + classOff(upThis.#canvas, [`cambiare-start0`, `cambiare-start1`, `cambiare-start2`, `cambiare-start3`, `cambiare-start4`, `cambiare-start5`, `cambiare-start6`, `cambiare-start7`]); + classOn(upThis.#canvas, [`cambiare-start${port}`]); + }; + setRange(mode) { + let upThis = this; + classOff(upThis.#canvas, [`cambiare-port1`, `cambiare-port2`, `cambiare-port4`, `cambiare-compact`]); + classOn(upThis.#canvas, [`cambiare-${mode}`]); + }; attach(attachElement) { let upThis = this; upThis.#visualizer = attachElement; @@ -96,7 +127,7 @@ let Cambiare = class extends RootDisplay { attachElement.appendChild(containerElement); upThis.#container = containerElement; // Insert the canvas - let canvasElement = createElement("div", ["cambiare-canvas", "debug"]); + let canvasElement = createElement("div", ["cambiare-canvas", "cambiare-port1", "cambiare-start0", "debug"]); containerElement.appendChild(canvasElement); upThis.#canvas = canvasElement; // Start the resizer @@ -164,6 +195,7 @@ let Cambiare = class extends RootDisplay { // Opportunistic value refreshing upThis.addEventListener("mode", (ev) => { upThis.#sectInfo.mode.innerText = `${modeNames[ev.data]}`; + upThis.setMode(ev.data); }); upThis.addEventListener("mastervolume", (ev) => { let cramVolume = Math.round(ev.data * 100) / 100; diff --git a/src/cambiare_demo/index.js b/src/cambiare_demo/index.js index 0cc9b810..02c8cd32 100644 --- a/src/cambiare_demo/index.js +++ b/src/cambiare_demo/index.js @@ -41,6 +41,10 @@ audioFilePlayer.addEventListener("ended", () => { visualizer.reset(); }); +visualizer.addEventListener("mode", (ev) => { + Alpine.store("deviceMode", ev.data); +}); + const srcPaths = ['../../midi-demo-data/collection/octavia/', './demo/']; let getBlobFrom = async function (filename) { let i = 0; @@ -58,12 +62,15 @@ let getBlobFrom = async function (filename) { let audioUri; self.gMode = async function (mode) { + visualizer.device.switchMode(mode, true); Alpine.store("deviceMode", mode); }; self.gRange = async function (mode) { + visualizer.setRange(mode); Alpine.store("showRange", mode); }; self.gPort = async function (port) { + visualizer.setPort(port); Alpine.store("startPort", port); }; self.gDemo = async function ({file, id}) { diff --git a/test/cambiare.htm b/test/cambiare.htm index 713fe500..9ba7551e 100644 --- a/test/cambiare.htm +++ b/test/cambiare.htm @@ -26,7 +26,7 @@
line out
-
+
Set mode to