UNPKG

@magenta/music

Version:

Make music with machine learning, in the browser.

1 lines 119 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mm=t():e.mm=t()}(global,(function(){return function(e){var t={};function n(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=34)}([function(e,t){e.exports=require("@tensorflow/tfjs")},function(e,t,n){"use strict";n.r(t),n.d(t,"DEFAULT_QUARTERS_PER_MINUTE",(function(){return r})),n.d(t,"DEFAULT_STEPS_PER_BAR",(function(){return o})),n.d(t,"DEFAULT_STEPS_PER_QUARTER",(function(){return i})),n.d(t,"DEFAULT_STEPS_PER_SECOND",(function(){return s})),n.d(t,"DEFAULT_VELOCITY",(function(){return a})),n.d(t,"DEFAULT_PROGRAM",(function(){return u})),n.d(t,"DEFAULT_TICKS_PER_QUARTER",(function(){return c})),n.d(t,"DEFAULT_CHANNEL",(function(){return p})),n.d(t,"DRUM_CHANNEL",(function(){return l})),n.d(t,"NON_DRUM_CHANNELS",(function(){return m})),n.d(t,"DEFAULT_DRUM_PITCH_CLASSES",(function(){return d})),n.d(t,"MIN_MIDI_VELOCITY",(function(){return f})),n.d(t,"MAX_MIDI_VELOCITY",(function(){return h})),n.d(t,"MIDI_VELOCITIES",(function(){return S})),n.d(t,"NO_CHORD",(function(){return g})),n.d(t,"NUM_PITCH_CLASSES",(function(){return y})),n.d(t,"MIN_MIDI_PITCH",(function(){return w})),n.d(t,"MAX_MIDI_PITCH",(function(){return b})),n.d(t,"MIDI_PITCHES",(function(){return N})),n.d(t,"MIN_PIANO_PITCH",(function(){return q})),n.d(t,"MAX_PIANO_PITCH",(function(){return O})),n.d(t,"MIN_DRUM_PITCH",(function(){return T})),n.d(t,"MAX_DRUM_PITCH",(function(){return P})),n.d(t,"MIN_MIDI_PROGRAM",(function(){return I})),n.d(t,"MAX_MIDI_PROGRAM",(function(){return A})),n.d(t,"LO_CLICK_PITCH",(function(){return z})),n.d(t,"HI_CLICK_PITCH",(function(){return v})),n.d(t,"LO_CLICK_CLASS",(function(){return E})),n.d(t,"HI_CLICK_CLASS",(function(){return _}));const r=120,o=16,i=4,s=100,a=80,u=0,c=220,p=0,l=9,m=[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15],d=[[36,35],[38,27,28,31,32,33,34,37,39,40,56,65,66,75,85],[42,44,54,68,69,70,71,73,78,80],[46,67,72,74,79,81],[45,29,41,61,64,84],[48,47,60,63,77,86,87],[50,30,43,62,76,83],[49,55,57,58],[51,52,53,59,82]],f=0,h=127,S=h-f+1,g="N.C.",y=12,w=0,b=127,N=b-w+1,q=21,O=108,T=35,P=81,I=0,A=127,z=89,v=90,E=9,_=10},,function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var r=n(13),o=r.tensorflow.magenta.NoteSequence},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(6);!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)}},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 p})),n.d(t,"stepsPerQuarterToStepsPerSecond",(function(){return l})),n.d(t,"quantizeToStep",(function(){return m})),n.d(t,"quantizeNoteSequence",(function(){return h})),n.d(t,"isQuantizedSequence",(function(){return S})),n.d(t,"assertIsQuantizedSequence",(function(){return g})),n.d(t,"isRelativeQuantizedSequence",(function(){return y})),n.d(t,"assertIsRelativeQuantizedSequence",(function(){return w})),n.d(t,"isAbsoluteQuantizedSequence",(function(){return b})),n.d(t,"assertIsAbsoluteQuantizedSequence",(function(){return N})),n.d(t,"unquantizeSequence",(function(){return q})),n.d(t,"createQuantizedNoteSequence",(function(){return O})),n.d(t,"mergeInstruments",(function(){return T})),n.d(t,"replaceInstruments",(function(){return P})),n.d(t,"mergeConsecutiveNotes",(function(){return I})),n.d(t,"applySustainControlChanges",(function(){return A})),n.d(t,"concatenate",(function(){return z})),n.d(t,"trim",(function(){return v})),n.d(t,"split",(function(){return k}));var r=n(3),o=n(1);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 p(e){return r.a.decode(r.a.encode(e).finish())}function l(e,t){return e*t/60}function m(e,t,n=.5){const r=e*t;return Math.floor(r+(1-n))}function d(e){return e.controlChanges.concat(e.textAnnotations)}function f(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 h(e,t){const n=p(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)f(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 h=l(t,n.tempos[0].qpm);return n.totalQuantizedSteps=m(e.totalTime,h),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)}d(e).forEach(e=>{if(e.quantizedStep=m(e.time,t),e.quantizedStep<0)throw new a("Got negative event time: step = "+e.quantizedStep)})}(n,h),n}function S(e){return e.quantizationInfo&&(e.quantizationInfo.stepsPerQuarter>0||e.quantizationInfo.stepsPerSecond>0)}function g(e){if(!S(e))throw new c(`NoteSequence ${e.id} is not quantized (missing quantizationInfo)`)}function y(e){return e.quantizationInfo&&e.quantizationInfo.stepsPerQuarter>0}function w(e){if(!y(e))throw new 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 N(e){if(!b(e))throw new c(`NoteSequence ${e.id} is not quantized or is quantized based on relative timing`)}function q(e,t){w(e),f(e);const n=p(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}),d(n).forEach(e=>{e.time=i(e.time)}),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function O(e=o.DEFAULT_STEPS_PER_QUARTER,t=o.DEFAULT_QUARTERS_PER_MINUTE){return r.a.create({quantizationInfo:{stepsPerQuarter:e},tempos:[{qpm:t}]})}function T(e){const t=p(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 P(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=p(e);return s.notes=i.sort((e,t)=>{const n=e.instrument-t.instrument;return n||e.quantizedStartStep-t.quantizedStartStep}),s}function I(e){g(e);const t=p(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 A(e,t=64){let n;!function(e){e[e.SUSTAIN_ON=0]="SUSTAIN_ON",e[e.SUSTAIN_OFF=1]="SUSTAIN_OFF",e[e.NOTE_ON=2]="NOTE_ON",e[e.NOTE_OFF=3]="NOTE_OFF"}(n||(n={}));if(S(e))throw new Error("Can only apply sustain to unquantized NoteSequence.");const r=p(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 z(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(S(e[0])){for(let t=0;t<e.length;++t)if(g(e[t]),e[t].quantizationInfo.stepsPerQuarter!==e[0].quantizationInfo.stepsPerQuarter)throw new Error("Not all sequences have the same quantizationInfo");return E(e,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",t)}return E(e,"totalTime","startTime","endTime",t)}function v(e,t,n,r){return S(e)?_(e,t,n,"totalQuantizedSteps","quantizedStartStep","quantizedEndStep",r):_(e,t,n,"totalTime","startTime","endTime",r)}function E(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=p(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 _(e,t,n,r,o,i,s){const a=p(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 k(e,t){g(e);const n=p(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,l=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=l}else u.quantizedStartStep=c,u.quantizedEndStep=l;if((u.quantizedEndStep>t||u.quantizedStartStep>t)&&(e-=1),0!==a.length){const e=p(n);e.notes=a,e.totalQuantizedSteps=t,i.push(e)}a=[],s+=t}}if(0!==a.length){const e=p(n);e.notes=a,e.totalQuantizedSteps=t,i.push(e)}return i}},function(e,t,n){"use strict";n.d(t,"a",(function(){return r})),n.d(t,"d",(function(){return o})),n.d(t,"c",(function(){return i})),n.d(t,"b",(function(){return s}));const r=n(18),o=n(19);n(21);function i(){throw new Error("Cannot check if Safari in Node.js")}function s(e){throw new Error("Cannot use offline audio context in Node.js")}},,,function(e,t){e.exports=require("tonal")},function(e,t,n){"use strict";n.r(t),n.d(t,"NO_EVENT",(function(){return s})),n.d(t,"NOTE_OFF",(function(){return a})),n.d(t,"Melody",(function(){return u})),n.d(t,"MelodyRhythm",(function(){return c})),n.d(t,"MelodyShape",(function(){return p})),n.d(t,"MelodyRegister",(function(){return l}));var r=n(0),o=n(3),i=n(5);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 p=-1;return s.forEach(e=>{if(e.quantizedStartStep===p){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,p=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 p{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 l{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)}}},,function(e,t,n){"use strict";n.r(t),n.d(t,"Performance",(function(){return a}));var r=n(3),o=n(1),i=n(5),s=n(4);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})),p=u.map((e,t)=>({step:e.quantizedEndStep,index:t,isOffset:1})),l=c.concat(p).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,d=[];let f=0,h=n;for(const e of l){if(e.step>f){for(;e.step>f+t;)d.push({type:"time-shift",steps:t}),f+=t;d.push({type:"time-shift",steps:e.step-f}),f=e.step}if(e.isOffset)d.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!==h&&(d.push({type:"velocity-change",velocityBin:t}),h=t)}d.push({type:"note-on",pitch:u[e.index].pitch})}}const S=!!s.some(e=>e.isDrum)&&(!s.some(e=>!e.isDrum)||void 0),g=Array.from(new Set(s.map(e=>e.program))),y=S||1!==g.length?void 0:g[0],w=new a(d,t,n,y,S);return w.setNumSteps(e.totalQuantizedSteps),w}getNumSteps(){return this.events.filter(e=>"time-shift"===e.type).map(e=>e.steps).reduce((e,t)=>e+t,0)}setNumSteps(e){let t=this.getNumSteps();if(t<e){if(this.events.length){const n=this.events[this.events.length-1];if("time-shift"===n.type){const 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 p=u.get(c.pitch);if(p.length){const[t,o]=p.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}}},function(e,t,n){"use strict";var r,o,i=n(24),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 expected");t.pitchBends[n]=c.tensorflow.magenta.NoteSequence.PitchBend.fromObject(e.pitchBends[n])}}if(e.controlChanges){if(!Array.isArray(e.controlChanges))throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: array expected");for(t.controlChanges=[],n=0;n<e.controlChanges.length;++n){if("object"!=typeof e.controlChanges[n])throw TypeError(".tensorflow.magenta.NoteSequence.controlChanges: object expected");t.controlChanges[n]=c.tensorflow.magenta.NoteSequence.ControlChange.fromObject(e.controlChanges[n])}}if(e.partInfos){if(!Array.isArray(e.partInfos))throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: array expected");for(t.partInfos=[],n=0;n<e.partInfos.length;++n){if("object"!=typeof e.partInfos[n])throw TypeError(".tensorflow.magenta.NoteSequence.partInfos: object expected");t.partInfos[n]=c.tensorflow.magenta.NoteSequence.PartInfo.fromObject(e.partInfos[n])}}if(null!=e.sourceInfo){if("object"!=typeof e.sourceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.sourceInfo: object expected");t.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.fromObject(e.sourceInfo)}if(e.textAnnotations){if(!Array.isArray(e.textAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: array expected");for(t.textAnnotations=[],n=0;n<e.textAnnotations.length;++n){if("object"!=typeof e.textAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.textAnnotations: object expected");t.textAnnotations[n]=c.tensorflow.magenta.NoteSequence.TextAnnotation.fromObject(e.textAnnotations[n])}}if(e.sectionAnnotations){if(!Array.isArray(e.sectionAnnotations))throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: array expected");for(t.sectionAnnotations=[],n=0;n<e.sectionAnnotations.length;++n){if("object"!=typeof e.sectionAnnotations[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionAnnotations: object expected");t.sectionAnnotations[n]=c.tensorflow.magenta.NoteSequence.SectionAnnotation.fromObject(e.sectionAnnotations[n])}}if(e.sectionGroups){if(!Array.isArray(e.sectionGroups))throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: array expected");for(t.sectionGroups=[],n=0;n<e.sectionGroups.length;++n){if("object"!=typeof e.sectionGroups[n])throw TypeError(".tensorflow.magenta.NoteSequence.sectionGroups: object expected");t.sectionGroups[n]=c.tensorflow.magenta.NoteSequence.SectionGroup.fromObject(e.sectionGroups[n])}}if(null!=e.quantizationInfo){if("object"!=typeof e.quantizationInfo)throw TypeError(".tensorflow.magenta.NoteSequence.quantizationInfo: object expected");t.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.fromObject(e.quantizationInfo)}if(null!=e.subsequenceInfo){if("object"!=typeof e.subsequenceInfo)throw TypeError(".tensorflow.magenta.NoteSequence.subsequenceInfo: object expected");t.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.fromObject(e.subsequenceInfo)}if(null!=e.sequenceMetadata){if("object"!=typeof e.sequenceMetadata)throw TypeError(".tensorflow.magenta.NoteSequence.sequenceMetadata: object expected");t.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.fromObject(e.sequenceMetadata)}return t},e.toObject=function(e,t){t||(t={});var n={};if((t.arrays||t.defaults)&&(n.timeSignatures=[],n.keySignatures=[],n.tempos=[],n.notes=[],n.pitchBends=[],n.controlChanges=[],n.partInfos=[],n.textAnnotations=[],n.sectionAnnotations=[],n.sectionGroups=[]),t.defaults){if(n.id="",n.filename="",n.collectionName="",n.ticksPerQuarter=0,n.totalTime=0,n.sourceInfo=null,n.quantizationInfo=null,u.Long){var r=new u.Long(0,0,!1);n.totalQuantizedSteps=t.longs===String?r.toString():t.longs===Number?r.toNumber():r}else n.totalQuantizedSteps=t.longs===String?"0":0;n.subsequenceInfo=null,u.Long?(r=new u.Long(0,0,!1),n.referenceNumber=t.longs===String?r.toString():t.longs===Number?r.toNumber():r):n.referenceNumber=t.longs===String?"0":0,n.sequenceMetadata=null}if(null!=e.id&&e.hasOwnProperty("id")&&(n.id=e.id),null!=e.filename&&e.hasOwnProperty("filename")&&(n.filename=e.filename),null!=e.collectionName&&e.hasOwnProperty("collectionName")&&(n.collectionName=e.collectionName),null!=e.ticksPerQuarter&&e.hasOwnProperty("ticksPerQuarter")&&(n.ticksPerQuarter=e.ticksPerQuarter),e.timeSignatures&&e.timeSignatures.length){n.timeSignatures=[];for(var o=0;o<e.timeSignatures.length;++o)n.timeSignatures[o]=c.tensorflow.magenta.NoteSequence.TimeSignature.toObject(e.timeSignatures[o],t)}if(e.keySignatures&&e.keySignatures.length)for(n.keySignatures=[],o=0;o<e.keySignatures.length;++o)n.keySignatures[o]=c.tensorflow.magenta.NoteSequence.KeySignature.toObject(e.keySignatures[o],t);if(e.tempos&&e.tempos.length)for(n.tempos=[],o=0;o<e.tempos.length;++o)n.tempos[o]=c.tensorflow.magenta.NoteSequence.Tempo.toObject(e.tempos[o],t);if(e.notes&&e.notes.length)for(n.notes=[],o=0;o<e.notes.length;++o)n.notes[o]=c.tensorflow.magenta.NoteSequence.Note.toObject(e.notes[o],t);if(null!=e.totalTime&&e.hasOwnProperty("totalTime")&&(n.totalTime=t.json&&!isFinite(e.totalTime)?String(e.totalTime):e.totalTime),e.pitchBends&&e.pitchBends.length)for(n.pitchBends=[],o=0;o<e.pitchBends.length;++o)n.pitchBends[o]=c.tensorflow.magenta.NoteSequence.PitchBend.toObject(e.pitchBends[o],t);if(e.controlChanges&&e.controlChanges.length)for(n.controlChanges=[],o=0;o<e.controlChanges.length;++o)n.controlChanges[o]=c.tensorflow.magenta.NoteSequence.ControlChange.toObject(e.controlChanges[o],t);if(e.partInfos&&e.partInfos.length)for(n.partInfos=[],o=0;o<e.partInfos.length;++o)n.partInfos[o]=c.tensorflow.magenta.NoteSequence.PartInfo.toObject(e.partInfos[o],t);if(null!=e.sourceInfo&&e.hasOwnProperty("sourceInfo")&&(n.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.toObject(e.sourceInfo,t)),e.textAnnotations&&e.textAnnotations.length)for(n.textAnnotations=[],o=0;o<e.textAnnotations.length;++o)n.textAnnotations[o]=c.tensorflow.magenta.NoteSequence.TextAnnotation.toObject(e.textAnnotations[o],t);if(null!=e.quantizationInfo&&e.hasOwnProperty("quantizationInfo")&&(n.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.toObject(e.quantizationInfo,t)),null!=e.totalQuantizedSteps&&e.hasOwnProperty("totalQuantizedSteps")&&("number"==typeof e.totalQuantizedSteps?n.totalQuantizedSteps=t.longs===String?String(e.totalQuantizedSteps):e.totalQuantizedSteps:n.totalQuantizedSteps=t.longs===String?u.Long.prototype.toString.call(e.totalQuantizedSteps):t.longs===Number?new u.LongBits(e.totalQuantizedSteps.low>>>0,e.totalQuantizedSteps.high>>>0).toNumber():e.totalQuantizedSteps),null!=e.subsequenceInfo&&e.hasOwnProperty("subsequenceInfo")&&(n.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.toObject(e.subsequenceInfo,t)),null!=e.referenceNumber&&e.hasOwnProperty("referenceNumber")&&("number"==typeof e.referenceNumber?n.referenceNumber=t.longs===String?String(e.referenceNumber):e.referenceNumber:n.referenceNumber=t.longs===String?u.Long.prototype.toString.call(e.referenceNumber):t.longs===Number?new u.LongBits(e.referenceNumber.low>>>0,e.referenceNumber.high>>>0).toNumber():e.referenceNumber),null!=e.sequenceMetadata&&e.hasOwnProperty("sequenceMetadata")&&(n.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.toObject(e.sequenceMetadata,t)),e.sectionAnnotations&&e.sectionAnnotations.length)for(n.sectionAnnotations=[],o=0;o<e.sectionAnnotations.length;++o)n.sectionAnnotations[o]=c.tensorflow.magenta.NoteSequence.SectionAnnotation.toObject(e.sectionAnnotations[o],t);if(e.sectionGroups&&e.sectionGroups.length)for(n.sectionGroups=[],o=0;o<e.sectionGroups.length;++o)n.sectionGroups[o]=c.tensorflow.magenta.NoteSequence.SectionGroup.toObject(e.sectionGroups[o],t);return n},e.prototype.toJSON=function(){return this.constructor.toObject(this,i.util.toJSONOptions)},e.Note=function(){function e(e){if(e)for(var t=Object.keys(e),n=0;n<t.length;++n)null!=e[t[n]]&&(this[t[n]]=e[t[n]])}return e.prototype.pitch=0,e.prototype.pitchName=0,e.prototype.velocity=0,e.prototype.startTime=0,e.prototype.quantizedStartStep=u.Long?u.Long.fromBits(0,0,!1):0,e.prototype.endTime=0,e.prototype.quantizedEndStep=u.Long?u.Long.fromBits(0,0,!1):0,e.prototype.numerator=0,e.prototype.denominator=0,e.prototype.instrument=0,e.prototype.program=0,e.prototype.isDrum=!1,e.prototype.part=0,e.prototype.voice=0,e.create=function(t){return new e(t)},e.encode=function(e,t){return t||(t=a.create()),null!=e.pitch&&e.hasOwnProperty("pitch")&&t.uint32(8).int32(e.pitch),null!=e.velocity&&e.hasOwnProperty("velocity")&&t.uint32(16).int32(e.velocity),null!=e.startTime&&e.hasOwnProperty("startTime")&&t.uint32(25).double(e.startTime),null!=e.endTime&&e.hasOwnProperty("endTime")&&t.uint32(33).double(e.endTime),null!=e.numerator&&e.hasOwnProperty("numerator")&&t.uint32(40).int32(e.numerator),null!=e.denominator&&e.hasOwnProperty("denominator")&&t.uint32(48).int32(e.denominator),null!=e.instrument&&e.hasOwnProperty("instrument")&&t.uint32(56).int32(e.instrument),null!=e.program&&e.hasOwnProperty("program")&&t.uint32(64).int32(e.program),null!=e.isDrum&&e.hasOwnProperty("isDrum")&&t.uint32(72).bool(e.isDrum),null!=e.part&&e.hasOwnProperty("part")&&t.uint32(80).int32(e.part),null!=e.pitchName&&e.hasOwnProperty("pitchName")&&t.uint32(88).int32(e.pitchName),null!=e.voice&&e.hasOwnProperty("voice")&&t.uint32(96).int32(e.voice),null!=e.quantizedStartStep&&e.hasOwnProperty("quantizedStartStep")&&t.uint32(104).int64(e.quantizedStartStep),null!=e.quantizedEndStep&&e.hasOwnProperty("quantizedEndStep")&&t.uint32(112).int64(e.quantizedEndStep),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.Note;e.pos<n;){var o=e.uint32();switch(o>>>3){case 1:r.pitch=e.int32();break;case 11:r.pitchName=e.int32();break;case 2:r.velocity=e.int32();break;case 3:r.startTime=e.double();break;case 13:r.quantizedStartStep=u.Long?e.int64().toNumber():e.int64();break;case 4:r.endTime=e.double();break;case 14:r.quantizedEndStep=u.Long?e.int64().toNumber():e.int64();break;case 5:r.numerator=e.int32();break;case 6:r.denominator=e.int32();break;case 7:r.instrument=e.int32();break;case 8:r.program=e.int32();break;case 9:r.isDrum=e.bool();break;case 10:r.part=e.int32();break;case 12:r.voice=e.int32();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.pitch&&e.hasOwnProperty("pitch")&&!u.isInteger(e.pitch))return"pitch: integer expected";if(null!=e.pitchName&&e.hasOwnProperty("pitchName"))switch(e.pitchName){default:return"pitchName: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 32:case 33:case 34:case 35:}return null!=e.velocity&&e.hasOwnProperty("velocity")&&!u.isInteger(e.velocity)?"velocity: integer expected":null!=e.startTime&&e.hasOwnProperty("startTime")&&"number"!=typeof e.startTime?"startTime: number expected":null!=e.quantizedStartStep&&e.hasOwnProperty("quantizedStartStep")&&!(u.isInteger(e.quantizedStartStep)||e.quantizedStartStep&&u.isInteger(e.quantizedStartStep.low)&&u.isInteger(e.quantizedStartStep.high))?"quantizedStartStep: integer|Long expected":null!=e.endTime&&e.hasOwnProperty("endTime")&&"number"!=typeof e.endTime?"endTime: number expected":null!=e.quantizedEndStep&&e.hasOwnProperty("quantizedEndStep")&&!(u.isInteger(e.quantizedEndStep)||e.quantizedEndStep&&u.isInteger(e.quantizedEndStep.low)&&u.isInteger(e.quantizedEndStep.high))?"quantizedEndStep: integer|Long expected":null!=e.numerator&&e.hasOwnProperty("numerator")&&!u.isInteger(e.numerator)?"numerator: integer expected":null!=e.denominator&&e.hasOwnProperty("denominator")&&!u.isInteger(e.denominator)?"denominator: integer expected":null!=e.instrument&&e.hasOwnProperty("instrument")&&!u.isInteger(e.instrument)?"instrument: integer expected":null!=e.program&&e.hasOwnProperty("program")&&!u.isInteger(e.program)?"program: integer expected":null!=e.isDrum&&e.hasOwnProperty("isDrum")&&"boolean"!=typeof e.isDrum?"isDrum: boolean expected":null!=e.part&&e.hasOwnProperty("part")&&!u.isInteger(e.part)?"part: integer expected":null!=e.voice&&e.hasOwnProperty("voice")&&!u.isInteger(e.voice)?"voice: integer expected":null},e.fromObject=function(e){if(e instanceof c.tensorflow.magenta.NoteSequence.Note)return e;var t=new c.tensorflow.magenta.NoteSequence.Note;switch(null!=e.pitch&&(t.pitch=0|e.pitch),e.pitchName){case"UNKNOWN_PITCH_NAME":case 0:t.pitchName=0;break;case"F_FLAT_FLAT":case 1:t.pitchName=1;break;case"C_FLAT_FLAT":case 2:t.pitchName=2;break;case"G_FLAT_FLAT":case 3:t.pitchName=3;break;case"D_FLAT_FLAT":case 4:t.pitchName=4;break;case"A_FLAT_FLAT":case 5:t.pitchName=5;break;case"E_FLAT_FLAT":case 6:t.pitchName=6;break;case"B_FLAT_FLAT":case 7:t.pitchName=7;break;case"F_FLAT":case 8:t.pitchName=8;break;case"C_FLAT":case 9:t.pitchName=9;break;case"G_FLAT":case 10:t.pitchName=10;break;case"D_FLAT":case 11:t.pitchName=11;break;case"A_FLAT":case 12:t.pitchName=12;break;case"E_FLAT":case 13:t.pitchName=13;break;case"B_FLAT":case 14:t.pitchName=14;break;case"F":case 15:t.pitchName=15;break;case"C":case 16:t.pitchName=16;break;case"G":case 17:t.pitchName=17;break;case"D":case 18:t.pitchName=18;break;case"A":case 19:t.pitchName=19;break;case"E":case 20:t.pitchName=20;break;case"B":case 21:t.pitchName=21;break;case"F_SHARP":case 22:t.pitchName=22;break;case"C_SHARP":case 23:t.pitchName=23;break;case"G_SHARP":case 24:t.pitchName=24;break;case"D_SHARP":case 25:t.pitchName=25;break;case"A_SHARP":case 26:t.pitchName=26;break;case"E_SHARP":case 27:t.pitchName=27;break;case"B_SHARP":case 28:t.pitchName=28;break;case"F_SHARP_SHARP":case 29:t.pitchName=29;break;case"C_SHARP_SHARP":case 30:t.pitchName=30;break;case"G_SHARP_SHARP":case 31:t.pitchName=31;break;case"D_SHARP_SHARP":case 32:t.pitchName=32;break;case"A_SHARP_SHARP":case 33:t.pitchName=33;break;case"E_SHARP_SHARP":case 34:t.pitchName=34;break;case"B_SHARP_SHARP":case 35:t.pitchName=35}return null!=e.velocity&&(t.velocity=0|e.velocity),null!=e.startTime&&(t.startTime=Number(e.startTime)),null!=e.quantizedStartStep&&(u.Long?(t.quantizedStart