spessasynth_core 4.3.3 → 4.3.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/dist/index.d.ts CHANGED
@@ -956,11 +956,17 @@ declare class BasicSample {
956
956
  */
957
957
  sampleType: SampleType;
958
958
  /**
959
- * Relative to the start of the sample in sample points.
959
+ * The sample's loop start index, inclusive.
960
+ * In sample data points, relative to the start of the sample.
961
+ *
962
+ * Minimum allowed value is 0.
960
963
  */
961
964
  loopStart: number;
962
965
  /**
963
- * Relative to the start of the sample in sample points.
966
+ * The sample's loop end index, exclusive.
967
+ * In sample data points, relative to the start of the sample.
968
+ *
969
+ * Maximum allowed value is the sample data length.
964
970
  */
965
971
  loopEnd: number;
966
972
  /**
@@ -981,14 +987,14 @@ declare class BasicSample {
981
987
  */
982
988
  protected audioData?: Float32Array;
983
989
  /**
984
- * The basic representation of a sample
985
- * @param sampleName The sample's name
986
- * @param sampleRate The sample's rate in Hz
987
- * @param originalKey The sample's pitch as a MIDI note number
988
- * @param pitchCorrection The sample's pitch correction in cents
989
- * @param sampleType The sample's type, an enum that can indicate SF3
990
- * @param loopStart The sample's loop start relative to the sample start in sample points
991
- * @param loopEnd The sample's loop end relative to the sample start in sample points
990
+ * The basic representation of a sample.
991
+ * @param sampleName The sample's name.
992
+ * @param sampleRate The sample's rate in Hz.
993
+ * @param originalKey The sample's pitch as a MIDI note number.
994
+ * @param pitchCorrection The sample's pitch correction in cents.
995
+ * @param sampleType The sample's type, an enum that can indicate SF3.
996
+ * @param loopStart The sample's loop start relative to the sample start in sample points.
997
+ * @param loopEnd The sample's loop end relative to the sample start in sample points. Inclusive.
992
998
  */
993
999
  constructor(sampleName: string, sampleRate: number, originalKey: number, pitchCorrection: number, sampleType: SampleType, loopStart: number, loopEnd: number);
994
1000
  /**
package/dist/index.js CHANGED
@@ -2583,16 +2583,15 @@ function getNoteTimesInternal(midi, minDrumLength = 0) {
2583
2583
  let i = 0;
2584
2584
  let unfinished = 0;
2585
2585
  const unfinishedNotes = [];
2586
- for (let i = 0; i < 16; i++) unfinishedNotes.push([]);
2586
+ for (let i = 0; i < 16; i++) unfinishedNotes.push(/* @__PURE__ */ new Map());
2587
2587
  const noteOff = (midiNote, channel) => {
2588
- const noteIndex = unfinishedNotes[channel].findIndex((n) => n.midiNote === midiNote);
2589
- const note = unfinishedNotes[channel][noteIndex];
2590
- if (note) {
2591
- const time = elapsedTime - note.start;
2592
- note.length = time;
2593
- if (channel === 9) note.length = Math.max(time, minDrumLength);
2594
- unfinishedNotes[channel].splice(noteIndex, 1);
2595
- }
2588
+ const ch = unfinishedNotes[channel];
2589
+ const noteIndex = ch.get(midiNote);
2590
+ if (noteIndex === void 0) return;
2591
+ const note = noteTimes[channel][noteIndex];
2592
+ const time = elapsedTime - note.start;
2593
+ note.length = channel === 9 ? Math.max(time, minDrumLength) : time;
2594
+ ch.delete(midiNote);
2596
2595
  unfinished--;
2597
2596
  };
2598
2597
  const { timeline, tracks } = midi;
@@ -2602,27 +2601,30 @@ function getNoteTimesInternal(midi, minDrumLength = 0) {
2602
2601
  const status = event.statusByte >> 4;
2603
2602
  const channel = event.statusByte & 15;
2604
2603
  if (status === 8) noteOff(event.data[0], channel);
2605
- else if (status === 9) if (event.data[1] === 0) noteOff(event.data[0], channel);
2606
- else {
2607
- noteOff(event.data[0], channel);
2608
- const noteTime = {
2609
- midiNote: event.data[0],
2610
- start: elapsedTime,
2611
- length: -1,
2612
- velocity: event.data[1] / 127
2613
- };
2614
- noteTimes[channel].push(noteTime);
2615
- unfinishedNotes[channel].push(noteTime);
2616
- unfinished++;
2617
- }
2618
- else if (event.statusByte === 81) oneTickToSeconds = 60 / (getTempo(event) * midi.timeDivision);
2604
+ else if (status === 9) {
2605
+ const midiNote = event.data[0];
2606
+ const velocity = event.data[1];
2607
+ if (velocity === 0) noteOff(midiNote, channel);
2608
+ else {
2609
+ noteOff(midiNote, channel);
2610
+ const noteTime = {
2611
+ midiNote,
2612
+ start: elapsedTime,
2613
+ length: -1,
2614
+ velocity
2615
+ };
2616
+ const times = noteTimes[channel];
2617
+ times.push(noteTime);
2618
+ unfinishedNotes[channel].set(midiNote, times.length - 1);
2619
+ unfinished++;
2620
+ }
2621
+ } else if (event.statusByte === 81) oneTickToSeconds = 60 / (getTempo(event) * midi.timeDivision);
2619
2622
  if (++i >= timeline.length) break;
2620
2623
  elapsedTime += oneTickToSeconds * (tracks[timeline[i].tr].events[timeline[i].ev].ticks - event.ticks);
2621
2624
  }
2622
- if (unfinished > 0) for (const [channel, channelNotes] of unfinishedNotes.entries()) for (const note of channelNotes) {
2623
- const time = elapsedTime - note.start;
2624
- note.length = time;
2625
- if (channel === 9) note.length = Math.max(time, minDrumLength);
2625
+ if (unfinished > 0) for (let channel = 0; channel < unfinishedNotes.length; channel++) for (const noteIndex of unfinishedNotes[channel].values()) {
2626
+ const note = noteTimes[channel][noteIndex];
2627
+ note.length = elapsedTime - note.start;
2626
2628
  }
2627
2629
  return noteTimes;
2628
2630
  }
@@ -4488,20 +4490,31 @@ function processEventInternal(event, trackIndex) {
4488
4490
  channel += offset;
4489
4491
  switch (status) {
4490
4492
  case MIDIMessageTypes.noteOn: {
4493
+ let playingNotes = this.playingNotes[channel];
4494
+ if (!playingNotes) {
4495
+ while (this.playingNotes.length <= channel) this.playingNotes.push(/* @__PURE__ */ new Map());
4496
+ playingNotes = this.playingNotes[channel];
4497
+ }
4491
4498
  const velocity = event.data[1];
4492
4499
  if (velocity > 0) {
4493
4500
  this.synth.noteOn(channel, event.data[0], velocity);
4494
- this.playingNotes[channel].set(event.data[0], velocity);
4501
+ playingNotes.set(event.data[0], velocity);
4495
4502
  } else {
4496
4503
  this.synth.noteOff(channel, event.data[0]);
4497
- this.playingNotes[channel].delete(event.data[0]);
4504
+ playingNotes.delete(event.data[0]);
4498
4505
  }
4499
4506
  break;
4500
4507
  }
4501
- case MIDIMessageTypes.noteOff:
4508
+ case MIDIMessageTypes.noteOff: {
4509
+ let playingNotes = this.playingNotes[channel];
4510
+ if (!playingNotes) {
4511
+ while (this.playingNotes.length <= channel) this.playingNotes.push(/* @__PURE__ */ new Map());
4512
+ playingNotes = this.playingNotes[channel];
4513
+ }
4502
4514
  this.synth.noteOff(channel, event.data[0]);
4503
- this.playingNotes[channel].delete(event.data[0]);
4515
+ playingNotes.delete(event.data[0]);
4504
4516
  break;
4517
+ }
4505
4518
  case MIDIMessageTypes.pitchWheel:
4506
4519
  this.synth.pitchWheel(channel, event.data[1] << 7 | event.data[0]);
4507
4520
  break;
@@ -5039,7 +5052,7 @@ var SpessaSynthSequencer = class {
5039
5052
  constructor(spessasynthProcessor) {
5040
5053
  this.synth = spessasynthProcessor;
5041
5054
  this.absoluteStartTime = this.synth.currentTime;
5042
- for (let i = 0; i < 16; i++) this.playingNotes.push(/* @__PURE__ */ new Map());
5055
+ this.playingNotes = this.synth.midiChannels.map(() => /* @__PURE__ */ new Map());
5043
5056
  }
5044
5057
  _midiData;
5045
5058
  /**
@@ -6004,8 +6017,8 @@ function applySnapshot$1(snapshot) {
6004
6017
  this.systemExclusive(MIDIUtils.gsData(64, 3, 0, [is.type >> 8, is.type & 127]));
6005
6018
  for (let i = 0; i < is.params.length; i++) if (is.params[i] !== 255) this.systemExclusive(MIDIUtils.gsData(64, 3, 3 + i, [is.params[i]]));
6006
6019
  for (let channel = 0; channel < is.channels.length; channel++) this.systemExclusive(MIDIUtils.gsData(64, 64 | MIDIUtils.channelToSyx(channel), 34, [is.channels[channel] ? 1 : 0]));
6007
- for (const [parameter, value] of Object.entries(this.midiParameters)) this.setMIDIParameter(parameter, value);
6008
- for (const [parameter, value] of Object.entries(this.systemParameters)) this.setSystemParameter(parameter, value);
6020
+ for (const [parameter, value] of Object.entries(snapshot.midiParameters)) this.setMIDIParameter(parameter, value);
6021
+ for (const [parameter, value] of Object.entries(snapshot.systemParameters)) this.setSystemParameter(parameter, value);
6009
6022
  }
6010
6023
  function getSynthesizerSnapshot() {
6011
6024
  return {
@@ -7961,11 +7974,17 @@ var BasicSample = class {
7961
7974
  */
7962
7975
  sampleType;
7963
7976
  /**
7964
- * Relative to the start of the sample in sample points.
7977
+ * The sample's loop start index, inclusive.
7978
+ * In sample data points, relative to the start of the sample.
7979
+ *
7980
+ * Minimum allowed value is 0.
7965
7981
  */
7966
7982
  loopStart;
7967
7983
  /**
7968
- * Relative to the start of the sample in sample points.
7984
+ * The sample's loop end index, exclusive.
7985
+ * In sample data points, relative to the start of the sample.
7986
+ *
7987
+ * Maximum allowed value is the sample data length.
7969
7988
  */
7970
7989
  loopEnd;
7971
7990
  /**
@@ -7986,14 +8005,14 @@ var BasicSample = class {
7986
8005
  */
7987
8006
  audioData;
7988
8007
  /**
7989
- * The basic representation of a sample
7990
- * @param sampleName The sample's name
7991
- * @param sampleRate The sample's rate in Hz
7992
- * @param originalKey The sample's pitch as a MIDI note number
7993
- * @param pitchCorrection The sample's pitch correction in cents
7994
- * @param sampleType The sample's type, an enum that can indicate SF3
7995
- * @param loopStart The sample's loop start relative to the sample start in sample points
7996
- * @param loopEnd The sample's loop end relative to the sample start in sample points
8008
+ * The basic representation of a sample.
8009
+ * @param sampleName The sample's name.
8010
+ * @param sampleRate The sample's rate in Hz.
8011
+ * @param originalKey The sample's pitch as a MIDI note number.
8012
+ * @param pitchCorrection The sample's pitch correction in cents.
8013
+ * @param sampleType The sample's type, an enum that can indicate SF3.
8014
+ * @param loopStart The sample's loop start relative to the sample start in sample points.
8015
+ * @param loopEnd The sample's loop end relative to the sample start in sample points. Inclusive.
7997
8016
  */
7998
8017
  constructor(sampleName, sampleRate, originalKey, pitchCorrection, sampleType, loopStart, loopEnd) {
7999
8018
  this.name = sampleName;
@@ -13051,8 +13070,8 @@ function applySnapshot(snapshot) {
13051
13070
  this.setSystemParameter("presetLock", false);
13052
13071
  if (snapshot.patch) this.setPatch(snapshot.patch);
13053
13072
  this.lockedSystem = snapshot.lockedSystem;
13054
- for (const [parameter, value] of Object.entries(this._midiParameters)) this.setMIDIParameter(parameter, value);
13055
- for (const [parameter, value] of Object.entries(this._systemParameters)) this.setSystemParameter(parameter, value);
13073
+ for (const [parameter, value] of Object.entries(snapshot.midiParameters)) this.setMIDIParameter(parameter, value);
13074
+ for (const [parameter, value] of Object.entries(snapshot.systemParameters)) this.setSystemParameter(parameter, value);
13056
13075
  }
13057
13076
  //#endregion
13058
13077
  //#region src/synthesizer/audio_engine/channel/parameters/midi.ts
@@ -20459,7 +20478,6 @@ var SpessaSynthProcessor = class {
20459
20478
  applySnapshot(snapshot) {
20460
20479
  this.savedSnapshot = snapshot;
20461
20480
  applySnapshot$1.call(this.synthCore, snapshot);
20462
- this.reset();
20463
20481
  }
20464
20482
  /**
20465
20483
  * Gets a synthesizer snapshot from this processor instance.