PageSourceSearch

https://motif-self.vercel.app/assets/MIDIService-CF3kZgy9.js

js motif-self.vercel.app collected 2026-10-03 07:20:12 UTC 37,709 bytes, 2 lines download raw bytes

1var re=Object.defineProperty;var ne=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var $=(e,t,r)=>ne(e,typeof t!="symbol"?t+"":t,r);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))i(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const n of o.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&i(n)}).observe(document,{childList:!0,subtree:!0});function r(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(a){if(a.ep)return;a.ep=!0;const o=r(a);fetch(a.href,o)}})();var M=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ze(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ie(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function i(){return this instanceof i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(i){var a=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(r,i,a.get?a:{enumerable:!0,get:function(){return e[i]}})}),r}var G={},E={};function ae(e){var t=new k(e),r=t.readChunk();if(r.id!="MThd")throw"Bad MIDI file.  Expected 'MHdr', got: '"+r.id+"'";for(var i=oe(r.data),a=[],o=0;!t.eof()&&o<i.numTracks;o++){var n=t.readChunk();if(n.id!="MTrk")throw"Bad MIDI file.  Expected 'MTrk', got: '"+n.id+"'";var f=se(n.data);a.push(f)}return{header:i,tracks:a}}function oe(e){var t=new k(e),r=t.readUInt16(),i=t.readUInt16(),a={format:r,numTracks:i},o=t.readUInt16();return o&32768?(a.framesPerSecond=256-(o>>8),a.ticksPerFrame=o&255):a.ticksPerBeat=o,a}function se(e){for(var t=new k(e),r=[];!t.eof();){var i=o();r.push(i)}return r;var a;function o(){var n={};n.deltaTime=t.readVarInt();var f=t.readUInt8();if((f&240)===240)if(f===255){n.meta=!0;var c=t.readUInt8(),u=t.readVarInt();switch(c){case 0:if(n.type="sequenceNumber",u!==2)throw"Expected length for sequenceNumber event is 2, got "+u;return n.number=t.readUInt16(),n;case 1:return n.type="text",n.text=t.readString(u),n;case 2:return n.type="copyrightNotice",n.text=t.readString(u),n;case 3:return n.type="trackName",n.text=t.readString(u),n;case 4:return n.type="instrumentName",n.text=t.readString(u),n;case 5:return n.type="lyrics",n.text=t.readString(u),n;case 6:return n.type="marker",n.text=t.readString(u),n;case 7:return n.type="cuePoint",n.text=t.readString(u),n;case 32:if(n.type="channelPrefix",u!=1)throw"Expected length for channelPrefix event is 1, got "+u;return n.channel=t.readUInt8(),n;case 33:if(n.type="portPrefix",u!=1)throw"Expected length for portPrefix event is 1, got "+u;return n.port=t.readUInt8(),n;case 47:if(n.type="endOfTrack",u!=0)throw"Expected length for endOfTrack event is 0, got "+u;return n;case 81:if(n.type="setTempo",u!=3)throw"Expected length for setTempo event is 3, got "+u;return n.microsecondsPerBeat=t.readUInt24(),n;case 84:if(n.type="smpteOffset",u!=5)throw"Expected length for smpteOffset event is 5, got "+u;var m=t.readUInt8(),d={0:24,32:25,64:29,96:30};return n.frameRate=d[m&96],n.hour=m&31,n.min=t.readUInt8(),n.sec=t.readUInt8(),n.frame=t.readUInt8(),n.subFrame=t.readUInt8(),n;case 88:if(n.type="timeSignature",u!=2&&u!=4)throw"Expected length for timeSignature event is 4 or 2, got "+u;return n.numerator=t.readUInt8(),n.denominator=1<<t.readUInt8(),u===4?(n.metronome=t.readUInt8(),n.thirtyseconds=t.readUInt8()):(n.metronome=36,n.thirtyseconds=8),n;case 89:if(n.type="keySignature",u!=2)throw"Expected length for keySignature event is 2, got "+u;return n.key=t.readInt8(),n.scale=t.readUInt8(),n;case 127:return n.type="sequencerSpecific",n.data=t.readBytes(u),n;default:return n.type="unknownMeta",n.data=t.readBytes(u),n.metatypeByte=c,n}}else if(f==240){n.type="sysEx";var u=t.readVarInt();return n.data=t.readBytes(u),n}else if(f==247){n.type="endSysEx";var u=t.readVarInt();return n.data=t.readBytes(u),n}else throw"Unrecognised MIDI event type byte: "+f;else{var s;if(f&128)s=t.readUInt8(),a=f;else{if(a===null)throw"Running status byte encountered before status byte";s=f,f=a,n.running=!0}var h=f>>4;switch(n.channel=f&15,h){case 8:return n.type="noteOff",n.noteNumber=s,n.velocity=t.readUInt8(),n;case 9:var y=t.readUInt8();return n.type=y===0?"noteOff":"noteOn",n.noteNumber=s,n.velocity=y,y===0&&(n.byte9=!0),n;case 10:return n.type="noteAftertouch",n.noteNumber=s,n.amount=t.readUInt8(),n;case 11:return n.type="controller",n.controllerType=s,n.value=t.readUInt8(),n;case 12:return n.type="programChange",n.programNumber=s,n;case 13:return n.type="channelAftertouch",n.amount=s,n;case 14:return n.type="pitchBend",n.value=s+(t.readUInt8()<<7)-8192,n;default:throw"Unrecognised MIDI event type: "+h}}}}function k(e){this.buffer=e,this.bufferLen=this.buffer.length,this.pos=0}k.prototype.eof=function(){return this.pos>=this.bufferLen};k.prototype.readUInt8=function(){var e=this.buffer[this.pos];return this.pos+=1,e};k.prototype.readInt8=function(){var e=this.readUInt8();return e&128?e-256:e};k.prototype.readUInt16=function(){var e=this.readUInt8(),t=this.readUInt8();return(e<<8)+t};k.prototype.readInt16=function(){var e=this.readUInt16();return e&32768?e-65536:e};k.prototype.readUInt24=function(){var e=this.readUInt8(),t=this.readUInt8(),r=this.readUInt8();return(e<<16)+(t<<8)+r};k.prototype.readInt24=function(){var e=this.readUInt24();return e&8388608?e-16777216:e};k.prototype.readUInt32=function(){var e=this.readUInt8(),t=this.readUInt8(),r=this.readUInt8(),i=this.readUInt8();return(e<<24)+(t<<16)+(r<<8)+i};k.prototype.readBytes=function(e){var t=this.buffer.slice(this.pos,this.pos+e);return this.pos+=e,t};k.prototype.readString=function(e){var t=this.readBytes(e);return String.fromCharCode.apply(null,t)};k.prototype.readVarInt=function(){for(var e=0;!this.eof();){var t=this.readUInt8();if(t&128)e+=t&127,e<<=7;else return e+t}return e};k.prototype.readChunk=function(){var e=this.readString(4),t=this.readUInt32(),r=this.readBytes(t);return{id:e,length:t,data:r}};var ce=ae;function ue(e,t){if(typeof e!="object")throw"Invalid MIDI data";t=t||{};var r=e.header||{},i=e.tracks||[],a,o=i.length,n=new g;for(fe(n,r,o),a=0;a<o;a++)he(n,i[a],t);return n.buffer}function fe(e,t,r){var i=t.format==null?1:t.format,a=128;t.timeDivision?a=t.timeDivision:t.ticksPerFrame&&t.framesPerSecond?a=-(t.framesPerSecond&255)<<8|t.ticksPerFrame&255:t.ticksPerBeat&&(a=t.ticksPerBeat&32767);var o=new g;o.writeUInt16(i),o.writeUInt16(r),o.writeUInt16(a),e.writeChunk("MThd",o.buffer)}function he(e,t,r){var i=new g,a,o=t.length,n=null;for(a=0;a<o;a++)(r.running===!1||!r.running&&!t[a].running)&&(n=null),n=le(i,t[a],n,r.useByte9ForNoteOff);e.writeChunk("MTrk",i.buffer)}
1function le(e,t,r,i){var a=t.type,o=t.deltaTime,n=t.text||"",f=t.data||[],c=null;switch(e.writeVarInt(o),a){case"sequenceNumber":e.writeUInt8(255),e.writeUInt8(0),e.writeVarInt(2),e.writeUInt16(t.number);break;case"text":e.writeUInt8(255),e.writeUInt8(1),e.writeVarInt(n.length),e.writeString(n);break;case"copyrightNotice":e.writeUInt8(255),e.writeUInt8(2),e.writeVarInt(n.length),e.writeString(n);break;case"trackName":e.writeUInt8(255),e.writeUInt8(3),e.writeVarInt(n.length),e.writeString(n);break;case"instrumentName":e.writeUInt8(255),e.writeUInt8(4),e.writeVarInt(n.length),e.writeString(n);break;case"lyrics":e.writeUInt8(255),e.writeUInt8(5),e.writeVarInt(n.length),e.writeString(n);break;case"marker":e.writeUInt8(255),e.writeUInt8(6),e.writeVarInt(n.length),e.writeString(n);break;case"cuePoint":e.writeUInt8(255),e.writeUInt8(7),e.writeVarInt(n.length),e.writeString(n);break;case"channelPrefix":e.writeUInt8(255),e.writeUInt8(32),e.writeVarInt(1),e.writeUInt8(t.channel);break;case"portPrefix":e.writeUInt8(255),e.writeUInt8(33),e.writeVarInt(1),e.writeUInt8(t.port);break;case"endOfTrack":e.writeUInt8(255),e.writeUInt8(47),e.writeVarInt(0);break;case"setTempo":e.writeUInt8(255),e.writeUInt8(81),e.writeVarInt(3),e.writeUInt24(t.microsecondsPerBeat);break;case"smpteOffset":e.writeUInt8(255),e.writeUInt8(84),e.writeVarInt(5);var u={24:0,25:32,29:64,30:96},m=t.hour&31|u[t.frameRate];e.writeUInt8(m),e.writeUInt8(t.min),e.writeUInt8(t.sec),e.writeUInt8(t.frame),e.writeUInt8(t.subFrame);break;case"timeSignature":e.writeUInt8(255),e.writeUInt8(88),e.writeVarInt(4),e.writeUInt8(t.numerator);var d=Math.floor(Math.log(t.denominator)/Math.LN2)&255;e.writeUInt8(d),e.writeUInt8(t.metronome),e.writeUInt8(t.thirtyseconds||8);break;case"keySignature":e.writeUInt8(255),e.writeUInt8(89),e.writeVarInt(2),e.writeInt8(t.key),e.writeUInt8(t.scale);break;case"sequencerSpecific":e.writeUInt8(255),e.writeUInt8(127),e.writeVarInt(f.length),e.writeBytes(f);break;case"unknownMeta":t.metatypeByte!=null&&(e.writeUInt8(255),e.writeUInt8(t.metatypeByte),e.writeVarInt(f.length),e.writeBytes(f));break;case"sysEx":e.writeUInt8(240),e.writeVarInt(f.length),e.writeBytes(f);break;case"endSysEx":e.writeUInt8(247),e.writeVarInt(f.length),e.writeBytes(f);break;case"noteOff":var s=i!==!1&&t.byte9||i&&t.velocity==0?144:128;c=s|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.noteNumber),e.writeUInt8(t.velocity);break;case"noteOn":c=144|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.noteNumber),e.writeUInt8(t.velocity);break;case"noteAftertouch":c=160|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.noteNumber),e.writeUInt8(t.amount);break;case"controller":c=176|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.controllerType),e.writeUInt8(t.value);break;case"programChange":c=192|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.programNumber);break;case"channelAftertouch":c=208|t.channel,c!==r&&e.writeUInt8(c),e.writeUInt8(t.amount);break;case"pitchBend":c=224|t.channel,c!==r&&e.writeUInt8(c);var h=8192+t.value,y=h&127,b=h>>7&127;e.writeUInt8(y),e.writeUInt8(b);break;default:throw"Unrecognized event type: "+a}return c}function g(){this.buffer=[]}g.prototype.writeUInt8=function(e){this.buffer.push(e&255)};g.prototype.writeInt8=g.prototype.writeUInt8;g.prototype.writeUInt16=function(e){var t=e>>8&255,r=e&255;this.writeUInt8(t),this.writeUInt8(r)};g.prototype.writeInt16=g.prototype.writeUInt16;g.prototype.writeUInt24=function(e){var t=e>>16&255,r=e>>8&255,i=e&255;this.writeUInt8(t),this.writeUInt8(r),this.writeUInt8(i)};g.prototype.writeInt24=g.prototype.writeUInt24;g.prototype.writeUInt32=function(e){var t=e>>24&255,r=e>>16&255,i=e>>8&255,a=e&255;this.writeUInt8(t),this.writeUInt8(r),this.writeUInt8(i),this.writeUInt8(a)};g.prototype.writeInt32=g.prototype.writeUInt32;g.prototype.writeBytes=function(e){this.buffer=this.buffer.concat(Array.prototype.slice.call(e,0))};g.prototype.writeString=function(e){var t,r=e.length,i=[];for(t=0;t<r;t++)i.push(e.codePointAt(t));this.writeBytes(i)};g.prototype.writeVarInt=function(e){if(e<0)throw"Cannot write negative variable-length integer";if(e<=127)this.writeUInt8(e);else{var t=e,r=[];for(r.push(t&127),t>>=7;t;){var i=t&127|128;r.push(i),t>>=7}this.writeBytes(r.reverse())}};g.prototype.writeChunk=function(e,t){this.writeString(e),this.writeUInt32(t.length),this.writeBytes(t)};var de=ue;E.parseMidi=ce;E.writeMidi=de;var _={},S={};Object.defineProperty(S,"__esModule",{value:!0});S.insert=S.search=void 0;function Z(e,t,r){r===void 0&&(r="ticks");var i=0,a=e.length,o=a;if(a>0&&e[a-1][r]<=t)return a-1;for(;i<o;){var n=Math.floor(i+(o-i)/2),f=e[n],c=e[n+1];if(f[r]===t){for(var u=n;u<e.length;u++){var m=e[u];m[r]===t&&(n=u)}return n}else{if(f[r]<t&&c[r]>t)return n;f[r]>t?o=n:f[r]<t&&(i=n+1)}}return-1}S.search=Z;function pe(e,t,r){if(r===void 0&&(r="ticks"),e.length){var i=Z(e,t[r],r);e.splice(i+1,0,t)}else e.push(t)}S.insert=pe;
1(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Header=e.keySignatureKeys=void 0;var t=S,r=new WeakMap;e.keySignatureKeys=["Cb","Gb","Db","Ab","Eb","Bb","F","C","G","D","A","E","B","F#","C#"];var i=function(){function a(o){var n=this;if(this.tempos=[],this.timeSignatures=[],this.keySignatures=[],this.meta=[],this.name="",r.set(this,480),o){r.set(this,o.header.ticksPerBeat),o.tracks.forEach(function(c){c.forEach(function(u){u.meta&&(u.type==="timeSignature"?n.timeSignatures.push({ticks:u.absoluteTime,timeSignature:[u.numerator,u.denominator]}):u.type==="setTempo"?n.tempos.push({bpm:6e7/u.microsecondsPerBeat,ticks:u.absoluteTime}):u.type==="keySignature"&&n.keySignatures.push({key:e.keySignatureKeys[u.key+7],scale:u.scale===0?"major":"minor",ticks:u.absoluteTime}))})});var f=0;o.tracks[0].forEach(function(c){f+=c.deltaTime,c.meta&&(c.type==="trackName"?n.name=c.text:(c.type==="text"||c.type==="cuePoint"||c.type==="marker"||c.type==="lyrics")&&n.meta.push({text:c.text,ticks:f,type:c.type}))}),this.update()}}return a.prototype.update=function(){var o=this,n=0,f=0;this.tempos.sort(function(c,u){return c.ticks-u.ticks}),this.tempos.forEach(function(c,u){var m=u>0?o.tempos[u-1].bpm:o.tempos[0].bpm,d=c.ticks/o.ppq-f,s=60/m*d;c.time=s+n,n=c.time,f+=d}),this.timeSignatures.sort(function(c,u){return c.ticks-u.ticks}),this.timeSignatures.forEach(function(c,u){var m=u>0?o.timeSignatures[u-1]:o.timeSignatures[0],d=(c.ticks-m.ticks)/o.ppq,s=d/m.timeSignature[0]/(m.timeSignature[1]/4);m.measures=m.measures||0,c.measures=s+m.measures})},a.prototype.ticksToSeconds=function(o){var n=(0,t.search)(this.tempos,o);if(n!==-1){var f=this.tempos[n],c=f.time,u=(o-f.ticks)/this.ppq;return c+60/f.bpm*u}else{var m=o/this.ppq;return 60/120*m}},a.prototype.ticksToMeasures=function(o){var n=(0,t.search)(this.timeSignatures,o);if(n!==-1){var f=this.timeSignatures[n],c=(o-f.ticks)/this.ppq;return f.measures+c/(f.timeSignature[0]/f.timeSignature[1])/4}else return o/this.ppq/4},Object.defineProperty(a.prototype,"ppq",{get:function(){return r.get(this)},enumerable:!1,configurable:!0}),a.prototype.secondsToTicks=function(o){var n=(0,t.search)(this.tempos,o,"time");if(n!==-1){var f=this.tempos[n],c=f.time,u=o-c,m=u/(60/f.bpm);return Math.round(f.ticks+m*this.ppq)}else{var d=o/.5;return Math.round(d*this.ppq)}},a.prototype.toJSON=function(){return{keySignatures:this.keySignatures,meta:this.meta,name:this.name,ppq:this.ppq,tempos:this.tempos.map(function(o){return{bpm:o.bpm,ticks:o.ticks}}),timeSignatures:this.timeSignatures}},a.prototype.fromJSON=function(o){this.name=o.name,this.tempos=o.tempos.map(function(n){return Object.assign({},n)}),this.timeSignatures=o.timeSignatures.map(function(n){return Object.assign({},n)}),this.keySignatures=o.keySignatures.map(function(n){return Object.assign({},n)}),this.meta=o.meta.map(function(n){return Object.assign({},n)}),r.set(this,o.ppq),this.update()},a.prototype.setTempo=function(o){this.tempos=[{bpm:o,ticks:0}],this.update()},a}();e.Header=i})(_);var P={},K={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ControlChange=e.controlChangeIds=e.controlChangeNames=void 0,e.controlChangeNames={1:"modulationWheel",2:"breath",4:"footController",5:"portamentoTime",7:"volume",8:"balance",10:"pan",64:"sustain",65:"portamentoTime",66:"sostenuto",67:"softPedal",68:"legatoFootswitch",84:"portamentoControl"},e.controlChangeIds=Object.keys(e.controlChangeNames).reduce(function(a,o){return a[e.controlChangeNames[o]]=o,a},{});var t=new WeakMap,r=new WeakMap,i=function(){function a(o,n){t.set(this,n),r.set(this,o.controllerType),this.ticks=o.absoluteTime,this.value=o.value}return Object.defineProperty(a.prototype,"number",{get:function(){return r.get(this)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"name",{get:function(){return e.controlChangeNames[this.number]?e.controlChangeNames[this.number]:null},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"time",{get:function(){var o=t.get(this);return o.ticksToSeconds(this.ticks)},set:function(o){var n=t.get(this);this.ticks=n.secondsToTicks(o)}
1,enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return{number:this.number,ticks:this.ticks,time:this.time,value:this.value}},a}();e.ControlChange=i})(K);var j={};Object.defineProperty(j,"__esModule",{value:!0});j.createControlChanges=void 0;var F=K;function me(){return new Proxy({},{get:function(e,t){if(e[t])return e[t];if(F.controlChangeIds.hasOwnProperty(t))return e[F.controlChangeIds[t]]},set:function(e,t,r){return F.controlChangeIds.hasOwnProperty(t)?e[F.controlChangeIds[t]]=r:e[t]=r,!0}})}j.createControlChanges=me;var D={};Object.defineProperty(D,"__esModule",{value:!0});D.PitchBend=void 0;var J=new WeakMap,ye=function(){function e(t,r){J.set(this,r),this.ticks=t.absoluteTime,this.value=t.value}return Object.defineProperty(e.prototype,"time",{get:function(){var t=J.get(this);return t.ticksToSeconds(this.ticks)},set:function(t){var r=J.get(this);this.ticks=r.secondsToTicks(t)},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return{ticks:this.ticks,time:this.time,value:this.value}},e}();D.PitchBend=ye;var A={},T={};Object.defineProperty(T,"__esModule",{value:!0});T.DrumKitByPatchID=T.InstrumentFamilyByID=T.instrumentByPatchID=void 0;T.instrumentByPatchID=["acoustic grand piano","bright acoustic piano","electric grand piano","honky-tonk piano","electric piano 1","electric piano 2","harpsichord","clavi","celesta","glockenspiel","music box","vibraphone","marimba","xylophone","tubular bells","dulcimer","drawbar organ","percussive organ","rock organ","church organ","reed organ","accordion","harmonica","tango accordion","acoustic guitar (nylon)","acoustic guitar (steel)","electric guitar (jazz)","electric guitar (clean)","electric guitar (muted)","overdriven guitar","distortion guitar","guitar harmonics","acoustic bass","electric bass (finger)","electric bass (pick)","fretless bass","slap bass 1","slap bass 2","synth bass 1","synth bass 2","violin","viola","cello","contrabass","tremolo strings","pizzicato strings","orchestral harp","timpani","string ensemble 1","string ensemble 2","synthstrings 1","synthstrings 2","choir aahs","voice oohs","synth voice","orchestra hit","trumpet","trombone","tuba","muted trumpet","french horn","brass section","synthbrass 1","synthbrass 2","soprano sax","alto sax","tenor sax","baritone sax","oboe","english horn","bassoon","clarinet","piccolo","flute","recorder","pan flute","blown bottle","shakuhachi","whistle","ocarina","lead 1 (square)","lead 2 (sawtooth)","lead 3 (calliope)","lead 4 (chiff)","lead 5 (charang)","lead 6 (voice)","lead 7 (fifths)","lead 8 (bass + lead)","pad 1 (new age)","pad 2 (warm)","pad 3 (polysynth)","pad 4 (choir)","pad 5 (bowed)","pad 6 (metallic)","pad 7 (halo)","pad 8 (sweep)","fx 1 (rain)","fx 2 (soundtrack)","fx 3 (crystal)","fx 4 (atmosphere)","fx 5 (brightness)","fx 6 (goblins)","fx 7 (echoes)","fx 8 (sci-fi)","sitar","banjo","shamisen","koto","kalimba","bag pipe","fiddle","shanai","tinkle bell","agogo","steel drums","woodblock","taiko drum","melodic tom","synth drum","reverse cymbal","guitar fret noise","breath noise","seashore","bird tweet","telephone ring","helicopter","applause","gunshot"];T.InstrumentFamilyByID=["piano","chromatic percussion","organ","guitar","bass","strings","ensemble","brass","reed","pipe","synth lead","synth pad","synth effects","world","percussive","sound effects"];T.DrumKitByPatchID={0:"standard kit",8:"room kit",16:"power kit",24:"electronic kit",25:"tr-808 kit",32:"jazz kit",40:"brush kit",48:"orchestra kit",56:"sound fx kit"};Object.defineProperty(A,"__esModule",{value:!0});A.Instrument=void 0;var B=T,Q=new WeakMap,be=function(){function e(t,r){if(this.number=0,Q.set(this,r),this.number=0,t){var i=t.find(function(a){return a.type==="programChange"});i&&(this.number=i.programNumber)}}return Object.defineProperty(e.prototype,"name",{get:function(){return this.percussion?B.DrumKitByPatchID[this.number]:B.instrumentByPatchID[this.number]},set:function(t){var r=B.instrumentByPatchID.indexOf(t);r!==-1&&(this.number=r)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"family",{get:function(){return this.percussion?"drums":B.InstrumentFamilyByID[Math.floor(this.number/8)]}
1,enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"percussion",{get:function(){var t=Q.get(this);return t.channel===9},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return{family:this.family,number:this.number,name:this.name}},e.prototype.fromJSON=function(t){this.number=t.number},e}();A.Instrument=be;var V={};Object.defineProperty(V,"__esModule",{value:!0});V.Note=void 0;function ge(e){var t=Math.floor(e/12)-1;return ee(e)+t.toString()}function ee(e){var t=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],r=e%12;return t[r]}function ve(e){var t=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];return t.indexOf(e)}var Ie=function(){var e=/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,t={cbb:-2,cb:-1,c:0,"c#":1,cx:2,dbb:0,db:1,d:2,"d#":3,dx:4,ebb:2,eb:3,e:4,"e#":5,ex:6,fbb:3,fb:4,f:5,"f#":6,fx:7,gbb:5,gb:6,g:7,"g#":8,gx:9,abb:7,ab:8,a:9,"a#":10,ax:11,bbb:9,bb:10,b:11,"b#":12,bx:13};return function(r){var i=e.exec(r),a=i[1],o=i[2],n=t[a.toLowerCase()];return n+(parseInt(o,10)+1)*12}}(),C=new WeakMap,ke=function(){function e(t,r,i){C.set(this,i),this.midi=t.midi,this.velocity=t.velocity,this.noteOffVelocity=r.velocity,this.ticks=t.ticks,this.durationTicks=r.ticks-t.ticks}return Object.defineProperty(e.prototype,"name",{get:function(){return ge(this.midi)},set:function(t){this.midi=Ie(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"octave",{get:function(){return Math.floor(this.midi/12)-1},set:function(t){var r=t-this.octave;this.midi+=r*12},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pitch",{get:function(){return ee(this.midi)},set:function(t){this.midi=12*(this.octave+1)+ve(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"duration",{get:function(){var t=C.get(this);return t.ticksToSeconds(this.ticks+this.durationTicks)-t.ticksToSeconds(this.ticks)},set:function(t){var r=C.get(this),i=r.secondsToTicks(this.time+t);this.durationTicks=i-this.ticks},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"time",{get:function(){var t=C.get(this);return t.ticksToSeconds(this.ticks)},set:function(t){var r=C.get(this);this.ticks=r.secondsToTicks(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bars",{get:function(){var t=C.get(this);return t.ticksToMeasures(this.ticks)},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return{duration:this.duration,durationTicks:this.durationTicks,midi:this.midi,name:this.name,ticks:this.ticks,time:this.time,velocity:this.velocity}},e}();V.Note=ke;Object.defineProperty(P,"__esModule",{value:!0});P.Track=void 0;var L=S,we=K,xe=j,Ue=D,X=A,Te=V,N=new WeakMap,Se=function(){function e(t,r){var i=this;if(this.name="",this.notes=[],this.controlChanges=(0,xe.createControlChanges)(),this.pitchBends=[],N.set(this,r),t){var a=t.find(function(s){return s.type==="trackName"});this.name=a?a.text:""}if(this.instrument=new X.Instrument(t,this),this.channel=0,t){for(var o=t.filter(function(s){return s.type==="noteOn"}),n=t.filter(function(s){return s.type==="noteOff"}),f=function(){var s=o.shift();c.channel=s.channel;var h=n.findIndex(function(b){return b.noteNumber===s.noteNumber&&b.absoluteTime>=s.absoluteTime});if(h!==-1){var y=n.splice(h,1)[0];c.addNote({durationTicks:y.absoluteTime-s.absoluteTime,midi:s.noteNumber,noteOffVelocity:y.velocity/127,ticks:s.absoluteTime,velocity:s.velocity/127})}},c=this;o.length;)f();var u=t.filter(function(s){return s.type==="controller"});u.forEach(function(s){i.addCC({number:s.controllerType,ticks:s.absoluteTime,value:s.value/127})});var m=t.filter(function(s){return s.type==="pitchBend"});m.forEach(function(s){i.addPitchBend({ticks:s.absoluteTime,value:s.value/Math.pow(2,13)})});var d=t.find(function(s){return s.type==="endOfTrack"});this.endOfTrackTicks=d!==void 0?d.absoluteTime:void 0}}return e.prototype.addNote=function(t){var r=N.get(this),i=new Te.Note({midi:0,ticks:0,velocity:1},{ticks:0,velocity:0},r);return Object.assign(i,t),(0,L.insert)(this.notes,i,"ticks"),this},e.prototype.addCC=function(t){var r=N.get(this),i=new we.ControlChange({controllerType:t.number},r);return delete t.number,Object.assign(i,t),Array.isArray(this.controlChanges[i.number])||(this.controlChanges[i.number]=[]),(0,L.insert)(this.controlChanges[i.number],i,"ticks"),this},e.prototype.addPitchBend=function(t){var r=N.get(this),i=new Ue.Pit
1chBend({},r);return Object.assign(i,t),(0,L.insert)(this.pitchBends,i,"ticks"),this},Object.defineProperty(e.prototype,"duration",{get:function(){if(!this.notes.length)return 0;for(var t=this.notes[this.notes.length-1].time+this.notes[this.notes.length-1].duration,r=0;r<this.notes.length-1;r++){var i=this.notes[r].time+this.notes[r].duration;t<i&&(t=i)}return t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"durationTicks",{get:function(){if(!this.notes.length)return 0;for(var t=this.notes[this.notes.length-1].ticks+this.notes[this.notes.length-1].durationTicks,r=0;r<this.notes.length-1;r++){var i=this.notes[r].ticks+this.notes[r].durationTicks;t<i&&(t=i)}return t},enumerable:!1,configurable:!0}),e.prototype.fromJSON=function(t){var r=this;this.name=t.name,this.channel=t.channel,this.instrument=new X.Instrument(void 0,this),this.instrument.fromJSON(t.instrument),t.endOfTrackTicks!==void 0&&(this.endOfTrackTicks=t.endOfTrackTicks);for(var i in t.controlChanges)t.controlChanges[i]&&t.controlChanges[i].forEach(function(a){r.addCC({number:a.number,ticks:a.ticks,value:a.value})});t.notes.forEach(function(a){r.addNote({durationTicks:a.durationTicks,midi:a.midi,ticks:a.ticks,velocity:a.velocity})})},e.prototype.toJSON=function(){for(var t={},r=0;r<127;r++)this.controlChanges.hasOwnProperty(r)&&(t[r]=this.controlChanges[r].map(function(a){return a.toJSON()}));var i={channel:this.channel,controlChanges:t,pitchBends:this.pitchBends.map(function(a){return a.toJSON()}),instrument:this.instrument.toJSON(),name:this.name,notes:this.notes.map(function(a){return a.toJSON()})};return this.endOfTrackTicks!==void 0&&(i.endOfTrackTicks=this.endOfTrackTicks),i},e}();P.Track=Se;var H={};function Ce(e){var t=[];return te(e,t),t}function te(e,t){for(var r=0;r<e.length;r++){var i=e[r];Array.isArray(i)?te(i,t):t.push(i)}}const Me=Object.freeze(Object.defineProperty({__proto__:null,flatten:Ce},Symbol.toStringTag,{value:"Module"})),Oe=ie(Me);var U=M&&M.__spreadArray||function(e,t,r){if(r||arguments.length===2)for(var i=0,a=t.length,o;i<a;
1i++)(o||!(i in t))&&(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))};Object.defineProperty(H,"__esModule",{value:!0});H.encode=void 0;var Pe=E,Fe=_,Be=Oe;function Ne(e,t){return[{absoluteTime:e.ticks,channel:t,deltaTime:0,noteNumber:e.midi,type:"noteOn",velocity:Math.floor(e.velocity*127)},{absoluteTime:e.ticks+e.durationTicks,channel:t,deltaTime:0,noteNumber:e.midi,type:"noteOff",velocity:Math.floor(e.noteOffVelocity*127)}]}function _e(e){return(0,Be.flatten)(e.notes.map(function(t){return Ne(t,e.channel)}))}function Ee(e,t){return{absoluteTime:e.ticks,channel:t,controllerType:e.number,deltaTime:0,type:"controller",value:Math.floor(e.value*127)}}function je(e){for(var t=[],r=0;r<127;r++)e.controlChanges.hasOwnProperty(r)&&e.controlChanges[r].forEach(function(i){t.push(Ee(i,e.channel))});return t}function De(e,t){return{absoluteTime:e.ticks,channel:t,deltaTime:0,type:"pitchBend",value:e.value}}function Ae(e){var t=[];return e.pitchBends.forEach(function(r){t.push(De(r,e.channel))}),t}function Ve(e){return{absoluteTime:0,channel:e.channel,deltaTime:0,programNumber:e.instrument.number,type:"programChange"}}function He(e){return{absoluteTime:0,deltaTime:0,meta:!0,text:e,type:"trackName"}}function qe(e){return{absoluteTime:e.ticks,deltaTime:0,meta:!0,microsecondsPerBeat:Math.floor(6e7/e.bpm),type:"setTempo"}}function Je(e){return{absoluteTime:e.ticks,deltaTime:0,denominator:e.timeSignature[1],meta:!0,metronome:24,numerator:e.timeSignature[0],thirtyseconds:8,type:"timeSignature"}}function Le(e){var t=Fe.keySignatureKeys.indexOf(e.key);return{absoluteTime:e.ticks,deltaTime:0,key:t+7,meta:!0,scale:e.scale==="major"?0:1,type:"keySignature"}}function We(e){return{absoluteTime:e.ticks,deltaTime:0,meta:!0,text:e.text,type:e.type}}function Re(e){var t={header:{format:1,numTracks:e.tracks.length+1,ticksPerBeat:e.header.ppq},tracks:U([U(U(U(U([{absoluteTime:0,deltaTime:0,meta:!0,text:e.header.n
1ame,type:"trackName"}],e.header.keySignatures.map(function(r){return Le(r)}),!0),e.header.meta.map(function(r){return We(r)}),!0),e.header.tempos.map(function(r){return qe(r)}),!0),e.header.timeSignatures.map(function(r){return Je(r)}),!0)],e.tracks.map(function(r){return U(U(U([He(r.name),Ve(r)],_e(r),!0),je(r),!0),Ae(r),!0)}),!0)};return t.tracks=t.tracks.map(function(r){r=r.sort(function(a,o){return a.absoluteTime-o.absoluteTime});var i=0;return r.forEach(function(a){a.deltaTime=a.absoluteTime-i,i=a.absoluteTime,delete a.absoluteTime}),r.push({deltaTime:0,meta:!0,type:"endOfTrack"}),r}),new Uint8Array((0,Pe.writeMidi)(t))}H.encode=Re;(function(e){var t=M&&M.__awaiter||function(d,s,h,y){function b(l){return l instanceof h?l:new h(function(I){I(l)})}return new(h||(h=Promise))(function(l,I){function w(v){try{p(y.next(v))}catch(O){I(O)}}function x(v){try{p(y.throw(v))}catch(O){I(O)}}function p(v){v.done?l(v.value):b(v.value).then(w,x)}p((y=y.apply(d,s||[])).next())})},r=M&&M.__generator||function(d,s){var h={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},y,b,l,I;return I={next:w(0),throw:w(1),return:w(2)},typeof Symbol=="function"&&(I[Symbol.iterator]=function(){return this}),I;function w(p){return function(v){return x([p,v])}}function x(p){if(y)throw new TypeError("Generator is already executing.");for(;h;)try{if(y=1,b&&(l=p[0]&2?b.return:p[0]?b.throw||((l=b.return)&&l.call(b),0):b.next)&&!(l=l.call(b,p[1])).done)return l;switch(b=0,l&&(p=[p[0]&2,l.value]),p[0]){case 0:case 1:l=p;break;case 4:return h.label++,{value:p[1],done:!1};case 5:h.label++,b=p[1],p=[0];continue;case 7:p=h.ops.pop(),h.trys.pop();continue;default:if(l=h.trys,!(l=l.length>0&&l[l.length-1])&&(p[0]===6||p[0]===2)){h=0;continue}if(p[0]===3&&(!l||p[1]>l[0]&&p[1]<l[3])){h.label=p[1];break}if(p[0]===6&&h.label<l[1]){h.label=l[1],l=p;break}if(l&&h.label<l[2]){h.label=l[2],h.ops.push(p);break}l[2]&&h.ops.pop(),h.trys.pop();continue}p=s.call(d,h)}catch(v){p=[6,v],b=0}finally{y=l=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}};Object.defineProperty(e,"__esModule",{value:!0}),e.Header=e.Track=e.Midi=void 0;var i=E,a=_,o=P,n=H,f=function(){function d(s){var h=this,y=null;if(s){var b=s instanceof ArrayBuffer?new Uint8Array(s):s;y=(0,i.parseMidi)(b),y.tracks.forEach(function(l){var I=0;l.forEach(function(w){I+=w.deltaTime,w.absoluteTime=I})}),y.tracks=m(y.tracks)}this.header=new a.Header(y),this.tracks=[],s&&(this.tracks=y.tracks.map(function(l){return new o.Track(l,h.header)}),y.header.format===1&&this.tracks[0].duration===0&&this.tracks.shift())}return d.fromUrl=function(s){return t(this,void 0,void 0,function(){var h,y;return r(this,function(b){switch(b.label){case 0:return[4,fetch(s)];case 1:return h=b.sent(),h.ok?[4,h.arrayBuffer()]:[3,3];case 2:return y=b.sent(),[2,new d(y)];case 3:throw new Error("Could not load '".concat(s,"'"))}})})},Object.defineProperty(d.prototype,"name",{get:function(){return this.header.name},set:function(s){this.header.name=s},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"duration",{get:function(){var s=this.tracks.map(function(h){return h.duration});return Math.max.apply(Math,s)},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"durationTicks",{get:function(){var s=this.tracks.map(function(h){return h.durationTicks});return Math.max.apply(Math,s)},enumerable:!1,configurable:!0}),d.prototype.addTrack=function(){var s=new o.Track(void 0,this.header);return this.tracks.push(s),s},d.prototype.toArray=function(){return(0,n.encode)(this)},d.prototype.toJSON=function(){return{header:this.header.toJSON(),tracks:this.tracks.map(function(s){return s.toJSON()})}},d.prototype.fromJSON=function(s){var h=this;this.header=new a.Header,this.header.fromJSON(s.header),this.tracks=s.tracks.map(function(y){var b=new o.Track(void 0,h.header);return b.fromJSON(y),b})},d.prototype.clone=function(){var s=new d;return s.fromJSON(this.toJSON()),s},d}();e.Midi=f;var c=P;Object.defineProperty(e,"Track",{enumerable:!0,get:function(){return c.Track}});var u=_;Object.defineProperty(e,"Header",{enumerable:!0,get:function(){return u.Header}});function m(d){for(var s=[],h=0;h<d.length;h++)for(var y=s.length,b=new Map,l=Array(16).fill(0),I=0,w=d[h];I<w.length;I++){var x=w[I],p=y,v=x.channel;if(v!==void 0){x.type==="programChange"&&(l[v]=x.programNumber);var O=l[v],q="".concat(O," ").concat(v);b.has(q)?p=b.get(q):(p=y+b.size,b.set(q,p))}s[p]||s.push([]),s[p].push(x)}return s}})(G);class ze{static parseMIDI(t){try{const r=new G.Midi(t),i=[];return r.tracks.forEach((a,o)=>
1{a.notes.forEach(n=>{i.push({time:n.time,duration:n.duration,pitch:n.midi,velocity:n.velocity,track:o,channel:a.channel})})}),i.sort((a,o)=>a.time-o.time),console.log(`Parsed ${i.length} notes from ${r.tracks.length} tracks`),i}catch(r){throw console.error("MIDI parsing error:",r),new Error(`Failed to parse MIDI: ${r instanceof Error?r.message:"Unknown error"}`)}}static getMIDIInfo(t){var r;try{const i=new G.Midi(t);return{duration:i.duration,trackCount:i.tracks.length,noteCount:i.tracks.reduce((a,o)=>a+o.notes.length,0),tempo:((r=i.header.tempos[0])==null?void 0:r.bpm)||120}}catch(i){return console.error("MIDI info extraction error:",i),{duration:0,trackCount:0,noteCount:0,tempo:120}}}}const W="https://bitmidi.com",Ge="Sorry, it seems BitMidi search is down right now. Please try again later.";class R extends Error{constructor(t){super(Ge),this.name="BitMidiSearchUnavailableError",t instanceof Error&&(this.cause=t)}}async function Ke(e){var f;const t=`${W}/api/midi/search?q=${encodeURIComponent(e)}`;let r;try{r=await fetch(t,{cache:"no-store"})}catch(c){throw new R(c)}if(!r.ok)throw new R(`HTTP ${r.status}`);let i;try{i=await r.json()}catch(c){throw new R(c)}const a=(f=i==null?void 0:i.result)==null?void 0:f.results;if(!Array.isArray(a))return[];const o=[];for(const c of a){const u=String(c.id??"").trim(),m=String(c.name??"").trim();if(!u||!m)continue;const d=c.downloadUrl||`/uploads/${u}.mid`,s=d.startsWith("http")?d:`${W}${d}`,h=c.url||(c.slug?`/${c.slug}`:""),y=h.startsWith("http")?h:`${W}${h}`;o.push({id:`bitmidi_${u}`,title:m,source:"bitmidi",pageUrl:y,midiUrl:s,confidence:Xe(m,e)})}const n=new Set;return o.filter(c=>c.confidence<=.3||n.has(c.midiUrl)?!1:(n.add(c.midiUrl),!0)).sort((c,u)=>u.confidence-c.confidence).slice(0,10)}const $e=new Set(["the","and","or","but","in","on","at","to","for","of","with","by"]);function Y(e){return e.toLowerCase().replace(/[^\w\s]/g," ").split(/\s+/).filter(t=>t.length>1).filter(t=>!$e.has(t))}function Qe(e){const t=e.match(/^(.+?)\s*[-:]\s*(.+)$/);if(t)return{artist:t[1].trim(),song:t[2].trim()};const r=e.split(/\s+/);if(r.length>=3){const i=r.slice(0,2).join(" "),a=r.slice(2).join(" ");return a.length>i.length?{artist:i,song:a}:{artist:r[0],song:r.slice(1).join(" ")}}return null}function Xe(e,t){const r=e.toLowerCase(),i=t.toLowerCase();let a=0;const o=Y(r),n=Y(i);r===i?a+=1:r.includes(i)&&(a+=.8);const f=Qe(i);if(f){const u=r.includes(f.artist),m=r.includes(f.song);u&&m?a+=.9:u?a+=.4:m&&(a+=.5)}else if(n.length>0){const m=n.filter(d=>o.some(s=>s.includes(d)||d.includes(s))).length/n.length;a+=m*.6,m===1&&(a+=.2)}const c=[{pattern:/karaoke|kar|midkar/,penalty:.3},{pattern:/vocal|lyrics/,penalty:.2},{pattern:/demo|test|sample/,penalty:.2},{pattern:/incomplete|broken/,penalty:.5}];for(const{pattern:u,penalty:m}of c)u.test(r)&&(a-=m);return e.includes(".mid")&&(a+=.1),a+=.1,Math.max(0,Math.min(1,a))}const z={};class et{constructor(t){$(this,"baseUrl");const r=z==null?void 0:z.VITE_API_URL;t?this.baseUrl=t:r?this.baseUrl=r:!1?this.baseUrl="http://localhost:3001":this.baseUrl=""}async fetchWithRetry(t,r,i=2e4){const a=async()=>{const o=new AbortController,n=window.setTimeout(()=>o.abort(),i);try{return await fetch(t,{...r,cache:"no-store",signal:o.signal})}finally{window.clearTimeout(n)}};try{return await a()}catch{return await new Promise(n=>window.setTimeout(n,200)),await a()}}async search(t){return await Ke(t)}async fetchMIDI(t){if(this.isBitMidiUrl(t))try{const r=await this.fetchWithRetry(t);if(r.ok){const i=await r.arrayBuffer();if(i.byteLength>=14)return i}}catch{}try{const r=await this.fetchWithRetry(`${this.baseUrl}/api/midi/fetch?u=${encodeURIComponent(t)}`);if(!r.ok)throw new Error(`Fetch failed: ${r.status}`);return await r.arrayBuffer()}catch(r){return console.error("MIDI fetch error:",r),null}}async parseMIDI(t){try{const r=await this.fetchMIDI(t);if(!r)return null;const i=ze.getMIDIInfo(r);return{durationSec:i.duration,tempoBpm:i.tempo,tracks:[],noteCount:i.noteCount,issues:[]}}catch(r){return console.error("MIDI parse error:",r),null}}isBitMidiUrl(t){try{const r=new URL(t).hostname.toLowerCase();return r==="bitmidi.com"||r.endsWith(".bitmidi.com")}catch{return!1}}async checkHealth(){try{return(await fetch(`${this.baseUrl}/health`)).ok}catch{return!1}}}export{Ge as B,et as M,ze as a,Ze as b,G as c,ie as g};
2//# sourceMappingURL=MIDIService-CF3kZgy9.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.