mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-13 06:19:33 -04:00
Avoid referencing found MIDI device name
This commit is contained in:
+18
-5
@@ -483,6 +483,8 @@ class MidiInput {
|
||||
* @param {string | number} input MIDI device name or index defaulting to 0
|
||||
*/
|
||||
constructor(input) {
|
||||
this.stateKey = typeof input === 'string' ? input : undefined;
|
||||
|
||||
const device = getDevice(input, WebMidi.inputs);
|
||||
if (!device) {
|
||||
throw new Error(
|
||||
@@ -490,8 +492,6 @@ class MidiInput {
|
||||
);
|
||||
}
|
||||
|
||||
this.name = device.name;
|
||||
|
||||
this._refs = {};
|
||||
this._refsByChan = {};
|
||||
|
||||
@@ -540,7 +540,13 @@ class MidiInput {
|
||||
}
|
||||
|
||||
_loadState(chan) {
|
||||
const initialDataRaw = localStorage.getItem(`strudel-midin-${this.name}-chan${chan !== undefined ? chan : 'all'}`);
|
||||
if (!this.stateKey) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const initialDataRaw = localStorage.getItem(
|
||||
`strudel-midin-${this.stateKey}-chan${chan !== undefined ? chan : 'all'}`,
|
||||
);
|
||||
if (!initialDataRaw) {
|
||||
return {};
|
||||
}
|
||||
@@ -549,7 +555,7 @@ class MidiInput {
|
||||
return JSON.parse(initialDataRaw);
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
`Failed to parse MIDI state from localStorage for input "${this.name}" and channel "${chan}"`,
|
||||
`Failed to parse MIDI state from localStorage for input "${this.stateKey}" and channel "${chan}"`,
|
||||
initialDataRaw,
|
||||
err,
|
||||
);
|
||||
@@ -558,9 +564,16 @@ class MidiInput {
|
||||
}
|
||||
|
||||
_saveState(chan, cc, value) {
|
||||
if (!this.stateKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
const state = this._loadState(chan);
|
||||
state[cc] = value;
|
||||
localStorage.setItem(`strudel-midin-${this.name}-chan${chan !== undefined ? chan : 'all'}`, JSON.stringify(state));
|
||||
localStorage.setItem(
|
||||
`strudel-midin-${this.stateKey}-chan${chan !== undefined ? chan : 'all'}`,
|
||||
JSON.stringify(state),
|
||||
);
|
||||
}
|
||||
|
||||
_sendAllStates(output) {
|
||||
|
||||
Reference in New Issue
Block a user