spessasynth_core 4.0.10 → 4.0.11
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 +3 -3
- package/dist/index.js +43 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3084,7 +3084,7 @@ declare class BasicMIDI {
|
|
|
3084
3084
|
*/
|
|
3085
3085
|
tracks: MIDITrack[];
|
|
3086
3086
|
/**
|
|
3087
|
-
* The time division of the sequence, representing the number of ticks per beat.
|
|
3087
|
+
* The time division of the sequence, representing the number of MIDI ticks per beat.
|
|
3088
3088
|
*/
|
|
3089
3089
|
timeDivision: number;
|
|
3090
3090
|
/**
|
|
@@ -3093,7 +3093,7 @@ declare class BasicMIDI {
|
|
|
3093
3093
|
duration: number;
|
|
3094
3094
|
/**
|
|
3095
3095
|
* The tempo changes in the sequence, ordered from the last change to the first.
|
|
3096
|
-
* Each change is represented by an object with a tick position and a tempo value in beats per minute.
|
|
3096
|
+
* Each change is represented by an object with a MIDI tick position and a tempo value in beats per minute.
|
|
3097
3097
|
*/
|
|
3098
3098
|
tempoChanges: TempoChange[];
|
|
3099
3099
|
/**
|
|
@@ -3462,7 +3462,7 @@ interface RMIDInfoData {
|
|
|
3462
3462
|
}
|
|
3463
3463
|
interface TempoChange {
|
|
3464
3464
|
/**
|
|
3465
|
-
* MIDI ticks of the change.
|
|
3465
|
+
* MIDI ticks of the change, absolute value from the start of the MIDI file.
|
|
3466
3466
|
*/
|
|
3467
3467
|
ticks: number;
|
|
3468
3468
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2721,13 +2721,6 @@ function loadMIDIFromArrayBufferInternal(outputMIDI, arrayBuffer, fileName) {
|
|
|
2721
2721
|
SpessaSynthInfo(`%cAll tracks parsed correctly!`, consoleColors.recognized);
|
|
2722
2722
|
outputMIDI.flush(false);
|
|
2723
2723
|
SpessaSynthGroupEnd();
|
|
2724
|
-
SpessaSynthInfo(
|
|
2725
|
-
`%cMIDI file parsed. Total tick time: %c${outputMIDI.lastVoiceEventTick}%c, total seconds time: %c${outputMIDI.duration}`,
|
|
2726
|
-
consoleColors.info,
|
|
2727
|
-
consoleColors.recognized,
|
|
2728
|
-
consoleColors.info,
|
|
2729
|
-
consoleColors.recognized
|
|
2730
|
-
);
|
|
2731
2724
|
}
|
|
2732
2725
|
|
|
2733
2726
|
// src/utils/load_date.ts
|
|
@@ -2839,7 +2832,7 @@ var BasicMIDI2 = class _BasicMIDI {
|
|
|
2839
2832
|
*/
|
|
2840
2833
|
tracks = [];
|
|
2841
2834
|
/**
|
|
2842
|
-
* The time division of the sequence, representing the number of ticks per beat.
|
|
2835
|
+
* The time division of the sequence, representing the number of MIDI ticks per beat.
|
|
2843
2836
|
*/
|
|
2844
2837
|
timeDivision = 0;
|
|
2845
2838
|
/**
|
|
@@ -2848,7 +2841,7 @@ var BasicMIDI2 = class _BasicMIDI {
|
|
|
2848
2841
|
duration = 0;
|
|
2849
2842
|
/**
|
|
2850
2843
|
* The tempo changes in the sequence, ordered from the last change to the first.
|
|
2851
|
-
* Each change is represented by an object with a tick position and a tempo value in beats per minute.
|
|
2844
|
+
* Each change is represented by an object with a MIDI tick position and a tempo value in beats per minute.
|
|
2852
2845
|
*/
|
|
2853
2846
|
tempoChanges = [{ ticks: 0, tempo: 120 }];
|
|
2854
2847
|
/**
|
|
@@ -2985,15 +2978,24 @@ var BasicMIDI2 = class _BasicMIDI {
|
|
|
2985
2978
|
* @returns The time in seconds.
|
|
2986
2979
|
*/
|
|
2987
2980
|
midiTicksToSeconds(ticks) {
|
|
2981
|
+
ticks = Math.max(ticks, 0);
|
|
2982
|
+
if (this.tempoChanges.length < 1) {
|
|
2983
|
+
throw new Error(
|
|
2984
|
+
"There are no tempo changes in the sequence. At least one is needed."
|
|
2985
|
+
);
|
|
2986
|
+
}
|
|
2987
|
+
if (this.tempoChanges[this.tempoChanges.length - 1].ticks !== 0) {
|
|
2988
|
+
throw new Error(
|
|
2989
|
+
`The last tempo change is not at 0 ticks. Got ${this.tempoChanges[this.tempoChanges.length - 1].ticks} ticks.`
|
|
2990
|
+
);
|
|
2991
|
+
}
|
|
2992
|
+
let tempoIndex = this.tempoChanges.findIndex((v) => v.ticks <= ticks);
|
|
2988
2993
|
let totalSeconds = 0;
|
|
2989
|
-
while (
|
|
2990
|
-
const tempo = this.tempoChanges
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
const timeSinceLastTempo = ticks - tempo.ticks;
|
|
2995
|
-
totalSeconds += timeSinceLastTempo * 60 / (tempo.tempo * this.timeDivision);
|
|
2996
|
-
ticks -= timeSinceLastTempo;
|
|
2994
|
+
while (tempoIndex < this.tempoChanges.length) {
|
|
2995
|
+
const tempo = this.tempoChanges[tempoIndex++];
|
|
2996
|
+
const ticksSinceLastTempo = ticks - tempo.ticks;
|
|
2997
|
+
totalSeconds += ticksSinceLastTempo * 60 / (tempo.tempo * this.timeDivision);
|
|
2998
|
+
ticks = tempo.ticks;
|
|
2997
2999
|
}
|
|
2998
3000
|
return totalSeconds;
|
|
2999
3001
|
}
|
|
@@ -3525,10 +3527,19 @@ var BasicMIDI2 = class _BasicMIDI {
|
|
|
3525
3527
|
);
|
|
3526
3528
|
}
|
|
3527
3529
|
this.duration = this.midiTicksToSeconds(this.lastVoiceEventTick);
|
|
3530
|
+
if (this.duration === 0) {
|
|
3531
|
+
throw new Error("The MIDI file no duration.");
|
|
3532
|
+
}
|
|
3528
3533
|
if (this.binaryName && this.binaryName.length < 1) {
|
|
3529
3534
|
this.binaryName = void 0;
|
|
3530
3535
|
}
|
|
3531
|
-
SpessaSynthInfo(
|
|
3536
|
+
SpessaSynthInfo(
|
|
3537
|
+
`%cMIDI file parsed. Total tick time: %c${this.lastVoiceEventTick}%c, total seconds time: %c${formatTime(Math.ceil(this.duration)).time}`,
|
|
3538
|
+
consoleColors.info,
|
|
3539
|
+
consoleColors.recognized,
|
|
3540
|
+
consoleColors.info,
|
|
3541
|
+
consoleColors.recognized
|
|
3542
|
+
);
|
|
3532
3543
|
SpessaSynthGroupEnd();
|
|
3533
3544
|
}
|
|
3534
3545
|
};
|
|
@@ -4727,6 +4738,8 @@ function setTimeToInternal(time, ticks = void 0) {
|
|
|
4727
4738
|
Array.from(defaultControllerArray)
|
|
4728
4739
|
);
|
|
4729
4740
|
}
|
|
4741
|
+
let savedTempo = void 0;
|
|
4742
|
+
let savedTempoTrack = 0;
|
|
4730
4743
|
function resetAllControllers(chan) {
|
|
4731
4744
|
pitchWheels[chan] = 8192;
|
|
4732
4745
|
if (savedControllers?.[chan] === void 0) {
|
|
@@ -4806,6 +4819,12 @@ function setTimeToInternal(time, ticks = void 0) {
|
|
|
4806
4819
|
}
|
|
4807
4820
|
break;
|
|
4808
4821
|
}
|
|
4822
|
+
case midiMessageTypes.setTempo:
|
|
4823
|
+
const tempoBPM = 6e7 / readBigEndian(event.data, 3);
|
|
4824
|
+
this.oneTickToSeconds = 60 / (tempoBPM * this._midiData.timeDivision);
|
|
4825
|
+
savedTempo = event;
|
|
4826
|
+
savedTempoTrack = trackIndex;
|
|
4827
|
+
break;
|
|
4809
4828
|
default:
|
|
4810
4829
|
this.processEvent(event, trackIndex);
|
|
4811
4830
|
break;
|
|
@@ -4886,6 +4905,12 @@ function setTimeToInternal(time, ticks = void 0) {
|
|
|
4886
4905
|
}
|
|
4887
4906
|
}
|
|
4888
4907
|
}
|
|
4908
|
+
if (savedTempo) {
|
|
4909
|
+
this.callEvent("metaEvent", {
|
|
4910
|
+
event: savedTempo,
|
|
4911
|
+
trackIndex: savedTempoTrack
|
|
4912
|
+
});
|
|
4913
|
+
}
|
|
4889
4914
|
if (this.paused) {
|
|
4890
4915
|
this.pausedTime = this.playedTime;
|
|
4891
4916
|
}
|