UNPKG

@magenta/music

Version:

Make music with machine learning, in the browser.

1 lines 276 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mm=t():e.mm=t()}(global,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=39)}([function(e,t){e.exports=require("@tensorflow/tfjs")},function(e,t,n){"use strict";n.r(t),n.d(t,"DEFAULT_QUARTERS_PER_MINUTE",(function(){return i})),n.d(t,"DEFAULT_STEPS_PER_BAR",(function(){return r})),n.d(t,"DEFAULT_STEPS_PER_QUARTER",(function(){return o})),n.d(t,"DEFAULT_STEPS_PER_SECOND",(function(){return s})),n.d(t,"DEFAULT_VELOCITY",(function(){return a})),n.d(t,"DEFAULT_PROGRAM",(function(){return c})),n.d(t,"DEFAULT_TICKS_PER_QUARTER",(function(){return u})),n.d(t,"DEFAULT_CHANNEL",(function(){return l})),n.d(t,"DRUM_CHANNEL",(function(){return h})),n.d(t,"NON_DRUM_CHANNELS",(function(){return p})),n.d(t,"DEFAULT_DRUM_PITCH_CLASSES",(function(){return d})),n.d(t,"MIN_MIDI_VELOCITY",(function(){return m})),n.d(t,"MAX_MIDI_VELOCITY",(function(){return f})),n.d(t,"MIDI_VELOCITIES",(function(){return g})),n.d(t,"NO_CHORD",(function(){return S})),n.d(t,"NUM_PITCH_CLASSES",(function(){return y})),n.d(t,"MIN_MIDI_PITCH",(function(){return w})),n.d(t,"MAX_MIDI_PITCH",(function(){return b})),n.d(t,"MIDI_PITCHES",(function(){return v})),n.d(t,"MIN_PIANO_PITCH",(function(){return N})),n.d(t,"MAX_PIANO_PITCH",(function(){return T})),n.d(t,"MIN_DRUM_PITCH",(function(){return P})),n.d(t,"MAX_DRUM_PITCH",(function(){return O})),n.d(t,"MIN_MIDI_PROGRAM",(function(){return q})),n.d(t,"MAX_MIDI_PROGRAM",(function(){return A})),n.d(t,"LO_CLICK_PITCH",(function(){return E})),n.d(t,"HI_CLICK_PITCH",(function(){return I})),n.d(t,"LO_CLICK_CLASS",(function(){return z})),n.d(t,"HI_CLICK_CLASS",(function(){return _}));const i=120,r=16,o=4,s=100,a=80,c=0,u=220,l=0,h=9,p=[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15],d=[[36,35],[38,27,28,31,32,33,34,37,39,40,56,65,66,75,85],[42,44,54,68,69,70,71,73,78,80],[46,67,72,74,79,81],[45,29,41,61,64,84],[48,47,60,63,77,86,87],[50,30,43,62,76,83],[49,55,57,58],[51,52,53,59,82]],m=0,f=127,g=f-m+1,S="N.C.",y=12,w=0,b=127,v=b-w+1,N=21,T=108,P=35,O=81,q=0,A=127,E=89,I=90,z=9,_=10},function(e,t){e.exports=require("tone")},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(13),r=i.tensorflow.magenta.NoteSequence},function(e,t,n){"use strict";n.r(t),n.d(t,"Level",(function(){return i})),n.d(t,"verbosity",(function(){return o})),n.d(t,"setVerbosity",(function(){return s})),n.d(t,"log",(function(){return a})),n.d(t,"logWithDuration",(function(){return c}));var i,r=n(6);!function(e){e[e.NONE=0]="NONE",e[e.WARN=5]="WARN",e[e.INFO=10]="INFO",e[e.DEBUG=20]="DEBUG"}(i||(i={}));let o=10;function s(e){e=e}function a(e,t="Magenta.js",n=10){if(0===n)throw Error("Logging level cannot be NONE.");if(o>=n){(5===n?console.warn:console.log)(`%c ${t} `,"background:magenta; color:white",e)}}function c(e,t,n="Magenta.js",i=10){a(`${e} in ${((r.d.now()-t)/1e3).toPrecision(3)}s`,n,i)}},function(e,t,n){"use strict";n.r(t),n.d(t,"MultipleTimeSignatureException",(function(){return o})),n.d(t,"BadTimeSignatureException",(function(){return s})),n.d(t,"NegativeTimeException",(function(){return a})),n.d(t,"MultipleTempoException",(function(){return c})),n.d(t,"QuantizationStatusException",(function(){return u})),n.d(t,"clone",(function(){return l})),n.d(t,"stepsPerQuarterToStepsPerSecond",(function(){return h})),n.d(t,"quantizeToStep",(function(){return p})),n.d(t,"quantizeNoteSequence",(function(){return f})),n.d(t,"isQuantizedSequence",(function(){return g})),n.d(t,"assertIsQuantizedSequence",(function(){return S})),n.d(t,"isRelativeQuantizedSequence",(function(){return y})),n.d(t,"assertIsRelativeQuantizedSequence",(function(){return w})),n.d(t,"isAbsoluteQuantizedSequence",(function(){return b})),n.d(t,"assertIsAbsoluteQuantizedSequence",(function(){return v})),n.d(t,"unquantizeSequence",(function(){return N})),n.d(t,"createQuantizedNoteSequence",(function(){return T})),n.d(t,"mergeInstruments",(function(){return P})),n.d(t,"replaceInstruments",(function(){return O})),n.d(t,"mergeConsecutiveNotes",(function(){return q})),n.d(t,"applySustainControlChanges",(function(){return A})),n.d(t,"concatenate",(function(){return E})),n.d(t,"trim",(function(){return I})),n.d(t,"split",(function(){return C}));var i=n(3),r=n(1);class o extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class s extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class a extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class c extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class u extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}function l(e){return i.a.decode(i.a.encode(e).finish())}function h(e,t){return e*t/60}function p(e,t,n=.5){const i=e*t;return Math.floor(i+(1-n))}function d(e){return e.controlChanges.concat(e.textAnnotations)}function m(e){if(e.tempos&&0!==e.tempos.length){if(e.tempos.sort((e,t)=>e.time-t.time),0!==e.tempos[0].time&&e.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 "+`${e.tempos[0].qpm} qpm at ${e.tempos[0].time} seconds.`);for(let t=1;t<e.tempos.length;t++)if(e.tempos[t].qpm!==e.tempos[0].qpm)throw new c(`NoteSequence has at least one tempo change from ${e.tempos[0].qpm} qpm to ${e.tempos[t].qpm}qpm at ${e.tempos[t].time} seconds.`)}}function f(e,t){const n=l(e);if(n.quantizationInfo=i.a.QuantizationInfo.create({stepsPerQuarter:t}),n.timeSignatures.length>0){if(n.timeSignatures.sort((e,t)=>e.time-t.time),0!==n.timeSignatures[0].time&&(4!==n.timeSignatures[0].numerator||4!==n.timeSignatures[0].denominator))throw new o(`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 e=1;e<n.timeSignatures.length;e++){const t=n.timeSignatures[e];if(t.numerator!==n.timeSignatures[0].numerator||t.denominator!==n.timeSignatures[0].denominator)throw new o("NoteSequence has at least one time signature change from "+n.timeSignatures[0].numerator+"/"+n.timeSignatures[0].denominator+" to "+`${t.numerator}/${t.denominator} `+`at ${t.time} seconds`)}n.timeSignatures[0].time=0,n.timeSignatures=[n.timeSignatures[0]]}else{const e=i.a.TimeSignature.create({numerator:4,denominator:4,time:0});n.timeSignatures.push(e)}const c=n.timeSignatures[0];if(!(u=c.denominator)||0!=(u&u-1))throw new s(`Denominator is not a power of 2. Time signature: ${c.numerator}/${c.denominator}`);var u;if(0===c.numerator)throw new s(`Numerator is 0. Time signature: ${c.numerator}/${c.denominator}`);if(n.tempos.length>0)m(n),n.tempos[0].time=0,n.tempos=[n.tempos[0]];else{const e=i.a.Tempo.create({qpm:r.DEFAULT_QUARTERS_PER_MINUTE,time:0});n.tempos.push(e)}const f=h(t,n.tempos[0].qpm);return n.totalQuantizedSteps=p(e.totalTime,f),function(e,t){for(const n of e.notes){if(n.quantizedStartStep=p(n.startTime,t),n.quantizedEndStep=p(n.endTime,t),n.quantizedEndStep===n.quantizedStartStep&&(n.quantizedEndStep+=1),n.quantizedStartStep<0||n.quantizedEndStep<0)throw new a("Got negative note time: start_step = "+n.quantizedStartStep+", end_step = "+n.quantizedEndStep);n.quantizedEndStep>e.totalQuantizedSteps&&(e.totalQuantizedSteps=n.quantizedEndStep)}d(e).forEach(e=>{if(e.quantizedStep=p(e.time,t),e.quantizedStep<0)throw new a("Got negative event time: step = "+e.quantizedStep)})}(n,f),n}function g(e){return e.quantizationInfo&&(e.quantizationInfo.stepsPerQuarter>0||e.quantizationInfo.stepsPerSecond>0)}function S(e){if(!g(e))throw new u(`NoteSequence ${e.id} is not quantized (missing quantizationInfo)`)}function y(e){return e.quantizationInfo&&e.quantizationInfo.stepsPerQuarter>0}function w(e){if(!y(e))throw new u(`NoteSequence ${e.id} is not quantized or is quantized based on absolute timing`)}function b(e){return e.quantizationInfo&&e.quantizationInfo.stepsPerSecond>0}function v(e){if(!b(e))throw new u(`NoteSequence ${e.id} is not quantized or is quantized based on relative timing`)}function N(e,t){w(e),m(e);const n=l(e);t?n.tempos&&n.tempos.length>0?n.tempos[0].qpm=t:n.tempos.push(i.a.Tempo.create({time:0,qpm:t})):t=e.tempos&&e.tempos.length>0?n.tempos[0].qpm:r.DEFAULT_QUARTERS_PER_MINUTE;const o=e=>e/n.quantizationInfo.stepsPerQuarter*(60/t);return n.totalTime=o(n.totalQuantizedSteps),n.notes.forEach(e=>{e.startTime=o(e.quantizedStartStep),e.endTime=o(e.quantizedEndStep),n.totalTime=Math.max(n.totalTime,e.endTime),delete e.quantizedStartStep,delete e.quantizedEndStep}),d(n).forEach(e=>{e.time=o(e.time)}),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function T(e=r.DEFAULT_STEPS_PER_QUARTER,t=r.DEFAULT_QUARTERS_PER_MINUTE){return i.a.create({quantizationInfo:{stepsPerQuarter:e},tempos:[{qpm:t}]})}function P(e){const t=l(e),n=t.notes.concat(t.pitchBends).concat(t.controlChanges),i=Array.from(new Set(n.filter(e=>!e.isDrum).map(e=>e.program)));return n.forEach(e=>{e.isDrum?(e.program=0,e.instrument=i.length):e.instrument=i.indexOf(e.program)}),t}function O(e,t){const n=new Set(e.notes.map(e=>e.instrument)),r=new Set(t.notes.map(e=>e.instrument)),o=[];e.notes.forEach(e=>{r.has(e.instrument)||o.push(i.a.Note.create(e))}),t.notes.forEach(e=>{n.has(e.instrument)&&o.push(i.a.Note.create(e))});const s=l(e);return s.notes=o.sort((e,t)=>{const n=e.instrument-t.instrument;return n||e.quantizedStartStep-t.quantizedStartStep}),s}function q(e){S(e);const t=l(e);t.notes=[];const n=e.notes.sort((e,t)=>{const n=e.instrument-t.instrument;return n||e.quantizedStartStep-t.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,t.notes.push(r);let o=0;for(let e=1;e<n.length;e++){const r=n[e],s=t.notes[o];if(s.instrument===r.instrument&&s.pitch===r.pitch&&r.quantizedStartStep===s.quantizedEndStep&&r.quantizedStartStep%16!=0)t.notes[o].quantizedEndStep+=r.quantizedEndStep-r.quantizedStartStep;else{const r=new i.a.Note;r.pitch=n[e].pitch,r.instrument=n[e].instrument,r.quantizedStartStep=n[e].quantizedStartStep,r.quantizedEndStep=n[e].quantizedEndStep,t.notes.push(r),o++}}return t}function A(e,t=64){let n;!function(e){e[e.SUSTAIN_ON=0]="SUSTAIN_ON",e[e.SUSTAIN_OFF=1]="SUSTAIN_OFF",e[e.NOTE_ON=2]="NOTE_ON",e[e.NOTE_OFF=3]="NOTE_OFF"}(n||(n={}));if(g(e))throw new Error("Can only apply sustain to unquantized NoteSequence.");const i=l(e),r=[];for(const e of i.notes)!1===e.isDrum&&(null!==e.startTime&&r.push({time:e.startTime,type:n.NOTE_ON,event:e}),null!==e.endTime&&r.push({time:e.endTime,type:n.NOTE_OFF,event:e}));for(const e of i.controlChanges)if(e.controlNumber===t){const t=e.controlValue;t>=64?r.push({time:e.time,type:n.SUSTAIN_ON,event:e}):t<64&&r.push({time:e.time,type:n.SUSTAIN_OFF,event:e})}r.sort((e,t)=>e.time-t.time);const o={},s={};let a=0;for(const e of r){a=e.time;const t=e.type,r=e.event;if(t===n.SUSTAIN_ON)s[r.instrument]=!0;else if(t===n.SUSTAIN_OFF){s[r.instrument]=!1;const e=[];r.instrument in o||(o[r.instrument]=[]);for(const t of o[r.instrument])t.endTime<a?(t.endTime=a,a>i.totalTime&&(i.totalTime=a)):e.push(t);o[r.instrument]=e}else if(t===n.NOTE_ON){if(!0===s[r.instrument]){const e=[];r.instrument in o||(o[r.instrument]=[]);for(const t of o[r.instrument])t.pitch===r.pitch?(t.endTime=a,t.startTime===t.endTime&&i.notes.push(t)):e.push(t);o[r.instrument]=e}r.instrument in o||(o[r.instrument]=[]),o[r.instrument].push(r)}else if(t===n.NOTE_OFF)if(!0===s[r.instrument]);else{const e=o[r.instrument].indexOf(r);e>-1&&o[r.instrument].splice(e,1)}}for(const e of Object.values(o))for(const t of e)t.endTime=a,i.totalTime=a;return i}function E(e,t){if(t&&t.length!==e.length)throw new Error("Number of sequences to concatenate and their individual\n durations does not match.");if(g(e[0])){for(let t=0;t<e.length;++t)if(S(e[t]),e[t].quantizationInfo.stepsPerQuarter!==e[0].quantizationInfo.stepsPerQuarter)throw new Error("Not all sequences have the same quantizationInfo");return z(e,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",t)}return z(e,"totalTime","startTime","endTime",t)}function I(e,t,n,i){return g(e)?_(e,t,n,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",i):_(e,t,n,"totalTime","startTime","endTime",i)}function z(e,t,n,r,o){let s,a=0;for(let c=0;c<e.length;++c){const u=o?o[c]:e[c][t];if(0===u)throw Error(`Sequence ${e[c].id} has no ${t}, and no individual duration was provided.`);0===c?s=l(e[0]):Array.prototype.push.apply(s.notes,e[c].notes.map(e=>{const t=i.a.Note.create(e);return t[n]+=a,t[r]+=a,t})),a+=u}return s[t]=a,s}function _(e,t,n,i,r,o,s){const a=l(e);a[i]=n,a.notes=a.notes.filter(e=>e[r]>=t&&e[r]<=n&&(s||e[o]<=n)),a[i]-=t;for(let e=0;e<a.notes.length;e++)a.notes[e][r]-=t,a.notes[e][o]-=t,s&&(a.notes[e][o]=Math.min(a.notes[e][o],a[i]));return a}function C(e,t){S(e);const n=l(e),r=n.notes.sort((e,t)=>e.quantizedStartStep-t.quantizedStartStep),o=[];let s=0,a=[];for(let e=0;e<r.length;e++){const c=r[e],u=c.quantizedStartStep,h=c.quantizedEndStep;if(c.quantizedStartStep-=s,c.quantizedEndStep-=s,!(c.quantizedStartStep<0))if(c.quantizedEndStep<=t)a.push(c);else{if(c.quantizedStartStep<t){const e=i.a.Note.create(c);e.quantizedEndStep=t,e.startTime=e.endTime=void 0,a.push(e),c.quantizedStartStep=s+t,c.quantizedEndStep=h}else c.quantizedStartStep=u,c.quantizedEndStep=h;if((c.quantizedEndStep>t||c.quantizedStartStep>t)&&(e-=1),0!==a.length){const e=l(n);e.notes=a,e.totalQuantizedSteps=t,o.push(e)}a=[],s+=t}}if(0!==a.length){const e=l(n);e.notes=a,e.totalQuantizedSteps=t,o.push(e)}return o}},function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"d",(function(){return r})),n.d(t,"c",(function(){return o})),n.d(t,"b",(function(){return s}));const i=n(18),r=n(19);n(21);function o(){throw new Error("Cannot check if Safari in Node.js")}function s(e){throw new Error("Cannot use offline audio context in Node.js")}},function(e,t){e.exports=require("@tensorflow/tfjs-core")},function(e,t,n){"use strict";n.d(t,"e",(function(){return l})),n.d(t,"d",(function(){return h})),n.d(t,"f",(function(){return p})),n.d(t,"i",(function(){return d})),n.d(t,"j",(function(){return f})),n.d(t,"a",(function(){return S})),n.d(t,"h",(function(){return y})),n.d(t,"b",(function(){return v})),n.d(t,"g",(function(){return T})),n.d(t,"c",(function(){return P}));var i=n(0),r=n(17),o=n(22),s=n(27),a=n(6),c=n(4);const u=Object(a.b)(16e3);async function l(e){return Object(a.a)(e).then(e=>e.arrayBuffer()).then(e=>u.decodeAudioData(e))}async function h(e){const t=new FileReader;return new Promise((n,i)=>{t.onerror=()=>{t.abort(),i(new DOMException("Something went wrong reading that file."))},t.onload=()=>{n(t.result)},t.readAsArrayBuffer(e)}).then(e=>u.decodeAudioData(e))}function p(e,t){t.power||(t.power=2);const n=function(e,t){const n=t.nFft||2048,i=t.winLength||n,r=t.hopLength||Math.floor(i/4);let o=v(i);o=y(o,n);const s=function(e,t,n){const i=Math.floor((e.length-t)/n)+1,r=Array.from({length:i},(e,n)=>new Float32Array(t));for(let o=0;o<i;o++){const i=o*n,s=e.slice(i,i+t);r[o].set(s),s.length}return r}(e=function(e,t){const n=w(e,t);for(let e=0;e<t;e++)n[e]=n[2*t-e],n[n.length-e-1]=n[n.length-2*t+e-1];return n}(e,Math.floor(n/2)),n,r),a=[],c=s.length,u=n+2;for(let e=0;e<c;e++){const t=new Float32Array(u);a[e]=t}for(let e=0;e<c;e++){const t=b(S(s[e],o));a[e].set(t.slice(0,u))}return a}(e,t),[i,r]=function(e,t){const n=e.map(e=>function(e,t){return e.map(e=>Math.pow(e,t))}(function(e){const t=new Float32Array(e.length/2);for(let n=0;n<e.length/2;n++)t[n]=Math.sqrt(e[2*n]*e[2*n]+e[2*n+1]*e[2*n+1]);return t}(e),t)),i=e[0].length-1;return[n,i]}(n,t.power);t.nFft=r;return function(e,t){const n=[];for(let i=0;i<e.length;i++)n[i]=g(e[i],t);return n}(i,function(e){const t=e.fMin||0,n=e.fMax||e.sampleRate/2,i=e.nMels||128,r=e.nFft||2048,o=function(e,t){return N(0,e/2,Math.floor(1+t/2))}(e.sampleRate,r),s=function(e,t,n){const i=O(t),r=O(n),o=N(i,r,e);return o.map(e=>function(e){return 700*(Math.exp(e/1125)-1)}(e))}(i+2,t,n),a=function(e){const t=new Float32Array(e.length-1);for(let n=0;n<e.length;n++)t[n]=e[n+1]-e[n];return t}(s),c=function(e,t){const n=[];for(let i=0;i<e.length;i++)n[i]=new Float32Array(t.length);for(let i=0;i<e.length;i++)for(let r=0;r<t.length;r++)n[i][r]=e[i]-t[r];return n}(s,o),u=c[0].length,l=[];for(let e=0;e<i;e++){l[e]=new Float32Array(u);for(let t=0;t<c[e].length;t++){const n=-c[e][t]/a[e],i=c[e+2][t]/a[e+1],r=Math.max(0,Math.min(n,i));l[e][t]=r}}for(let e=0;e<l.length;e++){const t=2/(s[2+e]-s[e]);l[e]=l[e].map(e=>e*t)}return l}(t))}function d(e,t=1e-10,n=80){const i=e.length,r=e[0].length,o=[];for(let e=0;e<i;e++)o[e]=new Float32Array(r);for(let n=0;n<i;n++)for(let i=0;i<r;i++){const r=e[n][i];o[n][i]=10*Math.log10(Math.max(t,r))}if(n){if(n<0)throw new Error("topDb must be non-negative.");for(let e=0;e<i;e++){const t=o[e].reduce((e,t)=>Math.max(e,t));for(let i=0;i<r;i++)o[e][i]=Math.max(o[e][i],t-n)}}return o}function m(e){if(1===e.numberOfChannels)return e.getChannelData(0);if(2!==e.numberOfChannels)throw Error(e.numberOfChannels+" channel audio is not supported.");const t=e.getChannelData(0),n=e.getChannelData(1),i=new Float32Array(e.length);for(let r=0;r<e.length;++r)i[r]=(t[r]+n[r])/2;return i}async function f(e,t=16e3){if(e.sampleRate===t)return m(e);const n=e.sampleRate,i=e.length*t/n;if(a.c){c.log("Safari does not support WebAudio resampling, so this may be slow.","O&F",5);const t=m(e),n=new Float32Array(i);return s(o(n,[i]),o(t,[t.length])),n}{const n=new OfflineAudioContext(e.numberOfChannels,e.duration*t,t),i=n.createBufferSource();return i.buffer=e,i.connect(n.destination),i.start(),n.startRendering().then(e=>e.getChannelData(0))}}function g(e,t){if(e.length!==t[0].length)throw new Error(`Each entry in filterbank should have dimensions matching FFT. |mags| = ${e.length}, |filterbank[0]| = ${t[0].length}.`);const n=new Float32Array(t.length);for(let i=0;i<t.length;i++){const r=S(e,t[i]);n[i]=r.reduce((e,t)=>e+t)}return n}function S(e,t){if(e.length!==t.length)return console.error(`Buffer length ${e.length} != window length ${t.length}.`),null;const n=new Float32Array(e.length);for(let i=0;i<e.length;i++)n[i]=t[i]*e[i];return n}function y(e,t){if(e.length>t)throw new Error("Data is longer than length.");const n=Math.floor((t-e.length)/2);return w(e,[n,t-e.length-n])}function w(e,t){let n,i;"object"==typeof t?[n,i]=t:n=i=t;const r=new Float32Array(e.length+n+i);return r.set(e,n),r}function b(e){const t=new r(e.length),n=t.createComplexArray(),i=t.toComplexArray(e);return t.transform(n,i),n}function v(e){const t=new Float32Array(e);for(let n=0;n<e;n++)t[n]=.5*(1-Math.cos(2*Math.PI*n/(e-1)));return t}function N(e,t,n){const i=(t-e)/(n-1),r=new Float32Array(n);for(let t=0;t<n;t++)r[t]=e+i*t;return r}function T(e){let t=i.sub(e,69);return t=i.div(t,12),t=i.pow(2,t),t=i.mul(440,t),t}async function P(e){let t=i.sub(i.div(i.log(e),i.log(2)),i.div(i.log(440),i.log(2)));t=i.mul(12,t),t=i.add(t,69);return await t.array()}function O(e){return 1125*Math.log(1+e/700)}},function(e,t){e.exports=require("tonal")},function(e,t,n){"use strict";n.r(t),n.d(t,"NO_EVENT",(function(){return s})),n.d(t,"NOTE_OFF",(function(){return a})),n.d(t,"Melody",(function(){return c})),n.d(t,"MelodyRhythm",(function(){return u})),n.d(t,"MelodyShape",(function(){return l})),n.d(t,"MelodyRegister",(function(){return h}));var i=n(0),r=n(3),o=n(5);const s=0,a=1;class c{constructor(e,t,n){this.events=e,this.minPitch=t,this.maxPitch=n}static fromNoteSequence(e,t,n,i=!0,r){o.assertIsQuantizedSequence(e);const s=e.notes.sort((e,t)=>e.quantizedStartStep===t.quantizedStartStep?t.pitch-e.pitch:e.quantizedStartStep-t.quantizedStartStep),u=new Int32Array(r||e.totalQuantizedSteps);let l=-1;return s.forEach(e=>{if(e.quantizedStartStep===l){if(i)return;throw new Error("`NoteSequence` is not monophonic.")}if(e.pitch<t||e.pitch>n)throw Error("`NoteSequence` has a pitch outside of the valid range: "+e.pitch);u[e.quantizedStartStep]=e.pitch-t+2,u[e.quantizedEndStep]=a,l=e.quantizedStartStep}),new c(u,t,n)}toNoteSequence(e,t){const n=o.createQuantizedNoteSequence(e,t);let i=null;for(let e=0;e<this.events.length;++e){const t=this.events[e];switch(t){case s:break;case a:i&&(i.quantizedEndStep=e,n.notes.push(i),i=null);break;default:i&&(i.quantizedEndStep=e,n.notes.push(i)),i=r.a.Note.create({pitch:t-2+this.minPitch,quantizedStartStep:e})}}return i&&(i.quantizedEndStep=this.events.length,n.notes.push(i)),n.totalQuantizedSteps=this.events.length,n}}class u{constructor(){this.depth=1}extract(e){const t=e.events.length,n=i.buffer([t,1]);for(let i=0;i<t;++i)n.set(e.events[i]>=2?1:0,i,0);return n.toTensor().as2D(t,1)}}class l{constructor(){this.depth=3}extract(e){const t=e.events.length,n=i.buffer([t,3]);let r=null,o=null;for(let i=0;i<t;++i)if(e.events[i]>=2){if(null!==r){let t;0===n.get(r,0)&&0===n.get(r,1)&&0===n.get(r,2)&&(r=-1),t=e.events[i]<o?0:e.events[i]>o?2:1;for(let e=i;e>r;--e)n.set(1,e,t)}r=i,o=e.events[i]}if(r!==t-1)if(null===r||0===n.get(r,0)&&0===n.get(r,1)&&0===n.get(r,2))for(let e=0;e<t;++e)n.set(1,e,1);else for(let e=t-1;e>r;--e)for(let t=0;t<3;t++)n.set(n.get(r,t),e,t);return n.toTensor().as2D(t,3)}}class h{constructor(e){this.boundaryPitches=e,this.depth=e.length+1}meanMelodyPitch(e){let t=0,n=0,i=null;for(let r=0;r<e.events.length;++r)e.events[r]===a?i=null:e.events[r]>=2&&(i=e.minPitch+e.events[r]-2),null!==i&&(t+=i,n+=1);return n?t/n:null}extract(e){const t=e.events.length,n=this.meanMelodyPitch(e);if(null===n)return i.zeros([t,this.depth]);let r=0;for(;r<this.boundaryPitches.length&&n>=this.boundaryPitches[r];)r++;const o=i.buffer([t,this.depth]);for(let e=0;e<t;++e)o.set(1,e,r);return o.toTensor().as2D(t,this.depth)}}},function(e,t,n){"use strict";n.d(t,"c",(function(){return s})),n.d(t,"b",(function(){return a})),n.d(t,"e",(function(){return c})),n.d(t,"f",(function(){return u})),n.d(t,"d",(function(){return l})),n.d(t,"a",(function(){return h})),n.d(t,"h",(function(){return p})),n.d(t,"g",(function(){return d}));var i=n(0),r=n(8);var o=n(16);const s=16e3,a=250,c=25.58,u=63.07,l=.002,h=.7;async function p(e){let t;return t=await i.loadGraphModel(e,{fromTFHub:!0}),t}async function d(e,t,n){if("webgl"!==i.getBackend())throw new Error("Device does not support webgl.");const c=await Object(r.j)(e,s),u=c.length,l=await async function(e){const t=Math.floor(s/a),n=i.tensor1d(e,"float32"),r=e.length;if(null===n)return[];const o=n.mul(n).reshape([r,1]),c=i.conv1d(o,i.ones([1024,1,1]).div(1024),t,"same").sqrt().squeeze(),u=i.mul(i.log(i.maximum(1e-20,c)).div(i.log(10)),20),l=u.sub(20.7),h=i.maximum(l,-120),p=await h.array();return n.dispose(),o.dispose(),c.dispose(),u.dispose(),l.dispose(),h.dispose(),p}(c),{pitches:h,confidences:p}=await Object(o.a)(t,c,n);return{f0_hz:h,loudness_db:l,confidences:p,originalRecordedBufferLength:u}}},function(e,t,n){"use strict";n.r(t),n.d(t,"Performance",(function(){return a}));var i=n(3),r=n(1),o=n(5),s=n(4);class a{constructor(e,t,n,i,r){this.events=e,this.maxShiftSteps=t,this.numVelocityBins=n,this.program=i,this.isDrum=r}static fromNoteSequence(e,t,n,i){o.assertIsQuantizedSequence(e);const s=e.notes.filter((e,t)=>void 0===i||e.instrument===i),c=s.sort((e,t)=>e.startTime===t.startTime?e.pitch-t.pitch:e.startTime-t.startTime),u=c.map((e,t)=>({step:e.quantizedStartStep,index:t,isOffset:0})),l=c.map((e,t)=>({step:e.quantizedEndStep,index:t,isOffset:1})),h=u.concat(l).sort((e,t)=>e.step===t.step?e.index===t.index?e.isOffset-t.isOffset:e.index-t.index:e.step-t.step),p=n?Math.ceil((r.MIDI_VELOCITIES-1)/n):void 0,d=[];let m=0,f=n;for(const e of h){if(e.step>m){for(;e.step>m+t;)d.push({type:"time-shift",steps:t}),m+=t;d.push({type:"time-shift",steps:e.step-m}),m=e.step}if(e.isOffset)d.push({type:"note-off",pitch:c[e.index].pitch});else{if(p){const t=Math.floor((c[e.index].velocity-r.MIN_MIDI_VELOCITY-1)/p)+1;t!==f&&(d.push({type:"velocity-change",velocityBin:t}),f=t)}d.push({type:"note-on",pitch:c[e.index].pitch})}}const g=!!s.some(e=>e.isDrum)&&(!s.some(e=>!e.isDrum)||void 0),S=Array.from(new Set(s.map(e=>e.program))),y=g||1!==S.length?void 0:S[0],w=new a(d,t,n,y,g);return w.setNumSteps(e.totalQuantizedSteps),w}getNumSteps(){return this.events.filter(e=>"time-shift"===e.type).map(e=>e.steps).reduce((e,t)=>e+t,0)}setNumSteps(e){let t=this.getNumSteps();if(t<e){if(this.events.length){const n=this.events[this.events.length-1];if("time-shift"===n.type){const i=Math.min(e-t,this.maxShiftSteps-n.steps);n.steps+=i,t+=i}}for(;t<e;)t+this.maxShiftSteps>e?(this.events.push({type:"time-shift",steps:e-t}),t=e):(this.events.push({type:"time-shift",steps:this.maxShiftSteps}),t+=this.maxShiftSteps)}else if(t>e)for(;this.events.length&&t>e;){const n=this.events[this.events.length-1];"time-shift"===n.type?t-n.steps<e?(n.steps-=t-e,t=e):(this.events.pop(),t-=n.steps):this.events.pop()}}toNoteSequence(e){const t=this.numVelocityBins?Math.ceil((r.MIDI_VELOCITIES-1)/this.numVelocityBins):void 0,n=i.a.create();let o=0,a=void 0;const c=new Map;for(let e=r.MIN_MIDI_PITCH;e<=r.MAX_MIDI_PITCH;++e)c.set(e,[]);for(const u of this.events)switch(u.type){case"note-on":c.get(u.pitch).push([o,a]);break;case"note-off":const l=c.get(u.pitch);if(l.length){const[t,r]=l.shift();o>t?n.notes.push(i.a.Note.create({pitch:u.pitch,velocity:r,instrument:e,quantizedStartStep:t,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${u.pitch}, step = ${o})`,"Performance")}else s.log(`Ignoring note-off with no previous note-on:(pitch = ${u.pitch}, step = ${o})`,"Performance");break;case"time-shift":o+=u.steps;break;case"velocity-change":if(!t)throw new Error("Unexpected velocity change event: "+u);a=r.MIN_MIDI_VELOCITY+(u.velocityBin-1)*t+1;break;default:throw new Error("Unrecognized performance event: "+u)}return c.forEach((t,r)=>{for(const[a,c]of t)o>a?n.notes.push(i.a.Note.create({pitch:r,velocity:c,instrument:e,quantizedStartStep:a,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${r}, step = ${o})`,"Performance")}),n.totalQuantizedSteps=o,n}}},function(e,t,n){"use strict";var i,r,o=n(24),s=o.Reader,a=o.Writer,c=o.util,u=o.roots.default||(o.roots.default={});u.tensorflow=((r={}).magenta=((i={}).NoteSequence=function(){function e(e){if(this.timeSignatures=[],this.keySignatures=[],this.tempos=[],this.notes=[],this.pitchBends=[],this.controlChanges=[],this.partInfos=[],this.textAnnotations=[],this.sectionAnnotations=[],this.sectionGroups=[],e)for(var t=Object.keys(e),n=0;n<t.length;++n)null!=e[t[n]]&&(this[t[n]]=e[t[n]])}var t,n;return e.prototype.id="",e.prototype.filename="",e.prototype.referenceNumber=c.Long?c.Long.fromBits(0,0,!1):0,e.prototype.collectionName="",e.prototype.ticksPerQuarter=0,e.prototype.timeSignatures=c.emptyArray,e.prototype.keySignatures=c.emptyArray,e.prototype.tempos=c.emptyArray,e.prototype.notes=c.emptyArray,e.prototype.totalTime=0,e.prototype.totalQuantizedSteps=c.Long?c.Long.fromBits(0,0,!1):0,e.prototype.pitchBends=c.emptyArray,e.prototype.controlChanges=c.emptyArray,e.prototype.partInfos=c.emptyArray,e.prototype.sourceInfo=null,e.prototype.textAnnotations=c.emptyArray,e.prototype.sectionAnnotations=c.emptyArray,e.prototype.sectionGroups=c.emptyArray,e.prototype.quantizationInfo=null,e.prototype.subsequenceInfo=null,e.prototype.sequenceMetadata=null,e.create=function(t){return new e(t)},e.encode=function(e,t){if(t||(t=a.create()),null!=e.id&&e.hasOwnProperty("id")&&t.uint32(10).string(e.id),null!=e.filename&&e.hasOwnProperty("filename")&&t.uint32(18).string(e.filename),null!=e.collectionName&&e.hasOwnProperty("collectionName")&&t.uint32(26).string(e.collectionName),null!=e.ticksPerQuarter&&e.hasOwnProperty("ticksPerQuarter")&&t.uint32(32).int32(e.ticksPerQuarter),null!=e.timeSignatures&&e.timeSignatures.length)for(var n=0;n<e.timeSignatures.length;++n)u.tensorflow.magenta.NoteSequence.TimeSignature.encode(e.timeSignatures[n],t.uint32(42).fork()).ldelim();if(null!=e.keySignatures&&e.keySignatures.length)for(n=0;n<e.keySignatures.length;++n)u.tensorflow.magenta.NoteSequence.KeySignature.encode(e.keySignatures[n],t.uint32(50).fork()).ldelim();if(null!=e.tempos&&e.tempos.length)for(n=0;n<e.tempos.length;++n)u.tensorflow.magenta.NoteSequence.Tempo.encode(e.tempos[n],t.uint32(58).fork()).ldelim();if(null!=e.notes&&e.notes.length)for(n=0;n<e.notes.length;++n)u.tensorflow.magenta.NoteSequence.Note.encode(e.notes[n],t.uint32(66).fork()).ldelim();if(null!=e.totalTime&&e.hasOwnProperty("totalTime")&&t.uint32(73).double(e.totalTime),null!=e.pitchBends&&e.pitchBends.length)for(n=0;n<e.pitchBends.length;++n)u.tensorflow.magenta.NoteSequence.PitchBend.encode(e.pitchBends[n],t.uint32(82).fork()).ldelim();if(null!=e.controlChanges&&e.controlChanges.length)for(n=0;n<e.controlChanges.length;++n)u.tensorflow.magenta.NoteSequence.ControlChange.encode(e.controlChanges[n],t.uint32(90).fork()).ldelim();if(null!=e.partInfos&&e.partInfos.length)for(n=0;n<e.partInfos.length;++n)u.tensorflow.magenta.NoteSequence.PartInfo.encode(e.partInfos[n],t.uint32(98).fork()).ldelim();if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&u.tensorflow.magenta.NoteSequence.SourceInfo.encode(e.sourceInfo,t.uint32(106).fork()).ldelim(),null!=e.textAnnotations&&e.textAnnotations.length)for(n=0;n<e.textAnnotations.length;++n)u.tensorflow.magenta.NoteSequence.TextAnnotation.encode(e.textAnnotations[n],t.uint32(114).fork()).ldelim();if(null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&u.tensorflow.magenta.NoteSequence.QuantizationInfo.encode(e.quantizationInfo,t.uint32(122).fork()).ldelim(),null!=e.totalQuantizedSteps&&e.hasOwnProperty("totalQuantizedSteps")&&t.uint32(128).int64(e.totalQuantizedSteps),null!=e.subsequenceInfo&&e.hasOwnProperty("subsequenceInfo")&&u.tensorflow.magenta.NoteSequence.SubsequenceInfo.encode(e.subsequenceInfo,t.uint32(138).fork()).ldelim(),null!=e.referenceNumber&&e.hasOwnProperty("referenceNumber")&&t.uint32(144).int64(e.referenceNumber),null!=e.sequenceMetadata&&e.hasOwnProperty("sequenceMetadata")&&u.tensorflow.magenta.SequenceMetadata.encode(e.sequenceMetadata,t.uint32(154).fork()).ldelim(),null!=e.sectionAnnotations&&e.sectionAnnotations.length)for(n=0;n<e.sectionAnnotations.length;++n)u.tensorflow.magenta.NoteSequence.SectionAnnotation.encode(e.sectionAnnotations[n],t.uint32(162).fork()).ldelim();if(null!=e.sectionGroups&&e.sectionGroups.length)for(n=0;n<e.sectionGroups.length;++n)u.tensorflow.magenta.NoteSequence.SectionGroup.encode(e.sectionGroups[n],t.uint32(170).fork()).ldelim();return t},e.encodeDelimited=function(e,t){return this.encode(e,t).ldelim()},e.decode=function(e,t){e instanceof s||(e=s.create(e));for(var n=void 0===t?e.len:e.pos+t,i=new u.tensorflow.magenta.NoteSequence;e.pos<n;){var r=e.uint32();switch(r>>>3){case 1:i.id=e.string();break;case 2:i.filename=e.string();break;case 18:i.referenceNumber=c.Long?e.int64().toNumber():e.int64();break;case 3:i.collectionName=e.string();break;case 4:i.ticksPerQuarter=e.int32();break;case 5:i.timeSignatures&&i.timeSignatures.length||(i.timeSignatures=[]),i.timeSignatures.push(u.tensorflow.magenta.NoteSequence.TimeSignature.decode(e,e.uint32()));break;case 6:i.keySignatures&&i.keySignatures.length||(i.keySignatures=[]),i.keySignatures.push(u.tensorflow.magenta.NoteSequence.KeySignature.decode(e,e.uint32()));break;case 7:i.tempos&&i.tempos.length||(i.tempos=[]),i.tempos.push(u.tensorflow.magenta.NoteSequence.Tempo.decode(e,e.uint32()));break;case 8:i.notes&&i.notes.length||(i.notes=[]),i.notes.push(u.tensorflow.magenta.NoteSequence.Note.decode(e,e.uint32()));break;case 9:i.totalTime=e.double();break;case 16:i.totalQuantizedSteps=c.Long?e.int64().toNumber():e.int64();break;case 10:i.pitchBends&&i.pitchBends.length||(i.pitchBends=[]),i.pitchBends.push(u.tensorflow.magenta.NoteSequence.PitchBend.decode(e,e.uint32()));break;case 11:i.controlChanges&&i.controlChanges.length||(i.controlChanges=[]),i.controlChanges.push(u.tensorflow.magenta.NoteSequence.ControlChange.decode(e,e.uint32()));break;case 12:i.partInfos&&i.partInfos.length||(i.partInfos=[]),i.partInfos.push(u.tensorflow.magenta.NoteSequence.PartInfo.decode(e,e.uint32()));break;case 13:i.sourceInfo=u.tensorflow.magenta.NoteSequence.SourceInfo.decode(e,e.uint32());break;case 14:i.textAnnotations&&i.textAnnotations.length||(i.textAnnotations=[]),i.textAnnotations.push(u.tensorflow.magenta.NoteSequence.TextAnnotation.decode(e,e.uint32()));break;case 20:i.sectionAnnotations&&i.sectionAnnotations.length||(i.sectionAnnotations=[]),i.sectionAnnotations.push(u.tensorflow.magenta.NoteSequence.SectionAnnotation.decode(e,e.uint32()));break;case 21:i.sectionGroups&&i.sectionGroups.length||(i.sectionGroups=[]),i.sectionGroups.push(u.tensorflow.magenta.NoteSequence.SectionGroup.decode(e,e.uint32()));break;case 15:i.quantizationInfo=u.tensorflow.magenta.NoteSequence.QuantizationInfo.decode(e,e.uint32());break;case 17:i.subsequenceInfo=u.tensorflow.magenta.NoteSequence.SubsequenceInfo.decode(e,e.uint32());break;case 19:i.sequenceMetadata=u.tensorflow.magenta.SequenceMetadata.decode(e,e.uint32());break;default:e.skipType(7&r)}}return i},e.decodeDelimited=function(e){return e instanceof s||(e=new s(e)),this.decode(e,e.uint32())},e.verify=function(e){if("object"!=typeof e||null===e)return"object expected";if(null!=e.id&&e.hasOwnProperty("id")&&!c.isString(e.id))return"id: string expected";if(null!=e.filename&&e.hasOwnProperty("filename")&&!c.isString(e.filename))return"filename: string expected";if(null!=e.referenceNumber&&e.hasOwnProperty("referenceNumber")&&!(c.isInteger(e.referenceNumber)||e.referenceNumber&&c.isInteger(e.referenceNumber.low)&&c.isInteger(e.referenceNumber.high)))return"referenceNumber: integer|Long expected";if(null!=e.collectionName&&e.hasOwnProperty("collectionName")&&!c.isString(e.collectionName))return"collectionName: string expected";if(null!=e.ticksPerQuarter&&e.hasOwnProperty("ticksPerQuarter")&&!c.isInteger(e.ticksPerQuarter))return"ticksPerQuarter: integer expected";if(null!=e.timeSignatures&&e.hasOwnProperty("timeSignatures")){if(!Array.isArray(e.timeSignatures))return"timeSignatures: array expected";for(var t=0;t<e.timeSignatures.length;++t)if(n=u.tensorflow.magenta.NoteSequence.TimeSignature.verify(e.timeSignatures[t]))return"timeSignatures."+n}if(null!=e.keySignatures&&e.hasOwnProperty("keySignatures")){if(!Array.isArray(e.keySignatures))return"keySignatures: array expected";for(t=0;t<e.keySignatures.length;++t)if(n=u.tensorflow.magenta.NoteSequence.KeySignature.verify(e.keySignatures[t]))return"keySignatures."+n}if(null!=e.tempos&&e.hasOwnProperty("tempos")){if(!Array.isArray(e.tempos))return"tempos: array expected";for(t=0;t<e.tempos.length;++t)if(n=u.tensorflow.magenta.NoteSequence.Tempo.verify(e.tempos[t]))return"tempos."+n}if(null!=e.notes&&e.hasOwnProperty("notes")){if(!Array.isArray(e.notes))return"notes: array expected";for(t=0;t<e.notes.length;++t)if(n=u.tensorflow.magenta.NoteSequence.Note.verify(e.notes[t]))return"notes."+n}if(null!=e.totalTime&&e.hasOwnProperty("totalTime")&&"number"!=typeof e.totalTime)return"totalTime: number expected";if(null!=e.totalQuantizedSteps&&e.hasOwnProperty("totalQuantizedSteps")&&!(c.isInteger(e.totalQuantizedSteps)||e.totalQuantizedSteps&&c.isInteger(e.totalQuantizedSteps.low)&&c.isInteger(e.totalQuantizedSteps.high)))return"totalQuantizedSteps: integer|Long expected";if(null!=e.pitchBends&&e.hasOwnProperty("pitchBends")){if(!Array.isArray(e.pitchBends))return"pitchBends: array expected";for(t=0;t<e.pitchBends.length;++t)if(n=u.tensorflow.magenta.NoteSequence.PitchBend.verify(e.pitchBends[t]))return"pitchBends."+n}if(null!=e.controlChanges&&e.hasOwnProperty("controlChanges")){if(!Array.isArray(e.controlChanges))return"controlChanges: array expected";for(t=0;t<e.controlChanges.length;++t)if(n=u.tensorflow.magenta.NoteSequence.ControlChange.verify(e.controlChanges[t]))return"controlChanges."+n}if(null!=e.partInfos&&e.hasOwnProperty("partInfos")){if(!Array.isArray(e.partInfos))return"partInfos: array expected";for(t=0;t<e.partInfos.length;++t)if(n=u.tensorflow.magenta.NoteSequence.PartInfo.verify(e.partInfos[t]))return"partInfos."+n}if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&(n=u.tensorflow.magenta.NoteSequence.SourceInfo.verify(e.sourceInfo)))return"sourceInfo."+n;if(null!=e.textAnnotations&&e.hasOwnProperty("textAnnotations")){if(!Array.isArray(e.textAnnotations))return"textAnnotations: array expected";for(t=0;t<e.textAnnotations.length;++t)if(n=u.tensorflow.magenta.NoteSequence.TextAnnotation.verify(e.textAnnotations[t]))return"textAnnotations."+n}if(null!=e.sectionAnnotations&&e.hasOwnProperty("sectionAnnotations")){if(!Array.isArray(e.sectionAnnotations))return"sectionAnnotations: array expected";for(t=0;t<e.sectionAnnotations.length;++t)if(n=u.tensorflow.magenta.NoteSequence.SectionAnnotation.verify(e.sectionAnnotations[t]))return"sectionAnnotations."+n}if(null!=e.sectionGroups&&e.hasOwnProperty("sectionGroups")){if(!Array.isArray(e.sectionGroups))return"sectionGroups: array expected";for(t=0;t<e.sectionGroups.length;++t){var n;if(n=u.tensorflow.magenta.NoteSequence.SectionGroup.verify(e.sectionGroups[t]))return"sectionGroups."+n}}return null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&(n=u.tensorflow.magenta.NoteSequence.QuantizationInfo.verify(e.quantizationInfo))?"quantizationInfo."+n:null!=e.subsequenceInfo&&e.hasOwnProperty("subsequenceInfo")&&(n=u.tensorflow.magenta.NoteSequence.SubsequenceInfo.verify(e.subsequenceInfo))?"subsequenceInfo."+n:null!=e.sequenceMetadata&&e.hasOwnProperty("sequenceMetadata")&&(n=u.tensorflow.magenta.SequenceMetadata.verify(e.sequenceMetadata))?"sequenceMetadata."+n:null},e.fromObject=function(e){if(e instanceof u.tensorflow.magenta.NoteSequence)return e;var t=new u.tensorflow.magenta.NoteSequence;if(null!=e.id&&(t.id=String(e.id)),null!=e.filename&&(t.filename=String(e.filename)),null!=e.referenceNumber&&(c.Long?(t.referenceNumber=c.Long.fromValue(e.referenceNumber)).unsigned=!1:"string"==typeof e.referenceNumber?t.referenceNumber=parseInt(e.referenceNumber,10):"number"==typeof e.referenceNumber?t.referenceNumber=e.referenceNumber:"object"==typeof e.referenceNumber&&(t.referenceNumber=new c.LongBits(e.referenceNumber.low>>>0,e.referenceNumber.high>>>0).toNumber())),null!=e.collectionName&&(t.collectionName=String(e.collectionName)),null!=e.ticksPerQuarter&&(t.ticksPerQuarter=0|e.ticksPerQuarter),e.timeSignatures){if(!Array.isArray(e.timeSignatures))throw TypeError(".tensorflow.magenta.NoteSequence.timeSignatures: array expected");t.timeSignatures=[];for(var n=0;n<e.timeSignatures.length;++n){if("object"!=typeof e.timeSignatures[n])throw TypeError(".tensorflow.magenta.NoteSequence.timeSignatures: object expected");t.timeSignatures[n]=u.tensorflow.magenta.NoteSequence.TimeSignature.fromObject(e.timeSignatures[n])}}if(e.keySignatures){if(!Array.isArray(e.keySignatures))throw TypeError(".tensorflow.magenta.NoteSequence.keySignatures: array expected");for(t.keySignatures=[],n=0;n<e.keySignatures.length;++n){if("object"!=typeof e.keySignatures[n])throw TypeError(".tensorflow.magenta.NoteSequence.keySignatures: object expected");t.keySignatures[n]=u.tensorflow.magenta.NoteSequence.KeySignature.fromObject(e.keySignatures[n])}}if(e.tempos){if(!Array.isArray(e.tempos))throw TypeError(".tensorflow.magenta.NoteSequence.tempos: array expected");for(t.tempos=[],n=0;n<e.tempos.length;++n){if("object"!=typeof e.tempos[n])throw TypeError(".tensorflow.magenta.NoteSequence.tempos: object expected");t.tempos[n]=u.tensorflow.magenta.NoteSequence.Tempo.fromObject(e.tempos[n])}}if(e.notes){if(!Array.isArray(e.notes))throw TypeError(".tensorflow.magenta.NoteSequence.notes: array expected");for(t.notes=[],n=0;n<e.notes.length;++n){if("object"!=typeof e.notes[n])throw TypeError(".tensorflow.magenta.NoteSequence.notes: object expected");t.notes[n]=u.tensorflow.magenta.NoteSequence.Note.fromObject(e.notes[n])}}if(null!=e.totalTime&&(t.totalTime=Number(e.totalTime)),null!=e.totalQuantizedSteps&&(c.Long?(t.totalQuantizedSteps=c.Long.fromValue(e.totalQuantizedSteps)).unsigned=!1:"string"==typeof e.totalQuantizedSteps?t.totalQuantizedSteps=parseInt(e.totalQuantizedSteps,10):"number"==typeof e.totalQuantizedSteps?t.totalQuantizedSteps=e.totalQuantizedSteps:"object"==typeof e.totalQuantizedSteps&&(t.totalQuantizedSteps=new c.LongBits(e.totalQuantizedSteps.low>>>0,e.totalQuantizedSteps.high>>>0).toNumber())),e.pitchBends){if(!Array.isArray(e.pitchBends))throw TypeError(".tensorflow.magenta.NoteSequence.pitchBends: array expected");for(t.pitchBends=[],n=0;n<e.pitchBends.length;++n){if("object"!=typeof e.pitchBends[n])throw TypeError(".tensorflow.magenta.NoteSequence.pitchBends: object expected");t.pitchBends[n]=u.tensorflow.magenta.NoteSequence.PitchBend.fromObject(e.pitchBends[n])}}if(e.controlChanges){if(!Array.isArray(e.controlChanges))throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: array expected");for(t.controlChanges=[],n=0;n<e.controlChanges.length;++n){if("object"!=typeof e.controlChanges[n])throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: object expected");t.controlChanges[n]=u.tensorflow.magenta.NoteSequence.ControlChange.fromObject(e.controlChanges[n])}}if(e.partInfos){if(!Array.isArray(e.partInfos))throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: array expected");for(t.partInfos=[],n=0;n<e.partInfos.length;++n){if("object"!=typeof e.partInfos[n])throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: object expected");t.partInfos[n]=u.tensorflow.magenta.NoteSequence.PartInfo.fromObject(e.partInfos[n])}}if(null!=e.sourceInfo){if("object"!=typeof e.sourceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.sourceInfo: object expected");t.sourceInfo=u.tensorflow.magenta.NoteSequence.SourceInfo.fromObject(e.sourceInfo)}if(e.textAnnotations){if(!Array.isArray(e.textAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: array expected");for(t.textAnnotations=[],n=0;n<e.textAnnotations.length;++n){if("object"!=typeof e.textAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: object expected");t.textAnnotations[n]=u.tensorflow.magenta.NoteSequence.TextAnnotation.fromObject(e.textAnnotations[n])}}if(e.sectionAnnotations){if(!Array.isArray(e.sectionAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: array expected");for(t.sectionAnnotations=[],n=0;n<e.sectionAnnotations.length;++n){if("object"!=typeof e.sectionAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: object expected");t.sectionAnnotations[n]=u.tensorflow.magenta.NoteSequence.SectionAnnotation.fromObject(e.sectionAnnotations[n])}}if(e.sectionGroups){if(!Array.isArray(e.sectionGroups))throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: array expected");for(t.sectionGroups=[],n=0;n<e.sectionGroups.length;++n){if("object"!=typeof e.sectionGroups[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: object expected");t.sectionGroups[n]=u.tensorflow.magenta.NoteSequence.SectionGroup.fromObject(e.sectionGroups[n])}}if(null!=e.quantizationInfo){if("object"!=typeof e.quantizationInfo)throw TypeError(".tensorflow.magenta.NoteSequence.quantizationInfo: object expected");t.quantizationInfo=u.tensorflow.magenta.NoteSequence.QuantizationInfo.fromObject(e.quantizationInfo)}if(null!=e.subsequenceInfo){if("object"!=typeof e.subsequenceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.subsequenceInfo: object expected");t.subsequenceInfo=u.tensorflow.magenta.NoteSequence.SubsequenceInfo.fromObject(e.subsequenceInfo)}if(null!=e.sequenceMetadata){if("object"!=typeof e.sequenceMetadata)throw TypeError(".tensorflow.magenta.NoteSequence.sequenceMetadata: object expected");t.sequenceMetadata=u.tensorflow.magenta.SequenceMetadata.fromObject(e.sequenceMetadata)}return t},e.toObject=function(e,t){t||(t={});var n={};if((t.arrays||t.defaults)&&(n.timeSignatures=[],n.keySignatures=[],n.tempos=[],n.notes=[],n.pitchBends=[],n.controlChanges=[],n.partInfos=[],n.textAnnotations=[],n.sectionAnnotations=[],n.sectionGroups=[]),t.defaults){if(n.id="",n.filename="",n.collectionName="",n.ticksPerQuarter=0,n.totalTime=0,n.sourceInfo=null,n.quantizationInfo=null,c.Long){var i=new c.Long(0,0,!1);n.totalQuantizedSteps=t.longs===String?i.toString():t.longs===Number?i.toNumber():i}else n.totalQuantizedSteps=t.longs===String?"0":0;n.subsequenceInfo=null,c.Long?(i=new c.Long(0,0,!1),n.referenceNumber=t.longs===String?i.toString():t.longs===Number?i.toNumber():i):n.referenceNumber=t.longs===String?"0":0,n.sequenceMetadata=null}if(null!=e.id&&e.hasOwnProperty("id")&&(n.id=e.id),null!=e.filename&&e.hasOwnProperty("filename")&&(n.filename=e.filename),null!=e.collectionName&&e.hasOwnProperty("collectionName")&&(n.collectionName=e.collectionName),null!=e.ticksPerQuarter&&e.hasOwnProperty("ticksPerQuarter")&&(n.ticksPerQuarter=e.ticksPerQuarter),e.timeSignatures&&e.timeSignatures.length){n.timeSignatures=[];for(var r=0;r<e.timeSignatures.length;++r)n.timeSignatures[r]=u.tensorflow.magenta.NoteSequence.TimeSignature.toObject(e.timeSignatures[r],t)}if(e.keySignatures&&e.keySignatures.length)for(n.keySignatures=[],r=0;r<e.keySignatures.length;++r)n.keySignatures[r]=u.tensorflow.magenta.NoteSequence.KeySignature.toObject(e.keySignatures[r],t);if(e.tempos&&e.tempos.length)for(n.tempos=[],r=0;r<e.tempos.length;++r)n.tempos[r]=u.tensorflow.magenta.NoteSequence.Tempo.toObject(e.tempos[r],t);if(e.notes&&e.notes.length)for(n.notes=[],r=0;r<e.notes.length;++r)n.notes[r]=u.tensorflow.magenta.NoteSequence.Note.toObject(e.notes[r],t);if(null!=e.totalTime&&e.hasOwnProperty("totalTime")&&(n.totalTime=t.json&&!isFinite(e.totalTime)?String(e.totalTime):e.totalTime),e.pitchBends&&e.pitchBends.length)for(n.pitchBends=[],r=0;r<e.pitchBends.length;++r)n.pitchBends[r]=u.tensorflow.magenta.NoteSequence.PitchBend.toObject(e.pitchBends[r],t);if(e.controlChanges&&e.controlChanges.length)for(n.controlChanges=[],r=0;r<e.controlChanges.length;++r)n.controlChanges[r]=u.tensorflow.magenta.NoteSequence.ControlChange.toObject(e.controlChanges[r],t);if(e.partInfos&&e.partInfos.length)for(n.partInfos=[],r=0;r<e.partInfos.length;++r)n.partInfos[r]=u.tensorflow.magenta.NoteSequence.PartInfo.toObject(e.partInfos[r],t);if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&(n.sourceInfo=u.tensorflow.magenta.NoteSequence.SourceInfo.toObject(e.sourceInfo,t)),e.textAnnotations&&e.textAnnotations.length)for(n.textAnnotations=[],r=0;r<e.textAnnotations.length;++r)n.textAnnotations[r]=u.tensorflow.magenta.NoteSequence.TextAnnotation.toObject(e.textAnnotations[r],t);if(null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&(n.quantizationInfo=u.tensorflow.magenta.NoteSequence.QuantizationInfo.toObject(e.quantizationInfo,t)),null!=e.totalQuantizedSteps&&e.hasOwnProperty("totalQuantizedSteps")&&("number"==typeof e.totalQuantizedSteps?n.totalQuantizedSteps=t.longs===String?String(e.totalQuantizedSteps):e.totalQuantizedSteps:n.totalQuantizedSteps=t.longs===String?c.Long.prototype.toString.call(e.totalQuantizedSteps):t.longs===Number?new c.LongBits(e.totalQuantizedSteps.low>>>0,e.totalQuantizedSteps.high>>>0).toNumber():e.totalQuantizedSteps),null!=e.subsequenceInfo&&e.hasOwnProperty("subsequenceInfo")&&(n.subsequenceInfo=u.tensorflow.magenta.NoteSequence.SubsequenceInfo.toObject(e.subsequenceInfo,t)),null!=e.referenceNumber&&e.hasOwnProperty("referenceNumber")&&("number"==typeof e.referenceNumber?n.referenceNumber=t.longs===String?String(e.referenceNumber):e.referenceNumber:n.referenceNumber=t.longs===String?c.Long.prototype.toString.call(e.referenceNumber):t.longs===Number?new c.LongBits(e.referenceNumber.low>>>0,e.referenceNumber.high>>>0).toNumber():e.referenceNumber),null!=e.sequenceMetadata&&e.hasOwnProperty("sequenceMetadata")&&(n.sequenceMetadata=u.tensorflow.magenta.SequenceMetadata.toObject(e.sequenceMetadata,t)),e.sectionAnnotations&&e.sectionAnnotations.length)for(n.sectionAnnotations=[],r=0;r<e.sectionAnnotations.length;++r)n.sectionAnnotations[r]=u.tensorflow.magenta.NoteSequence.SectionAnnotation.toObject(e.sectionAnnotations[r],t);if(e.sectionGroups&&e.sectionGroups.length)for(n.sectionGroups=[],r=0;r<e.sectionGroups.length;++r)n.sectionGroups[r]=u.tensorflow.magenta.NoteSequence.SectionGroup.toObject(e.sectionGroups[r],t);return n},e.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},e.Note=function(){function e(e){if(e)for(var t=Object.keys(e),n=0;n<t.length;++n)null!=e[t[n]]&&(this[t[n]]=e[t[n]])}return e.prototype.pitch=0,e.prototype.pitchName=0,e.prototype.velocity=0,e.prototype.startTime=0,e.prototype.quantizedStartStep=c.Long?c.Long.fromBits(0,0,!1):0,e.prototype.endTime=0,e.prototype.quantizedEndStep=c.Long?c.Long.fromBits(0,0,!1):0,