From afeece017bac285dffc9c635242b9a57328ab8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lumi=C3=A8re=20=C3=89lev=C3=A9?= <88174309+PoneyClairDeLune@users.noreply.github.com> Date: Tue, 26 Sep 2023 07:16:51 +0000 Subject: [PATCH] Line in and demos are now mutually exclusive. --- src/basic/index.mjs | 4 ++++ src/cambiare/index.mjs | 9 +++++++-- src/cambiare_demo/index.js | 27 +++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/basic/index.mjs b/src/basic/index.mjs index 64191328..b81d0ffe 100644 --- a/src/basic/index.mjs +++ b/src/basic/index.mjs @@ -52,6 +52,10 @@ let RootDisplay = class extends CustomEventSource { upThis.dispatchEvent("tempo", upThis.#noteTempo); upThis.dispatchEvent("title", upThis.#titleName); }; + init() { + this.reset(); + this.#midiPool = undefined; + }; async loadFile(blob) { this.#midiPool = rawToPool(MidiParser.parse(new Uint8Array(await blob.arrayBuffer()))); }; diff --git a/src/cambiare/index.mjs b/src/cambiare/index.mjs index 2c990721..8f845808 100644 --- a/src/cambiare/index.mjs +++ b/src/cambiare/index.mjs @@ -287,8 +287,13 @@ let Cambiare = class extends RootDisplay { upThis.#sectInfo.events.innerText = `${sum.eventCount}`.padStart(3, "0"); upThis.#sectInfo.curPoly.innerText = `${curPoly}`.padStart(3, "0"); upThis.#sectInfo.maxPoly.innerText = `${upThis.#maxPoly}`.padStart(3, "0"); - upThis.#sectInfo.barCount.innerText = sum.noteBar + 1; - upThis.#sectInfo.barNote.innerText = Math.floor(sum.noteBeat) + 1; + if (upThis.#clockSource?.realtime) { + upThis.#sectInfo.barCount.innerText = "LIVE"; + upThis.#sectInfo.barNote.innerText = "0"; + } else { + upThis.#sectInfo.barCount.innerText = sum.noteBar + 1; + upThis.#sectInfo.barNote.innerText = Math.floor(sum.noteBeat) + 1; + }; upThis.#scrollMeta(true); let renderPortMax = upThis.#renderPort + upThis.#renderRange; for (let part = 0; part < allocated.ch; part ++) { diff --git a/src/cambiare_demo/index.js b/src/cambiare_demo/index.js index 62eb53bc..70bb7eba 100644 --- a/src/cambiare_demo/index.js +++ b/src/cambiare_demo/index.js @@ -25,13 +25,22 @@ self.Alpine = Alpine; let useMidiBus = false; let audioFilePlayer = $e("#audioFilePlayer"); -let timePlexer = {}; -Object.defineProperty(timePlexer, "currentTime", { +let timeMuxer = {}; +Object.defineProperty(timeMuxer, "currentTime", { get: () => { - return audioFilePlayer.currentTime || (Date.now() / 1000); + if (useMidiBus) { + return audioFilePlayer.currentTime || (Date.now() / 1000); + } else { + return audioFilePlayer.currentTime; + }; + } +}); +Object.defineProperty(timeMuxer, "realtime", { + get: () => { + return useMidiBus && !audioFilePlayer.currentTime; } }); -let visualizer = new Cambiare($e(".cambiare"), timePlexer); +let visualizer = new Cambiare($e(".cambiare"), timeMuxer); visualizer.reset(); Alpine.store("play", "smf"); @@ -90,6 +99,14 @@ self.gDemo = async function ({file, id, artist, title}) { URL.revokeObjectURL(audioUri); }; audioFilePlayer.src = ""; + if (!file) { + Alpine.store("activeDemo", -1); + console.debug(`Cleared out demos.`); + return; + } else { + useMidiBus = false; + Alpine.store("useMidiBus", false); + }; visualizer.dispatchEvent("title", `Loading demo: ${artist} - ${title} ... (MIDI)`); let midiBlob = await(await getBlobFrom(`${file}.mid`)).blob(); visualizer.dispatchEvent("title", `Loading demo: ${artist} - ${title} ... (audio)`); @@ -158,6 +175,8 @@ self.gOpenSnd = async function () { audioFilePlayer.src = audioUri; }; self.gOpenLni = function () { + gDemo({}); + visualizer.init(); useMidiBus = !useMidiBus; Alpine.store("useMidiBus", useMidiBus); visualizer.device.initOnReset = useMidiBus;