UNPKG

museaikit

Version:

A powerful music-focused AI toolkit

1 lines 270 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@tensorflow/tfjs"),require("tone")):"function"==typeof define&&define.amd?define(["tf","Tone"],e):"object"==typeof exports?exports.core=e(require("@tensorflow/tfjs"),require("tone")):t.core=e(t.tf,t.Tone)}(self,((__WEBPACK_EXTERNAL_MODULE__6364__,__WEBPACK_EXTERNAL_MODULE__4446__)=>(()=>{var __webpack_modules__={381:t=>{"use strict";t.exports={}},488:(t,e,n)=>{"use strict";n.r(e),n.d(e,{DEFAULT_DRUM_PITCH_CLASSES:()=>o.DEFAULT_DRUM_PITCH_CLASSES,DataConverter:()=>h,DrumRollConverter:()=>m,DrumsConverter:()=>p,DrumsOneHotConverter:()=>d,GrooveConverter:()=>T,MelodyConverter:()=>f,MelodyRhythmConverter:()=>S,MelodyShapeConverter:()=>y,MultitrackConverter:()=>P,TrioConverter:()=>b,TrioRhythmConverter:()=>w,converterFromSpec:()=>l});var i=n(6364),r=n(1758),o=n(5447),s=n(8171),a=n(584),u=n(3920),c=n(2596);function l(t){switch(t.type){case"MelodyConverter":return new f(t.args);case"MelodyRhythmConverter":return new S(t.args);case"MelodyShapeConverter":return new y(t.args);case"DrumsConverter":return new p(t.args);case"DrumRollConverter":return new m(t.args);case"TrioConverter":return new b(t.args);case"TrioRhythmConverter":return new w(t.args);case"DrumsOneHotConverter":return new d(t.args);case"MultitrackConverter":return new P(t.args);case"GrooveConverter":return new T(t.args);default:throw new Error(`Unknown DataConverter type: ${t}`)}}class h{numSteps;numSegments;NUM_SPLITS=0;SEGMENTED_BY_TRACK=!1;constructor(t){this.numSteps=t.numSteps,this.numSegments=t.numSegments}tensorSteps(t){return i.scalar(t.shape[0],"int32")}}class p extends h{pitchClasses;pitchToClass;depth;endTensor;constructor(t){super(t),this.pitchClasses=t.pitchClasses||o.DEFAULT_DRUM_PITCH_CLASSES,this.pitchToClass=new Map;for(let t=0;t<this.pitchClasses.length;++t)this.pitchClasses[t].forEach((e=>{this.pitchToClass.set(e,t)}));this.depth=this.pitchClasses.length+1}toTensor(t){c.assertIsQuantizedSequence(t);const e=this.numSteps||t.totalQuantizedSteps,n=i.buffer([e,this.pitchClasses.length+1],"int32");for(let t=0;t<e;++t)n.set(1,t,-1);return t.notes.forEach((t=>{n.set(1,t.quantizedStartStep,this.pitchToClass.get(t.pitch)),n.set(0,t.quantizedStartStep,-1)})),n.toTensor()}async toNoteSequence(t,e,n){const i=c.createQuantizedNoteSequence(e,n),o=t.argMax(1),s=await o.data();o.dispose();for(let t=0;t<s.length;++t)for(let e=0;e<this.pitchClasses.length;e++)s[t]>>e&1&&i.notes.push(r.A.Note.create({pitch:this.pitchClasses[e][0],quantizedStartStep:t,quantizedEndStep:t+1,isDrum:!0}));return i.totalQuantizedSteps=s.length,i}}class m extends p{async toNoteSequence(t,e,n){const i=c.createQuantizedNoteSequence(e,n),o=await t.data();for(let e=0;e<t.shape[0];++e){const t=o.slice(e*this.pitchClasses.length,(e+1)*this.pitchClasses.length);for(let n=0;n<t.length;++n)t[n]&&i.notes.push(r.A.Note.create({pitch:this.pitchClasses[n][0],quantizedStartStep:e,quantizedEndStep:e+1,isDrum:!0}))}return i.totalQuantizedSteps=t.shape[0],i}}class d extends p{constructor(t){super(t),this.depth=Math.pow(2,this.pitchClasses.length)}toTensor(t){c.assertIsRelativeQuantizedSequence(t);const e=this.numSteps||t.totalQuantizedSteps,n=Array(e).fill(0);for(const{pitch:e,quantizedStartStep:i}of t.notes)n[i]+=Math.pow(2,this.pitchToClass.get(e));return i.tidy((()=>i.oneHot(i.tensor1d(n,"int32"),this.depth)))}}class f extends h{minPitch;maxPitch;ignorePolyphony;depth;endTensor;NOTE_OFF=1;FIRST_PITCH=2;constructor(t){super(t),this.minPitch=t.minPitch,this.maxPitch=t.maxPitch,this.ignorePolyphony=t.ignorePolyphony,this.depth=t.maxPitch-t.minPitch+1+this.FIRST_PITCH}toTensor(t){const e=a.Melody.fromNoteSequence(t,this.minPitch,this.maxPitch,this.ignorePolyphony,this.numSteps);return i.tidy((()=>i.oneHot(i.tensor(e.events,[e.events.length],"int32"),this.depth)))}async toNoteSequence(t,e,n){const i=t.argMax(1),r=await i.data();i.dispose();return new a.Melody(r,this.minPitch,this.maxPitch).toNoteSequence(e,n)}}class g extends h{minPitch;maxPitch;ignorePolyphony;melodyControl;depth;endTensor;constructor(t,e){super(t),this.minPitch=t.minPitch,this.maxPitch=t.maxPitch,this.ignorePolyphony=t.ignorePolyphony,this.melodyControl=e,this.depth=e.depth}toTensor(t){const e=a.Melody.fromNoteSequence(t,this.minPitch,this.maxPitch,this.ignorePolyphony,this.numSteps);return this.melodyControl.extract(e)}}class S extends g{constructor(t){super(t,new a.MelodyRhythm)}async toNoteSequence(t,e,n){const i=c.createQuantizedNoteSequence(e,n),s=await t.data();for(let t=0;t<s.length;++t)s[t]&&i.notes.push(r.A.Note.create({pitch:o.DEFAULT_DRUM_PITCH_CLASSES[1][0],quantizedStartStep:t,quantizedEndStep:t+1,isDrum:!0}));return i.totalQuantizedSteps=s.length,i}}class y extends g{constructor(t){super(t,new a.MelodyShape)}async toNoteSequence(t,e,n){const i=c.createQuantizedNoteSequence(e,n),o=t.argMax(1),a=await o.data();o.dispose();let u=Math.round((this.maxPitch+this.minPitch)/2);for(let t=0;t<a.length;++t){switch(a[t]){case 0:u-=1,u<this.minPitch&&(u=this.minPitch,s.log("Pitch range exceeded when creating NoteSequence from shape.","MelodyShapeConverter"));break;case 2:u+=1,u>this.maxPitch&&(u=this.maxPitch,s.log("Pitch range exceeded when creating NoteSequence from shape.","MelodyShapeConverter"))}i.notes.push(r.A.Note.create({pitch:u,quantizedStartStep:t,quantizedEndStep:t+1}))}return i.totalQuantizedSteps=a.length,i}}class b extends h{melConverter;bassConverter;drumsConverter;depth;endTensor;NUM_SPLITS=3;MEL_PROG_RANGE=[0,31];BASS_PROG_RANGE=[32,39];constructor(t){super(t),t.melArgs.numSteps=t.numSteps,t.bassArgs.numSteps=t.numSteps,t.drumsArgs.numSteps=t.numSteps,this.melConverter=new f(t.melArgs),this.bassConverter=new f(t.bassArgs),this.drumsConverter=new d(t.drumsArgs),this.depth=this.melConverter.depth+this.bassConverter.depth+this.drumsConverter.depth}toTensor(t){c.assertIsQuantizedSequence(t);const e=c.clone(t),n=c.clone(t),r=c.clone(t);return e.notes=t.notes.filter((t=>!t.isDrum&&t.program>=this.MEL_PROG_RANGE[0]&&t.program<=this.MEL_PROG_RANGE[1])),n.notes=t.notes.filter((t=>!t.isDrum&&t.program>=this.BASS_PROG_RANGE[0]&&t.program<=this.BASS_PROG_RANGE[1])),r.notes=t.notes.filter((t=>t.isDrum)),i.tidy((()=>i.concat([this.melConverter.toTensor(e),this.bassConverter.toTensor(n),this.drumsConverter.toTensor(r)],-1)))}async toNoteSequence(t,e,n){const r=i.split(t,[this.melConverter.depth,this.bassConverter.depth,this.drumsConverter.depth],-1),o=await this.melConverter.toNoteSequence(r[0],e,n);o.notes.forEach((t=>{t.instrument=0,t.program=0}));const s=await this.bassConverter.toNoteSequence(r[1],e,n);o.notes.push(...s.notes.map((t=>(t.instrument=1,t.program=this.BASS_PROG_RANGE[0],t))));const a=await this.drumsConverter.toNoteSequence(r[2],e,n);return o.notes.push(...a.notes.map((t=>(t.instrument=2,t)))),r.forEach((t=>t.dispose())),o}}class w extends h{trioConverter;depth;endTensor;NUM_SPLITS=3;constructor(t){super(t),this.trioConverter=new b(t),this.depth=3}toTensor(t){return i.tidy((()=>{const e=this.trioConverter.toTensor(t),n=i.split(e,[this.trioConverter.melConverter.depth,this.trioConverter.bassConverter.depth,this.trioConverter.drumsConverter.depth],1),r=i.argMax(n[0],1),o=i.argMax(n[1],1),s=i.argMax(n[2],1),a=i.greater(r,1),u=i.greater(o,1),c=i.greater(s,0);return i.stack([a,u,c],1)}))}async toNoteSequence(t,e,n){const s=i.split(t,3,1),a=await Promise.all(s.map((t=>t.data()))),u=c.createQuantizedNoteSequence(e,n);for(let t=0;t<this.numSteps;++t)a[0][t]&&u.notes.push(r.A.Note.create({pitch:72,quantizedStartStep:t,quantizedEndStep:t+1,instrument:0,program:0})),a[1][t]&&u.notes.push(r.A.Note.create({pitch:36,quantizedStartStep:t,quantizedEndStep:t+1,instrument:1,program:32})),a[2][t]&&u.notes.push(r.A.Note.create({pitch:o.DEFAULT_DRUM_PITCH_CLASSES[1][0],quantizedStartStep:t,quantizedEndStep:t+1,instrument:2,isDrum:!0}));return u.totalQuantizedSteps=this.numSteps,u}}class P extends h{SEGMENTED_BY_TRACK=!0;stepsPerQuarter;totalSteps;numVelocityBins;minPitch;maxPitch;numPitches;performanceEventDepth;numPrograms;endToken;depth;endTensor;constructor(t){super(t),this.stepsPerQuarter=t.stepsPerQuarter,this.totalSteps=t.totalSteps,this.numVelocityBins=t.numVelocityBins,this.minPitch=t.minPitch?t.minPitch:o.MIN_MIDI_PITCH,this.maxPitch=t.maxPitch?t.maxPitch:o.MAX_MIDI_PITCH,this.numPitches=this.maxPitch-this.minPitch+1,this.performanceEventDepth=2*this.numPitches+this.totalSteps+this.numVelocityBins,this.numPrograms=o.MAX_MIDI_PROGRAM-o.MIN_MIDI_PROGRAM+2,this.endToken=this.performanceEventDepth+this.numPrograms,this.depth=this.endToken+1,this.endTensor=i.tidy((()=>i.oneHot(i.tensor1d([this.endToken],"int32"),this.depth).as1D()))}trackToTensor(t){const e=this.numSteps/this.numSegments;let n;if(t){for(;t.events.length>e-2;)t.events.pop();n=i.buffer([t.events.length+2],"int32"),n.set(this.performanceEventDepth+(t.isDrum?this.numPrograms-1:t.program),0),t.events.forEach(((t,e)=>{switch(t.type){case"note-on":n.set(t.pitch-this.minPitch,e+1);break;case"note-off":n.set(this.numPitches+t.pitch-this.minPitch,e+1);break;case"time-shift":n.set(2*this.numPitches+t.steps-1,e+1);break;case"velocity-change":n.set(2*this.numPitches+this.totalSteps+t.velocityBin-1,e+1);break;default:throw new Error(`Unrecognized performance event: ${t}`)}})),n.set(this.endToken,t.events.length+1)}else n=i.buffer([1],"int32",new Int32Array([this.endToken]));return i.tidy((()=>{const t=i.oneHot(n.toTensor(),this.depth);return t.pad([[0,e-t.shape[0]],[0,0]])}))}toTensor(t){if(c.assertIsRelativeQuantizedSequence(t),t.quantizationInfo.stepsPerQuarter!==this.stepsPerQuarter)throw new Error(`Steps per quarter note mismatch: ${t.quantizationInfo.stepsPerQuarter} != ${this.stepsPerQuarter}`);const e=c.clone(t);e.notes=t.notes.filter((t=>t.pitch>=this.minPitch&&t.pitch<=this.maxPitch));const n=new Set(e.notes.map((t=>t.instrument))),r=Array.from(n).map((t=>u.Performance.fromNoteSequence(e,this.totalSteps,this.numVelocityBins,t))).sort(((t,e)=>e.isDrum?-1:t.isDrum?1:t.program-e.program));for(;r.length>this.numSegments;)r.pop();for(r.forEach((t=>t.setNumSteps(this.totalSteps)));r.length<this.numSegments;)r.push(void 0);return i.tidy((()=>i.concat(r.map((t=>this.trackToTensor(t))),0)))}tokensToTrack(t){const e=t.indexOf(this.endToken),n=e>=0?e:t.length,i=t.slice(0,n),r=i.filter((t=>t<this.performanceEventDepth)),o=i.filter((t=>t>=this.performanceEventDepth)),[s,a]=o.length?o[0]-this.performanceEventDepth<this.numPrograms-1?[o[0]-this.performanceEventDepth,!1]:[0,!0]:[0,!1],c=Array.from(r).map((t=>{if(t<this.numPitches)return{type:"note-on",pitch:this.minPitch+t};if(t<2*this.numPitches)return{type:"note-off",pitch:this.minPitch+t-this.numPitches};if(t<2*this.numPitches+this.totalSteps)return{type:"time-shift",steps:t-2*this.numPitches+1};if(t<2*this.numPitches+this.totalSteps+this.numVelocityBins)return{type:"velocity-change",velocityBin:t-2*this.numPitches-this.totalSteps+1};throw new Error(`Invalid performance event token: ${t}`)}));return new u.Performance(c,this.totalSteps,this.numVelocityBins,s,a)}async toNoteSequence(t,e=this.stepsPerQuarter,n){const r=c.createQuantizedNoteSequence(e,n);r.totalQuantizedSteps=this.totalSteps;const o=i.tidy((()=>i.split(t.argMax(1),this.numSegments)));return(await Promise.all(o.map((async t=>{const e=await t.data(),n=this.tokensToTrack(e);return t.dispose(),n})))).forEach(((t,e)=>{t.setNumSteps(this.totalSteps),r.notes.push(...t.toNoteSequence(e).notes)})),r}}class T extends h{stepsPerQuarter;humanize;tapify;pitchClasses;pitchToClass;depth;endTensor;splitInstruments;TAPIFY_CHANNEL=3;constructor(t){super(t),this.stepsPerQuarter=t.stepsPerQuarter||o.DEFAULT_STEPS_PER_QUARTER,this.pitchClasses=t.pitchClasses||o.DEFAULT_DRUM_PITCH_CLASSES,this.pitchToClass=new Map;for(let t=0;t<this.pitchClasses.length;++t)this.pitchClasses[t].forEach((e=>{this.pitchToClass.set(e,t)}));this.humanize=t.humanize||!1,this.tapify=t.tapify||!1,this.splitInstruments=t.splitInstruments||!1,this.depth=3}toTensor(t){const e=c.isRelativeQuantizedSequence(t)?t:c.quantizeNoteSequence(t,this.stepsPerQuarter),n=this.numSteps,r=e.tempos&&e.tempos.length?e.tempos[0].qpm:o.DEFAULT_QUARTERS_PER_MINUTE,s=60/r/this.stepsPerQuarter,a=[];for(let t=0;t<n;++t)a.push(new Map);e.notes.forEach((t=>{if(!this.tapify&&!this.pitchToClass.has(t.pitch))return;const e=t.quantizedStartStep;if(e>=a.length)throw Error(`Model does not support sequences with more than ${n} steps (${n*s} seconds at qpm ${r}).`);const i=this.tapify?this.TAPIFY_CHANNEL:this.pitchToClass.get(t.pitch);(!a[e].has(i)||a[e].get(i).velocity<t.velocity)&&a[e].set(i,t)}));const u=this.pitchClasses.length,l=i.buffer([n,u]),h=i.buffer([n,u]),p=i.buffer([n,u]);function m(t){if(void 0===t.startTime)return 0;const e=t.startTime;return 2*(t.quantizedStartStep*s-e)/s}for(let t=0;t<n;++t)for(let e=0;e<u;++e){const n=a[t].get(e);l.set(n?1:0,t,e),this.humanize||this.tapify||h.set(n?n.velocity/o.MAX_MIDI_VELOCITY:0,t,e),this.humanize||p.set(n?m(n):0,t,e)}return i.tidy((()=>{const t=l.toTensor(),e=h.toTensor(),r=p.toTensor(),o=this.splitInstruments?n*u:n;return i.concat([t.as2D(o,-1),e.as2D(o,-1),r.as2D(o,-1)],1)}))}async toNoteSequence(t,e,n=o.DEFAULT_QUARTERS_PER_MINUTE){if(e&&e!==this.stepsPerQuarter)throw Error("`stepsPerQuarter` is set by the model.");e=this.stepsPerQuarter;const i=this.splitInstruments?t.shape[0]/this.pitchClasses.length:t.shape[0],s=60/n/this.stepsPerQuarter,a=r.A.create({totalTime:i*s,tempos:[{qpm:n}]}),u=await t.data();function c(t,e,n){return Math.min(Math.max(t,e),n)}const l=this.pitchClasses.length;for(let t=0;t<i;++t){const e=u.slice(t*l*this.depth,(t+1)*l*this.depth);for(let n=0;n<l;++n){const i=e[this.splitInstruments?n*this.depth:n],u=e[this.splitInstruments?n*this.depth+1:l+n],h=e[this.splitInstruments?n*this.depth+2:2*l+n];if(i>.5){const e=c(Math.round(u*o.MAX_MIDI_VELOCITY),o.MIN_MIDI_VELOCITY,o.MAX_MIDI_VELOCITY),i=c(h/2,-.5,.5);a.notes.push(r.A.Note.create({pitch:this.pitchClasses[n][0],startTime:(t-i)*s,endTime:(t-i+1)*s,velocity:e,isDrum:!0}))}}}return a}}},584:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Melody:()=>u,MelodyRegister:()=>h,MelodyRhythm:()=>c,MelodyShape:()=>l,NOTE_OFF:()=>a,NO_EVENT:()=>s});var i=n(6364),r=n(1758),o=n(2596);const s=0,a=1;class u{events;minPitch;maxPitch;constructor(t,e,n){this.events=t,this.minPitch=e,this.maxPitch=n}static fromNoteSequence(t,e,n,i=!0,r){o.assertIsQuantizedSequence(t);const s=t.notes.sort(((t,e)=>t.quantizedStartStep===e.quantizedStartStep?e.pitch-t.pitch:t.quantizedStartStep-e.quantizedStartStep)),c=new Int32Array(r||t.totalQuantizedSteps);let l=-1;return s.forEach((t=>{if(t.quantizedStartStep===l){if(i)return;throw new Error("`NoteSequence` is not monophonic.")}if(t.pitch<e||t.pitch>n)throw Error(`\`NoteSequence\` has a pitch outside of the valid range: ${t.pitch}`);c[t.quantizedStartStep]=t.pitch-e+2,c[t.quantizedEndStep]=a,l=t.quantizedStartStep})),new u(c,e,n)}toNoteSequence(t,e){const n=o.createQuantizedNoteSequence(t,e);let i=null;for(let t=0;t<this.events.length;++t){const e=this.events[t];switch(e){case s:break;case a:i&&(i.quantizedEndStep=t,n.notes.push(i),i=null);break;default:i&&(i.quantizedEndStep=t,n.notes.push(i)),i=r.A.Note.create({pitch:e-2+this.minPitch,quantizedStartStep:t})}}return i&&(i.quantizedEndStep=this.events.length,n.notes.push(i)),n.totalQuantizedSteps=this.events.length,n}}class c{depth=1;extract(t){const e=t.events.length,n=i.buffer([e,1]);for(let i=0;i<e;++i)n.set(t.events[i]>=2?1:0,i,0);return n.toTensor().as2D(e,1)}}class l{depth=3;extract(t){const e=t.events.length,n=i.buffer([e,3]);let r=null,o=null;for(let i=0;i<e;++i)if(t.events[i]>=2){if(null!==r){let e;0===n.get(r,0)&&0===n.get(r,1)&&0===n.get(r,2)&&(r=-1),e=t.events[i]<o?0:t.events[i]>o?2:1;for(let t=i;t>r;--t)n.set(1,t,e)}r=i,o=t.events[i]}if(r!==e-1)if(null===r||0===n.get(r,0)&&0===n.get(r,1)&&0===n.get(r,2))for(let t=0;t<e;++t)n.set(1,t,1);else for(let t=e-1;t>r;--t)for(let e=0;e<3;e++)n.set(n.get(r,e),t,e);return n.toTensor().as2D(e,3)}}class h{boundaryPitches;depth;constructor(t){this.boundaryPitches=t,this.depth=t.length+1}meanMelodyPitch(t){let e=0,n=0,i=null;for(let r=0;r<t.events.length;++r)t.events[r]===a?i=null:t.events[r]>=2&&(i=t.minPitch+t.events[r]-2),null!==i&&(e+=i,n+=1);return n?e/n:null}extract(t){const e=t.events.length,n=this.meanMelodyPitch(t);if(null===n)return i.zeros([e,this.depth]);let r=0;for(;r<this.boundaryPitches.length&&n>=this.boundaryPitches[r];)r++;const o=i.buffer([e,this.depth]);for(let t=0;t<e;++t)o.set(1,t,r);return o.toTensor().as2D(e,this.depth)}}},649:(t,e,n)=>{e.parseMidi=n(9718),e.writeMidi=n(8062)},760:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(8871),r=new WeakMap,o=function(){function t(t,e){if(this.number=0,r.set(this,e),this.number=0,t){var n=t.find((function(t){return"programChange"===t.type}));n&&(this.number=n.programNumber)}}return Object.defineProperty(t.prototype,"name",{get:function(){return this.percussion?i.DrumKitByPatchID[this.number]:i.instrumentByPatchID[this.number]},set:function(t){var e=i.instrumentByPatchID.indexOf(t);-1!==e&&(this.number=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"family",{get:function(){return this.percussion?"drums":i.InstrumentFamilyByID[Math.floor(this.number/8)]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"percussion",{get:function(){return 9===r.get(this).channel},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{family:this.family,name:this.name,number:this.number}},t.prototype.fromJSON=function(t){this.number=t.number},t}();e.Instrument=o},955:(t,e,n)=>{"use strict";n.r(e),n.d(e,{userAgent:()=>i});const i=""},1137:(t,e,n)=>{"use strict";t.exports=u;var i,r=n(5382),o=r.LongBits,s=r.utf8;function a(t,e){return RangeError("index out of range: "+t.pos+" + "+(e||1)+" > "+t.len)}function u(t){this.buf=t,this.pos=0,this.len=t.length}var c,l="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new u(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new u(t);throw Error("illegal buffer")},h=function(){return r.Buffer?function(t){return(u.create=function(t){return r.Buffer.isBuffer(t)?new i(t):l(t)})(t)}:l};function p(){var t=new o(0,0),e=0;if(!(this.len-this.pos>4)){for(;e<3;++e){if(this.pos>=this.len)throw a(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*e)>>>0,t}for(;e<4;++e)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(e=0,this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw a(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function m(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}function d(){if(this.pos+8>this.len)throw a(this,8);return new o(m(this.buf,this.pos+=4),m(this.buf,this.pos+=4))}u.create=h(),u.prototype._slice=r.Array.prototype.subarray||r.Array.prototype.slice,u.prototype.uint32=(c=4294967295,function(){if(c=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return c;if((this.pos+=5)>this.len)throw this.pos=this.len,a(this,10);return c}),u.prototype.int32=function(){return 0|this.uint32()},u.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)},u.prototype.bool=function(){return 0!==this.uint32()},u.prototype.fixed32=function(){if(this.pos+4>this.len)throw a(this,4);return m(this.buf,this.pos+=4)},u.prototype.sfixed32=function(){if(this.pos+4>this.len)throw a(this,4);return 0|m(this.buf,this.pos+=4)},u.prototype.float=function(){if(this.pos+4>this.len)throw a(this,4);var t=r.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},u.prototype.double=function(){if(this.pos+8>this.len)throw a(this,4);var t=r.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},u.prototype.bytes=function(){var t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw a(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,n):e===n?new this.buf.constructor(0):this._slice.call(this.buf,e,n)},u.prototype.string=function(){var t=this.bytes();return s.read(t,0,t.length)},u.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw a(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw a(this)}while(128&this.buf[this.pos++]);return this},u.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},u._configure=function(t){i=t,u.create=h(),i._configure();var e=r.Long?"toLong":"toNumber";r.merge(u.prototype,{int64:function(){return p.call(this)[e](!1)},uint64:function(){return p.call(this)[e](!0)},sint64:function(){return p.call(this).zzDecode()[e](!1)},fixed64:function(){return d.call(this)[e](!0)},sfixed64:function(){return d.call(this)[e](!1)}})}},1168:(t,e,n)=>{"use strict";function i(t,e){const n={};t.forEach((t=>{n[t.pitch]||(n[t.pitch]=[]),n[t.pitch].push(t)}));const i=[];return Object.keys(n).forEach((t=>{const r=n[+t].sort(((t,e)=>t.startTime-e.startTime)),o=[];let s=r[0];for(let t=1;t<r.length;t++){const n=r[t];n.startTime-s.endTime<e||n.startTime<=s.endTime?s.endTime=Math.max(s.endTime,n.endTime):(o.push(s),s=n)}o.push(s),i.push(...o)})),i}function r(t,e){const n=t.slice().sort(((t,e)=>t.startTime-e.startTime));let i=!0;for(;i;){i=!1;for(let t=0;t<n.length;t++){for(let r=t+1;r<n.length;r++)if(n[t].pitch!==n[r].pitch){const o=n[t].startTime<n[r].endTime&&n[r].startTime<n[t].endTime,s=n[r].startTime-n[t].endTime;if(o||s<e&&s>=0){if(!(n[t].endTime-n[t].startTime>=n[r].endTime-n[r].startTime)){n[r].startTime=Math.min(n[t].startTime,n[r].startTime),n[r].endTime=Math.max(n[t].endTime,n[r].endTime),n.splice(t,1),i=!0;break}n[t].startTime=Math.min(n[t].startTime,n[r].startTime),n[t].endTime=Math.max(n[t].endTime,n[r].endTime),n.splice(r,1),i=!0;break}}if(i)break}}return n}function o(t,e){if(0===t.length)return t;const n=Math.min(...t.map((t=>t.startTime))),i=t.map((t=>({...t,startTime:t.startTime-n,endTime:t.endTime-n}))).slice().sort(((t,e)=>t.startTime-e.startTime)),r=[];let o=0;for(let t=0;t<i.length;t++){let n=Math.round(i[t].startTime/e)*e,s=Math.round(i[t].endTime/e)*e;if(s<=n&&(s=n+e),n-=o,s-=o,t>0){if(i[t].startTime-i[t-1].endTime<e){const e=n-r[t-1].endTime;e>0&&(n-=e,s-=e,o+=e)}}r.push({...i[t],startTime:n,endTime:s})}return r}function s(t,e,n,s){const a=o(r(i(t.notes.map((t=>({...t}))),n),n).filter((t=>t.endTime-t.startTime>=e)),s);return{...t,notes:a}}n.r(e),n.d(e,{cleanNoteSequence:()=>s,mergeDifferentPitchNotes:()=>r,mergeSamePitchNotes:()=>i,quantizeNoteTimes:()=>o})},1705:(t,e)=>{"use strict";function n(t){return["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"][t%12]}Object.defineProperty(e,"__esModule",{value:!0});var i,r,o=(i=/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,r={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},function(t){var e=i.exec(t),n=e[1],o=e[2];return r[n.toLowerCase()]+12*(parseInt(o,10)+1)}),s=new WeakMap,a=function(){function t(t,e,n){s.set(this,n),this.midi=t.midi,this.velocity=t.velocity,this.noteOffVelocity=e.velocity,this.ticks=t.ticks,this.durationTicks=e.ticks-t.ticks}return Object.defineProperty(t.prototype,"name",{get:function(){return t=this.midi,e=Math.floor(t/12)-1,n(t)+e.toString();var t,e},set:function(t){this.midi=o(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"octave",{get:function(){return Math.floor(this.midi/12)-1},set:function(t){var e=t-this.octave;this.midi+=12*e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pitch",{get:function(){return n(this.midi)},set:function(t){this.midi=12*(this.octave+1)+["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"].indexOf(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"duration",{get:function(){var t=s.get(this);return t.ticksToSeconds(this.ticks+this.durationTicks)-t.ticksToSeconds(this.ticks)},set:function(t){var e=s.get(this).secondsToTicks(this.time+t);this.durationTicks=e-this.ticks},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"time",{get:function(){return s.get(this).ticksToSeconds(this.ticks)},set:function(t){var e=s.get(this);this.ticks=e.secondsToTicks(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bars",{get:function(){return s.get(this).ticksToMeasures(this.ticks)},enumerable:!0,configurable:!0}),t.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}},t}();e.Note=a},1720:function(t,e,n){"use strict";var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function s(t){try{u(i.next(t))}catch(t){o(t)}}function a(t){try{u(i.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var o=n(649),s=n(8767),a=n(3752),u=n(5578),c=function(){function t(t){var e=this,n=null;t&&(t instanceof ArrayBuffer&&(t=new Uint8Array(t)),(n=o.parseMidi(t)).tracks.forEach((function(t){var e=0;t.forEach((function(t){e+=t.deltaTime,t.absoluteTime=e}))})),n.tracks=function(t){for(var e=[],n=0;n<t.length;n++)for(var i=e.length,r=new Map,o=Array(16).fill(0),s=0,a=t[n];s<a.length;s++){var u=a[s],c=i,l=u.channel;if(void 0!==l){"programChange"===u.type&&(o[l]=u.programNumber);var h=o[l]+" "+l;r.has(h)?c=r.get(h):(c=i+r.size,r.set(h,c))}e[c]||e.push([]),e[c].push(u)}return e}(n.tracks)),this.header=new a.Header(n),this.tracks=[],t&&(this.tracks=n.tracks.map((function(t){return new u.Track(t,e.header)})),1===n.header.format&&0===this.tracks[0].duration&&this.tracks.shift())}return t.fromUrl=function(e){return i(this,void 0,void 0,(function(){var n;return r(this,(function(i){switch(i.label){case 0:return[4,fetch(e)];case 1:return(n=i.sent()).ok?[4,n.arrayBuffer()]:[3,3];case 2:return[2,new t(i.sent())];case 3:throw new Error("could not load "+e)}}))}))},Object.defineProperty(t.prototype,"name",{get:function(){return this.header.name},set:function(t){this.header.name=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"duration",{get:function(){var t=this.tracks.map((function(t){return t.duration}));return Math.max.apply(Math,t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"durationTicks",{get:function(){var t=this.tracks.map((function(t){return t.durationTicks}));return Math.max.apply(Math,t)},enumerable:!0,configurable:!0}),t.prototype.addTrack=function(){var t=new u.Track(void 0,this.header);return this.tracks.push(t),t},t.prototype.toArray=function(){return s.encode(this)},t.prototype.toJSON=function(){return{header:this.header.toJSON(),tracks:this.tracks.map((function(t){return t.toJSON()}))}},t.prototype.fromJSON=function(t){var e=this;this.header=new a.Header,this.header.fromJSON(t.header),this.tracks=t.tracks.map((function(t){var n=new u.Track(void 0,e.header);return n.fromJSON(t),n}))},t.prototype.clone=function(){var e=new t;return e.fromJSON(this.toJSON()),e},t}();e.Midi=c;var l=n(5578);e.Track=l.Track;var h=n(3752);e.Header=h.Header},1758:(t,e,n)=>{"use strict";n.d(e,{A:()=>r});var i=n(7151),r=i.tensorflow.magenta.NoteSequence},1925:module=>{"use strict";function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(t){}return null}module.exports=inquire},1979:(t,e)=>{"use strict";var n=e;n.length=function(t){var e=t.length;if(!e)return 0;for(var n=0;--e%4>1&&"="===t.charAt(e);)++n;return Math.ceil(3*t.length)/4-n};for(var i=new Array(64),r=new Array(123),o=0;o<64;)r[i[o]=o<26?o+65:o<52?o+71:o<62?o-4:o-59|43]=o++;n.encode=function(t,e,n){for(var r,o=null,s=[],a=0,u=0;e<n;){var c=t[e++];switch(u){case 0:s[a++]=i[c>>2],r=(3&c)<<4,u=1;break;case 1:s[a++]=i[r|c>>4],r=(15&c)<<2,u=2;break;case 2:s[a++]=i[r|c>>6],s[a++]=i[63&c],u=0}a>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,s)),a=0)}return u&&(s[a++]=i[r],s[a++]=61,1===u&&(s[a++]=61)),o?(a&&o.push(String.fromCharCode.apply(String,s.slice(0,a))),o.join("")):String.fromCharCode.apply(String,s.slice(0,a))};var s="invalid encoding";n.decode=function(t,e,n){for(var i,o=n,a=0,u=0;u<t.length;){var c=t.charCodeAt(u++);if(61===c&&a>1)break;if(void 0===(c=r[c]))throw Error(s);switch(a){case 0:i=c,a=1;break;case 1:e[n++]=i<<2|(48&c)>>4,i=c,a=2;break;case 2:e[n++]=(15&i)<<4|(60&c)>>2,i=c,a=3;break;case 3:e[n++]=(3&i)<<6|c,a=0}}if(1===a)throw Error(s);return n-o},n.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},2596:(t,e,n)=>{"use strict";n.r(e),n.d(e,{BadTimeSignatureException:()=>a,MultipleTempoException:()=>c,MultipleTimeSignatureException:()=>s,NegativeTimeException:()=>u,QuantizationStatusException:()=>l,applySustainControlChanges:()=>M,assertIsAbsoluteQuantizedSequence:()=>T,assertIsQuantizedSequence:()=>y,assertIsRelativeQuantizedSequence:()=>w,clone:()=>h,concatenate:()=>_,createQuantizedNoteSequence:()=>v,isAbsoluteQuantizedSequence:()=>P,isQuantizedSequence:()=>S,isRelativeQuantizedSequence:()=>b,mergeConsecutiveNotes:()=>O,mergeInstruments:()=>A,quantizeNoteSequence:()=>g,quantizeToStep:()=>m,replaceInstruments:()=>I,split:()=>C,stepsPerQuarterToStepsPerSecond:()=>p,trim:()=>E,unquantizeSequence:()=>N});var i=n(1758),r=n(5447);const o=.5;class s extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class a extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class u extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class c extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class l extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}function h(t){return i.A.decode(i.A.encode(t).finish())}function p(t,e){return t*e/60}function m(t,e,n=o){const i=t*e;return Math.floor(i+(1-n))}function d(t){return t.controlChanges.concat(t.textAnnotations)}function f(t){if(t.tempos&&0!==t.tempos.length){if(t.tempos.sort(((t,e)=>t.time-e.time)),0!==t.tempos[0].time&&t.tempos[0].qpm!==r.DEFAULT_QUARTERS_PER_MINUTE)throw new c(`NoteSequence has an implicit tempo change from initial ${r.DEFAULT_QUARTERS_PER_MINUTE} qpm to ${t.tempos[0].qpm} qpm at ${t.tempos[0].time} seconds.`);for(let e=1;e<t.tempos.length;e++)if(t.tempos[e].qpm!==t.tempos[0].qpm)throw new c(`NoteSequence has at least one tempo change from ${t.tempos[0].qpm} qpm to ${t.tempos[e].qpm}qpm at ${t.tempos[e].time} seconds.`)}}function g(t,e){const n=h(t);if(n.quantizationInfo=i.A.QuantizationInfo.create({stepsPerQuarter:e}),n.timeSignatures.length>0){if(n.timeSignatures.sort(((t,e)=>t.time-e.time)),0!==n.timeSignatures[0].time&&(4!==n.timeSignatures[0].numerator||4!==n.timeSignatures[0].denominator))throw new s(`NoteSequence has an implicit change from initial 4/4 time signature to ${n.timeSignatures[0].numerator}/${n.timeSignatures[0].denominator} at ${n.timeSignatures[0].time} seconds.`);for(let t=1;t<n.timeSignatures.length;t++){const e=n.timeSignatures[t];if(e.numerator!==n.timeSignatures[0].numerator||e.denominator!==n.timeSignatures[0].denominator)throw new s(`NoteSequence has at least one time signature change from ${n.timeSignatures[0].numerator}/${n.timeSignatures[0].denominator} to ${e.numerator}/${e.denominator} at ${e.time} seconds`)}n.timeSignatures[0].time=0,n.timeSignatures=[n.timeSignatures[0]]}else{const t=i.A.TimeSignature.create({numerator:4,denominator:4,time:0});n.timeSignatures.push(t)}const o=n.timeSignatures[0];if(!(c=o.denominator)||c&c-1)throw new a(`Denominator is not a power of 2. Time signature: ${o.numerator}/${o.denominator}`);var c;if(0===o.numerator)throw new a(`Numerator is 0. Time signature: ${o.numerator}/${o.denominator}`);if(n.tempos.length>0)f(n),n.tempos[0].time=0,n.tempos=[n.tempos[0]];else{const t=i.A.Tempo.create({qpm:r.DEFAULT_QUARTERS_PER_MINUTE,time:0});n.tempos.push(t)}const l=p(e,n.tempos[0].qpm);return n.totalQuantizedSteps=m(t.totalTime,l),function(t,e){for(const n of t.notes){if(n.quantizedStartStep=m(n.startTime,e),n.quantizedEndStep=m(n.endTime,e),n.quantizedEndStep===n.quantizedStartStep&&(n.quantizedEndStep+=1),n.quantizedStartStep<0||n.quantizedEndStep<0)throw new u(`Got negative note time: start_step = ${n.quantizedStartStep}, end_step = ${n.quantizedEndStep}`);n.quantizedEndStep>t.totalQuantizedSteps&&(t.totalQuantizedSteps=n.quantizedEndStep)}d(t).forEach((t=>{if(t.quantizedStep=m(t.time,e),t.quantizedStep<0)throw new u(`Got negative event time: step = ${t.quantizedStep}`)}))}(n,l),n}function S(t){return t.quantizationInfo&&(t.quantizationInfo.stepsPerQuarter>0||t.quantizationInfo.stepsPerSecond>0)}function y(t){if(!S(t))throw new l(`NoteSequence ${t.id} is not quantized (missing quantizationInfo)`)}function b(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerQuarter>0}function w(t){if(!b(t))throw new l(`NoteSequence ${t.id} is not quantized or is quantized based on absolute timing`)}function P(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerSecond>0}function T(t){if(!P(t))throw new l(`NoteSequence ${t.id} is not quantized or is quantized based on relative timing`)}function N(t,e){w(t),f(t);const n=h(t);e?n.tempos&&n.tempos.length>0?n.tempos[0].qpm=e:n.tempos.push(i.A.Tempo.create({time:0,qpm:e})):e=t.tempos&&t.tempos.length>0?n.tempos[0].qpm:r.DEFAULT_QUARTERS_PER_MINUTE;const o=t=>t/n.quantizationInfo.stepsPerQuarter*(60/e);return n.totalTime=o(n.totalQuantizedSteps),n.notes.forEach((t=>{t.startTime=o(t.quantizedStartStep),t.endTime=o(t.quantizedEndStep),n.totalTime=Math.max(n.totalTime,t.endTime),delete t.quantizedStartStep,delete t.quantizedEndStep})),d(n).forEach((t=>{t.time=o(t.time)})),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function v(t=r.DEFAULT_STEPS_PER_QUARTER,e=r.DEFAULT_QUARTERS_PER_MINUTE){return i.A.create({quantizationInfo:{stepsPerQuarter:t},tempos:[{qpm:e}]})}function A(t){const e=h(t),n=e.notes.concat(e.pitchBends).concat(e.controlChanges),i=Array.from(new Set(n.filter((t=>!t.isDrum)).map((t=>t.program))));return n.forEach((t=>{t.isDrum?(t.program=0,t.instrument=i.length):t.instrument=i.indexOf(t.program)})),e}function I(t,e){const n=new Set(t.notes.map((t=>t.instrument))),r=new Set(e.notes.map((t=>t.instrument))),o=[];t.notes.forEach((t=>{r.has(t.instrument)||o.push(i.A.Note.create(t))})),e.notes.forEach((t=>{n.has(t.instrument)&&o.push(i.A.Note.create(t))}));const s=h(t);return s.notes=o.sort(((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep})),s}function O(t){y(t);const e=h(t);e.notes=[];const n=t.notes.sort(((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep})),r=new i.A.Note;r.pitch=n[0].pitch,r.instrument=n[0].instrument,r.quantizedStartStep=n[0].quantizedStartStep,r.quantizedEndStep=n[0].quantizedEndStep,e.notes.push(r);let o=0;for(let t=1;t<n.length;t++){const r=n[t],s=e.notes[o];if(s.instrument===r.instrument&&s.pitch===r.pitch&&r.quantizedStartStep===s.quantizedEndStep&&r.quantizedStartStep%16!=0)e.notes[o].quantizedEndStep+=r.quantizedEndStep-r.quantizedStartStep;else{const r=new i.A.Note;r.pitch=n[t].pitch,r.instrument=n[t].instrument,r.quantizedStartStep=n[t].quantizedStartStep,r.quantizedEndStep=n[t].quantizedEndStep,e.notes.push(r),o++}}return e}function M(t,e=64){let n;!function(t){t[t.SUSTAIN_ON=0]="SUSTAIN_ON",t[t.SUSTAIN_OFF=1]="SUSTAIN_OFF",t[t.NOTE_ON=2]="NOTE_ON",t[t.NOTE_OFF=3]="NOTE_OFF"}(n||(n={}));if(S(t))throw new Error("Can only apply sustain to unquantized NoteSequence.");const i=h(t),r=[];for(const t of i.notes)!1===t.isDrum&&(null!==t.startTime&&r.push({time:t.startTime,type:n.NOTE_ON,event:t}),null!==t.endTime&&r.push({time:t.endTime,type:n.NOTE_OFF,event:t}));for(const t of i.controlChanges)if(t.controlNumber===e){const e=t.controlValue;e>=64?r.push({time:t.time,type:n.SUSTAIN_ON,event:t}):e<64&&r.push({time:t.time,type:n.SUSTAIN_OFF,event:t})}r.sort(((t,e)=>t.time-e.time));const o={},s={};let a=0;for(const t of r){a=t.time;const e=t.type,r=t.event;if(e===n.SUSTAIN_ON)s[r.instrument]=!0;else if(e===n.SUSTAIN_OFF){s[r.instrument]=!1;const t=[];r.instrument in o||(o[r.instrument]=[]);for(const e of o[r.instrument])e.endTime<a?(e.endTime=a,a>i.totalTime&&(i.totalTime=a)):t.push(e);o[r.instrument]=t}else if(e===n.NOTE_ON){if(!0===s[r.instrument]){const t=[];r.instrument in o||(o[r.instrument]=[]);for(const e of o[r.instrument])e.pitch===r.pitch?(e.endTime=a,e.startTime===e.endTime&&i.notes.push(e)):t.push(e);o[r.instrument]=t}r.instrument in o||(o[r.instrument]=[]),o[r.instrument].push(r)}else if(e===n.NOTE_OFF)if(!0===s[r.instrument]);else{const t=o[r.instrument].indexOf(r);t>-1&&o[r.instrument].splice(t,1)}}for(const t of Object.values(o))for(const e of t)e.endTime=a,i.totalTime=a;return i}function _(t,e){if(e&&e.length!==t.length)throw new Error("Number of sequences to concatenate and their individual\n durations does not match.");if(S(t[0])){for(let e=0;e<t.length;++e)if(y(t[e]),t[e].quantizationInfo.stepsPerQuarter!==t[0].quantizationInfo.stepsPerQuarter)throw new Error("Not all sequences have the same quantizationInfo");return k(t,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",e)}return k(t,"totalTime","startTime","endTime",e)}function E(t,e,n,i){return S(t)?q(t,e,n,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",i):q(t,e,n,"totalTime","startTime","endTime",i)}function k(t,e,n,r,o){let s,a=0;for(let u=0;u<t.length;++u){const c=o?o[u]:t[u][e];if(0===c)throw Error(`Sequence ${t[u].id} has no ${e}, and no individual duration was provided.`);0===u?s=h(t[0]):Array.prototype.push.apply(s.notes,t[u].notes.map((t=>{const e=i.A.Note.create(t);return e[n]+=a,e[r]+=a,e}))),a+=c}return s[e]=a,s}function q(t,e,n,i,r,o,s){const a=h(t);a[i]=n,a.notes=a.notes.filter((t=>t[r]>=e&&t[r]<=n&&(s||t[o]<=n))),a[i]-=e;for(let t=0;t<a.notes.length;t++)a.notes[t][r]-=e,a.notes[t][o]-=e,s&&(a.notes[t][o]=Math.min(a.notes[t][o],a[i]));return a}function C(t,e){y(t);const n=h(t),r=n.notes.sort(((t,e)=>t.quantizedStartStep-e.quantizedStartStep)),o=[];let s=0,a=[];for(let t=0;t<r.length;t++){const u=r[t],c=u.quantizedStartStep,l=u.quantizedEndStep;if(u.quantizedStartStep-=s,u.quantizedEndStep-=s,!(u.quantizedStartStep<0))if(u.quantizedEndStep<=e)a.push(u);else{if(u.quantizedStartStep<e){const t=i.A.Note.create(u);t.quantizedEndStep=e,t.startTime=t.endTime=void 0,a.push(t),u.quantizedStartStep=s+e,u.quantizedEndStep=l}else u.quantizedStartStep=c,u.quantizedEndStep=l;if((u.quantizedEndStep>e||u.quantizedStartStep>e)&&(t-=1),0!==a.length){const t=h(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}a=[],s+=e}}if(0!==a.length){const t=h(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}return o}},2623:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(3248);e.createControlChanges=function(){return new Proxy({},{get:function(t,e){return t[e]?t[e]:i.controlChangeIds.hasOwnProperty(e)?t[i.controlChangeIds[e]]:void 0},set:function(t,e,n){return i.controlChangeIds.hasOwnProperty(e)?t[i.controlChangeIds[e]]=n:t[e]=n,!0}})}},2971:(t,e)=>{"use strict";var n=e;n.length=function(t){for(var e=0,n=0,i=0;i<t.length;++i)(n=t.charCodeAt(i))<128?e+=1:n<2048?e+=2:55296==(64512&n)&&56320==(64512&t.charCodeAt(i+1))?(++i,e+=4):e+=3;return e},n.read=function(t,e,n){if(n-e<1)return"";for(var i,r=null,o=[],s=0;e<n;)(i=t[e++])<128?o[s++]=i:i>191&&i<224?o[s++]=(31&i)<<6|63&t[e++]:i>239&&i<365?(i=((7&i)<<18|(63&t[e++])<<12|(63&t[e++])<<6|63&t[e++])-65536,o[s++]=55296+(i>>10),o[s++]=56320+(1023&i)):o[s++]=(15&i)<<12|(63&t[e++])<<6|63&t[e++],s>8191&&((r||(r=[])).push(String.fromCharCode.apply(String,o)),s=0);return r?(s&&r.push(String.fromCharCode.apply(String,o.slice(0,s))),r.join("")):String.fromCharCode.apply(String,o.slice(0,s))},n.write=function(t,e,n){for(var i,r,o=n,s=0;s<t.length;++s)(i=t.charCodeAt(s))<128?e[n++]=i:i<2048?(e[n++]=i>>6|192,e[n++]=63&i|128):55296==(64512&i)&&56320==(64512&(r=t.charCodeAt(s+1)))?(i=65536+((1023&i)<<10)+(1023&r),++s,e[n++]=i>>18|240,e[n++]=i>>12&63|128,e[n++]=i>>6&63|128,e[n++]=63&i|128):(e[n++]=i>>12|224,e[n++]=i>>6&63|128,e[n++]=63&i|128);return n-o}},3248:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!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(t,n){return t[e.controlChangeNames[n]]=n,t}),{});var n=new WeakMap,i=new WeakMap,r=function(){function t(t,e){n.set(this,e),i.set(this,t.controllerType),this.ticks=t.absoluteTime,this.value=t.value}return Object.defineProperty(t.prototype,"number",{get:function(){return i.get(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){return e.controlChangeNames[this.number]?e.controlChangeNames[this.number]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"time",{get:function(){return n.get(this).ticksToSeconds(this.ticks)},set:function(t){var e=n.get(this);this.ticks=e.secondsToTicks(t)},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{number:this.number,ticks:this.ticks,time:this.time,value:this.value}},t}();e.ControlChange=r},3331:t=>{"use strict";function e(t){return i(t,[])}function n(t,e){if("number"!=typeof e)throw new TypeError("Expected the depth to be a number");return r(t,[],e)}function i(t,e){for(var n=0;n<t.length;n++){var r=t[n];Array.isArray(r)?i(r,e):e.push(r)}return e}function r(t,e,n){n--;for(var i=0;i<t.length;i++){var o=t[i];n>-1&&Array.isArray(o)?r(o,e,n):e.push(o)}return e}t.exports=function(t){if(!Array.isArray(t))throw new TypeError("Expected value to be an array");return e(t)},t.exports.from=e,t.exports.depth=function(t,e){if(!Array.isArray(t))throw new TypeError("Expected value to be an array");return n(t,e)},t.exports.fromDepth=n},3474:t=>{"use strict";function e(){this._listeners={}}t.exports=e,e.prototype.on=function(t,e,n){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:n||this}),this},e.prototype.off=function(t,e){if(void 0===t)this._listeners={};else if(void 0===e)this._listeners[t]=[];else for(var n=this._listeners[t],i=0;i<n.length;)n[i].fn===e?n.splice(i,1):++i;return this},e.prototype.emit=function(t){var e=this._listeners[t];if(e){for(var n=[],i=1;i<arguments.length;)n.push(arguments[i++]);for(i=0;i<e.length;)e[i].fn.apply(e[i++].ctx,n)}return this}},3576:(t,e,n)=>{"use strict";n.r(e),n.d(e,{ChordEncoder:()=>nt,ChordEncodingException:()=>tt,ChordQuality:()=>X,ChordSymbolException:()=>Z,ChordSymbols:()=>et,MajorMinorChordEncoder:()=>rt,PitchChordEncoder:()=>st,TriadChordEncoder:()=>ot,chordEncoderFromType:()=>it});var i=n(6364),r="C C# Db D D# Eb E F F# Gb G G# Ab A A# Bb B".split(" "),o=function(t){return"string"!=typeof t?r.slice():r.filter((function(e){var n=e[1]||" ";return-1!==t.indexOf(n)}))},s=(o(" #"),o(" b"),/^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/);function a(t){"string"!=typeof t&&(t="");var e=s.exec(t);return[e[1].toUpperCase(),e[2].replace(/x/g,"##"),e[3],e[4]]}var u=Object.freeze({pc:null,name:null,step:null,alt:null,oct:null,octStr:null,chroma:null,midi:null,freq:null}),c=[0,2,4,5,7,9,11],l=function(t,e){return void 0===e&&(e={}),function(n){return e[n]||(e[n]=t(n))}}((function(t){var e=a(t);if(""===e[0]||""!==e[3])return u;var n=e[0],i=e[1],r=e[2],o={letter:n,acc:i,octStr:r,pc:n+i,name:n+i+r,step:(n.charCodeAt(0)+3)%7,alt:"b"===i[0]?-i.length:i.length,oct:r.length?+r:null,chroma:0,midi:null,freq:null};return o.chroma=(c[o.step]+o.alt+120)%12,o.midi=null!==o.oct?c[o.step]+o.alt+12*(o.oct+1):null,o.freq=h(o.midi),Object.freeze(o)})),h=function(t,e){return void 0===e&&(e=440),"number"==typeof t?Math.pow(2,(t-69)/12)*e:null},p=(Math.log(2),Math.log(440),function(t){return l(t).chroma}),m=function(t,e){return Array(e+1).join(t)},d=function(t,e){void 0===t&&(t={}),void 0===e&&(e=null);var n=e?Object.assign({},l(e),t):t,i=n.step,r=n.alt,o=n.oct;if("number"!=typeof i)return null;var s=function(t){return"CDEFGAB"[t]}(i);if(!s)return null;var a=s+function(t){return function(t,e){return"number"!=typeof t?"":e(t)}(t,(function(t){return t<0?m("b",-t):m("#",t)}))}(r);return o||0===o?a+o:a};var f=new RegExp("^([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})|(AA|A|P|M|m|d|dd)([-+]?\\d+)$"),g=[0,2,4,5,7,9,11],S="PMMPPMM",y=("1P 2m 2M 3m 3M 4P 5P 6m 6M 7m 7M 8P".split(" "),Object.freeze({name:null,num:null,q:null,step:null,alt:null,dir:null,type:null,simple:null,semitones:null,chroma:null,oct:null})),b=function(t){return(Math.abs(t)-1)%7},w=function(t){var e=function(t){var e=f.exec(""+t);return null===e?null:e[1]?[e[1],e[2]]:[e[4],e[3]]}(t);if(null===e)return y;var n,i,r={num:0,q:"d",name:"",type:"M",step:0,dir:-1,simple:1,alt:0,oct:0,semitones:0,chroma:0,ic:0};return r.num=+e[0],r.q=e[1],r.step=b(r.num),r.type=S[r.step],"M"===r.type&&"P"===r.q?y:(r.name=""+r.num+r.q,r.dir=r.num<0?-1:1,r.simple=8===r.num||-8===r.num?r.num:r.dir*(r.step+1),r.alt=(n=r.type,"M"===(i=r.q)&&"M"===n||"P"===i&&"P"===n?0:"m"===i&&"M"===n?-1:/^A+$/.test(i)?i.length:/^d+$/.test(i)?"P"===n?-i.length:-i.length-1:null),r.oct=Math.floor((Math.abs(r.num)-1)/7),r.semitones=r.dir*(g[r.step]+r.alt+12*r.oct),r.chroma=(r.dir*(g[r.step]+r.alt)%12+12)%12,Object.freeze(r))},P={};function T(t){return"string"!=typeof t?y:P[t]||(P[t]=w(t))}"P m M m M P d P m M m M".split(" ");var N=[0,2,4,-1,1,3,5],v=N.map((function(t){return Math.floor(7*t/12)})),A=[3,0,4,1,5,2,6];var I=function(t,e,n){var i=A[function(t){var e=(t+1)%7;return e<0?7+e:e}(t)],r=Math.floor((t+1)/7);return void 0===e?{step:i,alt:r,dir:n}:{step:i,alt:r,oct:e+4*r+v[i],dir:n}},O=function(t){return function(t,e){return void 0===e&&(e={}),function(n){return e[n]||(e[n]=t(n))}}((function(e){var n=t(e);return null===n.name?null:function(t){var e=t.step,n=t.alt,i=t.oct,r=t.dir;void 0===r&&(r=1);var o=N[e]+7*n;return null===i?[r*o]:[r*o,r*(i-v[e]-4*n)]}(n)}))},M=O(l),_=O(T);function E(t,e){if(1===arguments.length)return function(e){return E(t,e)};var n=M(t),i=_(e);if(null===n||null===i)return null;var r=1===n.length?[n[0]+i[0]]:[n[0]+i[0],n[1]+i[1]];return d(I(r[0],r[1]))}const k=JSON.parse('{"chromatic":["1P 2m 2M 3m 3M 4P 4A 5P 6m 6M 7m 7M"],"lydian":["1P 2M 3M 4A 5P 6M 7M"],"major":["1P 2M 3M 4P 5P 6M 7M",["ionian"]],"mixolydian":["1P 2M 3M 4P 5P 6M 7m",["dominant"]],"dorian":["1P 2M 3m 4P 5P 6M 7m"],"aeolian":["1P 2M 3m 4P 5P 6m 7m",["minor"]],"phrygian":["1P 2m 3m 4P 5P 6m 7m"],"locrian":["1P 2m 3m 4P 5d 6m 7m"],"melodic minor":["1P 2M 3m 4P 5P 6M 7M"],"melodic minor second mode":["1P 2m 3m 4P 5P 6M 7m"],"lydian augmented":["1P 2M 3M 4A 5A 6M 7M"],"lydian dominant":["1P 2M 3M 4A 5P 6M 7m",["lydian b7"]],"melodic minor fifth mode":["1P 2M 3M 4P 5P 6m 7m",["hindu","mixolydian b6M"]],"locrian #2":["1P 2M 3m 4P 5d 6m 7m",["half-diminished"]],"altered":["1P 2m 3m 3M 5d 6m 7m",["super locrian","diminished whole tone","pomeroy"]],"harmonic minor":["1P 2M 3m 4P 5P 6m 7M"],"phrygian dominant":["1P 2m 3M 4P 5P 6m 7m",["spanish","phrygian major"]],"half-whole diminished":["1P 2m 3m 3M 4A 5P 6M 7m",["dominant diminished"]],"diminished":["1P 2M 3m 4P 5d 6m 6M 7M",["whole-half diminished"]],"major pentatonic":["1P 2M 3M 5P 6M",["pentatonic"]],"lydian pentatonic":["1P 3M 4A 5P 7M",["chinese"]],"mixolydian pentatonic":["1P 3M 4P 5P 7m",["indian"]],"locrian pentatonic":["1P 3m 4P 5d 7m",["minor seven flat five pentatonic"]],"minor pentatonic":["1P 3m 4P 5P 7m"],"minor six pentatonic":["1P 3m 4P 5P 6M"],"minor hexatonic":["1P 2M 3m 4P 5P 7M"],"flat three pentatonic":["1P 2M 3m 5P 6M",["kumoi"]],"flat six pentatonic":["1P 2M 3M 5P 6m"],"major flat two pentatonic":["1P 2m 3M 5P 6M"],"whole tone pentatonic":["1P 3M 5d 6m 7m"],"ionian pentatonic":["1