Tweak cc init
This commit is contained in:
parent
47557cf06f
commit
1860d31624
1 changed files with 15 additions and 11 deletions
|
|
@ -497,20 +497,24 @@ class MidiInput {
|
||||||
this._refs = {};
|
this._refs = {};
|
||||||
this._refsByChan = {};
|
this._refsByChan = {};
|
||||||
|
|
||||||
this.cc = (cc, chan) => {
|
|
||||||
const initialState = this._loadState(chan);
|
|
||||||
const initialValue = initialState[cc] || 0;
|
|
||||||
|
|
||||||
if (chan !== undefined) {
|
|
||||||
return ref(() => this._refsByChan[cc]?.[chan] || initialValue);
|
|
||||||
}
|
|
||||||
return ref(() => this._refs[cc] || initialValue);
|
|
||||||
};
|
|
||||||
|
|
||||||
const midiListener = this._onMidiMessage.bind(this);
|
const midiListener = this._onMidiMessage.bind(this);
|
||||||
device.addListener('midimessage', midiListener);
|
device.addListener('midimessage', midiListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createCC(cc, chan) {
|
||||||
|
if (chan !== undefined && !(chan in this._refsByChan)) {
|
||||||
|
this._refsByChan[chan] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const lookupMap = chan === undefined ? this._refs : this._refsByChan[chan];
|
||||||
|
if (!(cc in lookupMap)) {
|
||||||
|
const initialState = this._loadState(chan);
|
||||||
|
lookupMap[cc] = initialState[cc] || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ref(() => lookupMap[cc]);
|
||||||
|
}
|
||||||
|
|
||||||
_onMidiMessage(e) {
|
_onMidiMessage(e) {
|
||||||
const ccNum = e.dataBytes[0];
|
const ccNum = e.dataBytes[0];
|
||||||
const v = e.dataBytes[1];
|
const v = e.dataBytes[1];
|
||||||
|
|
@ -593,5 +597,5 @@ export async function midin(input) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance.cc;
|
return instance.createCC.bind(instance);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue