|
|
import { workletMessageType } from "./worklet_system/message_protocol/worklet_message.js"; |
|
|
import { KeyModifier, workletKeyModifierMessageType } from "./worklet_system/worklet_methods/worklet_key_modifier.js"; |
|
|
|
|
|
export class KeyModifierManager |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
constructor(synth) |
|
|
{ |
|
|
this.synth = synth; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._keyModifiers = []; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_sendToWorklet(type, data) |
|
|
{ |
|
|
this.synth.post({ |
|
|
messageType: workletMessageType.keyModifierManager, |
|
|
messageData: [ |
|
|
type, |
|
|
data |
|
|
] |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addModifier(channel, midiNote, options) |
|
|
{ |
|
|
const velocity = options?.velocity ?? -1; |
|
|
const program = options?.patch?.program ?? -1; |
|
|
const bank = options?.patch?.bank ?? -1; |
|
|
const mod = new KeyModifier(velocity, bank, program); |
|
|
if (this._keyModifiers[channel] === undefined) |
|
|
{ |
|
|
this._keyModifiers[channel] = []; |
|
|
} |
|
|
this._keyModifiers[channel][midiNote] = mod; |
|
|
this._sendToWorklet( |
|
|
workletKeyModifierMessageType.addMapping, |
|
|
[channel, midiNote, mod] |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getModifier(channel, midiNote) |
|
|
{ |
|
|
return this._keyModifiers?.[channel]?.[midiNote]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteModifier(channel, midiNote) |
|
|
{ |
|
|
this._sendToWorklet( |
|
|
workletKeyModifierMessageType.deleteMapping, |
|
|
[channel, midiNote] |
|
|
); |
|
|
if (this._keyModifiers[channel]?.[midiNote] === undefined) |
|
|
{ |
|
|
return; |
|
|
} |
|
|
this._keyModifiers[channel][midiNote] = undefined; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clearModifiers() |
|
|
{ |
|
|
this._sendToWorklet(workletKeyModifierMessageType.clearMappings, undefined); |
|
|
this._keyModifiers = []; |
|
|
} |
|
|
} |