spessasynth_core 4.0.12 → 4.0.14

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.js CHANGED
@@ -3250,8 +3250,16 @@ var BasicMIDI2 = class _BasicMIDI {
3250
3250
  parseInternal() {
3251
3251
  SpessaSynthGroup("%cInterpreting MIDI events...", consoleColors.info);
3252
3252
  let karaokeHasTitle = false;
3253
- this.keyRange = { max: 0, min: 127 };
3253
+ this.tempoChanges = [{ ticks: 0, tempo: 120 }];
3254
3254
  this.extraMetadata = [];
3255
+ this.lyrics = [];
3256
+ this.firstNoteOn = 0;
3257
+ this.keyRange = { max: 0, min: 127 };
3258
+ this.lastVoiceEventTick = 0;
3259
+ this.portChannelOffsetMap = [0];
3260
+ this.loop = { start: 0, end: 0 };
3261
+ this.isKaraokeFile = false;
3262
+ this.isMultiPort = false;
3255
3263
  let nameDetected = false;
3256
3264
  if (typeof this.rmidiInfo.name !== "undefined") {
3257
3265
  nameDetected = true;
@@ -3272,11 +3280,17 @@ var BasicMIDI2 = class _BasicMIDI {
3272
3280
  // Cc change: loop points
3273
3281
  case midiMessageTypes.controllerChange:
3274
3282
  switch (e.data[0]) {
3283
+ // Touhou
3275
3284
  case 2:
3285
+ // RPG Maker
3286
+ case 111:
3287
+ // EMIDI/XMI
3276
3288
  case 116:
3277
3289
  loopStart = e.ticks;
3278
3290
  break;
3291
+ // Touhou
3279
3292
  case 4:
3293
+ // EMIDI/XMI
3280
3294
  case 117:
3281
3295
  if (loopEnd === null) {
3282
3296
  loopEnd = e.ticks;
@@ -3417,14 +3431,9 @@ var BasicMIDI2 = class _BasicMIDI {
3417
3431
  consoleColors.recognized,
3418
3432
  consoleColors.info
3419
3433
  );
3420
- if (loopStart !== null && loopEnd === null) {
3421
- loopStart = this.firstNoteOn;
3434
+ loopStart ??= this.firstNoteOn;
3435
+ if (loopEnd === null || loopEnd === 0) {
3422
3436
  loopEnd = this.lastVoiceEventTick;
3423
- } else {
3424
- loopStart ??= this.firstNoteOn;
3425
- if (loopEnd === null || loopEnd === 0) {
3426
- loopEnd = this.lastVoiceEventTick;
3427
- }
3428
3437
  }
3429
3438
  this.loop = { start: loopStart, end: loopEnd };
3430
3439
  SpessaSynthInfo(
@@ -3524,9 +3533,6 @@ var BasicMIDI2 = class _BasicMIDI {
3524
3533
  );
3525
3534
  }
3526
3535
  this.duration = this.midiTicksToSeconds(this.lastVoiceEventTick);
3527
- if (this.duration === 0) {
3528
- throw new Error("The MIDI file no duration.");
3529
- }
3530
3536
  if (this.binaryName && this.binaryName.length < 1) {
3531
3537
  this.binaryName = void 0;
3532
3538
  }
@@ -3932,6 +3938,11 @@ function loadNewSequenceInternal(parsedMidi) {
3932
3938
  if (!parsedMidi.tracks) {
3933
3939
  throw new Error("This MIDI has no tracks!");
3934
3940
  }
3941
+ if (parsedMidi.duration === 0) {
3942
+ SpessaSynthWarn("This MIDI file has a duration of exactly 0 seconds.");
3943
+ this.pausedTime = 0;
3944
+ return;
3945
+ }
3935
3946
  this.oneTickToSeconds = 60 / (120 * parsedMidi.timeDivision);
3936
3947
  this._midiData = parsedMidi;
3937
3948
  this.synth.clearEmbeddedBank();
@@ -5091,9 +5102,9 @@ var SpessaSynthSequencer = class {
5091
5102
  * @param value the playback rate to set.
5092
5103
  */
5093
5104
  set playbackRate(value) {
5094
- const time = this.currentTime;
5105
+ const t = this.currentTime;
5095
5106
  this._playbackRate = value;
5096
- this.currentTime = time;
5107
+ this.recalculateStartTime(t);
5097
5108
  }
5098
5109
  /**
5099
5110
  * The current time of the sequencer.
@@ -5129,11 +5140,6 @@ var SpessaSynthSequencer = class {
5129
5140
  } else {
5130
5141
  this.playingNotes = [];
5131
5142
  this.callEvent("timeChange", { newTime: time });
5132
- if (this._midiData.duration === 0) {
5133
- SpessaSynthWarn("No duration!");
5134
- this.callEvent("pause", { isFinished: true });
5135
- return;
5136
- }
5137
5143
  this.setTimeTo(time);
5138
5144
  this.recalculateStartTime(time);
5139
5145
  }
@@ -5150,7 +5156,10 @@ var SpessaSynthSequencer = class {
5150
5156
  */
5151
5157
  play() {
5152
5158
  if (!this._midiData) {
5153
- throw new Error("No songs loaded in the sequencer!");
5159
+ SpessaSynthWarn(
5160
+ "No songs loaded in the sequencer. Ignoring the play call."
5161
+ );
5162
+ return;
5154
5163
  }
5155
5164
  if (this.currentTime >= this._midiData.duration) {
5156
5165
  this.currentTime = 0;