-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a new page for it in the synth too! cleanup the synth wiki page too
- Loading branch information
Showing
30 changed files
with
926 additions
and
222 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"name": "SpessaSynth", | ||
"version": "3.22.1", | ||
"version": "3.22.2", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node src/website/server/server.js" | ||
"start": "node src/website/server/server.js", | ||
"build": "src/website/minify_website.sh" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 | ||
{ | ||
/** | ||
* @param synth {Synthetizer} | ||
*/ | ||
constructor(synth) | ||
{ | ||
this.synth = synth; | ||
} | ||
|
||
/** | ||
* @private | ||
* @param type {workletKeyModifierMessageType} | ||
* @param data {any} | ||
*/ | ||
_sendToWorklet(type, data) | ||
{ | ||
this.synth.post({ | ||
messageType: workletMessageType.keyModifierManager, | ||
messageData: [ | ||
type, | ||
data | ||
] | ||
}); | ||
} | ||
|
||
/** | ||
* Modifies a single key | ||
* @param channel {number} the channel affected. Usually 0-15 | ||
* @param midiNote {number} the MIDI note to change. 0-127 | ||
* @param options {{ | ||
* velocity: number|undefined, | ||
* patch: { | ||
* bank: number, | ||
* program: number | ||
* }|undefined | ||
* }} the key's modifiers | ||
*/ | ||
addModifier(channel, midiNote, options) | ||
{ | ||
const velocity = options?.velocity || -1; | ||
const program = options?.patch?.program ?? -1; | ||
const bank = options?.patch?.bank ?? -1; | ||
this._sendToWorklet( | ||
workletKeyModifierMessageType.addMapping, | ||
[channel, midiNote, new KeyModifier(velocity, bank, program)] | ||
); | ||
} | ||
|
||
/** | ||
* Deletes a key modifier | ||
* @param channel {number} the channel affected. Usually 0-15 | ||
* @param midiNote {number} the MIDI note to change. 0-127 | ||
*/ | ||
deleteModifier(channel, midiNote) | ||
{ | ||
this._sendToWorklet( | ||
workletKeyModifierMessageType.deleteMapping, | ||
[channel, midiNote] | ||
); | ||
} | ||
|
||
/** | ||
* Clears ALL Modifiers | ||
*/ | ||
clearModifiers() | ||
{ | ||
this._sendToWorklet(workletKeyModifierMessageType.clearMappings, undefined); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/spessasynth_lib/synthetizer/worklet_system/worklet_methods/worklet_key_modifier.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
export class KeyModifier | ||
{ | ||
|
||
/** | ||
* The new override velocity. -1 means unchanged | ||
* @type {number} | ||
*/ | ||
velocity = -1; | ||
/** | ||
* The patch this key uses. -1 on either means default | ||
* @type {{bank: number, program: number}} | ||
*/ | ||
patch = { bank: -1, program: -1 }; | ||
|
||
/** | ||
* @param velocity {number} | ||
* @param bank {number} | ||
* @param program {number} | ||
*/ | ||
constructor(velocity = -1, bank = -1, program = -1) | ||
{ | ||
this.velocity = velocity; | ||
this.patch = { | ||
bank: bank, | ||
program: program | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* @enum {number} | ||
*/ | ||
export const workletKeyModifierMessageType = { | ||
addMapping: 0, // [channel<number, midiNote<number>, mapping<KeyModifier>] | ||
deleteMapping: 1, // [channel<number, midiNote<number>] | ||
clearMappings: 2 // <no data> | ||
}; | ||
|
||
export class WorkletKeyModifierManager | ||
{ | ||
/** | ||
* The velocity override mappings for MIDI keys | ||
* @type {KeyModifier[][]} | ||
* @private | ||
*/ | ||
_keyMappings = []; | ||
|
||
/** | ||
* @param type {workletKeyModifierMessageType} | ||
* @param data {any} | ||
*/ | ||
handleMessage(type, data) | ||
{ | ||
switch (type) | ||
{ | ||
default: | ||
return; | ||
|
||
case workletKeyModifierMessageType.addMapping: | ||
this.addMapping(...data); | ||
break; | ||
|
||
case workletKeyModifierMessageType.clearMappings: | ||
this.clearMappings(); | ||
break; | ||
|
||
case workletKeyModifierMessageType.deleteMapping: | ||
this.deleteMapping(...data); | ||
} | ||
} | ||
|
||
/** | ||
* @param channel {number} | ||
* @param midiNote {number} | ||
* @param mapping {KeyModifier} | ||
*/ | ||
addMapping(channel, midiNote, mapping) | ||
{ | ||
if (this._keyMappings[channel] === undefined) | ||
{ | ||
this._keyMappings[channel] = []; | ||
} | ||
this._keyMappings[channel][midiNote] = mapping; | ||
} | ||
|
||
deleteMapping(channel, midiNote) | ||
{ | ||
if (this._keyMappings[channel]?.[midiNote] === undefined) | ||
{ | ||
return; | ||
} | ||
this._keyMappings[channel][midiNote] = undefined; | ||
} | ||
|
||
clearMappings() | ||
{ | ||
this._keyMappings = []; | ||
} | ||
|
||
/** | ||
* @param channel {number} | ||
* @param midiNote {number} | ||
* @returns {number} velocity, -1 if unchanged | ||
*/ | ||
getVelocity(channel, midiNote) | ||
{ | ||
const modifier = this._keyMappings[channel]?.[midiNote]; | ||
if (modifier) | ||
{ | ||
return modifier.velocity; | ||
} | ||
return -1; | ||
} | ||
|
||
/** | ||
* @param channel {number} | ||
* @param midiNote {number} | ||
* @returns {boolean} | ||
*/ | ||
hasOverridePatch(channel, midiNote) | ||
{ | ||
const bank = this._keyMappings[channel]?.[midiNote]?.patch?.bank; | ||
return bank !== undefined && bank > 0; | ||
} | ||
|
||
/** | ||
* @param channel {number} | ||
* @param midiNote {number} | ||
* @returns {{bank: number, program: number}} -1 if unchanged | ||
*/ | ||
getPatch(channel, midiNote) | ||
{ | ||
const modifier = this._keyMappings[channel]?.[midiNote]; | ||
if (modifier) | ||
{ | ||
return modifier.patch; | ||
} | ||
throw new Error("No modifier."); | ||
} | ||
|
||
} |
Oops, something went wrong.