spessasynth_lib 3.24.27 → 3.24.28
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/index.js
CHANGED
|
@@ -8,7 +8,10 @@ import { Generator } from "./soundfont/basic_soundfont/generator.js";
|
|
|
8
8
|
import { Modulator } from "./soundfont/basic_soundfont/modulator.js";
|
|
9
9
|
import { BasicPresetZone } from "./soundfont/basic_soundfont/basic_zones.js";
|
|
10
10
|
import { BasicPreset } from "./soundfont/basic_soundfont/basic_preset.js";
|
|
11
|
+
import { BasicMIDI } from "./midi_parser/basic_midi.js";
|
|
12
|
+
import { MidiMessage } from "./midi_parser/midi_message.js";
|
|
11
13
|
import { MIDI } from './midi_parser/midi_loader.js';
|
|
14
|
+
import { RMIDINFOChunks } from "./midi_parser/rmidi_writer.js";
|
|
12
15
|
import { MIDIticksToSeconds } from './midi_parser/basic_midi.js';
|
|
13
16
|
import { MIDIBuilder } from "./midi_parser/midi_builder.js";
|
|
14
17
|
import { Synthetizer, VOICE_CAP, DEFAULT_PERCUSSION } from './synthetizer/synthetizer.js';
|
|
@@ -32,19 +35,28 @@ import { MIDIDeviceHandler} from "./external_midi/midi_handler.js";
|
|
|
32
35
|
import { WebMidiLinkHandler} from "./external_midi/web_midi_link.js";
|
|
33
36
|
import { formatTime, formatTitle, consoleColors, arrayToHexString } from './utils/other.js';
|
|
34
37
|
import { readBytesAsUintBigEndian } from './utils/byte_functions/big_endian.js';
|
|
38
|
+
import { readBytesAsString } from "./utils/byte_functions/string.js";
|
|
39
|
+
import { readLittleEndian } from "./utils/byte_functions/little_endian.js";
|
|
40
|
+
import { readVariableLengthQuantity } from "./utils/byte_functions/variable_length_quantity.js";
|
|
35
41
|
import { modulatorSources } from "./soundfont/basic_soundfont/modulator.js";
|
|
36
42
|
import { NON_CC_INDEX_OFFSET } from "./synthetizer/worklet_system/worklet_utilities/controller_tables.js";
|
|
37
43
|
import { ALL_CHANNELS_OR_DIFFERENT_ACTION } from './synthetizer/worklet_system/message_protocol/worklet_message.js';
|
|
44
|
+
import { DEFAULT_SYNTH_CONFIG } from "./synthetizer/audio_effects/effects_config.js";
|
|
38
45
|
import { trimSoundfont} from "./soundfont/basic_soundfont/write_sf2/soundfont_trimmer.js";
|
|
39
46
|
import { WORKLET_URL_ABSOLUTE } from './synthetizer/worklet_url.js';
|
|
47
|
+
import { SynthesizerSnapshot} from "./synthetizer/worklet_system/snapshot/synthesizer_snapshot.js";
|
|
48
|
+
import { ChannelSnapshot } from "./synthetizer/worklet_system/snapshot/channel_snapshot.js";
|
|
40
49
|
|
|
41
50
|
// Export modules
|
|
42
51
|
export {
|
|
43
52
|
// Synthesizer and Sequencer
|
|
44
53
|
Sequencer,
|
|
45
54
|
Synthetizer,
|
|
55
|
+
SynthesizerSnapshot,
|
|
56
|
+
ChannelSnapshot,
|
|
46
57
|
DEFAULT_PERCUSSION,
|
|
47
58
|
VOICE_CAP,
|
|
59
|
+
DEFAULT_SYNTH_CONFIG,
|
|
48
60
|
|
|
49
61
|
// SoundFont
|
|
50
62
|
BasicSoundFont,
|
|
@@ -61,13 +73,16 @@ export {
|
|
|
61
73
|
|
|
62
74
|
// MIDI
|
|
63
75
|
MIDI,
|
|
76
|
+
BasicMIDI,
|
|
64
77
|
MIDIBuilder,
|
|
65
78
|
IndexedByteArray,
|
|
79
|
+
MidiMessage,
|
|
66
80
|
writeMIDIFile,
|
|
67
81
|
writeRMIDI,
|
|
68
82
|
applySnapshotToMIDI,
|
|
69
83
|
modifyMIDI,
|
|
70
84
|
MIDIticksToSeconds,
|
|
85
|
+
RMIDINFOChunks,
|
|
71
86
|
|
|
72
87
|
// Utilities
|
|
73
88
|
audioBufferToWav,
|
|
@@ -86,7 +101,12 @@ export {
|
|
|
86
101
|
consoleColors,
|
|
87
102
|
formatTitle,
|
|
88
103
|
formatTime,
|
|
104
|
+
|
|
89
105
|
readBytesAsUintBigEndian,
|
|
106
|
+
readBytesAsString,
|
|
107
|
+
readLittleEndian,
|
|
108
|
+
readVariableLengthQuantity,
|
|
109
|
+
|
|
90
110
|
NON_CC_INDEX_OFFSET,
|
|
91
111
|
ALL_CHANNELS_OR_DIFFERENT_ACTION,
|
|
92
112
|
WORKLET_URL_ABSOLUTE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spessasynth_lib",
|
|
3
|
-
"version": "3.24.
|
|
3
|
+
"version": "3.24.28",
|
|
4
4
|
"description": "MIDI and SoundFont2/DLS library with no compromises",
|
|
5
5
|
"browser": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git+https://github.com/spessasus/SpessaSynth.git"
|
|
13
13
|
},
|
|
14
|
+
"main": "index.js",
|
|
14
15
|
"keywords": [
|
|
15
16
|
"soundfont",
|
|
16
17
|
"synthesizer",
|
package/sequencer/sequencer.js
CHANGED
|
@@ -99,7 +99,7 @@ export class Sequencer
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Fires on meta-event
|
|
102
|
-
* @type {Object<string, function([number, Uint8Array])>}
|
|
102
|
+
* @type {Object<string, function([number, Uint8Array, number])>}
|
|
103
103
|
*/
|
|
104
104
|
onMetaEvent = {};
|
|
105
105
|
|
|
@@ -438,7 +438,7 @@ export class Sequencer
|
|
|
438
438
|
|
|
439
439
|
/**
|
|
440
440
|
* Adds a new event that gets called when a meta-event occurs
|
|
441
|
-
* @param callback {function([number, Uint8Array])} the meta-event type and
|
|
441
|
+
* @param callback {function([number, Uint8Array, number])} the meta-event type, its data and the track number
|
|
442
442
|
* @param id {string} must be unique
|
|
443
443
|
*/
|
|
444
444
|
addOnMetaEvent(callback, id)
|
|
@@ -171,7 +171,10 @@ export function _processEvent(event, trackIndex)
|
|
|
171
171
|
}
|
|
172
172
|
if (statusByteData.status >= 0 && statusByteData.status < 0x80)
|
|
173
173
|
{
|
|
174
|
-
this.post(
|
|
174
|
+
this.post(
|
|
175
|
+
WorkletSequencerReturnMessageType.metaEvent,
|
|
176
|
+
[event.messageStatusByte, event.messageData, trackIndex]
|
|
177
|
+
);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
@@ -47,6 +47,6 @@ export const WorkletSequencerReturnMessageType = {
|
|
|
47
47
|
pause: 4, // no data
|
|
48
48
|
getMIDI: 5, // midiData<MIDI>
|
|
49
49
|
midiError: 6, // errorMSG<string>
|
|
50
|
-
metaEvent: 7, // [messageType<number>, messageData<Uint8Array>]
|
|
50
|
+
metaEvent: 7, // [messageType<number>, messageData<Uint8Array>, trackNum<number>]
|
|
51
51
|
loopCountChange: 8 // newLoopCount<number>
|
|
52
52
|
};
|
|
@@ -6,7 +6,7 @@ var Hn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(A,t)=>(
|
|
|
6
6
|
Transform type: ${A.transformType}
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
`}sumTransform(A){return new e(this.sourceEnum,this.secondarySourceEnum,this.modulatorDestination,this.transformAmount+A.transformAmount,this.transformType)}},Vt=960,Zt=QA.concave;function KA(e,A,t,n,s){return e<<10|A<<9|t<<8|n<<7|s}var dr=[new q(KA(Zt,0,1,0,K.noteOnVelocity),0,r.initialAttenuation,Vt,0),new q(129,0,r.vibLfoToPitch,50,0),new q(KA(Zt,0,1,1,m.mainVolume),0,r.initialAttenuation,Vt,0),new q(13,0,r.vibLfoToPitch,50,0),new q(526,16,r.fineTune,12700,0),new q(650,0,r.pan,500,0),new q(KA(Zt,0,1,1,m.expressionController),0,r.initialAttenuation,Vt,0),new q(219,0,r.reverbEffectsSend,200,0),new q(221,0,r.chorusEffectsSend,200,0)],fr=[new q(KA(QA.linear,0,0,0,K.polyPressure),0,r.vibLfoToPitch,50,0),new q(KA(QA.linear,0,0,1,m.tremoloDepth),0,r.modLfoToVolume,24,0),new q(KA(QA.convex,1,0,1,m.attackTime),0,r.attackVolEnv,6e3,0),new q(KA(QA.linear,1,0,1,m.releaseTime),0,r.releaseVolEnv,3600,0),new q(KA(QA.linear,1,0,1,m.brightness),0,r.initialFilterFc,6e3,0),new q(KA(QA.linear,1,0,1,m.filterResonance),0,r.initialFilterQ,250,0)],st=dr.concat(fr);var uA=128,ot=147,se=new Int16Array(ot).fill(0),dA=(e,A)=>se[e]=A<<7;dA(m.mainVolume,100);dA(m.balance,64);dA(m.expressionController,127);dA(m.pan,64);dA(m.portamentoOnOff,127);dA(m.filterResonance,64);dA(m.releaseTime,64);dA(m.attackTime,64);dA(m.brightness,64);dA(m.decayTime,64);dA(m.vibratoRate,64);dA(m.vibratoDepth,64);dA(m.vibratoDelay,64);dA(m.generalPurposeController6,64);dA(m.generalPurposeController8,64);dA(m.RPNLsb,127);dA(m.RPNMsb,127);dA(m.NRPNLsb,127);dA(m.NRPNMsb,127);var rt=1;se[m.portamentoControl]=rt;dA(uA+K.pitchWheel,64);dA(uA+K.pitchWheelRange,2);var sA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Wt=Object.keys(sA).length,Xt=new Float32Array(Wt);Xt[sA.modulationMultiplier]=1;var FA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6},_t={velocityOverride:128};var _n="spessasynth-worklet-system",zn=350,GA=9,it=16,at="gs";var Te={backwards:0,forwards:1,shuffleOn:2,shuffleOff:3},UA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10,setPreservePlaybackState:11},DA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6,metaEvent:7,loopCountChange:8};function Ae(e,A){let t=0;for(let n=8*(A-1);n>=0;n-=8)t|=e[e.currentIndex++]<<n;return t>>>0}function jn(e,A){if(this.sendMIDIMessages&&e.messageStatusByte>=128){this.sendMIDIMessage([e.messageStatusByte,...e.messageData]);return}let t=Ue(e.messageStatusByte),n=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(t.channel+=n,t.status){case G.noteOn:let s=e.messageData[1];if(s>0)this.synth.noteOn(t.channel,e.messageData[0],s),this.playingNotes.push({midiNote:e.messageData[0],channel:t.channel,velocity:s});else{this.synth.noteOff(t.channel,e.messageData[0]);let I=this.playingNotes.findIndex(d=>d.midiNote===e.messageData[0]&&d.channel===t.channel);I!==-1&&this.playingNotes.splice(I,1)}break;case G.noteOff:this.synth.noteOff(t.channel,e.messageData[0]);let o=this.playingNotes.findIndex(I=>I.midiNote===e.messageData[0]&&I.channel===t.channel);o!==-1&&this.playingNotes.splice(o,1);break;case G.pitchBend:this.synth.pitchWheel(t.channel,e.messageData[1],e.messageData[0]);break;case G.controllerChange:this.synth.controllerChange(t.channel,e.messageData[0],e.messageData[1]);break;case G.programChange:this.synth.programChange(t.channel,e.messageData[0]);break;case G.polyPressure:this.synth.polyPressure(t.channel,e.messageData[0],e.messageData[1]);break;case G.channelPressure:this.synth.channelPressure(t.channel,e.messageData[0]);break;case G.systemExclusive:this.synth.systemExclusive(e.messageData,n);break;case G.setTempo:e.messageData.currentIndex=0;let i=6e7/Ae(e.messageData,3);this.oneTickToSeconds=60/(i*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),L("invalid tempo! falling back to 120 BPM"),i=120);break;case G.timeSignature:case G.endOfTrack:case G.midiChannelPrefix:case G.songPosition:case G.activeSensing:case G.keySignature:case G.sequenceNumber:case G.sequenceSpecific:break;case G.text:case G.lyric:case G.copyright:case G.trackName:case G.marker:case G.cuePoint:case G.instrumentName:case G.programName:let l=-1;t.status===G.lyric&&(l=Math.min(this.midiData.lyricsTicks.indexOf(e.ticks),this.midiData.lyrics.length-1));let a=t.status;this.midiData.isKaraokeFile&&(t.status===G.text||t.status===G.lyric)&&(l=Math.min(this.midiData.lyricsTicks.indexOf(e.ticks),this.midiData.lyricsTicks.length),a=G.lyric),this.post(DA.textEvent,[e.messageData,a,l]);break;case G.midiPort:this.assignMIDIPort(A,e.messageData[0]);break;case G.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:L(`%cUnrecognized Event: %c${e.messageStatusByte}%c status byte: %c${Object.keys(G).find(I=>G[I]===t.status)}`,g.warn,g.unrecognized,g.warn,g.value);break}t.status>=0&&t.status<128&&this.post(DA.metaEvent,[e.messageStatusByte,e.messageData])}function $n(){for(let e=0;e<16;e++)this.synth.createWorkletChannel(!0)}function As(){if(!this.isActive)return;let e=this.currentTime;for(;this.playedTime<e;){let A=this._findFirstEventIndex(),t=this.tracks[A][this.eventIndex[A]];if(this._processEvent(t,A),this.eventIndex[A]++,A=this._findFirstEventIndex(),this.tracks[A].length<=this.eventIndex[A]){if(this.loop){this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}let n=this.tracks[A][this.eventIndex[A]];this.playedTime+=this.oneTickToSeconds*(n.ticks-t.ticks);let s=this.loop&&(this.loopCount>0||this.loopCount===-1);if(this.midiData.loop.end<=t.ticks&&s){this.loopCount!==1/0&&(this.loopCount--,this.post(DA.loopCountChange,this.loopCount)),this.setTimeTicks(this.midiData.loop.start);return}else if(e>=this.duration){if(s){this.loopCount!==1/0&&(this.loopCount--,this.post(DA.loopCountChange,this.loopCount)),this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function es(){let e=0,A=1/0;return this.tracks.forEach((t,n)=>{this.eventIndex[n]>=t.length||t[this.eventIndex[n]].ticks<A&&(e=n,A=t[this.eventIndex[n]].ticks)}),e}var De=class{timeDivision=0;duration=0;tempoChanges=[{ticks:0,tempo:120}];copyright="";tracksAmount=0;lyrics=[];lyricsTicks=[];firstNoteOn=0;keyRange={min:0,max:127};lastVoiceEventTick=0;midiPorts=[0];midiPortChannelOffsets=[0];usedChannelsOnTrack=[];loop={start:0,end:0};midiName="";midiNameUsesFileName=!1;fileName="";rawMidiName=void 0;format=0;RMIDInfo={};bankOffset=0;isKaraokeFile=!1};var gt=class extends De{isEmbedded=!1;constructor(A){super(),this.timeDivision=A.timeDivision,this.duration=A.duration,this.tempoChanges=A.tempoChanges,this.copyright=A.copyright,this.tracksAmount=A.tracksAmount,this.lyrics=A.lyrics,this.lyricsTicks=A.lyricsTicks,this.firstNoteOn=A.firstNoteOn,this.keyRange=A.keyRange,this.lastVoiceEventTick=A.lastVoiceEventTick,this.midiPorts=A.midiPorts,this.midiPortChannelOffsets=A.midiPortChannelOffsets,this.usedChannelsOnTrack=A.usedChannelsOnTrack,this.loop=A.loop,this.midiName=A.midiName,this.midiNameUsesFileName=A.midiNameUsesFileName,this.fileName=A.fileName,this.rawMidiName=A.rawMidiName,this.format=A.format,this.RMIDInfo=A.RMIDInfo,this.bankOffset=A.bankOffset,this.isKaraokeFile=A.isKaraokeFile,this.isEmbedded=A.embeddedSoundFont!==void 0}},Fa={duration:99999,firstNoteOn:0,loop:{start:0,end:123456},lastVoiceEventTick:123456,lyrics:[],copyright:"",midiPorts:[],midiPortChannelOffsets:[],tracksAmount:0,tempoChanges:[{ticks:0,tempo:120}],fileName:"NOT_LOADED.mid",midiName:"Loading...",rawMidiName:new Uint8Array([76,111,97,100,105,110,103,46,46,46]),usedChannelsOnTrack:[],timeDivision:0,keyRange:{min:0,max:127},isEmbedded:!1,RMIDInfo:{},bankOffset:0,midiNameUsesFileName:!1,format:0};function F(e,A){let t=0;for(let n=0;n<A;n++)t|=e[e.currentIndex++]<<n*8;return t>>>0}function ke(e,A,t){for(let n=0;n<t;n++)e[e.currentIndex++]=A>>n*8&255}function N(e,A){e[e.currentIndex++]=A&255,e[e.currentIndex++]=A>>8}function V(e,A){ke(e,A,4)}function oe(e,A){let t=A<<8|e;return t>32767?t-65536:t}function ts(e){return e>127?e-256:e}function _(e,A,t=void 0,n=!0){if(t){let s=e.slice(e.currentIndex,e.currentIndex+A);return e.currentIndex+=A,new TextDecoder(t.replace(/[^\x20-\x7E]/g,"")).decode(s.buffer)}else{let s=!1,o="";for(let i=0;i<A;i++){let l=e[e.currentIndex++];if(!s){if((l<32||l>127)&&l!==10){if(n){s=!0;continue}else if(l===0){s=!0;continue}}o+=String.fromCharCode(l)}}return o}}function It(e,A=0){let t=e.length;A>0&&(t=A);let n=new x(t);return kA(n,e,A),n}function Be(e){return It(e,e.length+1)}function kA(e,A,t=0){t>0&&A.length>t&&(A=A.slice(0,t));for(let n=0;n<A.length;n++)e[e.currentIndex++]=A.charCodeAt(n);if(t>A.length)for(let n=0;n<t-A.length;n++)e[e.currentIndex++]=0;return e}var nA=class{constructor(A,t,n){this.header=A,this.size=t,this.chunkData=n}};function z(e,A=!0,t=!1){let n=_(e,4),s=F(e,4),o;return A&&(o=new x(e.buffer.slice(e.currentIndex,e.currentIndex+s))),(A||t)&&(e.currentIndex+=s),s%2!==0&&e[e.currentIndex]===0&&e.currentIndex++,new nA(n,s,o)}function rA(e,A=void 0){let t=8+e.size;e.size%2!==0&&t++,A&&(t+=A.length);let n=new x(t);return A&&(n.set(A,n.currentIndex),n.currentIndex+=A.length),kA(n,e.header),V(n,t-8-(A?.length||0)),n.set(e.chunkData,n.currentIndex),n}function AA(e,A,t=!1,n=!1){if(t){let I=new Uint8Array(A.length+1);I.set(A),A=I}let s=8,o=s+A.length,i=A.length;o%2!==0&&o++;let l=e;n&&(o+=4,i+=4,s+=4,l="LIST");let a=new x(o);return kA(a,l),V(a,i),n&&kA(a,e),a.set(A,s),a}function NA(e,A){return e.find(t=>t.header!=="LIST"?!1:(t.chunkData.currentIndex=0,_(t.chunkData,4)===A))}function Ct(e){let A=0;for(;e;){let t=e[e.currentIndex++];if(A=A<<7|t&127,t>>7!==1)break}return A}var Et={name:"INAM",album:"IPRD",album2:"IALB",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var ht=class e extends De{embeddedSoundFont=void 0;tracks=[];isDLSRMIDI=!1;static copyFrom(A){let t=new e;return t.midiName=A.midiName,t.midiNameUsesFileName=A.midiNameUsesFileName,t.fileName=A.fileName,t.timeDivision=A.timeDivision,t.duration=A.duration,t.copyright=A.copyright,t.tracksAmount=A.tracksAmount,t.firstNoteOn=A.firstNoteOn,t.keyRange={...A.keyRange},t.lastVoiceEventTick=A.lastVoiceEventTick,t.loop={...A.loop},t.format=A.format,t.bankOffset=A.bankOffset,t.isKaraokeFile=A.isKaraokeFile,t.isDLSRMIDI=A.isDLSRMIDI,t.tempoChanges=[...A.tempoChanges],t.lyrics=A.lyrics.map(n=>new Uint8Array(n)),t.lyricsTicks=[...A.lyricsTicks],t.midiPorts=[...A.midiPorts],t.midiPortChannelOffsets=[...A.midiPortChannelOffsets],t.usedChannelsOnTrack=A.usedChannelsOnTrack.map(n=>new Set(n)),t.rawMidiName=A.rawMidiName?new Uint8Array(A.rawMidiName):void 0,t.embeddedSoundFont=A.embeddedSoundFont?A.embeddedSoundFont.slice(0):void 0,t.RMIDInfo={...A.RMIDInfo},t.tracks=A.tracks.map(n=>[...n]),t}_parseInternal(){$A("%cInterpreting MIDI events...",g.info);let A=!1;this.keyRange={max:0,min:127};let t=[],n=!1;typeof this.RMIDInfo.ICOP<"u"&&(n=!0);let s=!1;typeof this.RMIDInfo.INAM<"u"&&(s=!0);let o=null,i=null;for(let E=0;E<this.tracks.length;E++){let Q=this.tracks[E],B=new Set,p=!1;for(let f of Q){if(f.messageStatusByte>=128&&f.messageStatusByte<240){p=!0;for(let w=0;w<f.messageData.length;w++)f.messageData[w]=Math.min(127,f.messageData[w]);switch(f.ticks>this.lastVoiceEventTick&&(this.lastVoiceEventTick=f.ticks),f.messageStatusByte&240){case G.controllerChange:switch(f.messageData[0]){case 2:case 116:o=f.ticks;break;case 4:case 117:i===null?i=f.ticks:i=0;break;case 0:this.isDLSRMIDI&&f.messageData[1]!==0&&f.messageData[1]!==127&&(y("%cDLS RMIDI with offset 1 detected!",g.recognized),this.bankOffset=1)}break;case G.noteOn:B.add(f.messageStatusByte&15);let w=f.messageData[0];this.keyRange.min=Math.min(this.keyRange.min,w),this.keyRange.max=Math.max(this.keyRange.max,w);break}}f.messageData.currentIndex=0;let D=_(f.messageData,f.messageData.length);switch(f.messageData.currentIndex=0,f.messageStatusByte){case G.setTempo:f.messageData.currentIndex=0,this.tempoChanges.push({ticks:f.ticks,tempo:6e7/Ae(f.messageData,3)}),f.messageData.currentIndex=0;break;case G.marker:switch(D.trim().toLowerCase()){default:break;case"start":case"loopstart":o=f.ticks;break;case"loopend":i=f.ticks}f.messageData.currentIndex=0;break;case G.copyright:n||(f.messageData.currentIndex=0,t.push(_(f.messageData,f.messageData.length,void 0,!1)),f.messageData.currentIndex=0);break;case G.lyric:if(D.trim().startsWith("@KMIDI KARAOKE FILE")&&(this.isKaraokeFile=!0,y("%cKaraoke MIDI detected!",g.recognized)),this.isKaraokeFile)f.messageStatusByte=G.text;else{this.lyrics.push(f.messageData),this.lyricsTicks.push(f.ticks);break}case G.text:let R=D.trim();R.startsWith("@KMIDI KARAOKE FILE")?(this.isKaraokeFile=!0,y("%cKaraoke MIDI detected!",g.recognized)):this.isKaraokeFile&&(R.startsWith("@T")||R.startsWith("@A")?A?t.push(R.substring(2).trim()):(this.midiName=R.substring(2).trim(),A=!0,s=!0,this.rawMidiName=It(this.midiName)):R[0]!=="@"&&(this.lyrics.push(Jn(f.messageData)),this.lyricsTicks.push(f.ticks)));break}}if(this.usedChannelsOnTrack.push(B),!p){let f=Q.find(D=>D.messageStatusByte===G.trackName);if(f){f.messageData.currentIndex=0;let D=_(f.messageData,f.messageData.length);t.push(D)}}}this.tempoChanges.reverse(),y("%cCorrecting loops, ports and detecting notes...",g.info);let l=[];for(let E of this.tracks){let Q=E.find(B=>(B.messageStatusByte&240)===G.noteOn);Q&&l.push(Q.ticks)}this.firstNoteOn=Math.min(...l),y(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,g.info,g.recognized,g.info),o!==null&&i===null?(o=this.firstNoteOn,i=this.lastVoiceEventTick):(o===null&&(o=this.firstNoteOn),(i===null||i===0)&&(i=this.lastVoiceEventTick)),this.loop={start:o,end:i},y(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,g.info,g.recognized,g.info,g.recognized);let a=0;this.midiPorts=[],this.midiPortChannelOffsets=[];for(let E=0;E<this.tracks.length;E++)if(this.midiPorts.push(-1),this.usedChannelsOnTrack[E].size!==0)for(let Q of this.tracks[E]){if(Q.messageStatusByte!==G.midiPort)continue;let B=Q.messageData[0];this.midiPorts[E]=B,this.midiPortChannelOffsets[B]===void 0&&(this.midiPortChannelOffsets[B]=a,a+=16)}let I=1/0;for(let E of this.midiPorts)E!==-1&&I>E&&(I=E);if(I===1/0&&(I=0),this.midiPorts=this.midiPorts.map(E=>E===-1?I:E),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?y("%cNo additional MIDI Ports detected.",g.info):y("%cMIDI Ports detected!",g.recognized),!s)if(this.tracks.length>1){if(this.tracks[0].find(E=>E.messageStatusByte>=G.noteOn&&E.messageStatusByte<G.polyPressure)===void 0){let E=this.tracks[0].find(Q=>Q.messageStatusByte===G.trackName);E&&(this.rawMidiName=E.messageData,E.messageData.currentIndex=0,this.midiName=_(E.messageData,E.messageData.length,void 0,!1))}}else{let E=this.tracks[0].find(Q=>Q.messageStatusByte===G.trackName);E&&(this.rawMidiName=E.messageData,E.messageData.currentIndex=0,this.midiName=_(E.messageData,E.messageData.length,void 0,!1))}if(n||(this.copyright=t.map(E=>E.trim().replace(/(\r?\n)+/g,`
|
|
9
|
+
`}sumTransform(A){return new e(this.sourceEnum,this.secondarySourceEnum,this.modulatorDestination,this.transformAmount+A.transformAmount,this.transformType)}},Vt=960,Zt=QA.concave;function KA(e,A,t,n,s){return e<<10|A<<9|t<<8|n<<7|s}var dr=[new q(KA(Zt,0,1,0,K.noteOnVelocity),0,r.initialAttenuation,Vt,0),new q(129,0,r.vibLfoToPitch,50,0),new q(KA(Zt,0,1,1,m.mainVolume),0,r.initialAttenuation,Vt,0),new q(13,0,r.vibLfoToPitch,50,0),new q(526,16,r.fineTune,12700,0),new q(650,0,r.pan,500,0),new q(KA(Zt,0,1,1,m.expressionController),0,r.initialAttenuation,Vt,0),new q(219,0,r.reverbEffectsSend,200,0),new q(221,0,r.chorusEffectsSend,200,0)],fr=[new q(KA(QA.linear,0,0,0,K.polyPressure),0,r.vibLfoToPitch,50,0),new q(KA(QA.linear,0,0,1,m.tremoloDepth),0,r.modLfoToVolume,24,0),new q(KA(QA.convex,1,0,1,m.attackTime),0,r.attackVolEnv,6e3,0),new q(KA(QA.linear,1,0,1,m.releaseTime),0,r.releaseVolEnv,3600,0),new q(KA(QA.linear,1,0,1,m.brightness),0,r.initialFilterFc,6e3,0),new q(KA(QA.linear,1,0,1,m.filterResonance),0,r.initialFilterQ,250,0)],st=dr.concat(fr);var uA=128,ot=147,se=new Int16Array(ot).fill(0),dA=(e,A)=>se[e]=A<<7;dA(m.mainVolume,100);dA(m.balance,64);dA(m.expressionController,127);dA(m.pan,64);dA(m.portamentoOnOff,127);dA(m.filterResonance,64);dA(m.releaseTime,64);dA(m.attackTime,64);dA(m.brightness,64);dA(m.decayTime,64);dA(m.vibratoRate,64);dA(m.vibratoDepth,64);dA(m.vibratoDelay,64);dA(m.generalPurposeController6,64);dA(m.generalPurposeController8,64);dA(m.RPNLsb,127);dA(m.RPNMsb,127);dA(m.NRPNLsb,127);dA(m.NRPNMsb,127);var rt=1;se[m.portamentoControl]=rt;dA(uA+K.pitchWheel,64);dA(uA+K.pitchWheelRange,2);var sA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Wt=Object.keys(sA).length,Xt=new Float32Array(Wt);Xt[sA.modulationMultiplier]=1;var FA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6},_t={velocityOverride:128};var _n="spessasynth-worklet-system",zn=350,GA=9,it=16,at="gs";var Te={backwards:0,forwards:1,shuffleOn:2,shuffleOff:3},UA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10,setPreservePlaybackState:11},DA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6,metaEvent:7,loopCountChange:8};function Ae(e,A){let t=0;for(let n=8*(A-1);n>=0;n-=8)t|=e[e.currentIndex++]<<n;return t>>>0}function jn(e,A){if(this.sendMIDIMessages&&e.messageStatusByte>=128){this.sendMIDIMessage([e.messageStatusByte,...e.messageData]);return}let t=Ue(e.messageStatusByte),n=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(t.channel+=n,t.status){case G.noteOn:let s=e.messageData[1];if(s>0)this.synth.noteOn(t.channel,e.messageData[0],s),this.playingNotes.push({midiNote:e.messageData[0],channel:t.channel,velocity:s});else{this.synth.noteOff(t.channel,e.messageData[0]);let I=this.playingNotes.findIndex(d=>d.midiNote===e.messageData[0]&&d.channel===t.channel);I!==-1&&this.playingNotes.splice(I,1)}break;case G.noteOff:this.synth.noteOff(t.channel,e.messageData[0]);let o=this.playingNotes.findIndex(I=>I.midiNote===e.messageData[0]&&I.channel===t.channel);o!==-1&&this.playingNotes.splice(o,1);break;case G.pitchBend:this.synth.pitchWheel(t.channel,e.messageData[1],e.messageData[0]);break;case G.controllerChange:this.synth.controllerChange(t.channel,e.messageData[0],e.messageData[1]);break;case G.programChange:this.synth.programChange(t.channel,e.messageData[0]);break;case G.polyPressure:this.synth.polyPressure(t.channel,e.messageData[0],e.messageData[1]);break;case G.channelPressure:this.synth.channelPressure(t.channel,e.messageData[0]);break;case G.systemExclusive:this.synth.systemExclusive(e.messageData,n);break;case G.setTempo:e.messageData.currentIndex=0;let i=6e7/Ae(e.messageData,3);this.oneTickToSeconds=60/(i*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),L("invalid tempo! falling back to 120 BPM"),i=120);break;case G.timeSignature:case G.endOfTrack:case G.midiChannelPrefix:case G.songPosition:case G.activeSensing:case G.keySignature:case G.sequenceNumber:case G.sequenceSpecific:break;case G.text:case G.lyric:case G.copyright:case G.trackName:case G.marker:case G.cuePoint:case G.instrumentName:case G.programName:let l=-1;t.status===G.lyric&&(l=Math.min(this.midiData.lyricsTicks.indexOf(e.ticks),this.midiData.lyrics.length-1));let a=t.status;this.midiData.isKaraokeFile&&(t.status===G.text||t.status===G.lyric)&&(l=Math.min(this.midiData.lyricsTicks.indexOf(e.ticks),this.midiData.lyricsTicks.length),a=G.lyric),this.post(DA.textEvent,[e.messageData,a,l]);break;case G.midiPort:this.assignMIDIPort(A,e.messageData[0]);break;case G.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:L(`%cUnrecognized Event: %c${e.messageStatusByte}%c status byte: %c${Object.keys(G).find(I=>G[I]===t.status)}`,g.warn,g.unrecognized,g.warn,g.value);break}t.status>=0&&t.status<128&&this.post(DA.metaEvent,[e.messageStatusByte,e.messageData,A])}function $n(){for(let e=0;e<16;e++)this.synth.createWorkletChannel(!0)}function As(){if(!this.isActive)return;let e=this.currentTime;for(;this.playedTime<e;){let A=this._findFirstEventIndex(),t=this.tracks[A][this.eventIndex[A]];if(this._processEvent(t,A),this.eventIndex[A]++,A=this._findFirstEventIndex(),this.tracks[A].length<=this.eventIndex[A]){if(this.loop){this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}let n=this.tracks[A][this.eventIndex[A]];this.playedTime+=this.oneTickToSeconds*(n.ticks-t.ticks);let s=this.loop&&(this.loopCount>0||this.loopCount===-1);if(this.midiData.loop.end<=t.ticks&&s){this.loopCount!==1/0&&(this.loopCount--,this.post(DA.loopCountChange,this.loopCount)),this.setTimeTicks(this.midiData.loop.start);return}else if(e>=this.duration){if(s){this.loopCount!==1/0&&(this.loopCount--,this.post(DA.loopCountChange,this.loopCount)),this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function es(){let e=0,A=1/0;return this.tracks.forEach((t,n)=>{this.eventIndex[n]>=t.length||t[this.eventIndex[n]].ticks<A&&(e=n,A=t[this.eventIndex[n]].ticks)}),e}var De=class{timeDivision=0;duration=0;tempoChanges=[{ticks:0,tempo:120}];copyright="";tracksAmount=0;lyrics=[];lyricsTicks=[];firstNoteOn=0;keyRange={min:0,max:127};lastVoiceEventTick=0;midiPorts=[0];midiPortChannelOffsets=[0];usedChannelsOnTrack=[];loop={start:0,end:0};midiName="";midiNameUsesFileName=!1;fileName="";rawMidiName=void 0;format=0;RMIDInfo={};bankOffset=0;isKaraokeFile=!1};var gt=class extends De{isEmbedded=!1;constructor(A){super(),this.timeDivision=A.timeDivision,this.duration=A.duration,this.tempoChanges=A.tempoChanges,this.copyright=A.copyright,this.tracksAmount=A.tracksAmount,this.lyrics=A.lyrics,this.lyricsTicks=A.lyricsTicks,this.firstNoteOn=A.firstNoteOn,this.keyRange=A.keyRange,this.lastVoiceEventTick=A.lastVoiceEventTick,this.midiPorts=A.midiPorts,this.midiPortChannelOffsets=A.midiPortChannelOffsets,this.usedChannelsOnTrack=A.usedChannelsOnTrack,this.loop=A.loop,this.midiName=A.midiName,this.midiNameUsesFileName=A.midiNameUsesFileName,this.fileName=A.fileName,this.rawMidiName=A.rawMidiName,this.format=A.format,this.RMIDInfo=A.RMIDInfo,this.bankOffset=A.bankOffset,this.isKaraokeFile=A.isKaraokeFile,this.isEmbedded=A.embeddedSoundFont!==void 0}},Fa={duration:99999,firstNoteOn:0,loop:{start:0,end:123456},lastVoiceEventTick:123456,lyrics:[],copyright:"",midiPorts:[],midiPortChannelOffsets:[],tracksAmount:0,tempoChanges:[{ticks:0,tempo:120}],fileName:"NOT_LOADED.mid",midiName:"Loading...",rawMidiName:new Uint8Array([76,111,97,100,105,110,103,46,46,46]),usedChannelsOnTrack:[],timeDivision:0,keyRange:{min:0,max:127},isEmbedded:!1,RMIDInfo:{},bankOffset:0,midiNameUsesFileName:!1,format:0};function F(e,A){let t=0;for(let n=0;n<A;n++)t|=e[e.currentIndex++]<<n*8;return t>>>0}function ke(e,A,t){for(let n=0;n<t;n++)e[e.currentIndex++]=A>>n*8&255}function N(e,A){e[e.currentIndex++]=A&255,e[e.currentIndex++]=A>>8}function V(e,A){ke(e,A,4)}function oe(e,A){let t=A<<8|e;return t>32767?t-65536:t}function ts(e){return e>127?e-256:e}function _(e,A,t=void 0,n=!0){if(t){let s=e.slice(e.currentIndex,e.currentIndex+A);return e.currentIndex+=A,new TextDecoder(t.replace(/[^\x20-\x7E]/g,"")).decode(s.buffer)}else{let s=!1,o="";for(let i=0;i<A;i++){let l=e[e.currentIndex++];if(!s){if((l<32||l>127)&&l!==10){if(n){s=!0;continue}else if(l===0){s=!0;continue}}o+=String.fromCharCode(l)}}return o}}function It(e,A=0){let t=e.length;A>0&&(t=A);let n=new x(t);return kA(n,e,A),n}function Be(e){return It(e,e.length+1)}function kA(e,A,t=0){t>0&&A.length>t&&(A=A.slice(0,t));for(let n=0;n<A.length;n++)e[e.currentIndex++]=A.charCodeAt(n);if(t>A.length)for(let n=0;n<t-A.length;n++)e[e.currentIndex++]=0;return e}var nA=class{constructor(A,t,n){this.header=A,this.size=t,this.chunkData=n}};function z(e,A=!0,t=!1){let n=_(e,4),s=F(e,4),o;return A&&(o=new x(e.buffer.slice(e.currentIndex,e.currentIndex+s))),(A||t)&&(e.currentIndex+=s),s%2!==0&&e[e.currentIndex]===0&&e.currentIndex++,new nA(n,s,o)}function rA(e,A=void 0){let t=8+e.size;e.size%2!==0&&t++,A&&(t+=A.length);let n=new x(t);return A&&(n.set(A,n.currentIndex),n.currentIndex+=A.length),kA(n,e.header),V(n,t-8-(A?.length||0)),n.set(e.chunkData,n.currentIndex),n}function AA(e,A,t=!1,n=!1){if(t){let I=new Uint8Array(A.length+1);I.set(A),A=I}let s=8,o=s+A.length,i=A.length;o%2!==0&&o++;let l=e;n&&(o+=4,i+=4,s+=4,l="LIST");let a=new x(o);return kA(a,l),V(a,i),n&&kA(a,e),a.set(A,s),a}function NA(e,A){return e.find(t=>t.header!=="LIST"?!1:(t.chunkData.currentIndex=0,_(t.chunkData,4)===A))}function Ct(e){let A=0;for(;e;){let t=e[e.currentIndex++];if(A=A<<7|t&127,t>>7!==1)break}return A}var Et={name:"INAM",album:"IPRD",album2:"IALB",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var ht=class e extends De{embeddedSoundFont=void 0;tracks=[];isDLSRMIDI=!1;static copyFrom(A){let t=new e;return t.midiName=A.midiName,t.midiNameUsesFileName=A.midiNameUsesFileName,t.fileName=A.fileName,t.timeDivision=A.timeDivision,t.duration=A.duration,t.copyright=A.copyright,t.tracksAmount=A.tracksAmount,t.firstNoteOn=A.firstNoteOn,t.keyRange={...A.keyRange},t.lastVoiceEventTick=A.lastVoiceEventTick,t.loop={...A.loop},t.format=A.format,t.bankOffset=A.bankOffset,t.isKaraokeFile=A.isKaraokeFile,t.isDLSRMIDI=A.isDLSRMIDI,t.tempoChanges=[...A.tempoChanges],t.lyrics=A.lyrics.map(n=>new Uint8Array(n)),t.lyricsTicks=[...A.lyricsTicks],t.midiPorts=[...A.midiPorts],t.midiPortChannelOffsets=[...A.midiPortChannelOffsets],t.usedChannelsOnTrack=A.usedChannelsOnTrack.map(n=>new Set(n)),t.rawMidiName=A.rawMidiName?new Uint8Array(A.rawMidiName):void 0,t.embeddedSoundFont=A.embeddedSoundFont?A.embeddedSoundFont.slice(0):void 0,t.RMIDInfo={...A.RMIDInfo},t.tracks=A.tracks.map(n=>[...n]),t}_parseInternal(){$A("%cInterpreting MIDI events...",g.info);let A=!1;this.keyRange={max:0,min:127};let t=[],n=!1;typeof this.RMIDInfo.ICOP<"u"&&(n=!0);let s=!1;typeof this.RMIDInfo.INAM<"u"&&(s=!0);let o=null,i=null;for(let E=0;E<this.tracks.length;E++){let Q=this.tracks[E],B=new Set,p=!1;for(let f of Q){if(f.messageStatusByte>=128&&f.messageStatusByte<240){p=!0;for(let w=0;w<f.messageData.length;w++)f.messageData[w]=Math.min(127,f.messageData[w]);switch(f.ticks>this.lastVoiceEventTick&&(this.lastVoiceEventTick=f.ticks),f.messageStatusByte&240){case G.controllerChange:switch(f.messageData[0]){case 2:case 116:o=f.ticks;break;case 4:case 117:i===null?i=f.ticks:i=0;break;case 0:this.isDLSRMIDI&&f.messageData[1]!==0&&f.messageData[1]!==127&&(y("%cDLS RMIDI with offset 1 detected!",g.recognized),this.bankOffset=1)}break;case G.noteOn:B.add(f.messageStatusByte&15);let w=f.messageData[0];this.keyRange.min=Math.min(this.keyRange.min,w),this.keyRange.max=Math.max(this.keyRange.max,w);break}}f.messageData.currentIndex=0;let D=_(f.messageData,f.messageData.length);switch(f.messageData.currentIndex=0,f.messageStatusByte){case G.setTempo:f.messageData.currentIndex=0,this.tempoChanges.push({ticks:f.ticks,tempo:6e7/Ae(f.messageData,3)}),f.messageData.currentIndex=0;break;case G.marker:switch(D.trim().toLowerCase()){default:break;case"start":case"loopstart":o=f.ticks;break;case"loopend":i=f.ticks}f.messageData.currentIndex=0;break;case G.copyright:n||(f.messageData.currentIndex=0,t.push(_(f.messageData,f.messageData.length,void 0,!1)),f.messageData.currentIndex=0);break;case G.lyric:if(D.trim().startsWith("@KMIDI KARAOKE FILE")&&(this.isKaraokeFile=!0,y("%cKaraoke MIDI detected!",g.recognized)),this.isKaraokeFile)f.messageStatusByte=G.text;else{this.lyrics.push(f.messageData),this.lyricsTicks.push(f.ticks);break}case G.text:let R=D.trim();R.startsWith("@KMIDI KARAOKE FILE")?(this.isKaraokeFile=!0,y("%cKaraoke MIDI detected!",g.recognized)):this.isKaraokeFile&&(R.startsWith("@T")||R.startsWith("@A")?A?t.push(R.substring(2).trim()):(this.midiName=R.substring(2).trim(),A=!0,s=!0,this.rawMidiName=It(this.midiName)):R[0]!=="@"&&(this.lyrics.push(Jn(f.messageData)),this.lyricsTicks.push(f.ticks)));break}}if(this.usedChannelsOnTrack.push(B),!p){let f=Q.find(D=>D.messageStatusByte===G.trackName);if(f){f.messageData.currentIndex=0;let D=_(f.messageData,f.messageData.length);t.push(D)}}}this.tempoChanges.reverse(),y("%cCorrecting loops, ports and detecting notes...",g.info);let l=[];for(let E of this.tracks){let Q=E.find(B=>(B.messageStatusByte&240)===G.noteOn);Q&&l.push(Q.ticks)}this.firstNoteOn=Math.min(...l),y(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,g.info,g.recognized,g.info),o!==null&&i===null?(o=this.firstNoteOn,i=this.lastVoiceEventTick):(o===null&&(o=this.firstNoteOn),(i===null||i===0)&&(i=this.lastVoiceEventTick)),this.loop={start:o,end:i},y(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,g.info,g.recognized,g.info,g.recognized);let a=0;this.midiPorts=[],this.midiPortChannelOffsets=[];for(let E=0;E<this.tracks.length;E++)if(this.midiPorts.push(-1),this.usedChannelsOnTrack[E].size!==0)for(let Q of this.tracks[E]){if(Q.messageStatusByte!==G.midiPort)continue;let B=Q.messageData[0];this.midiPorts[E]=B,this.midiPortChannelOffsets[B]===void 0&&(this.midiPortChannelOffsets[B]=a,a+=16)}let I=1/0;for(let E of this.midiPorts)E!==-1&&I>E&&(I=E);if(I===1/0&&(I=0),this.midiPorts=this.midiPorts.map(E=>E===-1?I:E),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?y("%cNo additional MIDI Ports detected.",g.info):y("%cMIDI Ports detected!",g.recognized),!s)if(this.tracks.length>1){if(this.tracks[0].find(E=>E.messageStatusByte>=G.noteOn&&E.messageStatusByte<G.polyPressure)===void 0){let E=this.tracks[0].find(Q=>Q.messageStatusByte===G.trackName);E&&(this.rawMidiName=E.messageData,E.messageData.currentIndex=0,this.midiName=_(E.messageData,E.messageData.length,void 0,!1))}}else{let E=this.tracks[0].find(Q=>Q.messageStatusByte===G.trackName);E&&(this.rawMidiName=E.messageData,E.messageData.currentIndex=0,this.midiName=_(E.messageData,E.messageData.length,void 0,!1))}if(n||(this.copyright=t.map(E=>E.trim().replace(/(\r?\n)+/g,`
|
|
10
10
|
`)).filter(E=>E.length>0).join(`
|
|
11
11
|
`)||""),this.midiName=this.midiName.trim(),this.midiNameUsesFileName=!1,this.midiName.length===0){y("%cNo name detected. Using the alt name!",g.info),this.midiName=Yn(this.fileName),this.midiNameUsesFileName=!0,this.rawMidiName=new Uint8Array(this.midiName.length);for(let E=0;E<this.midiName.length;E++)this.rawMidiName[E]=this.midiName.charCodeAt(E)}else y(`%cMIDI Name detected! %c"${this.midiName}"`,g.info,g.recognized);let d=!0;for(let E of this.lyrics)if(E[0]===32||E[E.length-1]===32){d=!1;break}d&&(this.lyrics=this.lyrics.map(E=>{if(E[E.length-1]===45)return E;let Q=new Uint8Array(E.length+1);return Q.set(E,0),Q[E.length]=32,Q})),this.duration=ve(this.lastVoiceEventTick,this),y("%cSuccess!",g.recognized),O()}flush(){for(let A of this.tracks)A.sort((t,n)=>t.ticks-n.ticks);this._parseInternal()}};function ve(e,A){let t=0;for(;e>0;){let n=A.tempoChanges.find(o=>o.ticks<e),s=e-n.ticks;t+=s*60/(n.tempo*A.timeDivision),e-=s}return t}var lt=class extends ht{constructor(A,t=""){super(),mA("%cParsing MIDI File...",g.info),this.fileName=t;let n=new x(A),s,o=_(n,4);if(n.currentIndex-=4,o==="RIFF"){n.currentIndex+=8;let l=_(n,4,void 0,!1);if(l!=="RMID")throw O(),new SyntaxError(`Invalid RMIDI Header! Expected "RMID", got "${l}"`);let a=z(n);if(a.header!=="data")throw O(),new SyntaxError(`Invalid RMIDI Chunk header! Expected "data", got "${l}"`);for(s=a.chunkData;n.currentIndex<=n.length;){let I=n.currentIndex,d=z(n,!0);if(d.header==="RIFF"){let E=_(d.chunkData,4).toLowerCase();E==="sfbk"||E==="sfpk"||E==="dls "?(y("%cFound embedded soundfont!",g.recognized),this.embeddedSoundFont=n.slice(I,I+d.size).buffer):L(`Unknown RIFF chunk: "${E}"`),E==="dls "&&(this.isDLSRMIDI=!0)}else if(d.header==="LIST"&&_(d.chunkData,4)==="INFO"){for(y("%cFound RMIDI INFO chunk!",g.recognized),this.RMIDInfo={};d.chunkData.currentIndex<=d.size;){let Q=z(d.chunkData,!0);this.RMIDInfo[Q.header]=Q.chunkData}this.RMIDInfo.ICOP&&(this.copyright=_(this.RMIDInfo.ICOP,this.RMIDInfo.ICOP.length,void 0,!1).replaceAll(`
|
|
12
12
|
`," ")),this.RMIDInfo.INAM&&(this.rawMidiName=this.RMIDInfo[Et.name],this.midiName=_(this.rawMidiName,this.rawMidiName.length,void 0,!1).replaceAll(`
|