spessasynth_lib 3.25.1 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/midi_parser/midi_editor.js +48 -31
  2. package/midi_parser/rmidi_writer.js +57 -38
  3. package/midi_parser/used_keys_loaded.js +28 -23
  4. package/package.json +1 -1
  5. package/soundfont/basic_soundfont/basic_preset.js +12 -0
  6. package/soundfont/basic_soundfont/basic_soundfont.js +25 -15
  7. package/soundfont/dls/dls_preset.js +11 -1
  8. package/synthetizer/worklet_processor.min.js +12 -12
  9. package/synthetizer/worklet_system/main_processor.js +29 -2
  10. package/synthetizer/worklet_system/message_protocol/handle_message.js +1 -1
  11. package/synthetizer/worklet_system/snapshot/channel_snapshot.js +18 -3
  12. package/synthetizer/worklet_system/worklet_methods/controller_control/controller_change.js +2 -9
  13. package/synthetizer/worklet_system/worklet_methods/controller_control/reset_controllers.js +9 -4
  14. package/synthetizer/worklet_system/worklet_methods/program_change.js +10 -5
  15. package/synthetizer/worklet_system/worklet_methods/soundfont_management/clear_sound_font.js +2 -3
  16. package/synthetizer/worklet_system/worklet_methods/soundfont_management/get_preset.js +4 -2
  17. package/synthetizer/worklet_system/worklet_methods/soundfont_management/reload_sound_font.js +1 -2
  18. package/synthetizer/worklet_system/worklet_methods/system_exclusive.js +5 -4
  19. package/synthetizer/worklet_system/worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js +20 -5
  20. package/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +43 -20
  21. package/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +3 -3
  22. package/utils/sysex_detector.js +13 -1
  23. package/utils/xg_hacks.js +74 -9
package/utils/xg_hacks.js CHANGED
@@ -2,6 +2,19 @@ import { SpessaSynthInfo } from "./loggin.js";
2
2
  import { consoleColors } from "./other.js";
3
3
  import { DEFAULT_PERCUSSION } from "../synthetizer/synth_constants.js";
4
4
 
5
+ export const XG_SFX_VOICE = 64;
6
+
7
+ const GM2_DEFAULT_BANK = 121;
8
+
9
+ /**
10
+ * @param sys {SynthSystem}
11
+ * @returns {number}
12
+ */
13
+ export function getDefaultBank(sys)
14
+ {
15
+ return sys === "gm2" ? GM2_DEFAULT_BANK : 0;
16
+ }
17
+
5
18
  /**
6
19
  * @param bankNr {number}
7
20
  * @returns {boolean}
@@ -11,6 +24,15 @@ export function isXGDrums(bankNr)
11
24
  return bankNr === 120 || bankNr === 126 || bankNr === 127;
12
25
  }
13
26
 
27
+ /**
28
+ * @param bank {number}
29
+ * @returns {boolean}
30
+ */
31
+ export function isValidXGMSB(bank)
32
+ {
33
+ return isXGDrums(bank) || bank === XG_SFX_VOICE || bank === GM2_DEFAULT_BANK;
34
+ }
35
+
14
36
  /**
15
37
  * Bank select hacks abstracted here
16
38
  * @param bankBefore {number} the current bank number
@@ -29,12 +51,11 @@ export function parseBankSelect(bankBefore, bank, system, isLSB, isDrums, channe
29
51
  // 64 means SFX in MSB, so it is allowed
30
52
  let out = bankBefore;
31
53
  let drumsStatus = 0;
32
- const isValidMSB = b => isXGDrums(b) || b === 64;
33
54
  if (isLSB)
34
55
  {
35
- if (system === "xg")
56
+ if (isSystemXG(system))
36
57
  {
37
- if (!isValidMSB(bank))
58
+ if (!isValidXGMSB(bank))
38
59
  {
39
60
  out = bank;
40
61
  }
@@ -59,7 +80,7 @@ export function parseBankSelect(bankBefore, bank, system, isLSB, isDrums, channe
59
80
  break;
60
81
 
61
82
  case "xg":
62
- canSetBankSelect = isValidMSB(bank);
83
+ canSetBankSelect = isValidXGMSB(bank);
63
84
  // for xg, if msb is 120, 126 or 127, then it's drums
64
85
  if (isXGDrums(bank))
65
86
  {
@@ -112,17 +133,61 @@ export function parseBankSelect(bankBefore, bank, system, isLSB, isDrums, channe
112
133
 
113
134
 
114
135
  /**
136
+ * Chooses a bank number according to spessasynth logic
137
+ * That is:
138
+ * for GS, bank MSB if not drum, otherwise 128
139
+ * for XG: bank MSB if drum and MSB is valid, 128 othewise, bank MSB if it is SFX voice, LSB otherwise
115
140
  * @param msb {number}
116
141
  * @param lsb {number}
142
+ * @param isDrums {boolean}
143
+ * @param isXG {boolean}
144
+ * @returns {number}
117
145
  */
118
- export function chooseBank(msb, lsb)
146
+ export function chooseBank(msb, lsb, isDrums, isXG)
119
147
  {
120
- if (lsb > 0)
148
+ if (isXG)
121
149
  {
122
- if (!isXGDrums(msb) && msb !== 64)
150
+ if (isDrums)
151
+ {
152
+ if (isXGDrums(msb))
153
+ {
154
+ return msb;
155
+ }
156
+ else
157
+ {
158
+ return 128;
159
+ }
160
+ }
161
+ else
123
162
  {
124
- return lsb;
163
+ // check for SFX
164
+ if (isValidXGMSB(msb))
165
+ {
166
+ return msb;
167
+ }
168
+ // if lsb is 0 and msb is not, use that
169
+ if (lsb === 0 && msb !== 0)
170
+ {
171
+ return msb;
172
+ }
173
+ if (!isValidXGMSB(lsb))
174
+ {
175
+ return lsb;
176
+ }
177
+ return 0;
125
178
  }
126
179
  }
127
- return msb;
180
+ else
181
+ {
182
+ return isDrums ? 128 : msb;
183
+ }
184
+ }
185
+
186
+ /**
187
+ * @param system {SynthSystem}
188
+ * @returns boolean
189
+ */
190
+ export function isSystemXG(system)
191
+ {
192
+ return system === "gm2" || system === "xg";
128
193
  }