UNPKG

@magenta/music

Version:

Make music with machine learning, in the browser.

1 lines 156 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@tensorflow/tfjs")):"function"==typeof define&&define.amd?define(["tf"],t):"object"==typeof exports?exports.music_rnn=t(require("@tensorflow/tfjs")):e.music_rnn=t(e.tf)}(self,(function(__WEBPACK_EXTERNAL_MODULE__2__){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},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=186)}({10:function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var r=n(35),o=r.tensorflow.magenta.NoteSequence},12:function(e,t,n){"use strict";n.r(t),n.d(t,"Level",(function(){return r})),n.d(t,"verbosity",(function(){return i})),n.d(t,"setVerbosity",(function(){return s})),n.d(t,"log",(function(){return a})),n.d(t,"logWithDuration",(function(){return u}));var r,o=n(15);!function(e){e[e.NONE=0]="NONE",e[e.WARN=5]="WARN",e[e.INFO=10]="INFO",e[e.DEBUG=20]="DEBUG"}(r||(r={}));let i=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(i>=n){(5===n?console.warn:console.log)(`%c ${t} `,"background:magenta; color:white",e)}}function u(e,t,n="Magenta.js",r=10){a(`${e} in ${((o.d.now()-t)/1e3).toPrecision(3)}s`,n,r)}},13:function(e,t,n){"use strict";n.r(t),n.d(t,"MultipleTimeSignatureException",(function(){return i})),n.d(t,"BadTimeSignatureException",(function(){return s})),n.d(t,"NegativeTimeException",(function(){return a})),n.d(t,"MultipleTempoException",(function(){return u})),n.d(t,"QuantizationStatusException",(function(){return c})),n.d(t,"clone",(function(){return l})),n.d(t,"stepsPerQuarterToStepsPerSecond",(function(){return p})),n.d(t,"quantizeToStep",(function(){return m})),n.d(t,"quantizeNoteSequence",(function(){return d})),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 P})),n.d(t,"isAbsoluteQuantizedSequence",(function(){return b})),n.d(t,"assertIsAbsoluteQuantizedSequence",(function(){return w})),n.d(t,"unquantizeSequence",(function(){return M})),n.d(t,"createQuantizedNoteSequence",(function(){return N})),n.d(t,"mergeInstruments",(function(){return q})),n.d(t,"replaceInstruments",(function(){return O})),n.d(t,"mergeConsecutiveNotes",(function(){return A})),n.d(t,"applySustainControlChanges",(function(){return T})),n.d(t,"concatenate",(function(){return v})),n.d(t,"trim",(function(){return I})),n.d(t,"split",(function(){return E}));var r=n(10),o=n(8);class i 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 u 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)}}function l(e){return r.a.decode(r.a.encode(e).finish())}function p(e,t){return e*t/60}function m(e,t,n=.5){const r=e*t;return Math.floor(r+(1-n))}function f(e){return e.controlChanges.concat(e.textAnnotations)}function h(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!==o.DEFAULT_QUARTERS_PER_MINUTE)throw new u("NoteSequence has an implicit tempo change from initial "+o.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 u(`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 d(e,t){const n=l(e);if(n.quantizationInfo=r.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 i(`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 i("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=r.a.TimeSignature.create({numerator:4,denominator:4,time:0});n.timeSignatures.push(e)}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)h(n),n.tempos[0].time=0,n.tempos=[n.tempos[0]];else{const e=r.a.Tempo.create({qpm:o.DEFAULT_QUARTERS_PER_MINUTE,time:0});n.tempos.push(e)}const d=p(t,n.tempos[0].qpm);return n.totalQuantizedSteps=m(e.totalTime,d),function(e,t){for(const n of e.notes){if(n.quantizedStartStep=m(n.startTime,t),n.quantizedEndStep=m(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)}f(e).forEach(e=>{if(e.quantizedStep=m(e.time,t),e.quantizedStep<0)throw new a("Got negative event time: step = "+e.quantizedStep)})}(n,d),n}function g(e){return e.quantizationInfo&&(e.quantizationInfo.stepsPerQuarter>0||e.quantizationInfo.stepsPerSecond>0)}function S(e){if(!g(e))throw new c(`NoteSequence ${e.id} is not quantized (missing quantizationInfo)`)}function y(e){return e.quantizationInfo&&e.quantizationInfo.stepsPerQuarter>0}function P(e){if(!y(e))throw new c(`NoteSequence ${e.id} is not quantized or is quantized based on absolute timing`)}function b(e){return e.quantizationInfo&&e.quantizationInfo.stepsPerSecond>0}function w(e){if(!b(e))throw new c(`NoteSequence ${e.id} is not quantized or is quantized based on relative timing`)}function M(e,t){P(e),h(e);const n=l(e);t?n.tempos&&n.tempos.length>0?n.tempos[0].qpm=t:n.tempos.push(r.a.Tempo.create({time:0,qpm:t})):t=e.tempos&&e.tempos.length>0?n.tempos[0].qpm:o.DEFAULT_QUARTERS_PER_MINUTE;const i=e=>e/n.quantizationInfo.stepsPerQuarter*(60/t);return n.totalTime=i(n.totalQuantizedSteps),n.notes.forEach(e=>{e.startTime=i(e.quantizedStartStep),e.endTime=i(e.quantizedEndStep),n.totalTime=Math.max(n.totalTime,e.endTime),delete e.quantizedStartStep,delete e.quantizedEndStep}),f(n).forEach(e=>{e.time=i(e.time)}),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function N(e=o.DEFAULT_STEPS_PER_QUARTER,t=o.DEFAULT_QUARTERS_PER_MINUTE){return r.a.create({quantizationInfo:{stepsPerQuarter:e},tempos:[{qpm:t}]})}function q(e){const t=l(e),n=t.notes.concat(t.pitchBends).concat(t.controlChanges),r=Array.from(new Set(n.filter(e=>!e.isDrum).map(e=>e.program)));return n.forEach(e=>{e.isDrum?(e.program=0,e.instrument=r.length):e.instrument=r.indexOf(e.program)}),t}function O(e,t){const n=new Set(e.notes.map(e=>e.instrument)),o=new Set(t.notes.map(e=>e.instrument)),i=[];e.notes.forEach(e=>{o.has(e.instrument)||i.push(r.a.Note.create(e))}),t.notes.forEach(e=>{n.has(e.instrument)&&i.push(r.a.Note.create(e))});const s=l(e);return s.notes=i.sort((e,t)=>{const n=e.instrument-t.instrument;return n||e.quantizedStartStep-t.quantizedStartStep}),s}function A(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}),o=new r.a.Note;o.pitch=n[0].pitch,o.instrument=n[0].instrument,o.quantizedStartStep=n[0].quantizedStartStep,o.quantizedEndStep=n[0].quantizedEndStep,t.notes.push(o);let i=0;for(let e=1;e<n.length;e++){const o=n[e],s=t.notes[i];if(s.instrument===o.instrument&&s.pitch===o.pitch&&o.quantizedStartStep===s.quantizedEndStep&&o.quantizedStartStep%16!=0)t.notes[i].quantizedEndStep+=o.quantizedEndStep-o.quantizedStartStep;else{const o=new r.a.Note;o.pitch=n[e].pitch,o.instrument=n[e].instrument,o.quantizedStartStep=n[e].quantizedStartStep,o.quantizedEndStep=n[e].quantizedEndStep,t.notes.push(o),i++}}return t}function T(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 r=l(e),o=[];for(const e of r.notes)!1===e.isDrum&&(null!==e.startTime&&o.push({time:e.startTime,type:n.NOTE_ON,event:e}),null!==e.endTime&&o.push({time:e.endTime,type:n.NOTE_OFF,event:e}));for(const e of r.controlChanges)if(e.controlNumber===t){const t=e.controlValue;t>=64?o.push({time:e.time,type:n.SUSTAIN_ON,event:e}):t<64&&o.push({time:e.time,type:n.SUSTAIN_OFF,event:e})}o.sort((e,t)=>e.time-t.time);const i={},s={};let a=0;for(const e of o){a=e.time;const t=e.type,o=e.event;if(t===n.SUSTAIN_ON)s[o.instrument]=!0;else if(t===n.SUSTAIN_OFF){s[o.instrument]=!1;const e=[];o.instrument in i||(i[o.instrument]=[]);for(const t of i[o.instrument])t.endTime<a?(t.endTime=a,a>r.totalTime&&(r.totalTime=a)):e.push(t);i[o.instrument]=e}else if(t===n.NOTE_ON){if(!0===s[o.instrument]){const e=[];o.instrument in i||(i[o.instrument]=[]);for(const t of i[o.instrument])t.pitch===o.pitch?(t.endTime=a,t.startTime===t.endTime&&r.notes.push(t)):e.push(t);i[o.instrument]=e}o.instrument in i||(i[o.instrument]=[]),i[o.instrument].push(o)}else if(t===n.NOTE_OFF)if(!0===s[o.instrument]);else{const e=i[o.instrument].indexOf(o);e>-1&&i[o.instrument].splice(e,1)}}for(const e of Object.values(i))for(const t of e)t.endTime=a,r.totalTime=a;return r}function v(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 _(e,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",t)}return _(e,"totalTime","startTime","endTime",t)}function I(e,t,n,r){return g(e)?z(e,t,n,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",r):z(e,t,n,"totalTime","startTime","endTime",r)}function _(e,t,n,o,i){let s,a=0;for(let u=0;u<e.length;++u){const c=i?i[u]:e[u][t];if(0===c)throw Error(`Sequence ${e[u].id} has no ${t}, and no individual duration was provided.`);0===u?s=l(e[0]):Array.prototype.push.apply(s.notes,e[u].notes.map(e=>{const t=r.a.Note.create(e);return t[n]+=a,t[o]+=a,t})),a+=c}return s[t]=a,s}function z(e,t,n,r,o,i,s){const a=l(e);a[r]=n,a.notes=a.notes.filter(e=>e[o]>=t&&e[o]<=n&&(s||e[i]<=n)),a[r]-=t;for(let e=0;e<a.notes.length;e++)a.notes[e][o]-=t,a.notes[e][i]-=t,s&&(a.notes[e][i]=Math.min(a.notes[e][i],a[r]));return a}function E(e,t){S(e);const n=l(e),o=n.notes.sort((e,t)=>e.quantizedStartStep-t.quantizedStartStep),i=[];let s=0,a=[];for(let e=0;e<o.length;e++){const u=o[e],c=u.quantizedStartStep,p=u.quantizedEndStep;if(u.quantizedStartStep-=s,u.quantizedEndStep-=s,!(u.quantizedStartStep<0))if(u.quantizedEndStep<=t)a.push(u);else{if(u.quantizedStartStep<t){const e=r.a.Note.create(u);e.quantizedEndStep=t,e.startTime=e.endTime=void 0,a.push(e),u.quantizedStartStep=s+t,u.quantizedEndStep=p}else u.quantizedStartStep=c,u.quantizedEndStep=p;if((u.quantizedEndStep>t||u.quantizedStartStep>t)&&(e-=1),0!==a.length){const e=l(n);e.notes=a,e.totalQuantizedSteps=t,i.push(e)}a=[],s+=t}}if(0!==a.length){const e=l(n);e.notes=a,e.totalQuantizedSteps=t,i.push(e)}return i}},15:function(e,t,n){"use strict";(function(e){n.d(t,"a",(function(){return o})),n.d(t,"d",(function(){return i})),n.d(t,"c",(function(){return s})),n.d(t,"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!==e)return e;throw new Error("cannot find the global object")}(),o=r.fetch.bind(r),i=r.performance,s=(r.navigator,!!r.webkitOfflineAudioContext),a=void 0!==r.WorkerGlobalScope;function u(e){if(e=s?44100:e,a)throw new Error("Cannot use offline audio context in a web worker.");const t=r.webkitOfflineAudioContext;return s?new t(1,e,e):new r.OfflineAudioContext(1,e,e)}}).call(this,n(21))},18:function(e,t,n){"use strict";(function(e){var r=t;function o(e,t,n){for(var r=Object.keys(t),o=0;o<r.length;++o)void 0!==e[r[o]]&&n||(e[r[o]]=t[r[o]]);return e}function i(e){function t(e,n){if(!(this instanceof t))return new t(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),n&&o(this,n)}return(t.prototype=Object.create(Error.prototype)).constructor=t,Object.defineProperty(t.prototype,"name",{get:function(){return e}}),t.prototype.toString=function(){return this.name+": "+this.message},t}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!==e&&e&&e.process&&e.process.versions&&e.process.versions.node),r.global=r.isNode&&e||"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(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},r.isString=function(e){return"string"==typeof e||e instanceof String},r.isObject=function(e){return e&&"object"==typeof e},r.isset=r.isSet=function(e,t){var n=e[t];return!(null==n||!e.hasOwnProperty(t))&&("object"!=typeof n||(Array.isArray(n)?n.length:Object.keys(n).length)>0)},r.Buffer=function(){try{var e=r.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(e){return"number"==typeof e?r.Buffer?r._Buffer_allocUnsafe(e):new r.Array(e):r.Buffer?r._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},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(e){return e?r.LongBits.from(e).toHash():r.LongBits.zeroHash},r.longFromHash=function(e,t){var n=r.LongBits.fromHash(e);return r.Long?r.Long.fromBits(n.lo,n.hi,t):n.toNumber(Boolean(t))},r.merge=o,r.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},r.newError=i,r.ProtocolError=i("ProtocolError"),r.oneOfGetter=function(e){for(var t={},n=0;n<e.length;++n)t[e[n]]=1;return function(){for(var e=Object.keys(this),n=e.length-1;n>-1;--n)if(1===t[e[n]]&&void 0!==this[e[n]]&&null!==this[e[n]])return e[n]}},r.oneOfSetter=function(e){return function(t){for(var n=0;n<e.length;++n)e[n]!==t&&delete this[e[n]]}},r.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},r._configure=function(){var e=r.Buffer;e?(r._Buffer_from=e.from!==Uint8Array.from&&e.from||function(t,n){return new e(t,n)},r._Buffer_allocUnsafe=e.allocUnsafe||function(t){return new e(t)}):r._Buffer_from=r._Buffer_allocUnsafe=null}}).call(this,n(21))},186:function(e,t,n){"use strict";n.r(t),n.d(t,"MusicRNN",(function(){return p}));var r=n(2),o=n(48),i=n(37),s=n(36),a=n(15),u=n(12),c=n(13);class l{constructor(e,t,n){this.cells=e,this.attnLength=t,this.attnSize=n}static isWrapped(e){return"rnn/attention_cell_wrapper/kernel"in e}initialize(e){const t="rnn/attention_cell_wrapper/";this.attnInputMatrix=e[t+"kernel"],this.attnInputBias=e[t+"bias"],this.attnW=e[t+"attention/attn_w"],this.attnV=e[t+"attention/attn_v"],this.attnMatrix=e[t+"attention/kernel"],this.attnBias=e[t+"attention/bias"],this.attnOutputMatrix=e[t+"attention_output_projection/kernel"],this.attnOutputBias=e[t+"attention_output_projection/bias"]}initState(){return{attention:r.zeros([this.attnSize]),attentionState:r.zeros([1,this.attnSize*this.attnLength])}}call(e,t,n,o){const i=r.concat([e,o.attention.as2D(1,-1)],1),s=r.add(r.matMul(i,this.attnInputMatrix),this.attnInputBias.as2D(1,-1));[t,n]=r.multiRNNCell(this.cells,s,t,n);const a=r.reshape(o.attentionState,[-1,this.attnLength,1,this.attnSize]),u=r.conv2d(a,this.attnW,[1,1],"same"),c=[];for(let e=0;e<t.length;e++)c.push(t[e]),c.push(n[e]);const l=r.concat(c,1),p=r.matMul(l,this.attnMatrix).reshape([-1,1,1,this.attnSize]),m=r.sum(r.mul(this.attnV,r.tanh(r.add(u,p))),[2,3]),f=r.softmax(m),h=r.sum(r.mul(r.reshape(f,[-1,this.attnLength,1,1]),a),[1,2]).reshape([-1,this.attnSize]),d=o.attentionState.reshape([-1,this.attnLength,this.attnSize]),g=r.slice(d,[0,1,0],[d.shape[0],d.shape[1]-1,d.shape[2]]),S=r.add(r.matMul(r.concat([n[2],h],1),this.attnOutputMatrix),this.attnOutputBias),y=h.flatten(),P=r.concat([g,S.as3D(S.shape[0],1,S.shape[1])],1).reshape([-1,this.attnLength*this.attnSize]);return{output:S,c:t,h:n,attentionState:{attention:y,attentionState:P}}}}class p{constructor(e,t){this.checkpointURL=e,this.spec=t,this.initialized=!1,this.rawVars={},this.biasShapes=[],this.lstmCells=[]}isInitialized(){return this.initialized}instantiateFromSpec(){this.dataConverter=s.converterFromSpec(this.spec.dataConverter),this.attentionLength=this.spec.attentionLength,this.chordEncoder=this.spec.chordEncoder?i.chordEncoderFromType(this.spec.chordEncoder):void 0,this.auxInputs=this.spec.auxInputs?this.spec.auxInputs.map(e=>o.auxiliaryInputFromSpec(e)):void 0}async initialize(){this.dispose();const e=a.d.now();this.spec||await Object(a.a)(this.checkpointURL+"/config.json").then(e=>e.json()).then(e=>{if("MusicRNN"!==e.type)throw new Error("Attempted to instantiate MusicRNN model with incorrect type:\n "+e.type);this.spec=e}),this.instantiateFromSpec();const t=await Object(a.a)(this.checkpointURL+"/weights_manifest.json").then(e=>e.json()).then(e=>r.io.loadWeights(e,this.checkpointURL)),n=l.isWrapped(t),o=n?"rnn/attention_cell_wrapper/":"rnn/";this.forgetBias=r.scalar(1),this.lstmCells.length=0,this.biasShapes.length=0;let i=0;for(;;){const e=o+"multi_rnn_cell/cell_%d/basic_lstm_cell/".replace("%d",i.toString());if(!(e+"kernel"in t))break;this.lstmCells.push((n,o,i)=>r.basicLSTMCell(this.forgetBias,t[e+"kernel"],t[e+"bias"],n,o,i)),this.biasShapes.push(t[e+"bias"].shape[0]),++i}this.lstmFcW=t["fully_connected/weights"],this.lstmFcB=t["fully_connected/biases"],n&&(this.attentionWrapper=new l(this.lstmCells,this.attentionLength,this.biasShapes[0]/4),this.attentionWrapper.initialize(t)),this.rawVars=t,this.initialized=!0,u.logWithDuration("Initialized model",e,"MusicRNN")}dispose(){Object.keys(this.rawVars).forEach(e=>this.rawVars[e].dispose()),this.rawVars={},this.forgetBias&&(this.forgetBias.dispose(),this.forgetBias=void 0),this.initialized=!1}async continueSequence(e,t,n,r){return(await this.continueSequenceImpl(e,t,n,r,!1)).sequence}async continueSequenceAndReturnProbabilities(e,t,n,r){return this.continueSequenceImpl(e,t,n,r,!0)}async continueSequenceImpl(e,t,n,o,i){if(c.assertIsRelativeQuantizedSequence(e),this.chordEncoder&&!o)throw new Error("Chord progression expected but not provided.");if(!this.chordEncoder&&o)throw new Error("Unexpected chord progression provided.");this.initialized||await this.initialize();const s=a.d.now(),l=r.tidy(()=>{const s=this.dataConverter.toTensor(e),a=s.shape[0],u=s.shape[1],c=this.chordEncoder?this.chordEncoder.encodeProgression(o,a+t):void 0,l=this.auxInputs?r.concat(this.auxInputs.map(e=>e.getTensors(a+t)),1):void 0,p=this.sampleRnn(s,t,n,c,l,i),m=p.samples;return{samples:r.stack(m).as2D(m.length,u),probs:p.probs}}),p=await l,m=this.dataConverter.toNoteSequence(p.samples,e.quantizationInfo.stepsPerQuarter),f=[];if(i)for(let e=0;e<p.probs.length;e++)f.push(await p.probs[e].data()),p.probs[e].dispose();return l.samples.dispose(),m.then(()=>u.logWithDuration("Continuation completed",s,"MusicRNN",20)),{sequence:m,probs:f}}sampleRnn(e,t,n,o,i,s){const a=e.shape[0],u=e.shape[1];let c=[],l=[];for(let e=0;e<this.biasShapes.length;e++)c.push(r.zeros([1,this.biasShapes[e]/4])),l.push(r.zeros([1,this.biasShapes[e]/4]));let p,m=this.attentionWrapper?this.attentionWrapper.initState():null;e=e.toFloat();const f=[],h=[],d=r.split(e.toFloat(),a),g=o?r.split(o,o.shape[0]):void 0,S=i?r.split(i,i.shape[0]):void 0;for(let e=0;e<a+t;e++){let o;if(e<a)o=d[e];else{let e,t=p.matMul(this.lstmFcW).add(this.lstmFcB).as1D();n?(t=t.div(r.scalar(n)),e=r.multinomial(t,1).as1D()):e=t.argMax().as1D(),s&&h.push(r.softmax(t)),o=r.oneHot(e,u).toFloat(),f.push(o.as1D())}if(e===a+t-1)break;const i=[];if(g&&i.push(g[e+1]),i.push(o),S&&i.push(S[e]),o=r.concat(i,1),this.attentionWrapper){const e=this.attentionWrapper.call(o,c,l,m);c=e.c,l=e.h,m=e.attentionState,p=e.output}else[c,l]=r.multiRNNCell(this.lstmCells,o,c,l),p=l[l.length-1]}return{samples:f,probs:h}}}},2:function(e,t){e.exports=__WEBPACK_EXTERNAL_MODULE__2__},21:function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},23: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 u})),n.d(t,"MelodyRhythm",(function(){return c})),n.d(t,"MelodyShape",(function(){return l})),n.d(t,"MelodyRegister",(function(){return p}));var r=n(2),o=n(10),i=n(13);const s=0,a=1;class u{constructor(e,t,n){this.events=e,this.minPitch=t,this.maxPitch=n}static fromNoteSequence(e,t,n,r=!0,o){i.assertIsQuantizedSequence(e);const s=e.notes.sort((e,t)=>e.quantizedStartStep===t.quantizedStartStep?t.pitch-e.pitch:e.quantizedStartStep-t.quantizedStartStep),c=new Int32Array(o||e.totalQuantizedSteps);let l=-1;return s.forEach(e=>{if(e.quantizedStartStep===l){if(r)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);c[e.quantizedStartStep]=e.pitch-t+2,c[e.quantizedEndStep]=a,l=e.quantizedStartStep}),new u(c,t,n)}toNoteSequence(e,t){const n=i.createQuantizedNoteSequence(e,t);let r=null;for(let e=0;e<this.events.length;++e){const t=this.events[e];switch(t){case s:break;case a:r&&(r.quantizedEndStep=e,n.notes.push(r),r=null);break;default:r&&(r.quantizedEndStep=e,n.notes.push(r)),r=o.a.Note.create({pitch:t-2+this.minPitch,quantizedStartStep:e})}}return r&&(r.quantizedEndStep=this.events.length,n.notes.push(r)),n.totalQuantizedSteps=this.events.length,n}}class c{constructor(){this.depth=1}extract(e){const t=e.events.length,n=r.buffer([t,1]);for(let r=0;r<t;++r)n.set(e.events[r]>=2?1:0,r,0);return n.toTensor().as2D(t,1)}}class l{constructor(){this.depth=3}extract(e){const t=e.events.length,n=r.buffer([t,3]);let o=null,i=null;for(let r=0;r<t;++r)if(e.events[r]>=2){if(null!==o){let t;0===n.get(o,0)&&0===n.get(o,1)&&0===n.get(o,2)&&(o=-1),t=e.events[r]<i?0:e.events[r]>i?2:1;for(let e=r;e>o;--e)n.set(1,e,t)}o=r,i=e.events[r]}if(o!==t-1)if(null===o||0===n.get(o,0)&&0===n.get(o,1)&&0===n.get(o,2))for(let e=0;e<t;++e)n.set(1,e,1);else for(let e=t-1;e>o;--e)for(let t=0;t<3;t++)n.set(n.get(o,t),e,t);return n.toTensor().as2D(t,3)}}class p{constructor(e){this.boundaryPitches=e,this.depth=e.length+1}meanMelodyPitch(e){let t=0,n=0,r=null;for(let o=0;o<e.events.length;++o)e.events[o]===a?r=null:e.events[o]>=2&&(r=e.minPitch+e.events[o]-2),null!==r&&(t+=r,n+=1);return n?t/n:null}extract(e){const t=e.events.length,n=this.meanMelodyPitch(e);if(null===n)return r.zeros([t,this.depth]);let o=0;for(;o<this.boundaryPitches.length&&n>=this.boundaryPitches[o];)o++;const i=r.buffer([t,this.depth]);for(let e=0;e<t;++e)i.set(1,e,o);return i.toTensor().as2D(t,this.depth)}}},29:function(e,t,n){"use strict";n.r(t),n.d(t,"Performance",(function(){return a}));var r=n(10),o=n(8),i=n(13),s=n(12);class a{constructor(e,t,n,r,o){this.events=e,this.maxShiftSteps=t,this.numVelocityBins=n,this.program=r,this.isDrum=o}static fromNoteSequence(e,t,n,r){i.assertIsQuantizedSequence(e);const s=e.notes.filter((e,t)=>void 0===r||e.instrument===r),u=s.sort((e,t)=>e.startTime===t.startTime?e.pitch-t.pitch:e.startTime-t.startTime),c=u.map((e,t)=>({step:e.quantizedStartStep,index:t,isOffset:0})),l=u.map((e,t)=>({step:e.quantizedEndStep,index:t,isOffset:1})),p=c.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),m=n?Math.ceil((o.MIDI_VELOCITIES-1)/n):void 0,f=[];let h=0,d=n;for(const e of p){if(e.step>h){for(;e.step>h+t;)f.push({type:"time-shift",steps:t}),h+=t;f.push({type:"time-shift",steps:e.step-h}),h=e.step}if(e.isOffset)f.push({type:"note-off",pitch:u[e.index].pitch});else{if(m){const t=Math.floor((u[e.index].velocity-o.MIN_MIDI_VELOCITY-1)/m)+1;t!==d&&(f.push({type:"velocity-change",velocityBin:t}),d=t)}f.push({type:"note-on",pitch:u[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],P=new a(f,t,n,y,g);return P.setNumSteps(e.totalQuantizedSteps),P}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 r=Math.min(e-t,this.maxShiftSteps-n.steps);n.steps+=r,t+=r}}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((o.MIDI_VELOCITIES-1)/this.numVelocityBins):void 0,n=r.a.create();let i=0,a=void 0;const u=new Map;for(let e=o.MIN_MIDI_PITCH;e<=o.MAX_MIDI_PITCH;++e)u.set(e,[]);for(const c of this.events)switch(c.type){case"note-on":u.get(c.pitch).push([i,a]);break;case"note-off":const l=u.get(c.pitch);if(l.length){const[t,o]=l.shift();i>t?n.notes.push(r.a.Note.create({pitch:c.pitch,velocity:o,instrument:e,quantizedStartStep:t,quantizedEndStep:i,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${c.pitch}, step = ${i})`,"Performance")}else s.log(`Ignoring note-off with no previous note-on:(pitch = ${c.pitch}, step = ${i})`,"Performance");break;case"time-shift":i+=c.steps;break;case"velocity-change":if(!t)throw new Error("Unexpected velocity change event: "+c);a=o.MIN_MIDI_VELOCITY+(c.velocityBin-1)*t+1;break;default:throw new Error("Unrecognized performance event: "+c)}return u.forEach((t,o)=>{for(const[a,u]of t)i>a?n.notes.push(r.a.Note.create({pitch:o,velocity:u,instrument:e,quantizedStartStep:a,quantizedEndStep:i,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${o}, step = ${i})`,"Performance")}),n.totalQuantizedSteps=i,n}}},33:function(e,t,n){"use strict";e.exports=p;var r,o=n(18),i=o.LongBits,s=o.base64,a=o.utf8;function u(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}function c(){}function l(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}function p(){this.len=0,this.head=new u(c,0,0),this.tail=this.head,this.states=null}var m=function(){return o.Buffer?function(){return(p.create=function(){return new r})()}:function(){return new p}};function f(e,t,n){t[n]=255&e}function h(e,t){this.len=e,this.next=void 0,this.val=t}function d(e,t,n){for(;e.hi;)t[n++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[n++]=127&e.lo|128,e.lo=e.lo>>>7;t[n++]=e.lo}function g(e,t,n){t[n]=255&e,t[n+1]=e>>>8&255,t[n+2]=e>>>16&255,t[n+3]=e>>>24}p.create=m(),p.alloc=function(e){return new o.Array(e)},o.Array!==Array&&(p.alloc=o.pool(p.alloc,o.Array.prototype.subarray)),p.prototype._push=function(e,t,n){return this.tail=this.tail.next=new u(e,t,n),this.len+=t,this},h.prototype=Object.create(u.prototype),h.prototype.fn=function(e,t,n){for(;e>127;)t[n++]=127&e|128,e>>>=7;t[n]=e},p.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new h((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},p.prototype.int32=function(e){return e<0?this._push(d,10,i.fromNumber(e)):this.uint32(e)},p.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},p.prototype.uint64=function(e){var t=i.from(e);return this._push(d,t.length(),t)},p.prototype.int64=p.prototype.uint64,p.prototype.sint64=function(e){var t=i.from(e).zzEncode();return this._push(d,t.length(),t)},p.prototype.bool=function(e){return this._push(f,1,e?1:0)},p.prototype.fixed32=function(e){return this._push(g,4,e>>>0)},p.prototype.sfixed32=p.prototype.fixed32,p.prototype.fixed64=function(e){var t=i.from(e);return this._push(g,4,t.lo)._push(g,4,t.hi)},p.prototype.sfixed64=p.prototype.fixed64,p.prototype.float=function(e){return this._push(o.float.writeFloatLE,4,e)},p.prototype.double=function(e){return this._push(o.float.writeDoubleLE,8,e)};var S=o.Array.prototype.set?function(e,t,n){t.set(e,n)}:function(e,t,n){for(var r=0;r<e.length;++r)t[n+r]=e[r]};p.prototype.bytes=function(e){var t=e.length>>>0;if(!t)return this._push(f,1,0);if(o.isString(e)){var n=p.alloc(t=s.length(e));s.decode(e,n,0),e=n}return this.uint32(t)._push(S,t,e)},p.prototype.string=function(e){var t=a.length(e);return t?this.uint32(t)._push(a.write,t,e):this._push(f,1,0)},p.prototype.fork=function(){return this.states=new l(this),this.head=this.tail=new u(c,0,0),this.len=0,this},p.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},p.prototype.ldelim=function(){var e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=e.next,this.tail=t,this.len+=n),this},p.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),n=0;e;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t},p._configure=function(e){r=e,p.create=m(),r._configure()}},34:function(e,t,n){"use strict";e.exports=u;var r,o=n(18),i=o.LongBits,s=o.utf8;function a(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function u(e){this.buf=e,this.pos=0,this.len=e.length}var c,l="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new u(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new u(e);throw Error("illegal buffer")},p=function(){return o.Buffer?function(e){return(u.create=function(e){return o.Buffer.isBuffer(e)?new r(e):l(e)})(e)}:l};function m(){var e=new i(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw a(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw a(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function f(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function h(){if(this.pos+8>this.len)throw a(this,8);return new i(f(this.buf,this.pos+=4),f(this.buf,this.pos+=4))}u.create=p(),u.prototype._slice=o.Array.prototype.subarray||o.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 e=this.uint32();return e>>>1^-(1&e)|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 e=o.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},u.prototype.double=function(){if(this.pos+8>this.len)throw a(this,4);var e=o.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},u.prototype.bytes=function(){var e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw a(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,n):t===n?new this.buf.constructor(0):this._slice.call(this.buf,t,n)},u.prototype.string=function(){var e=this.bytes();return s.read(e,0,e.length)},u.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw a(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw a(this)}while(128&this.buf[this.pos++]);return this},u.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},u._configure=function(e){r=e,u.create=p(),r._configure();var t=o.Long?"toLong":"toNumber";o.merge(u.prototype,{int64:function(){return m.call(this)[t](!1)},uint64:function(){return m.call(this)[t](!0)},sint64:function(){return m.call(this).zzDecode()[t](!1)},fixed64:function(){return h.call(this)[t](!0)},sfixed64:function(){return h.call(this)[t](!1)}})}},35:function(e,t,n){"use strict";var r,o,i=n(49),s=i.Reader,a=i.Writer,u=i.util,c=i.roots.default||(i.roots.default={});c.tensorflow=((o={}).magenta=((r={}).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=u.Long?u.Long.fromBits(0,0,!1):0,e.prototype.collectionName="",e.prototype.ticksPerQuarter=0,e.prototype.timeSignatures=u.emptyArray,e.prototype.keySignatures=u.emptyArray,e.prototype.tempos=u.emptyArray,e.prototype.notes=u.emptyArray,e.prototype.totalTime=0,e.prototype.totalQuantizedSteps=u.Long?u.Long.fromBits(0,0,!1):0,e.prototype.pitchBends=u.emptyArray,e.prototype.controlChanges=u.emptyArray,e.prototype.partInfos=u.emptyArray,e.prototype.sourceInfo=null,e.prototype.textAnnotations=u.emptyArray,e.prototype.sectionAnnotations=u.emptyArray,e.prototype.sectionGroups=u.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)c.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)c.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)c.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)c.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)c.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)c.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)c.tensorflow.magenta.NoteSequence.PartInfo.encode(e.partInfos[n],t.uint32(98).fork()).ldelim();if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&c.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)c.tensorflow.magenta.NoteSequence.TextAnnotation.encode(e.textAnnotations[n],t.uint32(114).fork()).ldelim();if(null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&c.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")&&c.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")&&c.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)c.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)c.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,r=new c.tensorflow.magenta.NoteSequence;e.pos<n;){var o=e.uint32();switch(o>>>3){case 1:r.id=e.string();break;case 2:r.filename=e.string();break;case 18:r.referenceNumber=u.Long?e.int64().toNumber():e.int64();break;case 3:r.collectionName=e.string();break;case 4:r.ticksPerQuarter=e.int32();break;case 5:r.timeSignatures&&r.timeSignatures.length||(r.timeSignatures=[]),r.timeSignatures.push(c.tensorflow.magenta.NoteSequence.TimeSignature.decode(e,e.uint32()));break;case 6:r.keySignatures&&r.keySignatures.length||(r.keySignatures=[]),r.keySignatures.push(c.tensorflow.magenta.NoteSequence.KeySignature.decode(e,e.uint32()));break;case 7:r.tempos&&r.tempos.length||(r.tempos=[]),r.tempos.push(c.tensorflow.magenta.NoteSequence.Tempo.decode(e,e.uint32()));break;case 8:r.notes&&r.notes.length||(r.notes=[]),r.notes.push(c.tensorflow.magenta.NoteSequence.Note.decode(e,e.uint32()));break;case 9:r.totalTime=e.double();break;case 16:r.totalQuantizedSteps=u.Long?e.int64().toNumber():e.int64();break;case 10:r.pitchBends&&r.pitchBends.length||(r.pitchBends=[]),r.pitchBends.push(c.tensorflow.magenta.NoteSequence.PitchBend.decode(e,e.uint32()));break;case 11:r.controlChanges&&r.controlChanges.length||(r.controlChanges=[]),r.controlChanges.push(c.tensorflow.magenta.NoteSequence.ControlChange.decode(e,e.uint32()));break;case 12:r.partInfos&&r.partInfos.length||(r.partInfos=[]),r.partInfos.push(c.tensorflow.magenta.NoteSequence.PartInfo.decode(e,e.uint32()));break;case 13:r.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.decode(e,e.uint32());break;case 14:r.textAnnotations&&r.textAnnotations.length||(r.textAnnotations=[]),r.textAnnotations.push(c.tensorflow.magenta.NoteSequence.TextAnnotation.decode(e,e.uint32()));break;case 20:r.sectionAnnotations&&r.sectionAnnotations.length||(r.sectionAnnotations=[]),r.sectionAnnotations.push(c.tensorflow.magenta.NoteSequence.SectionAnnotation.decode(e,e.uint32()));break;case 21:r.sectionGroups&&r.sectionGroups.length||(r.sectionGroups=[]),r.sectionGroups.push(c.tensorflow.magenta.NoteSequence.SectionGroup.decode(e,e.uint32()));break;case 15:r.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.decode(e,e.uint32());break;case 17:r.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.decode(e,e.uint32());break;case 19:r.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.decode(e,e.uint32());break;default:e.skipType(7&o)}}return r},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")&&!u.isString(e.id))return"id: string expected";if(null!=e.filename&&e.hasOwnProperty("filename")&&!u.isString(e.filename))return"filename: string expected";if(null!=e.referenceNumber&&e.hasOwnProperty("referenceNumber")&&!(u.isInteger(e.referenceNumber)||e.referenceNumber&&u.isInteger(e.referenceNumber.low)&&u.isInteger(e.referenceNumber.high)))return"referenceNumber: integer|Long expected";if(null!=e.collectionName&&e.hasOwnProperty("collectionName")&&!u.isString(e.collectionName))return"collectionName: string expected";if(null!=e.ticksPerQuarter&&e.hasOwnProperty("ticksPerQuarter")&&!u.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=c.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=c.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=c.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=c.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")&&!(u.isInteger(e.totalQuantizedSteps)||e.totalQuantizedSteps&&u.isInteger(e.totalQuantizedSteps.low)&&u.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=c.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=c.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=c.tensorflow.magenta.NoteSequence.PartInfo.verify(e.partInfos[t]))return"partInfos."+n}if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&(n=c.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=c.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=c.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=c.tensorflow.magenta.NoteSequence.SectionGroup.verify(e.sectionGroups[t]))return"sectionGroups."+n}}return null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&(n=c.tensorflow.magenta.NoteSequence.QuantizationInfo.verify(e.quantizationInfo))?"quantizationInfo."+n:null!=e.subsequenceInfo&&e.hasOwnProperty("subsequenceInfo")&&(n=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.verify(e.subsequenceInfo))?"subsequenceInfo."+n:null!=e.sequenceMetadata&&e.hasOwnProperty("sequenceMetadata")&&(n=c.tensorflow.magenta.SequenceMetadata.verify(e.sequenceMetadata))?"sequenceMetadata."+n:null},e.fromObject=function(e){if(e instanceof c.tensorflow.magenta.NoteSequence)return e;var t=new c.tensorflow.magenta.NoteSequence;if(null!=e.id&&(t.id=String(e.id)),null!=e.filename&&(t.filename=String(e.filename)),null!=e.referenceNumber&&(u.Long?(t.referenceNumber=u.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 u.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]=c.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]=c.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]=c.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]=c.tensorflow.magenta.NoteSequence.Note.fromObject(e.notes[n])}}if(null!=e.totalTime&&(t.totalTime=Number(e.totalTime)),null!=e.totalQuantizedSteps&&(u.Long?(t.totalQuantizedSteps=u.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 u.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 expe