@marmooo/midy 0.4.1 → 0.4.2
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 +12 -0
- package/esm/midy-GM1.d.ts +8 -7
- package/esm/midy-GM1.d.ts.map +1 -1
- package/esm/midy-GM1.js +102 -58
- package/esm/midy-GM2.d.ts +8 -7
- package/esm/midy-GM2.d.ts.map +1 -1
- package/esm/midy-GM2.js +120 -68
- package/esm/midy-GMLite.d.ts +7 -6
- package/esm/midy-GMLite.d.ts.map +1 -1
- package/esm/midy-GMLite.js +98 -56
- package/esm/midy.d.ts +10 -7
- package/esm/midy.d.ts.map +1 -1
- package/esm/midy.js +162 -80
- package/package.json +1 -1
- package/script/midy-GM1.d.ts +8 -7
- package/script/midy-GM1.d.ts.map +1 -1
- package/script/midy-GM1.js +102 -58
- package/script/midy-GM2.d.ts +8 -7
- package/script/midy-GM2.d.ts.map +1 -1
- package/script/midy-GM2.js +120 -68
- package/script/midy-GMLite.d.ts +7 -6
- package/script/midy-GMLite.d.ts.map +1 -1
- package/script/midy-GMLite.js +98 -56
- package/script/midy.d.ts +10 -7
- package/script/midy.d.ts.map +1 -1
- package/script/midy.js +162 -80
package/script/midy-GM2.js
CHANGED
|
@@ -29,12 +29,6 @@ class Note {
|
|
|
29
29
|
writable: true,
|
|
30
30
|
value: false
|
|
31
31
|
});
|
|
32
|
-
Object.defineProperty(this, "pending", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: true
|
|
37
|
-
});
|
|
38
32
|
Object.defineProperty(this, "bufferSource", {
|
|
39
33
|
enumerable: true,
|
|
40
34
|
configurable: true,
|
|
@@ -110,6 +104,9 @@ class Note {
|
|
|
110
104
|
this.noteNumber = noteNumber;
|
|
111
105
|
this.velocity = velocity;
|
|
112
106
|
this.startTime = startTime;
|
|
107
|
+
this.ready = new Promise((resolve) => {
|
|
108
|
+
this.resolveReady = resolve;
|
|
109
|
+
});
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
const drumExclusiveClassesByKit = new Array(57);
|
|
@@ -231,8 +228,9 @@ const pitchEnvelopeKeys = [
|
|
|
231
228
|
"playbackRate",
|
|
232
229
|
];
|
|
233
230
|
const pitchEnvelopeKeySet = new Set(pitchEnvelopeKeys);
|
|
234
|
-
class MidyGM2 {
|
|
231
|
+
class MidyGM2 extends EventTarget {
|
|
235
232
|
constructor(audioContext) {
|
|
233
|
+
super();
|
|
236
234
|
Object.defineProperty(this, "mode", {
|
|
237
235
|
enumerable: true,
|
|
238
236
|
configurable: true,
|
|
@@ -393,6 +391,12 @@ class MidyGM2 {
|
|
|
393
391
|
writable: true,
|
|
394
392
|
value: false
|
|
395
393
|
});
|
|
394
|
+
Object.defineProperty(this, "loop", {
|
|
395
|
+
enumerable: true,
|
|
396
|
+
configurable: true,
|
|
397
|
+
writable: true,
|
|
398
|
+
value: false
|
|
399
|
+
});
|
|
396
400
|
Object.defineProperty(this, "playPromise", {
|
|
397
401
|
enumerable: true,
|
|
398
402
|
configurable: true,
|
|
@@ -612,7 +616,7 @@ class MidyGM2 {
|
|
|
612
616
|
}
|
|
613
617
|
return bufferSource;
|
|
614
618
|
}
|
|
615
|
-
|
|
619
|
+
scheduleTimelineEvents(scheduleTime, queueIndex) {
|
|
616
620
|
const timeOffset = this.resumeTime - this.startTime;
|
|
617
621
|
const lookAheadCheckTime = scheduleTime + timeOffset + this.lookAhead;
|
|
618
622
|
const schedulingOffset = this.startDelay - timeOffset;
|
|
@@ -624,7 +628,7 @@ class MidyGM2 {
|
|
|
624
628
|
const startTime = event.startTime + schedulingOffset;
|
|
625
629
|
switch (event.type) {
|
|
626
630
|
case "noteOn":
|
|
627
|
-
|
|
631
|
+
this.noteOn(event.channel, event.noteNumber, event.velocity, startTime);
|
|
628
632
|
break;
|
|
629
633
|
case "noteOff": {
|
|
630
634
|
this.noteOff(event.channel, event.noteNumber, event.velocity, startTime, false);
|
|
@@ -668,22 +672,23 @@ class MidyGM2 {
|
|
|
668
672
|
}
|
|
669
673
|
}
|
|
670
674
|
updateStates(queueIndex, nextQueueIndex) {
|
|
675
|
+
const now = this.audioContext.currentTime;
|
|
671
676
|
if (nextQueueIndex < queueIndex)
|
|
672
677
|
queueIndex = 0;
|
|
673
678
|
for (let i = queueIndex; i < nextQueueIndex; i++) {
|
|
674
679
|
const event = this.timeline[i];
|
|
675
680
|
switch (event.type) {
|
|
676
681
|
case "controller":
|
|
677
|
-
this.setControlChange(event.channel, event.controllerType, event.value,
|
|
682
|
+
this.setControlChange(event.channel, event.controllerType, event.value, now - this.resumeTime + event.startTime);
|
|
678
683
|
break;
|
|
679
684
|
case "programChange":
|
|
680
|
-
this.setProgramChange(event.channel, event.programNumber,
|
|
685
|
+
this.setProgramChange(event.channel, event.programNumber, now - this.resumeTime + event.startTime);
|
|
681
686
|
break;
|
|
682
687
|
case "pitchBend":
|
|
683
|
-
this.setPitchBend(event.channel, event.value + 8192,
|
|
688
|
+
this.setPitchBend(event.channel, event.value + 8192, now - this.resumeTime + event.startTime);
|
|
684
689
|
break;
|
|
685
690
|
case "sysEx":
|
|
686
|
-
this.handleSysEx(event.data,
|
|
691
|
+
this.handleSysEx(event.data, now - this.resumeTime + event.startTime);
|
|
687
692
|
}
|
|
688
693
|
}
|
|
689
694
|
}
|
|
@@ -691,58 +696,88 @@ class MidyGM2 {
|
|
|
691
696
|
if (this.audioContext.state === "suspended") {
|
|
692
697
|
await this.audioContext.resume();
|
|
693
698
|
}
|
|
699
|
+
const paused = this.isPaused;
|
|
694
700
|
this.isPlaying = true;
|
|
695
701
|
this.isPaused = false;
|
|
696
702
|
this.startTime = this.audioContext.currentTime;
|
|
703
|
+
if (paused) {
|
|
704
|
+
this.dispatchEvent(new Event("resumed"));
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
this.dispatchEvent(new Event("started"));
|
|
708
|
+
}
|
|
697
709
|
let queueIndex = this.getQueueIndex(this.resumeTime);
|
|
698
|
-
let
|
|
710
|
+
let exitReason;
|
|
699
711
|
this.notePromises = [];
|
|
700
|
-
while (
|
|
712
|
+
while (true) {
|
|
701
713
|
const now = this.audioContext.currentTime;
|
|
702
714
|
if (0 < this.lastActiveSensing &&
|
|
703
715
|
this.activeSensingThreshold < performance.now() - this.lastActiveSensing) {
|
|
704
716
|
await this.stopNotes(0, true, now);
|
|
705
717
|
await this.audioContext.suspend();
|
|
706
|
-
|
|
718
|
+
exitReason = "aborted";
|
|
707
719
|
break;
|
|
708
720
|
}
|
|
721
|
+
if (this.timeline.length <= queueIndex) {
|
|
722
|
+
await this.stopNotes(0, true, now);
|
|
723
|
+
if (this.loop) {
|
|
724
|
+
this.notePromises = [];
|
|
725
|
+
this.resetAllStates();
|
|
726
|
+
this.startTime = this.audioContext.currentTime;
|
|
727
|
+
this.resumeTime = 0;
|
|
728
|
+
queueIndex = 0;
|
|
729
|
+
this.dispatchEvent(new Event("looped"));
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
await this.audioContext.suspend();
|
|
734
|
+
exitReason = "ended";
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
709
738
|
if (this.isPausing) {
|
|
710
739
|
await this.stopNotes(0, true, now);
|
|
711
740
|
await this.audioContext.suspend();
|
|
712
741
|
this.notePromises = [];
|
|
742
|
+
this.isPausing = false;
|
|
743
|
+
exitReason = "paused";
|
|
713
744
|
break;
|
|
714
745
|
}
|
|
715
746
|
else if (this.isStopping) {
|
|
716
747
|
await this.stopNotes(0, true, now);
|
|
717
748
|
await this.audioContext.suspend();
|
|
718
|
-
|
|
749
|
+
this.isStopping = false;
|
|
750
|
+
exitReason = "stopped";
|
|
719
751
|
break;
|
|
720
752
|
}
|
|
721
753
|
else if (this.isSeeking) {
|
|
722
|
-
|
|
754
|
+
this.stopNotes(0, true, now);
|
|
723
755
|
this.startTime = this.audioContext.currentTime;
|
|
724
756
|
const nextQueueIndex = this.getQueueIndex(this.resumeTime);
|
|
725
757
|
this.updateStates(queueIndex, nextQueueIndex);
|
|
726
758
|
queueIndex = nextQueueIndex;
|
|
727
759
|
this.isSeeking = false;
|
|
760
|
+
this.dispatchEvent(new Event("seeked"));
|
|
728
761
|
continue;
|
|
729
762
|
}
|
|
730
|
-
queueIndex =
|
|
763
|
+
queueIndex = this.scheduleTimelineEvents(now, queueIndex);
|
|
731
764
|
const waitTime = now + this.noteCheckInterval;
|
|
732
765
|
await this.scheduleTask(() => { }, waitTime);
|
|
733
766
|
}
|
|
734
|
-
if (
|
|
735
|
-
const now = this.audioContext.currentTime;
|
|
736
|
-
await this.stopNotes(0, true, now);
|
|
737
|
-
await this.audioContext.suspend();
|
|
738
|
-
finished = true;
|
|
739
|
-
}
|
|
740
|
-
if (finished) {
|
|
767
|
+
if (exitReason !== "paused") {
|
|
741
768
|
this.notePromises = [];
|
|
742
769
|
this.resetAllStates();
|
|
743
770
|
this.lastActiveSensing = 0;
|
|
744
771
|
}
|
|
745
772
|
this.isPlaying = false;
|
|
773
|
+
if (exitReason === "paused") {
|
|
774
|
+
this.isPaused = true;
|
|
775
|
+
this.dispatchEvent(new Event("paused"));
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
this.isPaused = false;
|
|
779
|
+
this.dispatchEvent(new Event(exitReason));
|
|
780
|
+
}
|
|
746
781
|
}
|
|
747
782
|
ticksToSecond(ticks, secondsPerBeat) {
|
|
748
783
|
return ticks * secondsPerBeat / this.ticksPerBeat;
|
|
@@ -879,24 +914,20 @@ class MidyGM2 {
|
|
|
879
914
|
return;
|
|
880
915
|
this.isStopping = true;
|
|
881
916
|
await this.playPromise;
|
|
882
|
-
this.isStopping = false;
|
|
883
917
|
}
|
|
884
918
|
async pause() {
|
|
885
919
|
if (!this.isPlaying || this.isPaused)
|
|
886
920
|
return;
|
|
887
921
|
const now = this.audioContext.currentTime;
|
|
888
|
-
this.resumeTime = now
|
|
922
|
+
this.resumeTime = now + this.resumeTime - this.startTime;
|
|
889
923
|
this.isPausing = true;
|
|
890
924
|
await this.playPromise;
|
|
891
|
-
this.isPausing = false;
|
|
892
|
-
this.isPaused = true;
|
|
893
925
|
}
|
|
894
926
|
async resume() {
|
|
895
927
|
if (!this.isPaused)
|
|
896
928
|
return;
|
|
897
929
|
this.playPromise = this.playNotes();
|
|
898
930
|
await this.playPromise;
|
|
899
|
-
this.isPaused = false;
|
|
900
931
|
}
|
|
901
932
|
seekTo(second) {
|
|
902
933
|
this.resumeTime = second;
|
|
@@ -919,19 +950,23 @@ class MidyGM2 {
|
|
|
919
950
|
const now = this.audioContext.currentTime;
|
|
920
951
|
return now + this.resumeTime - this.startTime;
|
|
921
952
|
}
|
|
922
|
-
processScheduledNotes(channel, callback) {
|
|
953
|
+
async processScheduledNotes(channel, callback) {
|
|
923
954
|
const scheduledNotes = channel.scheduledNotes;
|
|
955
|
+
const tasks = [];
|
|
924
956
|
for (let i = channel.scheduleIndex; i < scheduledNotes.length; i++) {
|
|
925
957
|
const note = scheduledNotes[i];
|
|
926
958
|
if (!note)
|
|
927
959
|
continue;
|
|
928
960
|
if (note.ending)
|
|
929
961
|
continue;
|
|
930
|
-
callback(note);
|
|
962
|
+
const task = note.ready.then(() => callback(note));
|
|
963
|
+
tasks.push(task);
|
|
931
964
|
}
|
|
965
|
+
await Promise.all(tasks);
|
|
932
966
|
}
|
|
933
|
-
processActiveNotes(channel, scheduleTime, callback) {
|
|
967
|
+
async processActiveNotes(channel, scheduleTime, callback) {
|
|
934
968
|
const scheduledNotes = channel.scheduledNotes;
|
|
969
|
+
const tasks = [];
|
|
935
970
|
for (let i = channel.scheduleIndex; i < scheduledNotes.length; i++) {
|
|
936
971
|
const note = scheduledNotes[i];
|
|
937
972
|
if (!note)
|
|
@@ -940,8 +975,10 @@ class MidyGM2 {
|
|
|
940
975
|
continue;
|
|
941
976
|
if (scheduleTime < note.startTime)
|
|
942
977
|
break;
|
|
943
|
-
callback(note);
|
|
978
|
+
const task = note.ready.then(() => callback(note));
|
|
979
|
+
tasks.push(task);
|
|
944
980
|
}
|
|
981
|
+
await Promise.all(tasks);
|
|
945
982
|
}
|
|
946
983
|
createConvolutionReverbImpulse(audioContext, decay, preDecay) {
|
|
947
984
|
const sampleRate = audioContext.sampleRate;
|
|
@@ -1506,11 +1543,7 @@ class MidyGM2 {
|
|
|
1506
1543
|
return;
|
|
1507
1544
|
await this.setNoteAudioNode(channel, note, realtime);
|
|
1508
1545
|
this.setNoteRouting(channelNumber, note, startTime);
|
|
1509
|
-
note.
|
|
1510
|
-
const off = note.offEvent;
|
|
1511
|
-
if (off) {
|
|
1512
|
-
this.noteOff(channelNumber, noteNumber, off.velocity, off.startTime);
|
|
1513
|
-
}
|
|
1546
|
+
note.resolveReady();
|
|
1514
1547
|
}
|
|
1515
1548
|
disconnectNote(note) {
|
|
1516
1549
|
note.bufferSource.disconnect();
|
|
@@ -1554,7 +1587,7 @@ class MidyGM2 {
|
|
|
1554
1587
|
}, stopTime);
|
|
1555
1588
|
});
|
|
1556
1589
|
}
|
|
1557
|
-
noteOff(channelNumber, noteNumber,
|
|
1590
|
+
noteOff(channelNumber, noteNumber, _velocity, endTime, force) {
|
|
1558
1591
|
const channel = this.channels[channelNumber];
|
|
1559
1592
|
const state = channel.state;
|
|
1560
1593
|
if (!force) {
|
|
@@ -1573,13 +1606,11 @@ class MidyGM2 {
|
|
|
1573
1606
|
if (index < 0)
|
|
1574
1607
|
return;
|
|
1575
1608
|
const note = channel.scheduledNotes[index];
|
|
1576
|
-
if (note.pending) {
|
|
1577
|
-
note.offEvent = { velocity, startTime: endTime };
|
|
1578
|
-
return;
|
|
1579
|
-
}
|
|
1580
1609
|
note.ending = true;
|
|
1581
1610
|
this.setNoteIndex(channel, index);
|
|
1582
|
-
const promise =
|
|
1611
|
+
const promise = note.ready.then(() => {
|
|
1612
|
+
return this.releaseNote(channel, note, endTime);
|
|
1613
|
+
});
|
|
1583
1614
|
this.notePromises.push(promise);
|
|
1584
1615
|
return promise;
|
|
1585
1616
|
}
|
|
@@ -1690,7 +1721,7 @@ class MidyGM2 {
|
|
|
1690
1721
|
this.processActiveNotes(channel, scheduleTime, (note) => {
|
|
1691
1722
|
this.setEffects(channel, note, table, scheduleTime);
|
|
1692
1723
|
});
|
|
1693
|
-
this.applyVoiceParams(channel, 13);
|
|
1724
|
+
this.applyVoiceParams(channel, 13, scheduleTime);
|
|
1694
1725
|
}
|
|
1695
1726
|
handlePitchBendMessage(channelNumber, lsb, msb, scheduleTime) {
|
|
1696
1727
|
const pitchBend = msb * 128 + lsb;
|
|
@@ -1700,7 +1731,8 @@ class MidyGM2 {
|
|
|
1700
1731
|
const channel = this.channels[channelNumber];
|
|
1701
1732
|
if (channel.isDrum)
|
|
1702
1733
|
return;
|
|
1703
|
-
|
|
1734
|
+
if (!(0 <= scheduleTime))
|
|
1735
|
+
scheduleTime = this.audioContext.currentTime;
|
|
1704
1736
|
const state = channel.state;
|
|
1705
1737
|
const prev = state.pitchWheel * 2 - 1;
|
|
1706
1738
|
const next = (value - 8192) / 8192;
|
|
@@ -1994,7 +2026,8 @@ class MidyGM2 {
|
|
|
1994
2026
|
const channel = this.channels[channelNumber];
|
|
1995
2027
|
if (channel.isDrum)
|
|
1996
2028
|
return;
|
|
1997
|
-
|
|
2029
|
+
if (!(0 <= scheduleTime))
|
|
2030
|
+
scheduleTime = this.audioContext.currentTime;
|
|
1998
2031
|
channel.state.modulationDepthMSB = modulation / 127;
|
|
1999
2032
|
this.updateModulation(channel, scheduleTime);
|
|
2000
2033
|
}
|
|
@@ -2017,7 +2050,8 @@ class MidyGM2 {
|
|
|
2017
2050
|
});
|
|
2018
2051
|
}
|
|
2019
2052
|
setPortamentoTime(channelNumber, portamentoTime, scheduleTime) {
|
|
2020
|
-
|
|
2053
|
+
if (!(0 <= scheduleTime))
|
|
2054
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2021
2055
|
const channel = this.channels[channelNumber];
|
|
2022
2056
|
channel.state.portamentoTimeMSB = portamentoTime / 127;
|
|
2023
2057
|
if (channel.isDrum)
|
|
@@ -2025,7 +2059,8 @@ class MidyGM2 {
|
|
|
2025
2059
|
this.updatePortamento(channel, scheduleTime);
|
|
2026
2060
|
}
|
|
2027
2061
|
setVolume(channelNumber, volume, scheduleTime) {
|
|
2028
|
-
|
|
2062
|
+
if (!(0 <= scheduleTime))
|
|
2063
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2029
2064
|
const channel = this.channels[channelNumber];
|
|
2030
2065
|
channel.state.volumeMSB = volume / 127;
|
|
2031
2066
|
if (channel.isDrum) {
|
|
@@ -2045,7 +2080,8 @@ class MidyGM2 {
|
|
|
2045
2080
|
};
|
|
2046
2081
|
}
|
|
2047
2082
|
setPan(channelNumber, pan, scheduleTime) {
|
|
2048
|
-
|
|
2083
|
+
if (!(0 <= scheduleTime))
|
|
2084
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2049
2085
|
const channel = this.channels[channelNumber];
|
|
2050
2086
|
channel.state.panMSB = pan / 127;
|
|
2051
2087
|
if (channel.isDrum) {
|
|
@@ -2058,7 +2094,8 @@ class MidyGM2 {
|
|
|
2058
2094
|
}
|
|
2059
2095
|
}
|
|
2060
2096
|
setExpression(channelNumber, expression, scheduleTime) {
|
|
2061
|
-
|
|
2097
|
+
if (!(0 <= scheduleTime))
|
|
2098
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2062
2099
|
const channel = this.channels[channelNumber];
|
|
2063
2100
|
channel.state.expressionMSB = expression / 127;
|
|
2064
2101
|
this.updateChannelVolume(channel, scheduleTime);
|
|
@@ -2107,7 +2144,8 @@ class MidyGM2 {
|
|
|
2107
2144
|
const channel = this.channels[channelNumber];
|
|
2108
2145
|
if (channel.isDrum)
|
|
2109
2146
|
return;
|
|
2110
|
-
|
|
2147
|
+
if (!(0 <= scheduleTime))
|
|
2148
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2111
2149
|
channel.state.sustainPedal = value / 127;
|
|
2112
2150
|
if (64 <= value) {
|
|
2113
2151
|
this.processScheduledNotes(channel, (note) => {
|
|
@@ -2125,7 +2163,8 @@ class MidyGM2 {
|
|
|
2125
2163
|
const channel = this.channels[channelNumber];
|
|
2126
2164
|
if (channel.isDrum)
|
|
2127
2165
|
return;
|
|
2128
|
-
|
|
2166
|
+
if (!(0 <= scheduleTime))
|
|
2167
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2129
2168
|
channel.state.portamento = value / 127;
|
|
2130
2169
|
this.updatePortamento(channel, scheduleTime);
|
|
2131
2170
|
}
|
|
@@ -2133,7 +2172,8 @@ class MidyGM2 {
|
|
|
2133
2172
|
const channel = this.channels[channelNumber];
|
|
2134
2173
|
if (channel.isDrum)
|
|
2135
2174
|
return;
|
|
2136
|
-
|
|
2175
|
+
if (!(0 <= scheduleTime))
|
|
2176
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2137
2177
|
channel.state.sostenutoPedal = value / 127;
|
|
2138
2178
|
if (64 <= value) {
|
|
2139
2179
|
const sostenutoNotes = [];
|
|
@@ -2154,7 +2194,8 @@ class MidyGM2 {
|
|
|
2154
2194
|
if (channel.isDrum)
|
|
2155
2195
|
return;
|
|
2156
2196
|
const state = channel.state;
|
|
2157
|
-
|
|
2197
|
+
if (!(0 <= scheduleTime))
|
|
2198
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2158
2199
|
state.softPedal = softPedal / 127;
|
|
2159
2200
|
this.processScheduledNotes(channel, (note) => {
|
|
2160
2201
|
if (this.isPortamento(channel, note)) {
|
|
@@ -2168,7 +2209,8 @@ class MidyGM2 {
|
|
|
2168
2209
|
});
|
|
2169
2210
|
}
|
|
2170
2211
|
setReverbSendLevel(channelNumber, reverbSendLevel, scheduleTime) {
|
|
2171
|
-
|
|
2212
|
+
if (!(0 <= scheduleTime))
|
|
2213
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2172
2214
|
const channel = this.channels[channelNumber];
|
|
2173
2215
|
const state = channel.state;
|
|
2174
2216
|
state.reverbSendLevel = reverbSendLevel / 127;
|
|
@@ -2177,7 +2219,8 @@ class MidyGM2 {
|
|
|
2177
2219
|
});
|
|
2178
2220
|
}
|
|
2179
2221
|
setChorusSendLevel(channelNumber, chorusSendLevel, scheduleTime) {
|
|
2180
|
-
|
|
2222
|
+
if (!(0 <= scheduleTime))
|
|
2223
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2181
2224
|
const channel = this.channels[channelNumber];
|
|
2182
2225
|
const state = channel.state;
|
|
2183
2226
|
state.chorusSendLevel = chorusSendLevel / 127;
|
|
@@ -2251,7 +2294,8 @@ class MidyGM2 {
|
|
|
2251
2294
|
const channel = this.channels[channelNumber];
|
|
2252
2295
|
if (channel.isDrum)
|
|
2253
2296
|
return;
|
|
2254
|
-
|
|
2297
|
+
if (!(0 <= scheduleTime))
|
|
2298
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2255
2299
|
const state = channel.state;
|
|
2256
2300
|
const prev = state.pitchWheelSensitivity;
|
|
2257
2301
|
const next = value / 12800;
|
|
@@ -2271,7 +2315,8 @@ class MidyGM2 {
|
|
|
2271
2315
|
const channel = this.channels[channelNumber];
|
|
2272
2316
|
if (channel.isDrum)
|
|
2273
2317
|
return;
|
|
2274
|
-
|
|
2318
|
+
if (!(0 <= scheduleTime))
|
|
2319
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2275
2320
|
const prev = channel.fineTuning;
|
|
2276
2321
|
const next = value;
|
|
2277
2322
|
channel.fineTuning = next;
|
|
@@ -2288,7 +2333,8 @@ class MidyGM2 {
|
|
|
2288
2333
|
const channel = this.channels[channelNumber];
|
|
2289
2334
|
if (channel.isDrum)
|
|
2290
2335
|
return;
|
|
2291
|
-
|
|
2336
|
+
if (!(0 <= scheduleTime))
|
|
2337
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2292
2338
|
const prev = channel.coarseTuning;
|
|
2293
2339
|
const next = value;
|
|
2294
2340
|
channel.coarseTuning = next;
|
|
@@ -2305,12 +2351,14 @@ class MidyGM2 {
|
|
|
2305
2351
|
const channel = this.channels[channelNumber];
|
|
2306
2352
|
if (channel.isDrum)
|
|
2307
2353
|
return;
|
|
2308
|
-
|
|
2354
|
+
if (!(0 <= scheduleTime))
|
|
2355
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2309
2356
|
channel.modulationDepthRange = value;
|
|
2310
2357
|
this.updateModulation(channel, scheduleTime);
|
|
2311
2358
|
}
|
|
2312
2359
|
allSoundOff(channelNumber, _value, scheduleTime) {
|
|
2313
|
-
|
|
2360
|
+
if (!(0 <= scheduleTime))
|
|
2361
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2314
2362
|
return this.stopActiveNotes(channelNumber, 0, true, scheduleTime);
|
|
2315
2363
|
}
|
|
2316
2364
|
resetChannelStates(channelNumber) {
|
|
@@ -2369,7 +2417,8 @@ class MidyGM2 {
|
|
|
2369
2417
|
}
|
|
2370
2418
|
}
|
|
2371
2419
|
allNotesOff(channelNumber, _value, scheduleTime) {
|
|
2372
|
-
|
|
2420
|
+
if (!(0 <= scheduleTime))
|
|
2421
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2373
2422
|
return this.stopActiveNotes(channelNumber, 0, false, scheduleTime);
|
|
2374
2423
|
}
|
|
2375
2424
|
omniOff(channelNumber, value, scheduleTime) {
|
|
@@ -2418,7 +2467,8 @@ class MidyGM2 {
|
|
|
2418
2467
|
}
|
|
2419
2468
|
}
|
|
2420
2469
|
GM1SystemOn(scheduleTime) {
|
|
2421
|
-
|
|
2470
|
+
if (!(0 <= scheduleTime))
|
|
2471
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2422
2472
|
this.mode = "GM1";
|
|
2423
2473
|
for (let i = 0; i < this.channels.length; i++) {
|
|
2424
2474
|
this.allSoundOff(i, 0, scheduleTime);
|
|
@@ -2431,7 +2481,8 @@ class MidyGM2 {
|
|
|
2431
2481
|
this.channels[9].isDrum = true;
|
|
2432
2482
|
}
|
|
2433
2483
|
GM2SystemOn(scheduleTime) {
|
|
2434
|
-
|
|
2484
|
+
if (!(0 <= scheduleTime))
|
|
2485
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2435
2486
|
this.mode = "GM2";
|
|
2436
2487
|
for (let i = 0; i < this.channels.length; i++) {
|
|
2437
2488
|
this.allSoundOff(i, 0, scheduleTime);
|
|
@@ -2486,7 +2537,8 @@ class MidyGM2 {
|
|
|
2486
2537
|
this.setMasterVolume(volume, scheduleTime);
|
|
2487
2538
|
}
|
|
2488
2539
|
setMasterVolume(value, scheduleTime) {
|
|
2489
|
-
|
|
2540
|
+
if (!(0 <= scheduleTime))
|
|
2541
|
+
scheduleTime = this.audioContext.currentTime;
|
|
2490
2542
|
this.masterVolume.gain
|
|
2491
2543
|
.cancelScheduledValues(scheduleTime)
|
|
2492
2544
|
.setValueAtTime(value * value, scheduleTime);
|
package/script/midy-GMLite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class MidyGMLite {
|
|
1
|
+
export class MidyGMLite extends EventTarget {
|
|
2
2
|
static channelSettings: {
|
|
3
3
|
scheduleIndex: number;
|
|
4
4
|
detune: number;
|
|
@@ -29,6 +29,7 @@ export class MidyGMLite {
|
|
|
29
29
|
isPaused: boolean;
|
|
30
30
|
isStopping: boolean;
|
|
31
31
|
isSeeking: boolean;
|
|
32
|
+
loop: boolean;
|
|
32
33
|
playPromise: any;
|
|
33
34
|
timeline: any[];
|
|
34
35
|
notePromises: any[];
|
|
@@ -68,7 +69,7 @@ export class MidyGMLite {
|
|
|
68
69
|
createChannels(audioContext: any): any[];
|
|
69
70
|
createAudioBuffer(voiceParams: any): Promise<any>;
|
|
70
71
|
createBufferSource(channel: any, voiceParams: any, audioBuffer: any): any;
|
|
71
|
-
scheduleTimelineEvents(scheduleTime: any, queueIndex: any):
|
|
72
|
+
scheduleTimelineEvents(scheduleTime: any, queueIndex: any): any;
|
|
72
73
|
getQueueIndex(second: any): number;
|
|
73
74
|
resetAllStates(): void;
|
|
74
75
|
updateStates(queueIndex: any, nextQueueIndex: any): void;
|
|
@@ -90,8 +91,8 @@ export class MidyGMLite {
|
|
|
90
91
|
seekTo(second: any): void;
|
|
91
92
|
calcTotalTime(): number;
|
|
92
93
|
currentTime(): number;
|
|
93
|
-
processScheduledNotes(channel: any, callback: any): void
|
|
94
|
-
processActiveNotes(channel: any, scheduleTime: any, callback: any): void
|
|
94
|
+
processScheduledNotes(channel: any, callback: any): Promise<void>;
|
|
95
|
+
processActiveNotes(channel: any, scheduleTime: any, callback: any): Promise<void>;
|
|
95
96
|
cbToRatio(cb: any): number;
|
|
96
97
|
rateToCent(rate: any): number;
|
|
97
98
|
centToRate(cent: any): number;
|
|
@@ -112,10 +113,10 @@ export class MidyGMLite {
|
|
|
112
113
|
noteOn(channelNumber: any, noteNumber: any, velocity: any, startTime: any): Promise<void>;
|
|
113
114
|
disconnectNote(note: any): void;
|
|
114
115
|
releaseNote(channel: any, note: any, endTime: any): Promise<any>;
|
|
115
|
-
noteOff(channelNumber: any, noteNumber: any,
|
|
116
|
+
noteOff(channelNumber: any, noteNumber: any, _velocity: any, endTime: any, force: any): Promise<any>;
|
|
116
117
|
setNoteIndex(channel: any, index: any): void;
|
|
117
118
|
findNoteOffIndex(channel: any, noteNumber: any): any;
|
|
118
|
-
releaseSustainPedal(channelNumber: any, halfVelocity: any, scheduleTime: any):
|
|
119
|
+
releaseSustainPedal(channelNumber: any, halfVelocity: any, scheduleTime: any): Promise<any>[];
|
|
119
120
|
createMessageHandlers(): any[];
|
|
120
121
|
handleMessage(data: any, scheduleTime: any): void;
|
|
121
122
|
handleChannelMessage(statusByte: any, data1: any, data2: any, scheduleTime: any): void | Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"midy-GMLite.d.ts","sourceRoot":"","sources":["../src/midy-GMLite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"midy-GMLite.d.ts","sourceRoot":"","sources":["../src/midy-GMLite.js"],"names":[],"mappings":"AA6GA;IA8BE;;;;;;;;;MASE;IAEF,+BAgBC;IAxDD,aAAa;IACb,oBAAiB;IACjB,qBAAmB;IACnB,kBAAc;IACd,0BAAwB;IACxB,kBAAc;IACd,mBAAiB;IACjB,kBAAc;IACd,mBAAe;IACf,kBAAgB;IAChB,0BAAuD;IACvD,4BAAyB;IACzB,0BAAuB;IACvB,kCAA+B;IAC/B,mBAAkB;IAClB,mBAAkB;IAClB,kBAAiB;IACjB,oBAAmB;IACnB,mBAAkB;IAClB,cAAa;IACb,iBAAY;IACZ,gBAAc;IACd,oBAAkB;IAClB,sBAAwB;IACxB,2BAAqC;IACrC,+BAEE;IAeA,kBAAgC;IAChC,kBAA8C;IAC9C,eAAwD;IACxD,qBAGE;IACF,uBAAmD;IACnD;;;;;;;;;;;MAA2D;IAC3D,6BAA+D;IAC/D,gBAAiD;IAMnD,mCASC;IAED,2DAYC;IAED,yCAmBC;IAED,oCASC;IAED,sBAoCC;IAED,8DAWC;IAED;;;;MAeC;IAED,yCAaC;IAED,kDASC;IAED,0EAUC;IAED,gEAoDC;IAED,mCAOC;IAED,uBASC;IAED,yDAgCC;IAED,2BAyEC;IAED,uDAEC;IAED,wDAEC;IAED,qCAKC;IAED;;;MAwDC;IAED,kGAeC;IAED,mGAeC;IAED,wEAMC;IAED,uBAMC;IAED,sBAIC;IAED,uBAMC;IAED,wBAIC;IAED,0BAKC;IAED,wBAOC;IAED,sBAIC;IAED,kEAWC;IAED,kFAYC;IAED,2BAEC;IAED,8BAEC;IAED,8BAEC;IAED,4BAEC;IAED,wCAIC;IAED,2DAIC;IAED,+DAIC;IAED,sDAeC;IAED,qDAoBC;IAED,6CAIC;IAED,sDAsBC;IAED,kEAoBC;IAED,4GAkCC;IAED,uEA4CC;IAED,0EAiBC;IAED,8EAiBC;IAED,oEAUC;IAED,0FAoBC;IAED,gCASC;IAED,iEAqBC;IAED,qGAsBC;IAED,6CAUC;IAED,qDAUC;IAED,8FAeC;IAED,+BAmBC;IAED,kDAOC;IAED,sGA2BC;IAED,mFAGC;IAED,wFAGC;IAED,sEAUC;IAED,mEAYC;IAED,wDAKC;IAED,sDAOC;IAED,mDAMC;IAED,kDAKC;IAED;;;;;;;;;;;MAiCC;IAED,oFAMC;IAED,6EA2BC;IAED,qCAeC;IAED,+FAWC;IAED,wDASC;IAED,iFAKC;IAED,oEAKC;IAED;;;MAMC;IAED,8DAKC;IAED,4EAKC;IAED,sEAGC;IAED,2DAUC;IAED,yEAWC;IAED,kFAeC;IAED,uDAYC;IAED,gDAEC;IAED,gDAEC;IAED,sEAGC;IAED,qEAKC;IAED,2EAUC;IAED,gFAGC;IAED,6CAqBC;IAGD,8EAgCC;IAED,gFAGC;IAED,+EAgBC;IAED,qCASC;IAED,4EAaC;IAED,4DAGC;IAED,qDAKC;IAED,gDAYC;IAGD,6DAgBC;CACF"}
|