Skip to content

Commit

Permalink
Added support for voice element count.
Browse files Browse the repository at this point in the history
Currently supporting XG (MU90/QY100) and NS5R (GM-b,PrgA~C).
  • Loading branch information
PoneyClairDeLune committed Jul 24, 2024
1 parent 92fe981 commit e6d6fa4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/basic/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ let RootDisplay = class extends CustomEventSource {
#noteDenom = 4;
#noteBarOffset = 0;
#noteTime = 0;
// A cache for providing fast poly calculation
#voiceCache = new Array(allocated.ch);
#polyCache = new Uint8Array(allocated.ch);
smoothingAtk = 0;
smoothingDcy = 0;
reset() {
Expand Down Expand Up @@ -384,7 +387,8 @@ let RootDisplay = class extends CustomEventSource {
this.#noteTime = time;
};
let events = this.#midiPool?.step(time) || [];
let extraPoly = 0, notes = new Set(), noteVelo = {};
let extraPoly = 0, extraPolyEC = 0,
notes = new Set(), noteVelo = {};
let extraNotes = []; // Should be visualized before the final internal state!
let upThis = this;
let metaReplies = [];
Expand Down Expand Up @@ -422,6 +426,7 @@ let RootDisplay = class extends CustomEventSource {
state: upThis.device.NOTE_SUSTAIN // OctaviaDevice.NOTE_SUSTAIN
});
extraPoly ++;
extraPolyEC += upThis.#polyCache[raw.part];
};
};
};
Expand Down Expand Up @@ -452,18 +457,21 @@ let RootDisplay = class extends CustomEventSource {
upThis.#mimicStrength[i] += Math.floor(diff - (diff * (upThis.smoothingDcy ** rlsPower)));
};
});
let curPoly = 0;
let curPoly = 0, curPolyEC = 0;
chInUse.forEach(function (e, i) {
if (e) {
chKeyPr[i] = upThis.device.getVel(i);
chExt[i] = upThis.device.getExt(i);
curPoly += chKeyPr[i].size;
curPolyEC += chKeyPr[i].size * upThis.#polyCache[i];
};
});
let repObj = {
extraPoly,
extraPolyEC,
extraNotes,
curPoly,
curPolyEC,
chInUse,
chKeyPr,
chPitch,
Expand Down Expand Up @@ -532,6 +540,15 @@ let RootDisplay = class extends CustomEventSource {
upThis.#noteEvents.push(data);
//console.debug(data);
});
upThis.addEventListener("voice", ({data}) => {
let voice = upThis.getChVoice(data.part);
upThis.#voiceCache[data.part] = voice;
upThis.#polyCache[data.part] = voice.poly ?? 1;
});
upThis.addEventListener("reset", ({data}) => {
upThis.#polyCache.fill(1);
});
upThis.#polyCache.fill(1);
upThis.#metaRun[3] = function (type, data) {
if (upThis.#titleName?.length < 1) {
upThis.#titleName = data;
Expand Down
10 changes: 8 additions & 2 deletions src/cambiare/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ let Cambiare = class extends RootDisplay {
#metaMoveX = 0;
#metaMoveY = 0;
#maxPoly = 0;
#maxPolyEC = 0;
#metaGcThread;
#metaGcAt = 0;
#metaGcScheduled = false;
Expand Down Expand Up @@ -239,6 +240,7 @@ let Cambiare = class extends RootDisplay {
#sectMeta = {};
#sectPix = {};
eventViewMode = 0; // 0 for event count, 1 for FPS
useElementCount = true;
//#noteEvents = [];
#pitchEvents = [];
#style = "comb";
Expand Down Expand Up @@ -394,11 +396,15 @@ let Cambiare = class extends RootDisplay {
sum = upThis.render(clock),
timeNow = Date.now();
let curPoly = sum.curPoly + sum.extraPoly;
let curPolyEC = sum.curPolyEC + sum.extraPolyEC;
if (upThis.#maxPoly < curPoly) {
upThis.#maxPoly = curPoly;
};
upThis.#sectInfo.curPoly.setTextRaw(`${curPoly}`.padStart(3, "0"));
upThis.#sectInfo.maxPoly.setTextRaw(`${upThis.#maxPoly}`.padStart(3, "0"));
if (upThis.#maxPolyEC < curPolyEC) {
upThis.#maxPolyEC = curPolyEC;
};
upThis.#sectInfo.curPoly.setTextRaw(`${upThis.useElementCount ? curPolyEC : curPoly}`.padStart(3, "0"));
upThis.#sectInfo.maxPoly.setTextRaw(`${upThis.useElementCount ? upThis.#maxPolyEC : upThis.#maxPoly}`.padStart(3, "0"));
if (upThis.#clockSource?.realtime) {
upThis.#sectInfo.barCount.setTextRaw("LINE");
upThis.#sectInfo.barDelim.style.display = "none";
Expand Down
4 changes: 4 additions & 0 deletions src/cambiare_demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ self.gSetScheme = (scheme) => {
visualizer.setScheme(scheme);
Alpine.store("scheme", scheme);
};
self.gEcMode = (ecMode) => {
visualizer.useElementCount = ecMode;
Alpine.store("useElementCount", ecMode);
};

const propsMid = JSON.parse('{"extensions":[".mid",".MID",".kar",".KAR",".syx",".SYX",".s7e",".S7E",".mdat",".MDAT",".pcg",".PCG"],"startIn":"music","id":"midiOpener","description":"Open a MIDI file"}'),
propsAud = JSON.parse('{"mimeTypes":["audio/*"],"startIn":"music","id":"audioOpener","description":"Open an audio file"}');
Expand Down
6 changes: 5 additions & 1 deletion test/cambiare.htm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
</template>
<div class="column"></div>
</div>
<div class="columns is-multiline is-mobile is-vcentered" x-data="{ranges:[['port1','16ch'],['compact','Compact'],['port2','32ch'],['port4','64ch']],ports:[0,1,2,3,4,5,6,7],letters:'ABCDEFGH',max:8,size:{port1:1,compact:1,port2:2,port4:4}}">
<div class="columns is-multiline is-mobile is-vcentered" x-data="{ranges:[['port1','16ch'],['compact','Compact'],['port2','32ch'],['port4','64ch']],ports:[0,1,2,3,4,5,6,7],letters:'ABCDEFGH',max:8,size:{port1:1,compact:1,port2:2,port4:4},ecModes:[[false,'Ignore'],[true,'Used']]}">
<div class="column column-option"><b>Element count</b></div>
<template x-for="ecMode in ecModes">
<div class="column column-option column-button" @click="gEcMode(ecMode[0])" x-text="ecMode[1]" :active="($store.useElementCount??true)==ecMode[0]?'true':'false'"></div>
</template>
<div class="column column-option"><b>Display mode</b></div>
<template x-for="range in ranges">
<div class="column column-option column-button" @click="gRange(range[0])" x-text="range[1]" :active="($store.showRange||'port1')==range[0]?'true':'false'"></div>
Expand Down

0 comments on commit e6d6fa4

Please sign in to comment.