spessasynth_lib 3.25.3 → 3.25.5

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.
package/README.md CHANGED
@@ -55,7 +55,7 @@ Supported formats list:
55
55
  - **Easy to Use:** *Basic setup is just [two lines of code!](https://github.com/spessasus/SpessaSynth/wiki/Usage-As-Library#minimal-setup)*
56
56
  - **No dependencies:** *Batteries included!*
57
57
 
58
- ### Powerful Synthesizer
58
+ ### Powerful MIDI Synthesizer
59
59
  - Suitable for both **real-time** and **offline** synthesis
60
60
  - **Excellent SoundFont support:**
61
61
  - **Full Generator Support**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.25.3",
3
+ "version": "3.25.5",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "browser": "index.js",
6
6
  "type": "module",
@@ -66,11 +66,17 @@ export class Sequencer
66
66
  onTextEvent;
67
67
 
68
68
  /**
69
- * The sequence's data, except for the track data.
69
+ * The current MIDI data, with the exclusion of the embedded sound bank and event data.
70
70
  * @type {MIDIData}
71
71
  */
72
72
  midiData;
73
73
 
74
+ /**
75
+ * The current MIDI data for all songs, like the midiData property.
76
+ * @type {MIDIData[]}
77
+ */
78
+ songListData = [];
79
+
74
80
  /**
75
81
  * @type {Object<string, function(MIDIData)>}
76
82
  * @private
@@ -285,11 +291,11 @@ export class Sequencer
285
291
  this._shuffleSongs = value;
286
292
  if (value)
287
293
  {
288
- this._sendMessage(WorkletSequencerMessageType.changeSong, SongChangeType.shuffleOn);
294
+ this._sendMessage(WorkletSequencerMessageType.changeSong, [SongChangeType.shuffleOn]);
289
295
  }
290
296
  else
291
297
  {
292
- this._sendMessage(WorkletSequencerMessageType.changeSong, SongChangeType.shuffleOff);
298
+ this._sendMessage(WorkletSequencerMessageType.changeSong, [SongChangeType.shuffleOff]);
293
299
  }
294
300
  }
295
301
 
@@ -476,14 +482,30 @@ export class Sequencer
476
482
  });
477
483
  }
478
484
 
485
+ /**
486
+ * Switch to the next song in the playlist
487
+ */
479
488
  nextSong()
480
489
  {
481
- this._sendMessage(WorkletSequencerMessageType.changeSong, SongChangeType.forwards);
490
+ this._sendMessage(WorkletSequencerMessageType.changeSong, [SongChangeType.forwards]);
482
491
  }
483
492
 
493
+ /**
494
+ * Switch to the previous song in the playlist
495
+ */
484
496
  previousSong()
485
497
  {
486
- this._sendMessage(WorkletSequencerMessageType.changeSong, SongChangeType.backwards);
498
+ this._sendMessage(WorkletSequencerMessageType.changeSong, [SongChangeType.backwards]);
499
+ }
500
+
501
+ /**
502
+ * Sets the song index in the playlist
503
+ * @param index
504
+ */
505
+ setSongIndex(index)
506
+ {
507
+ const clamped = Math.max(Math.min(this.songsAmount - 1, index), 0);
508
+ this._sendMessage(WorkletSequencerMessageType.changeSong, [SongChangeType.index, clamped]);
487
509
  }
488
510
 
489
511
  /**
@@ -536,19 +558,15 @@ export class Sequencer
536
558
  break;
537
559
 
538
560
  case WorkletSequencerReturnMessageType.songChange:
539
- /**
540
- * messageData is expected to be {MIDIData}
541
- * @type {MIDIData}
542
- */
543
- let songChangeData = messageData[0];
544
- this.songIndex = messageData[1];
561
+ this.songIndex = messageData[0];
562
+ const songChangeData = this.songListData[this.songIndex];
545
563
  this.midiData = songChangeData;
546
564
  this.hasDummyData = false;
547
565
  this.absoluteStartTime = 0;
548
566
  this.duration = this.midiData.duration;
549
567
  this._callEvents(this.onSongChange, songChangeData);
550
568
  // if is auto played, unpause
551
- if (messageData[2] === true)
569
+ if (messageData[1] === true)
552
570
  {
553
571
  this.unpause();
554
572
  }
@@ -626,6 +644,10 @@ export class Sequencer
626
644
  }
627
645
  break;
628
646
 
647
+ case WorkletSequencerReturnMessageType.songListChange:
648
+ this.songListData = messageData;
649
+ break;
650
+
629
651
  default:
630
652
  break;
631
653
  }
@@ -61,7 +61,7 @@ export function processMessage(messageType, messageData)
61
61
  break;
62
62
 
63
63
  case WorkletSequencerMessageType.changeSong:
64
- switch (messageData)
64
+ switch (messageData[0])
65
65
  {
66
66
  case SongChangeType.forwards:
67
67
  this.nextSong();
@@ -81,6 +81,12 @@ export function processMessage(messageType, messageData)
81
81
  this.shuffleSongIndexes();
82
82
  this.songIndex = 0;
83
83
  this.loadCurrentSong();
84
+ break;
85
+
86
+ case SongChangeType.index:
87
+ this.songIndex = messageData[1];
88
+ this.loadCurrentSong();
89
+ break;
84
90
  }
85
91
  break;
86
92
 
@@ -1,8 +1,9 @@
1
1
  export const SongChangeType = {
2
- backwards: 0,
3
- forwards: 1,
4
- shuffleOn: 2,
5
- shuffleOff: 3
2
+ backwards: 0, // no additional data
3
+ forwards: 1, // no additional data
4
+ shuffleOn: 2, // no additional data
5
+ shuffleOff: 3, // no additional data
6
+ index: 4 // songIndex<number>
6
7
  };
7
8
 
8
9
  /**
@@ -14,8 +15,8 @@ export const SongChangeType = {
14
15
  * @property {number} setTime - 4 -> time<number>
15
16
  * @property {number} changeMIDIMessageSending - 5 -> sendMIDIMessages<boolean>
16
17
  * @property {number} setPlaybackRate - 6 -> playbackRate<number>
17
- * @property {number} setLoop - 7 -> [loop<boolean>, count<number]
18
- * @property {number} changeSong - 8 -> changeType<number> 0 - back, 1 - forward, 2 - shuffle ON, 3 - shuffle OFF
18
+ * @property {number} setLoop - 7 -> [loop<boolean>, count<number>]
19
+ * @property {number} changeSong - 8 -> [changeType<SongChangeType>, data<number>]
19
20
  * @property {number} getMIDI - 9 -> (no data)
20
21
  * @property {number} setSkipToFirstNote -10 -> skipToFirstNoteOn<boolean>
21
22
  * @property {number} setPreservePlaybackState -11 -> preservePlaybackState<boolean>
@@ -41,12 +42,13 @@ export const WorkletSequencerMessageType = {
41
42
  */
42
43
  export const WorkletSequencerReturnMessageType = {
43
44
  midiEvent: 0, // [...midiEventBytes<number>]
44
- songChange: 1, // [midiData<MIDIData>, songIndex<number>, isAutoPlayed<boolean>]
45
+ songChange: 1, // [songIndex<number>, isAutoPlayed<boolean>]
45
46
  textEvent: 2, // [messageData<number[]>, statusByte<number>, lyricsIndex<number>]
46
47
  timeChange: 3, // newAbsoluteTime<number>
47
48
  pause: 4, // no data
48
49
  getMIDI: 5, // midiData<MIDI>
49
50
  midiError: 6, // errorMSG<string>
50
51
  metaEvent: 7, // [messageType<number>, messageData<Uint8Array>, trackNum<number>]
51
- loopCountChange: 8 // newLoopCount<number>
52
+ loopCountChange: 8, // newLoopCount<number>
53
+ songListChange: 9 // songListData<MIDIData[]>
52
54
  };
@@ -127,7 +127,7 @@ export function loadNewSequence(parsedMidi, autoPlay = true)
127
127
  this.firstNoteTime = this.midiData.MIDIticksToSeconds(this.midiData.firstNoteOn);
128
128
  SpessaSynthInfo(`%cTotal song time: ${formatTime(Math.ceil(this.duration)).time}`, consoleColors.recognized);
129
129
 
130
- this.post(WorkletSequencerReturnMessageType.songChange, [new MIDIData(this.midiData), this.songIndex, autoPlay]);
130
+ this.post(WorkletSequencerReturnMessageType.songChange, [this.songIndex, autoPlay]);
131
131
 
132
132
  if (this.duration <= 1)
133
133
  {
@@ -190,6 +190,8 @@ export function loadNewSongList(midiBuffers, autoPlay = true)
190
190
  this.loop = false;
191
191
  }
192
192
  this.shuffleSongIndexes();
193
+ const midiDatas = this.songs.map(s => new MIDIData(s));
194
+ this.post(WorkletSequencerReturnMessageType.songListChange, midiDatas);
193
195
  this.loadCurrentSong(autoPlay);
194
196
  }
195
197
 
@@ -20,8 +20,9 @@ export const DLSSources = {
20
20
  volume: 0x87,
21
21
  pan: 0x8a,
22
22
  expression: 0x8b,
23
- chorus: 0xdb,
24
- reverb: 0xdd,
23
+ // note: these are flipped unintentionally in DLS2 table 9. Argh!
24
+ chorus: 0xdd,
25
+ reverb: 0xdb,
25
26
 
26
27
  pitchWheelRange: 0x100,
27
28
  fineTune: 0x101,
@@ -155,6 +155,9 @@ export class Synthetizer
155
155
  return new AudioWorkletNode(ctx, name, opts);
156
156
  };
157
157
  }
158
+ /**
159
+ * @type {AudioWorkletNode}
160
+ */
158
161
  this.worklet = workletConstructor(this.context, WORKLET_PROCESSOR_NAME, {
159
162
  outputChannelCount: processorChannelCount,
160
163
  numberOfOutputs: processorOutputsCount,
@@ -526,6 +529,24 @@ export class Synthetizer
526
529
  }
527
530
  }
528
531
 
532
+ /**
533
+ * Disconnects the individual audio outputs to the given audio nodes. In the app, it's used by the renderer.
534
+ * @param audioNodes {AudioNode[]}
535
+ */
536
+ disconnectIndividualOutputs(audioNodes)
537
+ {
538
+ if (audioNodes.length !== this._outputsAmount)
539
+ {
540
+ throw new Error(`input nodes amount differs from the system's outputs amount!
541
+ Expected ${this._outputsAmount} got ${audioNodes.length}`);
542
+ }
543
+ for (let outputNumber = 0; outputNumber < this._outputsAmount; outputNumber++)
544
+ {
545
+ // + 2 because chorus and reverb come first!
546
+ this.worklet.disconnect(audioNodes[outputNumber], outputNumber + 2);
547
+ }
548
+ }
549
+
529
550
  /*
530
551
  * Disables the GS NRPN parameters like vibrato or drum key tuning.
531
552
  */