jianpurender
Version:
Render music score using SVG on browsers.
1 lines • 30.1 kB
JavaScript
(()=>{"use strict";var t,e={75:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DURATION_LINE_SCALES=e.SMALL_FONT_SIZE_MULTIPLIER=e.FONT_SIZE_MULTIPLIER=e.AUGMENTATION_SPACING_FACTOR=e.ACCIDENTAL_SPACING_FACTOR=e.AUGMENTATION_DASH_FACTOR=e.DOT_SIZE_FACTOR=e.OCTAVE_DOT_OFFSET_FACTOR=e.UNDERLINE_SPACING_FACTOR=e.COMPACT_SPACING_FACTOR=e.LINE_STROKE_WIDTH=void 0,e.LINE_STROKE_WIDTH=1,e.COMPACT_SPACING_FACTOR=1.5,e.UNDERLINE_SPACING_FACTOR=.2,e.OCTAVE_DOT_OFFSET_FACTOR=1,e.DOT_SIZE_FACTOR=.1,e.AUGMENTATION_DASH_FACTOR=.8,e.ACCIDENTAL_SPACING_FACTOR=.1,e.AUGMENTATION_SPACING_FACTOR=.2,e.FONT_SIZE_MULTIPLIER=1.2,e.SMALL_FONT_SIZE_MULTIPLIER=.75,e.DURATION_LINE_SCALES=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},88:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuSVGRender=e.ScrollType=void 0;var n,r=i(75),a=i(811),s=i(388),o=i(567),h=i(186),u=i(214);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(e.ScrollType=n={}));var l=function(){function t(t,e,i){var a,s,u,l,c,d,g,m,f,p,S,T=this;this.handleScrollEvent=function(t){T.lastKnownScrollLeft=T.parentElement.scrollLeft,T.isScrolling||window.requestAnimationFrame((function(){T.updateOverlaySignaturesForScroll(T.lastKnownScrollLeft),T.isScrolling=!1})),T.isScrolling=!0},this.jianpuInfo=t,this.div=i,this.config={noteHeight:null!==(a=e.noteHeight)&&void 0!==a?a:20,noteSpacingFactor:null!==(s=e.noteSpacingFactor)&&void 0!==s?s:r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:null!==(u=e.pixelsPerTimeStep)&&void 0!==u?u:0,noteColor:this.parseColorString(null!==(l=e.noteColor)&&void 0!==l?l:"black"),activeNoteColor:this.parseColorString(null!==(c=e.activeNoteColor)&&void 0!==c?c:"red"),defaultKey:null!==(d=e.defaultKey)&&void 0!==d?d:0,scrollType:null!==(g=e.scrollType)&&void 0!==g?g:n.PAGE,fontFamily:null!==(m=e.fontFamily)&&void 0!==m?m:"sans-serif",width:null!==(f=e.width)&&void 0!==f?f:0,height:null!==(p=e.height)&&void 0!==p?p:0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(S=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==S?S:o.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}return t.prototype.parseColorString=function(t){return/^[a-z]+$/i.test(t)||t.startsWith("rgb(")?t:/^\d+,\s*\d+,\s*\d+$/.test(t)?"rgb(".concat(t,")"):t},t.prototype.clear=function(){for(var t;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(a.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,a.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(a.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,a.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,a.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,a.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(t=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==t?t:o.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()},t.prototype.updateLayout=function(t){this.width=null!=t?t:this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);var e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width","".concat(this.width)),this.mainSVG.setAttribute("height","".concat(this.height)),this.mainG.setAttribute("transform","translate(0, ".concat(this.yBaseline+e,")")),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height","".concat(this.height)),this.overlayG.setAttribute("transform","translate(0, ".concat(this.yBaseline,")"))},t.prototype.redraw=function(t,e){var i=this,r=-1,s=this.config.pixelsPerTimeStep<=0;if(t){var o="".concat(t.start,"-").concat(t.pitch);if(this.playingNotes.forEach((function(t,e){if(e!==o){var n=i.mainSVG.querySelector('g[data-id="'.concat(e,'"]'));n&&(0,a.resetElementHighlight)(n,i.config.noteColor),i.playingNotes.delete(e)}})),!this.playingNotes.has(o)){var h=this.mainSVG.querySelector('g[data-id="'.concat(o,'"]'));if(h){(0,a.highlightElement)(h,this.config.activeNoteColor),this.playingNotes.set(o,t);var u=h.getBoundingClientRect(),l=this.mainSVG.getBoundingClientRect();r=u.left-l.left+this.parentElement.scrollLeft;var c=h.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||c)&&this.scrollIntoViewIfNeeded(r)}}if(!s&&this.signaturesBlinking){var d=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>d&&(this.signaturesBlinking=!1,(0,a.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);var g=this.width,m=this.width,f=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,p=0,S=new Map;this.jianpuModel.jianpuBlockMap.forEach((function(t,e){if(e>=i.lastRenderedQ-1e-9){g=s?m:i.jianpuModel.measuresInfo.quartersToTime(e,e)*i.config.pixelsPerTimeStep;var n=i.drawJianpuBlock(t,g,S);s?m+=n:m=Math.max(m,g+n);var r=i.mainSVG.querySelector('g[data-block-start="'.concat(t.start,'"]'));if(r)try{var a=r.getBBox(),o=a.y,h=a.y+a.height;p=Math.min(p,o),f=Math.max(f,h)}catch(t){}i.lastRenderedQ=e+t.length}})),this.height=Math.max(this.height,f-p+this.config.noteHeight),this.updateLayout(m)}return r},t.prototype.drawJianpuBlock=function(t,e,i){var n=0,o=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),u=(0,a.createSVGGroupChild)(this.musicG,"block-".concat(t.start));if(u.setAttribute("data-block-start","".concat(t.start)),h&&t.start>1e-6){var l=e-(o?.6*this.estimatedNoteWidth:4),c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE);(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)}var m=this.updateCurrentKey(t.start),f=this.updateCurrentTimeSignature(t.start),p=0;if((m||f)&&t.start>1e-6){var S=e+n;p=this.drawSignatures(this.signaturesG,S,m,f),o&&(n+=p+.2*this.estimatedNoteWidth)}var T=e+n,v=0;if(t.notes.length>0?v=this.drawNotes(t,T,i,u):t.length>1e-6&&(v=this.drawRest(t,T,u)),o){n+=v;var A=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?A*=1:t.length<.0625?A*=.05:t.length<.125?A*=.1:t.length<.25?A*=.2:t.length<.5?A*=.4:t.length<1&&(A*=.5),n+=A}else n=Math.max(p,v);return this.jianpuModel.isLastMeasureAtQ(t.start+t.length)&&(l=e+n,c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE),(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)),n},t.prototype.drawNotes=function(t,e,i,n){var o=this,h=e,u=e,l=.1*this.estimatedNoteWidth,c="".concat(this.numberFontSize,"px"),d="".concat(this.smallFontSize,"px"),g=t.durationLines,m=void 0===g?0:g,f=t.augmentationDots,p=void 0===f?0:f,S=t.augmentationDash,T=void 0!==S&&S;return t.notes.forEach((function(e){var g,f,S,v="".concat(e.start,"-").concat(e.pitch),A=(0,a.createSVGGroupChild)(n,v);t.isMeasureBeginning()&&A.setAttribute("data-is-measure-start","true");var E=h,_=E;if(0!==e.accidental){var I=s.ACCIDENTAL_TEXT[e.accidental];(0,a.drawSVGText)(A,I,E+l,0,d,"normal","end","text-top",o.config.noteColor)}var N=0;if(T){var y=o.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,M=y/50,C=(0,a.drawSVGPath)(A,s.augmentationDashPath,E,0,M,1);(0,a.setStroke)(C,o.config.noteColor,r.LINE_STROKE_WIDTH),_=E+(N=y)}else{var L="".concat(e.jianpuNumber);_=E+(N=(0,a.drawSVGText)(A,L,E,0,c,"normal","start","middle",o.config.noteColor).getBBox().width)}if(0!==e.octaveDot&&!1===T)for(var b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),O=E+N/2,R=2.8*H,G=o.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR,D=0;D<Math.abs(e.octaveDot);D++){var P=(e.octaveDot>0?-G:.6*G)-D*R*(e.octaveDot>0?1:-1);(0,a.drawSVGPath)(A,s.dotPath,O,P,b,b)}if(m>0)for(var w=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,F=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,k=N/s.PATH_SCALE*(null!==(g=r.DURATION_LINE_SCALES.get(m))&&void 0!==g?g:1),V=0;V<m;V++){var x=w+V*F,B=(0,a.drawSVGPath)(A,s.underlinePath,E,x,k,1);(0,a.setStroke)(B,o.config.noteColor,r.LINE_STROKE_WIDTH)}var U=_+l;if(p>0){var H;for(b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),D=0;D<p;D++)(0,a.drawSVGPath)(A,s.dotPath,U,0,b,b),U+=H+l;_=U+l}var j=_;if(e.tiedTo&&!T)i.set(e,{g:A,xNoteRight:j,yNoteBaseline:0});else if(e.tiedFrom){for(var Q=e.tiedFrom;Q.tiedFrom;)Q=Q.tiedFrom;var J=i.get(Q);if(J){var K=1*J.xNoteRight,W=(T?E-2.2*o.estimatedNoteWidth:E-l)-K,q=1.2*-o.config.noteHeight,Z=W/s.PATH_SCALE*1.3,z=o.config.noteHeight/s.PATH_SCALE*1.6;W>1&&(0,a.drawSVGPath)(J.g,s.tiePath,K-(null!==(S=null===(f=J.g.getCTM())||void 0===f?void 0:f.e)&&void 0!==S?S:0),q,Z,z);for(var X=Q;X&&X!==e;){i.delete(X);var Y=X.tiedTo;Y&&(X=Y)}}else console.warn("Missing linked SVG details for first tied note:",Q)}u=Math.max(u,_)})),u-e},t.prototype.drawRest=function(t,e,i){var n,o="".concat(this.numberFontSize,"px"),h=.1*this.estimatedNoteWidth,u=t.durationLines,l=void 0===u?0:u,c=t.augmentationDots,d=void 0===c?0:c,g=e,m=g,f=(0,a.drawSVGText)(i,"0",g,0,o,"normal","start","middle",this.config.noteColor).getBBox().width;if(m=g+f,l>0)for(var p=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,S=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,T=f/s.PATH_SCALE*(null!==(n=r.DURATION_LINE_SCALES.get(l))&&void 0!==n?n:1),v=0;v<l;v++){var A=p+v*S,E=(0,a.drawSVGPath)(i,s.underlinePath,g,A,T,1);(0,a.setStroke)(E,this.config.noteColor,r.LINE_STROKE_WIDTH)}var _=m+h;if(d>0){for(var I=this.config.noteHeight*r.DOT_SIZE_FACTOR,N=I/(.15*s.PATH_SCALE),y=0;y<d;y++)(0,a.drawSVGPath)(i,s.dotPath,_,0,N,N),_+=I+h;m=_+h}return m-e},t.prototype.drawSignatures=function(t,e,i,n){var r,s=e,o=.3*this.estimatedNoteWidth,h="".concat(this.smallFontSize,"px"),l="".concat(this.numberFontSize,"px");if(i){var c=null!==(r=u.PITCH_CLASS_NAMES[this.currentKey%12])&&void 0!==r?r:"C",d="1=".concat(c);s+=(0,a.drawSVGText)(t,d,s,0,l,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(n){var g="".concat(this.currentTimeSignature.numerator,"/").concat(this.currentTimeSignature.denominator);s+=(0,a.drawSVGText)(t,g,s,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+o}var m=s-e;try{var f=t.getBBox(),p=f.y,S=f.y+f.height,T=Math.max(this.yBaseline+S,this.yBaseline-p)+.5*this.config.noteHeight;this.height=Math.max(this.height,T)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,a.setBlinkAnimation)(this.overlayG,!0)),m},t.prototype.updateCurrentKey=function(t){var e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)},t.prototype.updateCurrentTimeSignature=function(t){var e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=e,0))},t.prototype.scrollIntoViewIfNeeded=function(t){var e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft,r=i;this.config.scrollType===n.PAGE?t<i+20?r=t-20:t>i+e-20&&(r=t-e+20):r=t-.5*e,r=Math.max(0,Math.min(r,this.parentElement.scrollWidth-e)),Math.abs(r-i)>1&&(this.parentElement.scrollTo({left:r,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(r))},t.prototype.updateOverlaySignaturesForScroll=function(t){var e,i=this.pixelsToTime(t),n=this.jianpuModel.measuresInfo.keySignatureAtQ(i),r=null!==(e=this.jianpuModel.measuresInfo.timeSignatureAtQ(i))&&void 0!==e?e:this.currentTimeSignature,s=!1;if(n!==this.currentKey&&(this.currentKey=n,s=!0),r.numerator===this.currentTimeSignature.numerator&&r.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=r,s=!0),s){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,a.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,a.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}},t.prototype.pixelsToTime=function(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)},t}();e.JianpuSVGRender=l},186:function(t,e,i){var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuModel=void 0,e.mapMidiToJianpu=u;var r=i(567),a=i(980),s=i(826),o=i(214),h=function(){function t(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}return t.prototype.isLastMeasureAtQ=function(t){return t>=this.lastQ-1e-6},t.prototype.getTotalDuration=function(){return this.lastQ},t.prototype.update=function(t,e){var i=this;this.jianpuInfo=t,t.notes.sort((function(t,e){return t.start-e.start})),this.lastQ=0,t.notes.forEach((function(t){i.lastQ=Math.max(i.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[r.DEFAULT_TEMPO],t.tempos.sort((function(t,e){return t.start-e.start})),t.tempos[0].start>1e-6&&t.tempos.unshift(n(n({},r.DEFAULT_TEMPO),{start:0}));var s=void 0!==e?{start:0,key:e}:n({},r.DEFAULT_KEY_SIGNATURE);t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[s],t.keySignatures.sort((function(t,e){return t.start-e.start})),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift(n(n({},s),{start:0})),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[r.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort((function(t,e){return t.start-e.start})),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift(n(n({},r.DEFAULT_TIME_SIGNATURE),{start:0})),this.measuresInfo=new a.MeasuresInfo(t,this.lastQ),this.infoToBlocks()},t.prototype.infoToBlocks=function(){var t=this,e=new Map,i=0;if(this.jianpuInfo.notes.forEach((function(n){var r=n.start,a=t.measuresInfo.measureNumberAtQ(r);if(r>i+1e-6){var o=i,h=r-o,u=t.measuresInfo.measureNumberAtQ(o),l=new s.JianpuBlock(o,h,[],u);e.set(o,l)}var c=t.measuresInfo.keySignatureAtQ(r),d=t.createJianpuNote(n,c),g=e.get(r);g||(g=new s.JianpuBlock(r,0,[],a),e.set(r,g)),g.addNote(d),i=Math.max(i,r+g.length)})),this.lastQ>i+1e-6){var n=i,r=this.lastQ-n;if(r>1e-6){var a=this.measuresInfo.measureNumberAtQ(n),o=new s.JianpuBlock(n,r,[],a);e.set(n,o)}}this.jianpuBlockMap=new Map;var h=Array.from(e.keys()).sort((function(t,e){return t-e})),u=[];h.forEach((function(t){u.push(e.get(t))}));for(var l=new Set;u.length>0;){var c=u.shift();l.has(c.start)&&this.jianpuBlockMap.has(c.start);var d=c.splitToBeat(this.measuresInfo);if(d)c.mergeToMap(this.jianpuBlockMap),l.add(c.start),u.unshift(d);else{var g=c,m=null;do{m=g.splitToStandardSymbol(this.measuresInfo),g.mergeToMap(this.jianpuBlockMap),l.add(g.start),m&&(g=m)}while(m)}}this.jianpuBlockMap.forEach((function(e){e.calculateRenderProperties(t.measuresInfo)}))},t.prototype.createJianpuNote=function(t,e){var i=u(t.pitch,e);return n(n({},t),{jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental})},t}();function u(t,e){var i=e%12,n=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(n-=12);var r=(t-(n+12*Math.round((t-n)/12))+12)%12,a=o.MAJOR_SCALE_INTERVALS[r],s=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],s=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],s=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],s=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],s=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],s=2;break;default:console.warn("Unexpected chromatic interval ".concat(r," in mapMidiToJianpu. Defaulting to sharp of lower valid degree."));var h=(r-1+12)%12,u=(r+1+12)%12,l=o.MAJOR_SCALE_INTERVALS[h],c=o.MAJOR_SCALE_INTERVALS[u];void 0!==l?(a=l,s=1):void 0!==c?(a=c,s=2):(a=1,s=1,console.error("Could not determine Jianpu number components for MIDI ".concat(t,", interval ").concat(r," from tonic in key ").concat(e,".")))}void 0===a&&(console.error("Jianpu number became undefined for MIDI ".concat(t," (interval ").concat(r,", key ").concat(e,") after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.")),a=1,s=1)}return{jianpuNumber:a,octaveDot:Math.floor((t-n)/12),accidental:s}}e.JianpuModel=h},214:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MIDDLE_C_MIDI=e.MAJOR_SCALE_INTERVALS=e.PITCH_CLASS_NAMES=e.MAX_QUARTER_DIVISION=e.MIN_RESOLUTION=void 0,e.MIN_RESOLUTION=.0625,e.MAX_QUARTER_DIVISION=240,e.PITCH_CLASS_NAMES=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],e.MAJOR_SCALE_INTERVALS={0:1,2:2,4:3,5:4,7:5,9:6,11:7},e.MIDDLE_C_MIDI=60},229:function(t,e,i){var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(e,i);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,r)}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),r=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||n(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(i(88),e),r(i(186),e),r(i(826),e),r(i(567),e)},388:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.dotPath=e.tiePath=e.augmentationDashPath=e.underlinePath=e.barPath=e.ACCIDENTAL_TEXT=e.ACCIDENTAL_PATHS=e.PATH_SCALE=void 0,e.PATH_SCALE=100,e.ACCIDENTAL_PATHS=[null,"m 30,15 h 40 m -35,20 h 40 M 50,0 v 50 M 70,5 v 50","m 45,5 v 40 c 0,15 20,15 20,0 V 20 C 65,5 45,5 45,5 Z","M 45,5 v 45 M 65,0 v 45 H 45 m 20,10 H 45"],e.ACCIDENTAL_TEXT=["","#","b"],e.barPath="m 0,-50 v 100",e.underlinePath="m 0,0 h 100",e.augmentationDashPath="m 0,0 h 50",e.tiePath="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",e.dotPath="M 0 0 a 15 15 0 1 0 0.0001 0 z"},567:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_TIME_SIGNATURE=e.DEFAULT_KEY_SIGNATURE=e.DEFAULT_TEMPO=void 0,e.getMeasureLength=function(t){return t.numerator*(4/t.denominator)},e.DEFAULT_TEMPO={start:0,qpm:60},e.DEFAULT_KEY_SIGNATURE={start:0,key:0},e.DEFAULT_TIME_SIGNATURE={start:0,numerator:4,denominator:4}},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SVGNS=void 0,e.drawSVGPath=function(t,i,n,r,a,s,o){void 0===o&&(o=1);var h=document.createElementNS(e.SVGNS,"path");return h.setAttributeNS(null,"d",i),h.setAttributeNS(null,"transform","translate(".concat(n,", ").concat(r,") scale(").concat(a,", ").concat(s,")")),o<1&&h.setAttributeNS(null,"opacity","".concat(o)),t.appendChild(h),h},e.drawSVGText=function(t,i,n,r,a,s,o,h,u,l){void 0===s&&(s="normal"),void 0===o&&(o="middle"),void 0===h&&(h="middle"),void 0===u&&(u="currentColor"),void 0===l&&(l=1);var c=document.createElementNS(e.SVGNS,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",a),c.setAttributeNS(null,"font-weight",s),c.setAttributeNS(null,"x","".concat(n)),c.setAttributeNS(null,"y","".concat(r)),c.setAttributeNS(null,"text-anchor",o),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==u&&c.setAttributeNS(null,"fill",u),l<1&&c.setAttributeNS(null,"opacity","".concat(l));var d=document.createTextNode(i);return c.appendChild(d),t.appendChild(c),c},e.createSVGGroupChild=function(t,i){var n=document.createElementNS(e.SVGNS,"g");return i&&n.setAttribute("data-id",i),t.appendChild(n),n},e.setBlinkAnimation=function(t,i,n){void 0===i&&(i=!0),void 0===n&&(n="1s");var r=t.querySelector('animate[attributeName="opacity"]');return i?r?(r.setAttributeNS(null,"repeatCount","indefinite"),r.beginElement()):((r=document.createElementNS(e.SVGNS,"animate")).setAttributeNS(null,"attributeName","opacity"),r.setAttributeNS(null,"values","1;0.2;1"),r.setAttributeNS(null,"keyTimes","0;0.5;1"),r.setAttributeNS(null,"dur",n),r.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(r)):(r&&(r.endElement(),r.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t},e.setFill=function(t,e){t.setAttributeNS(null,"fill",e)},e.setStroke=function(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width","".concat(i))},e.highlightElement=function(t,e){var i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((function(t){i.push(t)})),i.forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t},e.resetElementHighlight=function(t,e){t.querySelectorAll("text, path").forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))},e.SVGNS="http://www.w3.org/2000/svg"},826:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuBlock=void 0,e.splitJianpuNote=a;var n=i(214);function r(t){return Math.abs(t)<1e-6}function a(t,e){var i=t.start+t.length;if(e<=t.start||e>=i||r(i-e))return null;var n=i-e;t.length=e-t.start;var a={start:e,length:n,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(a.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=a),t.tiedTo=a,a}var s=function(){function t(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=[]),void 0===n&&(n=1),this.start=t,this.length=e,this.notes=i,this.measureNumber=n}return t.prototype.addNote=function(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!r(this.start-t.start))return console.warn("JianpuBlock: Attempted to add note at ".concat(t.start," to block starting at ").concat(this.start,". Ignoring.")),!1;for(var e=!1,i=!1,n=0;n<this.notes.length;n++)if(this.notes[n].pitch===t.pitch){i=!0,t.length<this.notes[n].length&&(this.notes[n].tiedFrom&&(t.tiedFrom=this.notes[n].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[n].tiedTo&&(t.tiedTo=this.notes[n].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[n]=t,e=!0);break}i||this.notes.push(t);for(var a=1/0,s=0,o=this.notes;s<o.length;s++){var h=o[s];a=Math.min(a,h.length)}return this.length=a,!i||e},t.prototype.split=function(e,i){var n=this.start+this.length;if(e<=this.start||e>=n||r(n-e))return null;for(var s=n-e,o=e-this.start,h=new t(e,s,[],i.measureNumberAtQ(e)),u=[],l=0,c=this.notes;l<c.length;l++){var d=c[l],g=d.start+d.length;if(g>e+1e-6){var m=a(d,e);m?u.push(m):console.warn("Split failed for note, unexpected state.")}else r(g-e)}return u.forEach((function(t){return h.addNote(t)})),this.length=o,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h},t.prototype.splitToBeat=function(t){var e=t.timeSignatureAtQ(this.start);if(!e)return null;var i=t.measureLengthAtQ(this.start),n=t.measureNumberAtQ(this.start),a=this.start-(n-Math.floor(n))*i,s=this.start-a,o=4/e.denominator,h=s/o;this.beatBegin=r(h-Math.round(h));var u=a+(Math.floor(h+1e-6)+1)*o,l=a+i,c=this.start+this.length,d=null;u<c-1e-6&&u>this.start+1e-6&&(d=u),l<c-1e-6&&l>this.start+1e-6&&(null===d||l<d)&&(d=l);var g=null;if(null!==d)(g=this.split(d,t))&&(this.beatEnd=!0);else{var m=(s+this.length)/o;this.beatEnd=r(m-Math.round(m)),this.beatEnd||(this.beatEnd=r(c-l))}return this.isTieStart=this.notes.some((function(t){return t.tiedFrom})),this.isTieEnd=this.notes.some((function(t){return t.tiedTo})),g&&(g.isTieStart=g.notes.some((function(t){return t.tiedFrom})),g.isTieEnd=g.notes.some((function(t){return t.tiedTo})),this.notes.some((function(t){return t.tiedTo&&t.start+t.length>d}))&&delete this.isTieEnd),g},t.prototype.calculateRenderProperties=function(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;var e=this.length;if(!(r(e)||e<0)){if(t.allowDottedRests||this.notes.length>0){if(r(e-1.5))return void(this.augmentationDots=1);if(r(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(r(e-.375))return this.durationLines=2,void(this.augmentationDots=1);r(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){var i=this.notes[0],n=t.timeSignatureAtQ(this.start);if(!n)return;var a=Math.max(4/n.denominator,1);if(!(this.measureNumber%1<=1e-6)&&i.tiedFrom&&r(i.tiedFrom.length-a)&&i.tiedFrom.pitch===i.pitch&&i.length>=1){var s=!0;if(i.tiedTo){var o=i.start+i.length;s=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(o))&&i.tiedTo.length>=1}s&&(this.augmentationDash=!0)}}}},t.prototype.splitToStandardSymbol=function(t){var e=this.length;if(r(e)||e<n.MIN_RESOLUTION-1e-6)return null;var i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));for(var a=0,s=0,o=i;s<o.length;s++){var h=o[s];if(e>=h-1e-6){a=h;break}}r(a)&&e<(a=n.MIN_RESOLUTION)-1e-6&&e>1e-6&&console.warn("Block length ".concat(e," is too small, rendering as ").concat(a));var u=null;return e>a+1e-6?(u=this.split(this.start+a,t),this.length!==a&&(console.warn("Adjusting block length after split from ".concat(this.length," to ").concat(a)),this.length=a)):this.length=a,u},t.prototype.mergeToMap=function(t){var e=t.get(this.start);e?(this.notes.forEach((function(t){return e.addNote(t)})),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)},t.prototype.isMeasureBeginning=function(){return r(this.measureNumber-Math.floor(this.measureNumber))},t}();e.JianpuBlock=s},980:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MeasuresInfo=void 0;var n=i(567),r=i(214),a=function(){function t(t,e){this.allowDottedRests=!0,this.measuresInfo=[];for(var i=0,a=0,s=0,o=t.tempos[0],h=t.keySignatures[0],u=t.timeSignatures[0],l=1,c=(0,n.getMeasureLength)(u),d=u.start,g=r.MIN_RESOLUTION,m=0;m<e;m+=g){var f={start:m,measureNumber:l+(m-d)/c,measureLength:c,tempo:o,keySignature:h,timeSignature:u};i<t.tempos.length&&Math.abs(t.tempos[i].start-m)<g/2&&(o=t.tempos[i++],f.tempo=o,f.tempoChange=!0),a<t.keySignatures.length&&Math.abs(t.keySignatures[a].start-m)<g/2&&(h=t.keySignatures[a++],f.keySignature=h,f.keyChange=!0),s<t.timeSignatures.length&&Math.abs(t.timeSignatures[s].start-m)<g/2&&(l+=(t.timeSignatures[s].start-d)/c,l=Math.round(1e3*l)/1e3,u=t.timeSignatures[s++],f.timeSignature=u,c=(0,n.getMeasureLength)(u),f.measureLength=c,f.measureNumber=l,f.timeChange=!0,d=f.start),this.measuresInfo.push(f)}}return t.prototype.findIndex=function(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/r.MIN_RESOLUTION)))},t.prototype.measureNumberAtQ=function(t){if(0===this.measuresInfo.length)return 1;var e=this.findIndex(t),i=this.measuresInfo[e],n=(t-i.start)/i.measureLength;return i.measureNumber+n+1e-9},t.prototype.measureLengthAtQ=function(t){if(0===this.measuresInfo.length)return(0,n.getMeasureLength)(n.DEFAULT_TIME_SIGNATURE);var e=this.findIndex(t);return this.measuresInfo[e].measureLength},t.prototype.tempoAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TEMPO.qpm;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.tempoChange&&s?a.tempo.qpm:-1},t.prototype.keySignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_KEY_SIGNATURE.key;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.keyChange&&s?a.keySignature.key:-1},t.prototype.timeSignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TIME_SIGNATURE;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.timeChange&&s?a.timeSignature:null},t.prototype.quartersToTime=function(t,e){var i=this.tempoAtQ(e);return i<=0?0:t/i*60},t.prototype.timeToQuarters=function(t,e){var i=this.tempoAtQ(e);if(i<=0)return 0;var n=t*i/60;return Math.round(n*r.MAX_QUARTER_DIVISION)/r.MAX_QUARTER_DIVISION},t.prototype.isBeatStart=function(t){if(0===this.measuresInfo.length)return!1;var e=this.findIndex(t),i=this.measuresInfo[e],n=i.timeSignature,a=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/n.denominator);return Math.abs(a-Math.round(a))<r.MIN_RESOLUTION/2},t}();e.MeasuresInfo=a}},i={};t=function t(n){var r=i[n];if(void 0!==r)return r.exports;var a=i[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(229),window.jr=t})();