UNPKG

@magenta/music

Version:

Make music with machine learning, in the browser.

1 lines 242 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,(function(__WEBPACK_EXTERNAL_MODULE__2__,__WEBPACK_EXTERNAL_MODULE__9__){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=73)}([,,function(t,e){t.exports=__WEBPACK_EXTERNAL_MODULE__2__},,,,,,function(t,e,n){"use strict";n.r(e),n.d(e,"DEFAULT_QUARTERS_PER_MINUTE",(function(){return r})),n.d(e,"DEFAULT_STEPS_PER_BAR",(function(){return i})),n.d(e,"DEFAULT_STEPS_PER_QUARTER",(function(){return o})),n.d(e,"DEFAULT_STEPS_PER_SECOND",(function(){return s})),n.d(e,"DEFAULT_VELOCITY",(function(){return a})),n.d(e,"DEFAULT_PROGRAM",(function(){return u})),n.d(e,"DEFAULT_TICKS_PER_QUARTER",(function(){return c})),n.d(e,"DEFAULT_CHANNEL",(function(){return l})),n.d(e,"DRUM_CHANNEL",(function(){return h})),n.d(e,"NON_DRUM_CHANNELS",(function(){return p})),n.d(e,"DEFAULT_DRUM_PITCH_CLASSES",(function(){return f})),n.d(e,"MIN_MIDI_VELOCITY",(function(){return m})),n.d(e,"MAX_MIDI_VELOCITY",(function(){return d})),n.d(e,"MIDI_VELOCITIES",(function(){return g})),n.d(e,"NO_CHORD",(function(){return S})),n.d(e,"NUM_PITCH_CLASSES",(function(){return y})),n.d(e,"MIN_MIDI_PITCH",(function(){return b})),n.d(e,"MAX_MIDI_PITCH",(function(){return w})),n.d(e,"MIDI_PITCHES",(function(){return P})),n.d(e,"MIN_PIANO_PITCH",(function(){return v})),n.d(e,"MAX_PIANO_PITCH",(function(){return N})),n.d(e,"MIN_DRUM_PITCH",(function(){return T})),n.d(e,"MAX_DRUM_PITCH",(function(){return O})),n.d(e,"MIN_MIDI_PROGRAM",(function(){return I})),n.d(e,"MAX_MIDI_PROGRAM",(function(){return M})),n.d(e,"LO_CLICK_PITCH",(function(){return A})),n.d(e,"HI_CLICK_PITCH",(function(){return k})),n.d(e,"LO_CLICK_CLASS",(function(){return q})),n.d(e,"HI_CLICK_CLASS",(function(){return E}));const r=120,i=16,o=4,s=100,a=80,u=0,c=220,l=0,h=9,p=[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15],f=[[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,d=127,g=d-m+1,S="N.C.",y=12,b=0,w=127,P=w-b+1,v=21,N=108,T=35,O=81,I=0,M=127,A=89,k=90,q=9,E=10},function(t,e){t.exports=__WEBPACK_EXTERNAL_MODULE__9__},function(t,e,n){"use strict";n.d(e,"a",(function(){return i}));var r=n(35),i=r.tensorflow.magenta.NoteSequence},,function(t,e,n){"use strict";n.r(e),n.d(e,"Level",(function(){return r})),n.d(e,"verbosity",(function(){return o})),n.d(e,"setVerbosity",(function(){return s})),n.d(e,"log",(function(){return a})),n.d(e,"logWithDuration",(function(){return u}));var r,i=n(15);!function(t){t[t.NONE=0]="NONE",t[t.WARN=5]="WARN",t[t.INFO=10]="INFO",t[t.DEBUG=20]="DEBUG"}(r||(r={}));let o=10;function s(t){t=t}function a(t,e="Magenta.js",n=10){if(0===n)throw Error("Logging level cannot be NONE.");if(o>=n){(5===n?console.warn:console.log)(`%c ${e} `,"background:magenta; color:white",t)}}function u(t,e,n="Magenta.js",r=10){a(`${t} in ${((i.d.now()-e)/1e3).toPrecision(3)}s`,n,r)}},function(t,e,n){"use strict";n.r(e),n.d(e,"MultipleTimeSignatureException",(function(){return o})),n.d(e,"BadTimeSignatureException",(function(){return s})),n.d(e,"NegativeTimeException",(function(){return a})),n.d(e,"MultipleTempoException",(function(){return u})),n.d(e,"QuantizationStatusException",(function(){return c})),n.d(e,"clone",(function(){return l})),n.d(e,"stepsPerQuarterToStepsPerSecond",(function(){return h})),n.d(e,"quantizeToStep",(function(){return p})),n.d(e,"quantizeNoteSequence",(function(){return d})),n.d(e,"isQuantizedSequence",(function(){return g})),n.d(e,"assertIsQuantizedSequence",(function(){return S})),n.d(e,"isRelativeQuantizedSequence",(function(){return y})),n.d(e,"assertIsRelativeQuantizedSequence",(function(){return b})),n.d(e,"isAbsoluteQuantizedSequence",(function(){return w})),n.d(e,"assertIsAbsoluteQuantizedSequence",(function(){return P})),n.d(e,"unquantizeSequence",(function(){return v})),n.d(e,"createQuantizedNoteSequence",(function(){return N})),n.d(e,"mergeInstruments",(function(){return T})),n.d(e,"replaceInstruments",(function(){return O})),n.d(e,"mergeConsecutiveNotes",(function(){return I})),n.d(e,"applySustainControlChanges",(function(){return M})),n.d(e,"concatenate",(function(){return A})),n.d(e,"trim",(function(){return k})),n.d(e,"split",(function(){return _}));var r=n(10),i=n(8);class o extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}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)}}function l(t){return r.a.decode(r.a.encode(t).finish())}function h(t,e){return t*e/60}function p(t,e,n=.5){const r=t*e;return Math.floor(r+(1-n))}function f(t){return t.controlChanges.concat(t.textAnnotations)}function m(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!==i.DEFAULT_QUARTERS_PER_MINUTE)throw new u("NoteSequence has an implicit tempo change from initial "+i.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 u(`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 d(t,e){const n=l(t);if(n.quantizationInfo=r.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 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 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 o("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=r.a.TimeSignature.create({numerator:4,denominator:4,time:0});n.timeSignatures.push(t)}const u=n.timeSignatures[0];if(!(c=u.denominator)||0!=(c&c-1))throw new s(`Denominator is not a power of 2. Time signature: ${u.numerator}/${u.denominator}`);var c;if(0===u.numerator)throw new s(`Numerator is 0. Time signature: ${u.numerator}/${u.denominator}`);if(n.tempos.length>0)m(n),n.tempos[0].time=0,n.tempos=[n.tempos[0]];else{const t=r.a.Tempo.create({qpm:i.DEFAULT_QUARTERS_PER_MINUTE,time:0});n.tempos.push(t)}const d=h(e,n.tempos[0].qpm);return n.totalQuantizedSteps=p(t.totalTime,d),function(t,e){for(const n of t.notes){if(n.quantizedStartStep=p(n.startTime,e),n.quantizedEndStep=p(n.endTime,e),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>t.totalQuantizedSteps&&(t.totalQuantizedSteps=n.quantizedEndStep)}f(t).forEach(t=>{if(t.quantizedStep=p(t.time,e),t.quantizedStep<0)throw new a("Got negative event time: step = "+t.quantizedStep)})}(n,d),n}function g(t){return t.quantizationInfo&&(t.quantizationInfo.stepsPerQuarter>0||t.quantizationInfo.stepsPerSecond>0)}function S(t){if(!g(t))throw new c(`NoteSequence ${t.id} is not quantized (missing quantizationInfo)`)}function y(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerQuarter>0}function b(t){if(!y(t))throw new c(`NoteSequence ${t.id} is not quantized or is quantized based on absolute timing`)}function w(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerSecond>0}function P(t){if(!w(t))throw new c(`NoteSequence ${t.id} is not quantized or is quantized based on relative timing`)}function v(t,e){b(t),m(t);const n=l(t);e?n.tempos&&n.tempos.length>0?n.tempos[0].qpm=e:n.tempos.push(r.a.Tempo.create({time:0,qpm:e})):e=t.tempos&&t.tempos.length>0?n.tempos[0].qpm:i.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}),f(n).forEach(t=>{t.time=o(t.time)}),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function N(t=i.DEFAULT_STEPS_PER_QUARTER,e=i.DEFAULT_QUARTERS_PER_MINUTE){return r.a.create({quantizationInfo:{stepsPerQuarter:t},tempos:[{qpm:e}]})}function T(t){const e=l(t),n=e.notes.concat(e.pitchBends).concat(e.controlChanges),r=Array.from(new Set(n.filter(t=>!t.isDrum).map(t=>t.program)));return n.forEach(t=>{t.isDrum?(t.program=0,t.instrument=r.length):t.instrument=r.indexOf(t.program)}),e}function O(t,e){const n=new Set(t.notes.map(t=>t.instrument)),i=new Set(e.notes.map(t=>t.instrument)),o=[];t.notes.forEach(t=>{i.has(t.instrument)||o.push(r.a.Note.create(t))}),e.notes.forEach(t=>{n.has(t.instrument)&&o.push(r.a.Note.create(t))});const s=l(t);return s.notes=o.sort((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep}),s}function I(t){S(t);const e=l(t);e.notes=[];const n=t.notes.sort((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep}),i=new r.a.Note;i.pitch=n[0].pitch,i.instrument=n[0].instrument,i.quantizedStartStep=n[0].quantizedStartStep,i.quantizedEndStep=n[0].quantizedEndStep,e.notes.push(i);let o=0;for(let t=1;t<n.length;t++){const i=n[t],s=e.notes[o];if(s.instrument===i.instrument&&s.pitch===i.pitch&&i.quantizedStartStep===s.quantizedEndStep&&i.quantizedStartStep%16!=0)e.notes[o].quantizedEndStep+=i.quantizedEndStep-i.quantizedStartStep;else{const i=new r.a.Note;i.pitch=n[t].pitch,i.instrument=n[t].instrument,i.quantizedStartStep=n[t].quantizedStartStep,i.quantizedEndStep=n[t].quantizedEndStep,e.notes.push(i),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(g(t))throw new Error("Can only apply sustain to unquantized NoteSequence.");const r=l(t),i=[];for(const t of r.notes)!1===t.isDrum&&(null!==t.startTime&&i.push({time:t.startTime,type:n.NOTE_ON,event:t}),null!==t.endTime&&i.push({time:t.endTime,type:n.NOTE_OFF,event:t}));for(const t of r.controlChanges)if(t.controlNumber===e){const e=t.controlValue;e>=64?i.push({time:t.time,type:n.SUSTAIN_ON,event:t}):e<64&&i.push({time:t.time,type:n.SUSTAIN_OFF,event:t})}i.sort((t,e)=>t.time-e.time);const o={},s={};let a=0;for(const t of i){a=t.time;const e=t.type,i=t.event;if(e===n.SUSTAIN_ON)s[i.instrument]=!0;else if(e===n.SUSTAIN_OFF){s[i.instrument]=!1;const t=[];i.instrument in o||(o[i.instrument]=[]);for(const e of o[i.instrument])e.endTime<a?(e.endTime=a,a>r.totalTime&&(r.totalTime=a)):t.push(e);o[i.instrument]=t}else if(e===n.NOTE_ON){if(!0===s[i.instrument]){const t=[];i.instrument in o||(o[i.instrument]=[]);for(const e of o[i.instrument])e.pitch===i.pitch?(e.endTime=a,e.startTime===e.endTime&&r.notes.push(e)):t.push(e);o[i.instrument]=t}i.instrument in o||(o[i.instrument]=[]),o[i.instrument].push(i)}else if(e===n.NOTE_OFF)if(!0===s[i.instrument]);else{const t=o[i.instrument].indexOf(i);t>-1&&o[i.instrument].splice(t,1)}}for(const t of Object.values(o))for(const e of t)e.endTime=a,r.totalTime=a;return r}function A(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(g(t[0])){for(let e=0;e<t.length;++e)if(S(t[e]),t[e].quantizationInfo.stepsPerQuarter!==t[0].quantizationInfo.stepsPerQuarter)throw new Error("Not all sequences have the same quantizationInfo");return q(t,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",e)}return q(t,"totalTime","startTime","endTime",e)}function k(t,e,n,r){return g(t)?E(t,e,n,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",r):E(t,e,n,"totalTime","startTime","endTime",r)}function q(t,e,n,i,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=l(t[0]):Array.prototype.push.apply(s.notes,t[u].notes.map(t=>{const e=r.a.Note.create(t);return e[n]+=a,e[i]+=a,e})),a+=c}return s[e]=a,s}function E(t,e,n,r,i,o,s){const a=l(t);a[r]=n,a.notes=a.notes.filter(t=>t[i]>=e&&t[i]<=n&&(s||t[o]<=n)),a[r]-=e;for(let t=0;t<a.notes.length;t++)a.notes[t][i]-=e,a.notes[t][o]-=e,s&&(a.notes[t][o]=Math.min(a.notes[t][o],a[r]));return a}function _(t,e){S(t);const n=l(t),i=n.notes.sort((t,e)=>t.quantizedStartStep-e.quantizedStartStep),o=[];let s=0,a=[];for(let t=0;t<i.length;t++){const u=i[t],c=u.quantizedStartStep,h=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=r.a.Note.create(u);t.quantizedEndStep=e,t.startTime=t.endTime=void 0,a.push(t),u.quantizedStartStep=s+e,u.quantizedEndStep=h}else u.quantizedStartStep=c,u.quantizedEndStep=h;if((u.quantizedEndStep>e||u.quantizedStartStep>e)&&(t-=1),0!==a.length){const t=l(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}a=[],s+=e}}if(0!==a.length){const t=l(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}return o}},,function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return i})),n.d(e,"d",(function(){return o})),n.d(e,"c",(function(){return s})),n.d(e,"b",(function(){return u}));const r=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==t)return t;throw new Error("cannot find the global object")}(),i=r.fetch.bind(r),o=r.performance,s=(r.navigator,!!r.webkitOfflineAudioContext),a=void 0!==r.WorkerGlobalScope;function u(t){if(t=s?44100:t,a)throw new Error("Cannot use offline audio context in a web worker.");const e=r.webkitOfflineAudioContext;return s?new e(1,t,t):new r.OfflineAudioContext(1,t,t)}}).call(this,n(21))},,,function(t,e,n){"use strict";(function(t){var r=e;function i(t,e,n){for(var r=Object.keys(e),i=0;i<r.length;++i)void 0!==t[r[i]]&&n||(t[r[i]]=e[r[i]]);return t}function o(t){function e(t,n){if(!(this instanceof e))return new e(t,n);Object.defineProperty(this,"message",{get:function(){return t}}),Error.captureStackTrace?Error.captureStackTrace(this,e):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),n&&i(this,n)}return(e.prototype=Object.create(Error.prototype)).constructor=e,Object.defineProperty(e.prototype,"name",{get:function(){return t}}),e.prototype.toString=function(){return this.name+": "+this.message},e}r.asPromise=n(51),r.base64=n(52),r.EventEmitter=n(53),r.float=n(54),r.inquire=n(55),r.utf8=n(56),r.pool=n(57),r.LongBits=n(58),r.isNode=Boolean(void 0!==t&&t&&t.process&&t.process.versions&&t.process.versions.node),r.global=r.isNode&&t||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||this,r.emptyArray=Object.freeze?Object.freeze([]):[],r.emptyObject=Object.freeze?Object.freeze({}):{},r.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},r.isString=function(t){return"string"==typeof t||t instanceof String},r.isObject=function(t){return t&&"object"==typeof t},r.isset=r.isSet=function(t,e){var n=t[e];return!(null==n||!t.hasOwnProperty(e))&&("object"!=typeof n||(Array.isArray(n)?n.length:Object.keys(n).length)>0)},r.Buffer=function(){try{var t=r.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(t){return"number"==typeof t?r.Buffer?r._Buffer_allocUnsafe(t):new r.Array(t):r.Buffer?r._Buffer_from(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(t){return t?r.LongBits.from(t).toHash():r.LongBits.zeroHash},r.longFromHash=function(t,e){var n=r.LongBits.fromHash(t);return r.Long?r.Long.fromBits(n.lo,n.hi,e):n.toNumber(Boolean(e))},r.merge=i,r.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)},r.newError=o,r.ProtocolError=o("ProtocolError"),r.oneOfGetter=function(t){for(var e={},n=0;n<t.length;++n)e[t[n]]=1;return function(){for(var t=Object.keys(this),n=t.length-1;n>-1;--n)if(1===e[t[n]]&&void 0!==this[t[n]]&&null!==this[t[n]])return t[n]}},r.oneOfSetter=function(t){return function(e){for(var n=0;n<t.length;++n)t[n]!==e&&delete this[t[n]]}},r.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},r._configure=function(){var t=r.Buffer;t?(r._Buffer_from=t.from!==Uint8Array.from&&t.from||function(e,n){return new t(e,n)},r._Buffer_allocUnsafe=t.allocUnsafe||function(e){return new t(e)}):r._Buffer_from=r._Buffer_allocUnsafe=null}}).call(this,n(21))},,,function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},,function(t,e,n){"use strict";n.r(e),n.d(e,"NO_EVENT",(function(){return s})),n.d(e,"NOTE_OFF",(function(){return a})),n.d(e,"Melody",(function(){return u})),n.d(e,"MelodyRhythm",(function(){return c})),n.d(e,"MelodyShape",(function(){return l})),n.d(e,"MelodyRegister",(function(){return h}));var r=n(2),i=n(10),o=n(13);const s=0,a=1;class u{constructor(t,e,n){this.events=t,this.minPitch=e,this.maxPitch=n}static fromNoteSequence(t,e,n,r=!0,i){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(i||t.totalQuantizedSteps);let l=-1;return s.forEach(t=>{if(t.quantizedStartStep===l){if(r)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 r=null;for(let t=0;t<this.events.length;++t){const e=this.events[t];switch(e){case s:break;case a:r&&(r.quantizedEndStep=t,n.notes.push(r),r=null);break;default:r&&(r.quantizedEndStep=t,n.notes.push(r)),r=i.a.Note.create({pitch:e-2+this.minPitch,quantizedStartStep:t})}}return r&&(r.quantizedEndStep=this.events.length,n.notes.push(r)),n.totalQuantizedSteps=this.events.length,n}}class c{constructor(){this.depth=1}extract(t){const e=t.events.length,n=r.buffer([e,1]);for(let r=0;r<e;++r)n.set(t.events[r]>=2?1:0,r,0);return n.toTensor().as2D(e,1)}}class l{constructor(){this.depth=3}extract(t){const e=t.events.length,n=r.buffer([e,3]);let i=null,o=null;for(let r=0;r<e;++r)if(t.events[r]>=2){if(null!==i){let e;0===n.get(i,0)&&0===n.get(i,1)&&0===n.get(i,2)&&(i=-1),e=t.events[r]<o?0:t.events[r]>o?2:1;for(let t=r;t>i;--t)n.set(1,t,e)}i=r,o=t.events[r]}if(i!==e-1)if(null===i||0===n.get(i,0)&&0===n.get(i,1)&&0===n.get(i,2))for(let t=0;t<e;++t)n.set(1,t,1);else for(let t=e-1;t>i;--t)for(let e=0;e<3;e++)n.set(n.get(i,e),t,e);return n.toTensor().as2D(e,3)}}class h{constructor(t){this.boundaryPitches=t,this.depth=t.length+1}meanMelodyPitch(t){let e=0,n=0,r=null;for(let i=0;i<t.events.length;++i)t.events[i]===a?r=null:t.events[i]>=2&&(r=t.minPitch+t.events[i]-2),null!==r&&(e+=r,n+=1);return n?e/n:null}extract(t){const e=t.events.length,n=this.meanMelodyPitch(t);if(null===n)return r.zeros([e,this.depth]);let i=0;for(;i<this.boundaryPitches.length&&n>=this.boundaryPitches[i];)i++;const o=r.buffer([e,this.depth]);for(let t=0;t<e;++t)o.set(1,t,i);return o.toTensor().as2D(e,this.depth)}}},,,,,,function(t,e,n){"use strict";n.r(e),n.d(e,"Performance",(function(){return a}));var r=n(10),i=n(8),o=n(13),s=n(12);class a{constructor(t,e,n,r,i){this.events=t,this.maxShiftSteps=e,this.numVelocityBins=n,this.program=r,this.isDrum=i}static fromNoteSequence(t,e,n,r){o.assertIsQuantizedSequence(t);const s=t.notes.filter((t,e)=>void 0===r||t.instrument===r),u=s.sort((t,e)=>t.startTime===e.startTime?t.pitch-e.pitch:t.startTime-e.startTime),c=u.map((t,e)=>({step:t.quantizedStartStep,index:e,isOffset:0})),l=u.map((t,e)=>({step:t.quantizedEndStep,index:e,isOffset:1})),h=c.concat(l).sort((t,e)=>t.step===e.step?t.index===e.index?t.isOffset-e.isOffset:t.index-e.index:t.step-e.step),p=n?Math.ceil((i.MIDI_VELOCITIES-1)/n):void 0,f=[];let m=0,d=n;for(const t of h){if(t.step>m){for(;t.step>m+e;)f.push({type:"time-shift",steps:e}),m+=e;f.push({type:"time-shift",steps:t.step-m}),m=t.step}if(t.isOffset)f.push({type:"note-off",pitch:u[t.index].pitch});else{if(p){const e=Math.floor((u[t.index].velocity-i.MIN_MIDI_VELOCITY-1)/p)+1;e!==d&&(f.push({type:"velocity-change",velocityBin:e}),d=e)}f.push({type:"note-on",pitch:u[t.index].pitch})}}const g=!!s.some(t=>t.isDrum)&&(!s.some(t=>!t.isDrum)||void 0),S=Array.from(new Set(s.map(t=>t.program))),y=g||1!==S.length?void 0:S[0],b=new a(f,e,n,y,g);return b.setNumSteps(t.totalQuantizedSteps),b}getNumSteps(){return this.events.filter(t=>"time-shift"===t.type).map(t=>t.steps).reduce((t,e)=>t+e,0)}setNumSteps(t){let e=this.getNumSteps();if(e<t){if(this.events.length){const n=this.events[this.events.length-1];if("time-shift"===n.type){const r=Math.min(t-e,this.maxShiftSteps-n.steps);n.steps+=r,e+=r}}for(;e<t;)e+this.maxShiftSteps>t?(this.events.push({type:"time-shift",steps:t-e}),e=t):(this.events.push({type:"time-shift",steps:this.maxShiftSteps}),e+=this.maxShiftSteps)}else if(e>t)for(;this.events.length&&e>t;){const n=this.events[this.events.length-1];"time-shift"===n.type?e-n.steps<t?(n.steps-=e-t,e=t):(this.events.pop(),e-=n.steps):this.events.pop()}}toNoteSequence(t){const e=this.numVelocityBins?Math.ceil((i.MIDI_VELOCITIES-1)/this.numVelocityBins):void 0,n=r.a.create();let o=0,a=void 0;const u=new Map;for(let t=i.MIN_MIDI_PITCH;t<=i.MAX_MIDI_PITCH;++t)u.set(t,[]);for(const c of this.events)switch(c.type){case"note-on":u.get(c.pitch).push([o,a]);break;case"note-off":const l=u.get(c.pitch);if(l.length){const[e,i]=l.shift();o>e?n.notes.push(r.a.Note.create({pitch:c.pitch,velocity:i,instrument:t,quantizedStartStep:e,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${c.pitch}, step = ${o})`,"Performance")}else s.log(`Ignoring note-off with no previous note-on:(pitch = ${c.pitch}, step = ${o})`,"Performance");break;case"time-shift":o+=c.steps;break;case"velocity-change":if(!e)throw new Error("Unexpected velocity change event: "+c);a=i.MIN_MIDI_VELOCITY+(c.velocityBin-1)*e+1;break;default:throw new Error("Unrecognized performance event: "+c)}return u.forEach((e,i)=>{for(const[a,u]of e)o>a?n.notes.push(r.a.Note.create({pitch:i,velocity:u,instrument:t,quantizedStartStep:a,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${i}, step = ${o})`,"Performance")}),n.totalQuantizedSteps=o,n}}},,,,function(t,e,n){"use strict";t.exports=h;var r,i=n(18),o=i.LongBits,s=i.base64,a=i.utf8;function u(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}function c(){}function l(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function h(){this.len=0,this.head=new u(c,0,0),this.tail=this.head,this.states=null}var p=function(){return i.Buffer?function(){return(h.create=function(){return new r})()}:function(){return new h}};function f(t,e,n){e[n]=255&t}function m(t,e){this.len=t,this.next=void 0,this.val=e}function d(t,e,n){for(;t.hi;)e[n++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[n++]=127&t.lo|128,t.lo=t.lo>>>7;e[n++]=t.lo}function g(t,e,n){e[n]=255&t,e[n+1]=t>>>8&255,e[n+2]=t>>>16&255,e[n+3]=t>>>24}h.create=p(),h.alloc=function(t){return new i.Array(t)},i.Array!==Array&&(h.alloc=i.pool(h.alloc,i.Array.prototype.subarray)),h.prototype._push=function(t,e,n){return this.tail=this.tail.next=new u(t,e,n),this.len+=e,this},m.prototype=Object.create(u.prototype),m.prototype.fn=function(t,e,n){for(;t>127;)e[n++]=127&t|128,t>>>=7;e[n]=t},h.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new m((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},h.prototype.int32=function(t){return t<0?this._push(d,10,o.fromNumber(t)):this.uint32(t)},h.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},h.prototype.uint64=function(t){var e=o.from(t);return this._push(d,e.length(),e)},h.prototype.int64=h.prototype.uint64,h.prototype.sint64=function(t){var e=o.from(t).zzEncode();return this._push(d,e.length(),e)},h.prototype.bool=function(t){return this._push(f,1,t?1:0)},h.prototype.fixed32=function(t){return this._push(g,4,t>>>0)},h.prototype.sfixed32=h.prototype.fixed32,h.prototype.fixed64=function(t){var e=o.from(t);return this._push(g,4,e.lo)._push(g,4,e.hi)},h.prototype.sfixed64=h.prototype.fixed64,h.prototype.float=function(t){return this._push(i.float.writeFloatLE,4,t)},h.prototype.double=function(t){return this._push(i.float.writeDoubleLE,8,t)};var S=i.Array.prototype.set?function(t,e,n){e.set(t,n)}:function(t,e,n){for(var r=0;r<t.length;++r)e[n+r]=t[r]};h.prototype.bytes=function(t){var e=t.length>>>0;if(!e)return this._push(f,1,0);if(i.isString(t)){var n=h.alloc(e=s.length(t));s.decode(t,n,0),t=n}return this.uint32(e)._push(S,e,t)},h.prototype.string=function(t){var e=a.length(t);return e?this.uint32(e)._push(a.write,e,t):this._push(f,1,0)},h.prototype.fork=function(){return this.states=new l(this),this.head=this.tail=new u(c,0,0),this.len=0,this},h.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new u(c,0,0),this.len=0),this},h.prototype.ldelim=function(){var t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=t.next,this.tail=e,this.len+=n),this},h.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),n=0;t;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e},h._configure=function(t){r=t,h.create=p(),r._configure()}},function(t,e,n){"use strict";t.exports=u;var r,i=n(18),o=i.LongBits,s=i.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 i.Buffer?function(t){return(u.create=function(t){return i.Buffer.isBuffer(t)?new r(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 f(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}function m(){if(this.pos+8>this.len)throw a(this,8);return new o(f(this.buf,this.pos+=4),f(this.buf,this.pos+=4))}u.create=h(),u.prototype._slice=i.Array.prototype.subarray||i.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)|0},u.prototype.bool=function(){return 0!==this.uint32()},u.prototype.fixed32=function(){if(this.pos+4>this.len)throw a(this,4);return f(this.buf,this.pos+=4)},u.prototype.sfixed32=function(){if(this.pos+4>this.len)throw a(this,4);return 0|f(this.buf,this.pos+=4)},u.prototype.float=function(){if(this.pos+4>this.len)throw a(this,4);var t=i.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=i.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){r=t,u.create=h(),r._configure();var e=i.Long?"toLong":"toNumber";i.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 m.call(this)[e](!0)},sfixed64:function(){return m.call(this)[e](!1)}})}},function(t,e,n){"use strict";var r,i,o=n(49),s=o.Reader,a=o.Writer,u=o.util,c=o.roots.default||(o.roots.default={});c.tensorflow=((i={}).magenta=((r={}).NoteSequence=function(){function t(t){if(this.timeSignatures=[],this.keySignatures=[],this.tempos=[],this.notes=[],this.pitchBends=[],this.controlChanges=[],this.partInfos=[],this.textAnnotations=[],this.sectionAnnotations=[],this.sectionGroups=[],t)for(var e=Object.keys(t),n=0;n<e.length;++n)null!=t[e[n]]&&(this[e[n]]=t[e[n]])}var e,n;return t.prototype.id="",t.prototype.filename="",t.prototype.referenceNumber=u.Long?u.Long.fromBits(0,0,!1):0,t.prototype.collectionName="",t.prototype.ticksPerQuarter=0,t.prototype.timeSignatures=u.emptyArray,t.prototype.keySignatures=u.emptyArray,t.prototype.tempos=u.emptyArray,t.prototype.notes=u.emptyArray,t.prototype.totalTime=0,t.prototype.totalQuantizedSteps=u.Long?u.Long.fromBits(0,0,!1):0,t.prototype.pitchBends=u.emptyArray,t.prototype.controlChanges=u.emptyArray,t.prototype.partInfos=u.emptyArray,t.prototype.sourceInfo=null,t.prototype.textAnnotations=u.emptyArray,t.prototype.sectionAnnotations=u.emptyArray,t.prototype.sectionGroups=u.emptyArray,t.prototype.quantizationInfo=null,t.prototype.subsequenceInfo=null,t.prototype.sequenceMetadata=null,t.create=function(e){return new t(e)},t.encode=function(t,e){if(e||(e=a.create()),null!=t.id&&t.hasOwnProperty("id")&&e.uint32(10).string(t.id),null!=t.filename&&t.hasOwnProperty("filename")&&e.uint32(18).string(t.filename),null!=t.collectionName&&t.hasOwnProperty("collectionName")&&e.uint32(26).string(t.collectionName),null!=t.ticksPerQuarter&&t.hasOwnProperty("ticksPerQuarter")&&e.uint32(32).int32(t.ticksPerQuarter),null!=t.timeSignatures&&t.timeSignatures.length)for(var n=0;n<t.timeSignatures.length;++n)c.tensorflow.magenta.NoteSequence.TimeSignature.encode(t.timeSignatures[n],e.uint32(42).fork()).ldelim();if(null!=t.keySignatures&&t.keySignatures.length)for(n=0;n<t.keySignatures.length;++n)c.tensorflow.magenta.NoteSequence.KeySignature.encode(t.keySignatures[n],e.uint32(50).fork()).ldelim();if(null!=t.tempos&&t.tempos.length)for(n=0;n<t.tempos.length;++n)c.tensorflow.magenta.NoteSequence.Tempo.encode(t.tempos[n],e.uint32(58).fork()).ldelim();if(null!=t.notes&&t.notes.length)for(n=0;n<t.notes.length;++n)c.tensorflow.magenta.NoteSequence.Note.encode(t.notes[n],e.uint32(66).fork()).ldelim();if(null!=t.totalTime&&t.hasOwnProperty("totalTime")&&e.uint32(73).double(t.totalTime),null!=t.pitchBends&&t.pitchBends.length)for(n=0;n<t.pitchBends.length;++n)c.tensorflow.magenta.NoteSequence.PitchBend.encode(t.pitchBends[n],e.uint32(82).fork()).ldelim();if(null!=t.controlChanges&&t.controlChanges.length)for(n=0;n<t.controlChanges.length;++n)c.tensorflow.magenta.NoteSequence.ControlChange.encode(t.controlChanges[n],e.uint32(90).fork()).ldelim();if(null!=t.partInfos&&t.partInfos.length)for(n=0;n<t.partInfos.length;++n)c.tensorflow.magenta.NoteSequence.PartInfo.encode(t.partInfos[n],e.uint32(98).fork()).ldelim();if(null!=t.sourceInfo&&t.hasOwnProperty("sourceInfo")&&c.tensorflow.magenta.NoteSequence.SourceInfo.encode(t.sourceInfo,e.uint32(106).fork()).ldelim(),null!=t.textAnnotations&&t.textAnnotations.length)for(n=0;n<t.textAnnotations.length;++n)c.tensorflow.magenta.NoteSequence.TextAnnotation.encode(t.textAnnotations[n],e.uint32(114).fork()).ldelim();if(null!=t.quantizationInfo&&t.hasOwnProperty("quantizationInfo")&&c.tensorflow.magenta.NoteSequence.QuantizationInfo.encode(t.quantizationInfo,e.uint32(122).fork()).ldelim(),null!=t.totalQuantizedSteps&&t.hasOwnProperty("totalQuantizedSteps")&&e.uint32(128).int64(t.totalQuantizedSteps),null!=t.subsequenceInfo&&t.hasOwnProperty("subsequenceInfo")&&c.tensorflow.magenta.NoteSequence.SubsequenceInfo.encode(t.subsequenceInfo,e.uint32(138).fork()).ldelim(),null!=t.referenceNumber&&t.hasOwnProperty("referenceNumber")&&e.uint32(144).int64(t.referenceNumber),null!=t.sequenceMetadata&&t.hasOwnProperty("sequenceMetadata")&&c.tensorflow.magenta.SequenceMetadata.encode(t.sequenceMetadata,e.uint32(154).fork()).ldelim(),null!=t.sectionAnnotations&&t.sectionAnnotations.length)for(n=0;n<t.sectionAnnotations.length;++n)c.tensorflow.magenta.NoteSequence.SectionAnnotation.encode(t.sectionAnnotations[n],e.uint32(162).fork()).ldelim();if(null!=t.sectionGroups&&t.sectionGroups.length)for(n=0;n<t.sectionGroups.length;++n)c.tensorflow.magenta.NoteSequence.SectionGroup.encode(t.sectionGroups[n],e.uint32(170).fork()).ldelim();return e},t.encodeDelimited=function(t,e){return this.encode(t,e).ldelim()},t.decode=function(t,e){t instanceof s||(t=s.create(t));for(var n=void 0===e?t.len:t.pos+e,r=new c.tensorflow.magenta.NoteSequence;t.pos<n;){var i=t.uint32();switch(i>>>3){case 1:r.id=t.string();break;case 2:r.filename=t.string();break;case 18:r.referenceNumber=u.Long?t.int64().toNumber():t.int64();break;case 3:r.collectionName=t.string();break;case 4:r.ticksPerQuarter=t.int32();break;case 5:r.timeSignatures&&r.timeSignatures.length||(r.timeSignatures=[]),r.timeSignatures.push(c.tensorflow.magenta.NoteSequence.TimeSignature.decode(t,t.uint32()));break;case 6:r.keySignatures&&r.keySignatures.length||(r.keySignatures=[]),r.keySignatures.push(c.tensorflow.magenta.NoteSequence.KeySignature.decode(t,t.uint32()));break;case 7:r.tempos&&r.tempos.length||(r.tempos=[]),r.tempos.push(c.tensorflow.magenta.NoteSequence.Tempo.decode(t,t.uint32()));break;case 8:r.notes&&r.notes.length||(r.notes=[]),r.notes.push(c.tensorflow.magenta.NoteSequence.Note.decode(t,t.uint32()));break;case 9:r.totalTime=t.double();break;case 16:r.totalQuantizedSteps=u.Long?t.int64().toNumber():t.int64();break;case 10:r.pitchBends&&r.pitchBends.length||(r.pitchBends=[]),r.pitchBends.push(c.tensorflow.magenta.NoteSequence.PitchBend.decode(t,t.uint32()));break;case 11:r.controlChanges&&r.controlChanges.length||(r.controlChanges=[]),r.controlChanges.push(c.tensorflow.magenta.NoteSequence.ControlChange.decode(t,t.uint32()));break;case 12:r.partInfos&&r.partInfos.length||(r.partInfos=[]),r.partInfos.push(c.tensorflow.magenta.NoteSequence.PartInfo.decode(t,t.uint32()));break;case 13:r.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.decode(t,t.uint32());break;case 14:r.textAnnotations&&r.textAnnotations.length||(r.textAnnotations=[]),r.textAnnotations.push(c.tensorflow.magenta.NoteSequence.TextAnnotation.decode(t,t.uint32()));break;case 20:r.sectionAnnotations&&r.sectionAnnotations.length||(r.sectionAnnotations=[]),r.sectionAnnotations.push(c.tensorflow.magenta.NoteSequence.SectionAnnotation.decode(t,t.uint32()));break;case 21:r.sectionGroups&&r.sectionGroups.length||(r.sectionGroups=[]),r.sectionGroups.push(c.tensorflow.magenta.NoteSequence.SectionGroup.decode(t,t.uint32()));break;case 15:r.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.decode(t,t.uint32());break;case 17:r.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.decode(t,t.uint32());break;case 19:r.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.decode(t,t.uint32());break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.id&&t.hasOwnProperty("id")&&!u.isString(t.id))return"id: string expected";if(null!=t.filename&&t.hasOwnProperty("filename")&&!u.isString(t.filename))return"filename: string expected";if(null!=t.referenceNumber&&t.hasOwnProperty("referenceNumber")&&!(u.isInteger(t.referenceNumber)||t.referenceNumber&&u.isInteger(t.referenceNumber.low)&&u.isInteger(t.referenceNumber.high)))return"referenceNumber: integer|Long expected";if(null!=t.collectionName&&t.hasOwnProperty("collectionName")&&!u.isString(t.collectionName))return"collectionName: string expected";if(null!=t.ticksPerQuarter&&t.hasOwnProperty("ticksPerQuarter")&&!u.isInteger(t.ticksPerQuarter))return"ticksPerQuarter: integer expected";if(null!=t.timeSignatures&&t.hasOwnProperty("timeSignatures")){if(!Array.isArray(t.timeSignatures))return"timeSignatures: array expected";for(var e=0;e<t.timeSignatures.length;++e)if(n=c.tensorflow.magenta.NoteSequence.TimeSignature.verify(t.timeSignatures[e]))return"timeSignatures."+n}if(null!=t.keySignatures&&t.hasOwnProperty("keySignatures")){if(!Array.isArray(t.keySignatures))return"keySignatures: array expected";for(e=0;e<t.keySignatures.length;++e)if(n=c.tensorflow.magenta.NoteSequence.KeySignature.verify(t.keySignatures[e]))return"keySignatures."+n}if(null!=t.tempos&&t.hasOwnProperty("tempos")){if(!Array.isArray(t.tempos))return"tempos: array expected";for(e=0;e<t.tempos.length;++e)if(n=c.tensorflow.magenta.NoteSequence.Tempo.verify(t.tempos[e]))return"tempos."+n}if(null!=t.notes&&t.hasOwnProperty("notes")){if(!Array.isArray(t.notes))return"notes: array expected";for(e=0;e<t.notes.length;++e)if(n=c.tensorflow.magenta.NoteSequence.Note.verify(t.notes[e]))return"notes."+n}if(null!=t.totalTime&&t.hasOwnProperty("totalTime")&&"number"!=typeof t.totalTime)return"totalTime: number expected";if(null!=t.totalQuantizedSteps&&t.hasOwnProperty("totalQuantizedSteps")&&!(u.isInteger(t.totalQuantizedSteps)||t.totalQuantizedSteps&&u.isInteger(t.totalQuantizedSteps.low)&&u.isInteger(t.totalQuantizedSteps.high)))return"totalQuantizedSteps: integer|Long expected";if(null!=t.pitchBends&&t.hasOwnProperty("pitchBends")){if(!Array.isArray(t.pitchBends))return"pitchBends: array expected";for(e=0;e<t.pitchBends.length;++e)if(n=c.tensorflow.magenta.NoteSequence.PitchBend.verify(t.pitchBends[e]))return"pitchBends."+n}if(null!=t.controlChanges&&t.hasOwnProperty("controlChanges")){if(!Array.isArray(t.controlChanges))return"controlChanges: array expected";for(e=0;e<t.controlChanges.length;++e)if(n=c.tensorflow.magenta.NoteSequence.ControlChange.verify(t.controlChanges[e]))return"controlChanges."+n}if(null!=t.partInfos&&t.hasOwnProperty("partInfos")){if(!Array.isArray(t.partInfos))return"partInfos: array expected";for(e=0;e<t.partInfos.length;++e)if(n=c.tensorflow.magenta.NoteSequence.PartInfo.verify(t.partInfos[e]))return"partInfos."+n}if(null!=t.sourceInfo&&t.hasOwnProperty("sourceInfo")&&(n=c.tensorflow.magenta.NoteSequence.SourceInfo.verify(t.sourceInfo)))return"sourceInfo."+n;if(null!=t.textAnnotations&&t.hasOwnProperty("textAnnotations")){if(!Array.isArray(t.textAnnotations))return"textAnnotations: array expected";for(e=0;e<t.textAnnotations.length;++e)if(n=c.tensorflow.magenta.NoteSequence.TextAnnotation.verify(t.textAnnotations[e]))return"textAnnotations."+n}if(null!=t.sectionAnnotations&&t.hasOwnProperty("sectionAnnotations")){if(!Array.isArray(t.sectionAnnotations))return"sectionAnnotations: array expected";for(e=0;e<t.sectionAnnotations.length;++e)if(n=c.tensorflow.magenta.NoteSequence.SectionAnnotation.verify(t.sectionAnnotations[e]))return"sectionAnnotations."+n}if(null!=t.sectionGroups&&t.hasOwnProperty("sectionGroups")){if(!Array.isArray(t.sectionGroups))return"sectionGroups: array expected";for(e=0;e<t.sectionGroups.length;++e){var n;if(n=c.tensorflow.magenta.NoteSequence.SectionGroup.verify(t.sectionGroups[e]))return"sectionGroups."+n}}return null!=t.quantizationInfo&&t.hasOwnProperty("quantizationInfo")&&(n=c.tensorflow.magenta.NoteSequence.QuantizationInfo.verify(t.quantizationInfo))?"quantizationInfo."+n:null!=t.subsequenceInfo&&t.hasOwnProperty("subsequenceInfo")&&(n=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.verify(t.subsequenceInfo))?"subsequenceInfo."+n:null!=t.sequenceMetadata&&t.hasOwnProperty("sequenceMetadata")&&(n=c.tensorflow.magenta.SequenceMetadata.verify(t.sequenceMetadata))?"sequenceMetadata."+n:null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence)return t;var e=new c.tensorflow.magenta.NoteSequence;if(null!=t.id&&(e.id=String(t.id)),null!=t.filename&&(e.filename=String(t.filename)),null!=t.referenceNumber&&(u.Long?(e.referenceNumber=u.Long.fromValue(t.referenceNumber)).unsigned=!1:"string"==typeof t.referenceNumber?e.referenceNumber=parseInt(t.referenceNumber,10):"number"==typeof t.referenceNumber?e.referenceNumber=t.referenceNumber:"object"==typeof t.referenceNumber&&(e.referenceNumber=new u.LongBits(t.referenceNumber.low>>>0,t.referenceNumber.high>>>0).toNumber())),null!=t.collectionName&&(e.collectionName=String(t.collectionName)),null!=t.ticksPerQuarter&&(e.ticksPerQuarter=0|t.ticksPerQuarter),t.timeSignatures){if(!Array.isArray(t.timeSignatures))throw TypeError(".tensorflow.magenta.NoteSequence.timeSignatures: array expected");e.timeSignatures=[];for(var n=0;n<t.timeSignatures.length;++n){if("object"!=typeof t.timeSignatures[n])throw TypeError(".tensorflow.magenta.NoteSequence.timeSignatures: object expected");e.timeSignatures[n]=c.tensorflow.magenta.NoteSequence.TimeSignature.fromObject(t.timeSignatures[n])}}if(t.keySignatures){if(!Array.isArray(t.keySignatures))throw TypeError(".tensorflow.magenta.NoteSequence.keySignatures: array expected");for(e.keySignatures=[],n=0;n<t.keySignatures.length;++n){if("object"!=typeof t.keySignatures[n])throw TypeError(".tensorflow.magenta.NoteSequence.keySignatures: object expected");e.keySignatures[n]=c.tensorflow.magenta.NoteSequence.KeySignature.fromObject(t.keySignatures[n])}}if(t.tempos){if(!Array.isArray(t.tempos))throw TypeError(".tensorflow.magenta.NoteSequence.tempos: array expected");for(e.tempos=[],n=0;n<t.tempos.length;++n){if("object"!=typeof t.tempos[n])throw TypeError(".tensorflow.magenta.NoteSequence.tempos: object expected");e.tempos[n]=c.tensorflow.magenta.NoteSequence.Tempo.fromObject(t.tempos[n])}}if(t.notes){if(!Array.isArray(t.notes))throw TypeError(".tensorflow.magenta.NoteSequence.notes: array expected");for(e.notes=[],n=0;n<t.notes.length;++n){if("object"!=typeof t.notes[n])throw TypeError(".tensorflow.magenta.NoteSequence.notes: object expected");e.notes[n]=c.tensorflow.magenta.NoteSequence.Note.fromObject(t.notes[n])}}if(null!=t.totalTime&&(e.totalTime=Number(t.totalTime)),null!=t.totalQuantizedSteps&&(u.Long?(e.totalQuantizedSteps=u.Long.fromValue(t.totalQuantizedSteps)).unsigned=!1:"string"==typeof t.totalQuantizedSteps?e.totalQuantizedSteps=parseInt(t.totalQuantizedSteps,10):"number"==typeof t.totalQuantizedSteps?e.totalQuantizedSteps=t.totalQuantizedSteps:"object"==typeof t.totalQuantizedSteps&&(e.totalQuantizedSteps=new u.LongBits(t.totalQuantizedSteps.low>>>0,t.totalQuantizedSteps.high>>>0).toNumber())),t.pitchBends){if(!Array.isArray(t.pitchBends))throw TypeError(".tensorflow.magenta.NoteSequence.pitchBends: array expected");for(e.pitchBends=[],n=0;n<t.pitchBends.length;++n){if("object"!=typeof t.pitchBends[n])throw TypeError(".tensorflow.magenta.NoteSequence.pitchBends: object expected");e.pitchBends[n]=c.tensorflow.magenta.NoteSequence.PitchBend.fromObject(t.pitchBends[n])}}if(t.controlChanges){if(!Array.isArray(t.controlChanges))throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: array expected");for(e.controlChanges=[],n=0;n<t.controlChanges.length;++n){if("object"!=typeof t.controlChanges[n])throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: object expected");e.controlChanges[n]=c.tensorflow.magenta.NoteSequence.ControlChange.fromObject(t.controlChanges[n])}}if(t.partInfos){if(!Array.isArray(t.partInfos))throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: array expected");for(e.partInfos=[],n=0;n<t.partInfos.length;++n){if("object"!=typeof t.partInfos[n])throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: object expected");e.partInfos[n]=c.tensorflow.magenta.NoteSequence.PartInfo.fromObject(t.partInfos[n])}}if(null!=t.sourceInfo){if("object"!=typeof t.sourceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.sourceInfo: object expected");e.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.fromObject(t.sourceInfo)}if(t.textAnnotations){if(!Array.isArray(t.textAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: array expected");for(e.textAnnotations=[],n=0;n<t.textAnnotations.length;++n){if("object"!=typeof t.textAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: object expected");e.textAnnotations[n]=c.tensorflow.magenta.NoteSequence.TextAnnotation.fromObject(t.textAnnotations[n])}}if(t.sectionAnnotations){if(!Array.isArray(t.sectionAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: array expected");for(e.sectionAnnotations=[],n=0;n<t.sectionAnnotations.length;++n){if("object"!=typeof t.sectionAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: object expected");e.sectionAnnotations[n]=c.tensorflow.magenta.NoteSequence.SectionAnnotation.fromObject(t.sectionAnnotations[n])}}if(t.sectionGroups){if(!Array.isArray(t.sectionGroups))throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: array expected");for(e.sectionGroups=[],n=0;n<t.sectionGroups.length;++n){if("object"!=typeof t.sectionGroups[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: object expected");e.sectionGroups[n]=c.tensorflow.magenta.NoteSequence.SectionGroup.fromObject(t.sectionGroups[n])}}if(null!=t.quantizationInfo){if("object"!=typeof t.quantizationInfo)throw TypeError(".tensorflow.magenta.NoteSequence.quantizationInfo: object expected");e.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.fromObject(t.quantizationInfo)}if(null!=t.subsequenceInfo){if("object"!=typeof t.subsequenceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.subsequenceInfo: object expected");e.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.fromObject(t.subsequenceInfo)}if(null!=t.sequenceMetadata){if("object"!=typeof t.sequenceMetadata)throw TypeError(".tensorflow.magenta.NoteSequence.sequenceMetadata: object expected");e.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.fromObject(t.sequenceMetadata)}return e},t.toObject=function(t,e){e||(e={});var n={};if((e.arrays||e.defaults)&&(n.timeSignatures=[],n.keySignatures=[],n.tempos=[],n.notes=[],n.pitchBends=[],n.controlChanges=[],n.partInfos=[],n.textAnnotations=[],n.sectionAnnotations=[],n.sectionGroups=[]),e.defaults){if(n.id="",n.filename="",n.collectionName="",n.ticksPerQuarter=0,n.totalTime=0,n.sourceInfo=null,n.quantizationInfo=null,u.Long){var r=new u.Long(0,0,!1);n.totalQuantizedSteps=e.longs===String?r.toString