src-legacy-fca58b40.js 660 KB

1
  1. System.register(["./node_modules-legacy-bf1d9d7f.js"],(function(e,t){"use strict";var i,s,n,r,o,a,l;return{setters:[e=>{i=e.D,s=e.l,n=e.V,r=e.N,o=e._,a=e.p,l=e.j}],execute:function(){e({a:Lt,b:function(e){return bt.includes(e)},i:Tt});class t{static ajax(e,t=9e3){let i;const s=e.indexOf(".mxl")>-1?"text/plain; charset=x-user-defined":"application/xml";if(XMLHttpRequest)i=new XMLHttpRequest;else{if(!ActiveXObject)return Promise.reject(new Error("XMLHttp not supported."));i=new ActiveXObject("Microsoft.XMLHTTP")}return i.timeout=t,new Promise(((t,n)=>{i.onreadystatechange=()=>{i.readyState===XMLHttpRequest.DONE&&(200===i.status||0===i.status&&i.responseText?t(i.responseText):n(new Error("Could not retrieve requested URL "+i.status)))},i.ontimeout=e=>{n(new Error("Server request Timeout"))},i.overrideMimeType(s),i.open("GET",e,!0),i.send()}))}}const h=class{constructor(e=0,t=1,i=0,s=!0){this.numerator=0,this.denominator=1,this.wholeValue=0,this.numerator=e,this.denominator=t,this.wholeValue=i,s&&this.simplify(),this.setRealValue()}static max(e,t){return e.RealValue>t.RealValue?e:t}static Equal(e,t){return e.wholeValue===t.wholeValue&&e.Denominator===t.Denominator&&e.Numerator===t.Numerator}static createFromFraction(e){return new h(e.numerator,e.denominator,e.wholeValue,!1)}static plus(e,t){const i=e.clone();return i.Add(t),i}static minus(e,t){const i=e.clone();return i.Sub(t),i}static multiply(e,t){return new h((e.wholeValue*e.denominator+e.numerator)*(t.wholeValue*t.denominator+t.numerator),e.denominator*t.denominator)}static greatestCommonDenominator(e,t){if(0===e)return t;if(1===t)return 1;for(;Math.abs(t)>=1&&Math.abs(e)>=1;)e>t?e-=t:t-=e;const i=Math.round(e);return Math.max(i,1)}toString(){let e=this.numerator+"/"+this.denominator;return 0!==this.wholeValue&&(e=this.wholeValue+" "+e),e}clone(){return new h(this.numerator,this.denominator,this.wholeValue,!1)}get Numerator(){return this.numerator}set Numerator(e){this.numerator!==e&&(this.numerator=e,this.simplify(),this.setRealValue())}get Denominator(){return this.denominator}set Denominator(e){this.denominator!==e&&(this.denominator=e,0!==this.numerator&&this.simplify(),this.setRealValue())}get WholeValue(){return this.wholeValue}set WholeValue(e){this.wholeValue!==e&&(this.wholeValue=e,this.setRealValue())}GetExpandedNumerator(){return this.wholeValue*this.denominator+this.numerator}calculateNumberOfNeededDots(){let e=1,t=2;const i=this.GetExpandedNumerator();for(;t<i;)e++,t=Math.pow(2,e);return Math.min(3,e-1)}IsNegative(){return this.realValue<0}get RealValue(){return this.realValue}expand(e){this.numerator*=e,this.denominator*=e,0!==this.wholeValue&&(this.numerator+=this.wholeValue*this.denominator,this.wholeValue=0)}Add(e){return this.numerator=(this.wholeValue*this.denominator+this.numerator)*e.denominator+(e.wholeValue*e.denominator+e.numerator)*this.denominator,this.denominator=this.denominator*e.denominator,this.wholeValue=0,this.simplify(),this.setRealValue(),this}Sub(e){return this.numerator=(this.wholeValue*this.denominator+this.numerator)*e.denominator-(e.wholeValue*e.denominator+e.numerator)*this.denominator,this.denominator=this.denominator*e.denominator,this.wholeValue=0,this.simplify(),this.setRealValue(),this}getHalfLength(){return new h(this.WholeValue,2).Add(new h(this.Numerator,2*this.Denominator))}Quantize(e){if(this.denominator<=e)return this;const t=new h(this.numerator+1,this.denominator,this.wholeValue);for(;t.Denominator>e;)t.Numerator++;if(this.numerator>this.denominator){const i=new h(this.numerator-1,this.denominator,this.wholeValue);for(;i.Denominator>e;)i.Numerator--;if(i.Denominator<t.Denominator)return i}return t}Equals(e){return this.realValue===(null==e?void 0:e.realValue)}CompareTo(e){const t=this.realValue-e.realValue;return t?t<0?-1:1:0}lt(e){return this.realValue<e.realValue}lte(e){return this.realValue<=e.realValue}gt(e){return!this.lte(e)}gte(e){return!this.lt(e)}setRealValue(){this.realValue=this.wholeValue+this.numerator/this.denominator}simplify(){if(0===this.numerator)return void(this.denominator=1);const e=h.greatestCommonDenominator(Math.abs(this.numerator),Math.abs(this.denominator));this.numerator/=e,this.denominator/=e;const t=Math.floor(this.numerator/this.denominator);if(0!==t&&(this.wholeValue+=t,this.numerator-=t*this.denominator,0===this.numerator&&(this.denominator=1)),this.denominator>h.maximumAllowedNumber){const e=this.denominator/h.maximumAllowedNumber;this.numerator=Math.round(this.numerator/e),this.denominator=Math.round(this.denominator/e)}if(this.numerator>h.maximumAllowedNumber){const e=this.numerator/h.maximumAllowedNumber;this.numerator=Math.round(this.numerator/e),this.denominator=Math.round(this.denominator/e)}}isOnBeat(e){const t=this.distanceFromBeat(e);return Math.abs(t)<h.FloatInaccuracyTolerance}distanceFromBeat(e){const t=new h(1,e.Denominator);return this.RealValue%t.RealValue}};let u=e("F",h);u.maximumAllowedNumber=46340,u.FloatInaccuracyTolerance=1e-4;class c{constructor(e){this.placement=e}static isStringInStringList(e,t){for(let i=0,s=e.length;i<s;++i){const s=e[i];if(t.toLowerCase()===s.toLowerCase().trim())return!0}return!1}get Placement(){return this.placement}static PlacementEnumFromString(e){switch(e.toLowerCase()){case"above":return 0;case"below":return 1;case"aboveorbelow":case"abovebelow":return 5;case"left":return 2;case"right":return 3;default:return 4}}}var d=(e=>(e[e.Above=0]="Above",e[e.Below=1]="Below",e[e.Left=2]="Left",e[e.Right=3]="Right",e[e.NotYetDefined=4]="NotYetDefined",e[e.AboveOrBelow=5]="AboveOrBelow",e))(d||{});const f=class extends c{constructor(e,t,i,s,n,r,o=""){super(t),super.parentMeasure=s,this.NumberXml=r,this.dynamicType=e,this.label=o,this.staffNumber=i,this.activeInstantaneousDynamic=n,this.startVolume=1,this.endVolume=1,this.setStartAndEndVolume(),""!==o&&this.setType()}setStartAndEndVolume(){this.activeInstantaneousDynamic&&(0===this.dynamicType&&(this.startVolume=this.activeInstantaneousDynamic.Volume,this.endVolume=1.2*this.activeInstantaneousDynamic.Volume),1===this.dynamicType&&(this.startVolume=this.activeInstantaneousDynamic.Volume,this.endVolume=.8*this.activeInstantaneousDynamic.Volume))}get DynamicType(){return this.dynamicType}set DynamicType(e){this.dynamicType=e}get StartMultiExpression(){return this.startMultiExpression}set StartMultiExpression(e){this.startMultiExpression=e}get EndMultiExpression(){return this.endMultiExpression}set EndMultiExpression(e){this.endMultiExpression=e}get Placement(){return this.placement}set Placement(e){this.placement=e}get StartVolume(){return this.startVolume}set StartVolume(e){this.startVolume=e}get EndVolume(){return this.endVolume}set EndVolume(e){this.endVolume=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get Label(){return this.label}set Label(e){this.label=e,this.setType()}static isInputStringContinuousDynamic(e){return!!e&&(f.isStringInStringList(f.listContinuousDynamicIncreasing,e)||f.isStringInStringList(f.listContinuousDynamicDecreasing,e))}getInterpolatedDynamic(e){const t=this.StartMultiExpression.AbsoluteTimestamp;let i;if(i=this.EndMultiExpression?this.EndMultiExpression.AbsoluteTimestamp:u.plus(this.startMultiExpression.SourceMeasureParent.AbsoluteTimestamp,this.startMultiExpression.SourceMeasureParent.Duration),e.lt(t))return-1;if(i.lt(e))return-2;const s=u.minus(e,t).RealValue/u.minus(i,t).RealValue;return Math.max(0,Math.min(99.9,this.startVolume+(this.endVolume-this.startVolume)*s))}isWedge(){return!this.label}setType(){f.isStringInStringList(f.listContinuousDynamicIncreasing,this.label)?this.dynamicType=0:f.isStringInStringList(f.listContinuousDynamicDecreasing,this.label)&&(this.dynamicType=1)}};let m=f;m.listContinuousDynamicIncreasing=["crescendo","cresc","cresc.","cres."],m.listContinuousDynamicDecreasing=["decrescendo","decresc","decr.","diminuendo","dim.","dim"];var p=(e=>(e[e.crescendo=0]="crescendo",e[e.diminuendo=1]="diminuendo",e))(p||{}),g=(e=>(e[e.p=0]="p",e[e.f=1]="f",e[e.s=2]="s",e[e.z=3]="z",e[e.m=4]="m",e[e.r=5]="r",e))(g||{});class S{constructor(e,t){this.message=e,t&&(this.message+=" "+t.toString())}}class y{constructor(e){this.message=e}}class b{constructor(e){this.message=e}}const M=class extends c{constructor(e,t,i,s,n){super(i),super.parentMeasure=n,this.dynamicEnum=P[e.toLowerCase()],this.soundDynamic=t,this.staffNumber=s}static staticConstructor(){M.dynamicToRelativeVolumeDict.setValue(13,1),M.dynamicToRelativeVolumeDict.setValue(12,126/127),M.dynamicToRelativeVolumeDict.setValue(11,125/127),M.dynamicToRelativeVolumeDict.setValue(10,124/127),M.dynamicToRelativeVolumeDict.setValue(9,122/127),M.dynamicToRelativeVolumeDict.setValue(8,108/127),M.dynamicToRelativeVolumeDict.setValue(7,76/127),M.dynamicToRelativeVolumeDict.setValue(14,.5),M.dynamicToRelativeVolumeDict.setValue(16,.5),M.dynamicToRelativeVolumeDict.setValue(17,.5),M.dynamicToRelativeVolumeDict.setValue(18,.5),M.dynamicToRelativeVolumeDict.setValue(19,.5),M.dynamicToRelativeVolumeDict.setValue(20,.5),M.dynamicToRelativeVolumeDict.setValue(21,.5),M.dynamicToRelativeVolumeDict.setValue(22,.5),M.dynamicToRelativeVolumeDict.setValue(23,.5),M.dynamicToRelativeVolumeDict.setValue(6,60/127),M.dynamicToRelativeVolumeDict.setValue(5,28/127),M.dynamicToRelativeVolumeDict.setValue(4,12/127),M.dynamicToRelativeVolumeDict.setValue(3,10/127),M.dynamicToRelativeVolumeDict.setValue(2,7/127),M.dynamicToRelativeVolumeDict.setValue(1,5/127),M.dynamicToRelativeVolumeDict.setValue(0,4/127)}get ParentMultiExpression(){return this.multiExpression}set ParentMultiExpression(e){this.multiExpression=e}get DynEnum(){return this.dynamicEnum}set DynEnum(e){this.dynamicEnum=e}get SoundDynamic(){return this.soundDynamic}set SoundDynamic(e){this.soundDynamic=e}get Placement(){return this.placement}set Placement(e){this.placement=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get Length(){return Math.abs(this.length)<1e-4&&(this.length=this.calculateLength()),this.length}get MidiVolume(){return 127*this.Volume}get Volume(){return M.dynamicToRelativeVolumeDict.getValue(this.dynamicEnum)}static isInputStringInstantaneousDynamic(e){return!!e&&M.isStringInStringList(M.listInstantaneousDynamics,e)}getDynamicExpressionSymbol(e){switch(e){case"p":return g.p;case"f":return g.f;case"s":return g.s;case"z":return g.z;case"m":return g.m;case"r":return g.r;default:throw new b("unknown DynamicExpressionSymbolEnum: "+e)}}calculateLength(){return s.debug("[Andrea] instantaneousDynamicExpression: not implemented: calculateLength!"),0}};let v=M;v.dynamicToRelativeVolumeDict=new i,v.listInstantaneousDynamics=["pppppp","ppppp","pppp","ppp","pp","p","ffffff","fffff","ffff","fff","ff","f","mf","mp","sf","sff","sp","spp","fp","rf","rfz","sfz","sffz","fz"];var P=(e=>(e[e.pppppp=0]="pppppp",e[e.ppppp=1]="ppppp",e[e.pppp=2]="pppp",e[e.ppp=3]="ppp",e[e.pp=4]="pp",e[e.p=5]="p",e[e.mp=6]="mp",e[e.mf=7]="mf",e[e.f=8]="f",e[e.ff=9]="ff",e[e.fff=10]="fff",e[e.ffff=11]="ffff",e[e.fffff=12]="fffff",e[e.ffffff=13]="ffffff",e[e.sf=14]="sf",e[e.sff=15]="sff",e[e.sfp=16]="sfp",e[e.sfpp=17]="sfpp",e[e.fp=18]="fp",e[e.rf=19]="rf",e[e.rfz=20]="rfz",e[e.sfz=21]="sfz",e[e.sffz=22]="sffz",e[e.fz=23]="fz",e[e.other=24]="other",e))(P||{});v.staticConstructor();class E{constructor(e,t){e instanceof m?this.continuousDynamicExpression=e:e instanceof v&&(this.instantaneousDynamicExpression=e),this.staffNumber=t}static Compare(e,t){return e.parMultiExpression().AbsoluteTimestamp.CompareTo(t.parMultiExpression().AbsoluteTimestamp)}parMultiExpression(){return this.continuousDynamicExpression?this.continuousDynamicExpression.StartMultiExpression:this.instantaneousDynamicExpression?this.instantaneousDynamicExpression.ParentMultiExpression:void 0}}class L{constructor(e){this.printObject=!0,this.parent=e}get Parent(){return this.parent}set Parent(e){this.parent=e}get PrintObject(){return this.printObject}set PrintObject(e){this.printObject=e}}class x extends L{constructor(e,t){super(void 0),this.rhythm=e,this.numerator=e.Numerator,this.denominator=e.Denominator,this.symbolEnum=t}get Rhythm(){return this.rhythm}set Rhythm(e){this.rhythm=e}get SymbolEnum(){return this.symbolEnum}set SymbolEnum(e){this.symbolEnum=e}clone(){return new x(this.rhythm.clone(),this.symbolEnum)}OperatorEquals(e){const t=this;return t===e||!(!t||!e)&&t.numerator===e.numerator&&t.denominator===e.denominator}OperatorNotEqual(e){return!(this===e)}ToString(){return"Rhythm: "+this.rhythm.toString()}}var T=(e=>(e[e.NONE=0]="NONE",e[e.COMMON=1]="COMMON",e[e.CUT=2]="CUT",e))(T||{});class w{constructor(e,t,i){this.currentMeasureIndex=0,this.currentPartIndex=0,this.currentVoiceEntryIndex=-1,this.currentDynamicEntryIndex=0,this.currentTempoEntryIndex=0,this.currentDynamicChangingExpressions=[],this.repetitionIterationCountDictKeys=[],this.repetitionIterationCountDictValues=[],this.currentRepetition=void 0,this.endReached=!1,this.frontReached=!1,this.currentTimeStamp=new u(0,1),this.currentEnrolledMeasureTimestamp=new u(0,1),this.currentRelativeInMeasureTimestamp=new u(0,1),this.currentVerticalContainerInMeasureTimestamp=new u(0,1),this.jumpResponsibleRepetition=void 0,this.activeDynamicExpressions=[],this.maxRepeatNum=1,this.dcResetDone=!1,this.SkipInvisibleNotes=!0,this.testNoteIdx=0;try{this.frontReached=!0,this.musicSheet=e,this.currentBpm=e.userStartTempoInBPM,this.currentVoiceEntries=void 0,this.frontReached=!1;for(const e of this.musicSheet.Repetitions)this.setRepetitionIterationCount(e,1);for(let t=0;t<e.getCompleteNumberOfStaves();t++)this.ActiveDynamicExpressions.push(void 0);this.currentMeasure=this.musicSheet.SourceMeasures[0],t||(t=new u);do{this.moveToNext()}while((!this.currentVoiceEntries||this.currentTimeStamp.lt(t))&&!this.endReached);for(let e=0;e<this.activeDynamicExpressions.length;e++)if(this.activeDynamicExpressions[e])if(this.activeDynamicExpressions[e]instanceof m){const t=this.activeDynamicExpressions[e];this.currentDynamicChangingExpressions.push(new E(t,e))}else{const t=this.activeDynamicExpressions[e];this.currentDynamicChangingExpressions.push(new E(t,e))}this.currentTempoChangingExpression=this.activeTempoExpression}catch(n){s.info("MusicPartManagerIterator: "+n)}}get EndReached(){return this.endReached}get FrontReached(){return this.frontReached}get CurrentMeasure(){return this.currentMeasure}get CurrentRepetition(){return this.currentRepetition}get CurrentRepetitionIteration(){return this.CurrentRepetition?this.getRepetitionIterationCount(this.CurrentRepetition):0}get CurrentJumpResponsibleRepetitionIterationBeforeJump(){return this.jumpResponsibleRepetition?this.getRepetitionIterationCount(this.jumpResponsibleRepetition)-1:0}get CurrentBpm(){return this.currentBpm}get CurrentVoiceEntries(){return this.currentVoiceEntries}get CurrentMeasureIndex(){return this.currentMeasureIndex}get CurrentEnrolledTimestamp(){return u.plus(this.currentEnrolledMeasureTimestamp,this.currentVerticalContainerInMeasureTimestamp)}get CurrentSourceTimestamp(){return this.currentTimeStamp}get CurrentRelativeInMeasureTimestamp(){return this.currentRelativeInMeasureTimestamp}get JumpOccurred(){return this.backJumpOccurred||this.forwardJumpOccurred}get ActiveTempoExpression(){return this.activeTempoExpression}get ActiveDynamicExpressions(){return this.activeDynamicExpressions}get CurrentTempoChangingExpression(){return this.currentTempoChangingExpression}get JumpResponsibleRepetition(){return this.jumpResponsibleRepetition}clone(e=void 0,t=void 0){const i=new w(this.musicSheet,null!=e?e:this.currentTimeStamp,t);return i.currentVoiceEntryIndex=this.currentVoiceEntryIndex,i.currentMappingPart=this.currentMappingPart,i.currentPartIndex=this.currentPartIndex,i.currentVoiceEntries=this.currentVoiceEntries,i.endReached=this.endReached,i.frontReached=this.frontReached,i}CurrentVisibleVoiceEntries(e){const t=[];if(!this.currentVoiceEntries)return t;if(e){for(const i of this.currentVoiceEntries)if(i.ParentVoice.Parent.IdString===e.IdString)return this.getVisibleEntries(i,t),t}else for(const i of this.currentVoiceEntries)this.getVisibleEntries(i,t);return t}CurrentAudibleVoiceEntries(e){const t=[];if(this.currentVoiceEntries)if(e){for(const i of this.currentVoiceEntries)if(i.ParentVoice.Parent.IdString===e.IdString)return this.getAudibleEntries(i,t),t}else for(const i of this.currentVoiceEntries)this.getAudibleEntries(i,t);return t}getCurrentDynamicChangingExpressions(){return this.currentDynamicChangingExpressions}CurrentScoreFollowingVoiceEntries(e){const t=[];if(!this.currentVoiceEntries)return t;if(e){for(const i of this.currentVoiceEntries)if(i.ParentVoice.Parent.IdString===e.IdString)return this.getScoreFollowingEntries(i,t),t}else for(const i of this.currentVoiceEntries)this.getScoreFollowingEntries(i,t);return t}currentPlaybackSettings(){return this.musicSheet.SheetPlaybackSetting}moveToPrevious(){this.frontReached||(this.currentVoiceEntries&&(this.currentVoiceEntries=[]),this.recursiveMoveBack())}moveToPreviousVisibleVoiceEntry(e){for(;!this.frontReached;)if(this.moveToPrevious(),this.checkEntries(e))return}moveToNext(){this.forwardJumpOccurred=this.backJumpOccurred=!1,this.endReached||(this.frontReached&&(this.frontReached=!1,this.currentVoiceEntryIndex=-1),this.currentVoiceEntries&&(this.currentVoiceEntries.length=0),this.recursiveMove(),this.currentMeasure||(this.currentTimeStamp=new u(99999,1),this.currentMeasure=this.musicSheet.SourceMeasures.last()),void 0!==this.CurrentTempoChangingExpression&&(void 0!==this.CurrentTempoChangingExpression.ContinuousTempo?this.currentBpm=this.CurrentTempoChangingExpression.ContinuousTempo.getInterpolatedTempo(this.CurrentSourceTimestamp):this.currentBpm=this.CurrentTempoChangingExpression.InstantaneousTempo.TempoInBpm))}moveToNextVisibleVoiceEntry(e){for(;!this.endReached;)if(this.moveToNext(),this.checkEntries(e))return}resetRepetitionIterationCount(e){if(this.maxRepeatNum<50){try{this.setRepetitionIterationCount(e,1),this.maxRepeatNum+=1}catch(t){throw new Error("循环规则,解析报错")}return 1}throw new Error("循环规则,解析报错")}incrementRepetitionIterationCount(e){return-1===this.repetitionIterationCountDictKeys.indexOf(e)?this.setRepetitionIterationCount(e,1):this.setRepetitionIterationCount(e,this.getRepetitionIterationCount(e)+1)}setRepetitionIterationCount(e,t){const i=this.repetitionIterationCountDictKeys.indexOf(e);return-1===i?(this.repetitionIterationCountDictKeys.push(e),this.repetitionIterationCountDictValues.push(t)):this.repetitionIterationCountDictValues[i]=t,t}getRepetitionIterationCount(e){const t=this.repetitionIterationCountDictKeys.indexOf(e);if(-1!==t)return this.repetitionIterationCountDictValues[t]}handleRepetitionsAtMeasureBegin(){for(let o=0,a=this.currentMeasure.FirstRepetitionInstructions.length;o<a;++o){const e=this.currentMeasure.FirstRepetitionInstructions[o];if(!e.parentRepetition)continue;const t=e.parentRepetition;this.currentRepetition=t,t.StartIndex===this.currentMeasureIndex&&void 0!==this.JumpResponsibleRepetition&&t!==this.JumpResponsibleRepetition&&t.StartIndex>=this.JumpResponsibleRepetition.StartIndex&&t.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&this.resetRepetitionIterationCount(t)}for(let o=0,a=this.repetitionIterationCountDictKeys.length;o<a;++o){const a=this.repetitionIterationCountDictKeys[o];var e,t,i,s,n,r;a&&void 0!==this.JumpResponsibleRepetition&&a!==this.JumpResponsibleRepetition&&a.StartIndex>=this.JumpResponsibleRepetition.StartIndex&&a.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&(4!==(null===(e=this.JumpResponsibleRepetition)||void 0===e||null===(t=e.BackwardJumpInstructions)||void 0===t||null===(i=t[0])||void 0===i?void 0:i.type)&&5!==(null===(s=this.JumpResponsibleRepetition)||void 0===s||null===(n=s.BackwardJumpInstructions)||void 0===n||null===(r=n[0])||void 0===r?void 0:r.type)||this.dcResetDone||(this.resetRepetitionIterationCount(a),this.dcResetDone=!0))}}handleRepetitionsAtMeasureEnd(){for(let s=0,n=this.currentMeasure.LastRepetitionInstructions.length;s<n;++s){const n=this.currentMeasure.LastRepetitionInstructions[s],r=n.parentRepetition;if(r){if(r.BackwardJumpInstructions.indexOf(n)>-1&&this.getRepetitionIterationCount(r)<r.UserNumberOfRepetitions)return void this.doBackJump(r);var e,t,i;if(n===r.forwardJumpInstruction&&(void 0!==this.JumpResponsibleRepetition&&r!==this.JumpResponsibleRepetition&&r.StartIndex>=this.JumpResponsibleRepetition.StartIndex&&r.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&4===(null===(e=this.JumpResponsibleRepetition)||void 0===e||null===(t=e.BackwardJumpInstructions)||void 0===t||null===(i=t[0])||void 0===i?void 0:i.type)&&this.resetRepetitionIterationCount(r),this.repetitionIterationCountDictKeys.contains(r))){const e=r.getForwardJumpTargetForIteration(this.getRepetitionIterationCount(r));if(e>=0)return this.currentMeasureIndex=e,this.currentMeasure=this.musicSheet.SourceMeasures[this.currentMeasureIndex],this.currentVoiceEntryIndex=-1,this.jumpResponsibleRepetition=r,void(this.forwardJumpOccurred=!0);-2===e&&(this.endReached=!0)}}}this.currentMeasureIndex++,void 0!==this.JumpResponsibleRepetition&&this.currentMeasureIndex>this.JumpResponsibleRepetition.EndIndex&&(this.jumpResponsibleRepetition=void 0)}doBackJump(e){this.currentMeasureIndex=e.getBackwardJumpTarget(),this.currentMeasure=this.musicSheet.SourceMeasures[this.currentMeasureIndex],this.currentVoiceEntryIndex=-1,this.incrementRepetitionIterationCount(e),this.jumpResponsibleRepetition=e,this.backJumpOccurred=!0}activateCurrentRhythmInstructions(){if(void 0!==this.currentMeasure&&this.currentMeasure.FirstInstructionsStaffEntries.length>0&&void 0!==this.currentMeasure.FirstInstructionsStaffEntries[0]){const e=this.currentMeasure.FirstInstructionsStaffEntries[0].Instructions;for(let t=0,i=e.length;t<i;++t){const i=e[t];i instanceof x&&(this.musicSheet.SheetPlaybackSetting.rhythm=i.Rhythm)}}}activateCurrentDynamicOrTempoInstructions(){const e=this.musicSheet.TimestampSortedDynamicExpressionsList;for(;this.currentDynamicEntryIndex>0&&(this.currentDynamicEntryIndex>=e.length||e[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.gte(this.CurrentSourceTimestamp));)this.currentDynamicEntryIndex--;for(;this.currentDynamicEntryIndex<e.length&&e[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.lt(this.CurrentSourceTimestamp);)this.currentDynamicEntryIndex++;for(;this.currentDynamicEntryIndex<e.length&&e[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.Equals(this.CurrentSourceTimestamp);){const t=e[this.currentDynamicEntryIndex],i=t.staffNumber;this.CurrentSourceTimestamp.Equals(t.parMultiExpression().AbsoluteTimestamp)&&(t.continuousDynamicExpression?this.activeDynamicExpressions[i]=t.continuousDynamicExpression:t.instantaneousDynamicExpression&&(this.activeDynamicExpressions[i]=t.instantaneousDynamicExpression)),this.currentDynamicEntryIndex++}this.currentDynamicChangingExpressions.length=0;for(let i=0;i<this.activeDynamicExpressions.length;i++)if(this.activeDynamicExpressions[i]){let e,t;if(this.activeDynamicExpressions[i]instanceof m){const s=this.activeDynamicExpressions[i];e=s.StartMultiExpression.AbsoluteTimestamp,t=s.EndMultiExpression.AbsoluteTimestamp,this.CurrentSourceTimestamp.gte(e)&&this.CurrentSourceTimestamp.lte(t)&&this.currentDynamicChangingExpressions.push(new E(s,i))}else{const e=this.activeDynamicExpressions[i];this.CurrentSourceTimestamp.Equals(e.ParentMultiExpression.AbsoluteTimestamp)&&this.currentDynamicChangingExpressions.push(new E(e,i))}}const t=this.musicSheet.TimestampSortedTempoExpressionsList;for(;this.currentTempoEntryIndex>0&&(this.currentTempoEntryIndex>=t.length||t[this.currentTempoEntryIndex].AbsoluteTimestamp.gte(this.CurrentSourceTimestamp));)this.currentTempoEntryIndex--;for(;this.currentTempoEntryIndex<t.length&&t[this.currentTempoEntryIndex].AbsoluteTimestamp.lt(this.CurrentSourceTimestamp);)this.currentTempoEntryIndex++;for(;this.currentTempoEntryIndex<t.length&&t[this.currentTempoEntryIndex].AbsoluteTimestamp.Equals(this.CurrentSourceTimestamp);)this.activeTempoExpression=t[this.currentTempoEntryIndex],this.currentTempoEntryIndex++;if(this.currentTempoChangingExpression=void 0,this.activeTempoExpression){let e=this.activeTempoExpression.AbsoluteTimestamp;this.activeTempoExpression.ContinuousTempo&&(e=this.activeTempoExpression.ContinuousTempo.AbsoluteEndTimestamp),(this.CurrentSourceTimestamp.gte(this.activeTempoExpression.AbsoluteTimestamp)||this.CurrentSourceTimestamp.lte(e))&&(this.currentTempoChangingExpression=this.activeTempoExpression)}}recursiveMoveBack(){if(this.currentVoiceEntryIndex>0){this.currentVoiceEntryIndex--;const e=this.currentMeasure.VerticalSourceStaffEntryContainers[this.currentVoiceEntryIndex];this.currentVoiceEntries=this.getVoiceEntries(e),this.currentVerticalContainerInMeasureTimestamp=e.Timestamp,this.currentRelativeInMeasureTimestamp=this.currentVerticalContainerInMeasureTimestamp,this.currentTimeStamp=u.plus(this.currentMeasure.AbsoluteTimestamp,this.currentVerticalContainerInMeasureTimestamp),this.activateCurrentDynamicOrTempoInstructions();const t=this.musicSheet.SelectionEnd;return t&&this.currentTimeStamp.lt(t)&&(this.endReached=!1),void(this.currentMeasureIndex=this.musicSheet.SourceMeasures.indexOf(this.CurrentMeasure))}if(0!==this.currentVoiceEntryIndex||0===this.currentMeasureIndex)this.frontReached=!0,this.currentTimeStamp=new u(-1,1);else{const e=this.musicSheet.SourceMeasures[this.currentMeasureIndex-1];this.currentMeasureIndex--,this.currentMeasure=this.musicSheet.SourceMeasures[this.currentMeasureIndex];const t=e.VerticalSourceStaffEntryContainers[e.VerticalSourceStaffEntryContainers.length-1];this.currentVoiceEntries=this.getVoiceEntries(t),this.currentVerticalContainerInMeasureTimestamp=t.Timestamp,this.currentVoiceEntryIndex=e.VerticalSourceStaffEntryContainers.length-1,this.currentTimeStamp=u.plus(this.currentMeasure.AbsoluteTimestamp,t.Timestamp),this.activateCurrentDynamicOrTempoInstructions();const i=this.musicSheet.SelectionEnd;i&&this.currentTimeStamp.lt(i)&&(this.endReached=!1)}}recursiveMove(){if(this.currentVoiceEntryIndex++,0===this.currentVoiceEntryIndex&&(this.handleRepetitionsAtMeasureBegin(),this.activateCurrentRhythmInstructions()),this.currentVoiceEntryIndex>=0&&this.currentVoiceEntryIndex<this.currentMeasure.VerticalSourceStaffEntryContainers.length){var e,t,i,s;const n=this.currentMeasure.VerticalSourceStaffEntryContainers[this.currentVoiceEntryIndex];this.currentVoiceEntries=this.getVoiceEntries(n),this.currentVerticalContainerInMeasureTimestamp=n.Timestamp,I.noteGraphicalId=(null===(e=this.currentVoiceEntries)||void 0===e||null===(t=e[0])||void 0===t||null===(i=t.notes)||void 0===i||null===(s=i[0])||void 0===s?void 0:s.NoteToGraphicalNoteObjectId)||0,this.currentRelativeInMeasureTimestamp=this.currentVerticalContainerInMeasureTimestamp,this.currentTimeStamp=u.plus(this.currentMeasure.AbsoluteTimestamp,this.currentVerticalContainerInMeasureTimestamp);const r=this.musicSheet.SelectionEnd;return r&&this.currentTimeStamp.gte(r)&&(this.endReached=!0),void this.activateCurrentDynamicOrTempoInstructions()}if(this.currentEnrolledMeasureTimestamp.Add(this.currentMeasure.Duration),this.handleRepetitionsAtMeasureEnd(),this.currentMeasureIndex>=0&&this.currentMeasureIndex<this.musicSheet.SourceMeasures.length)return this.currentMeasure=this.musicSheet.SourceMeasures[this.currentMeasureIndex],this.currentTimeStamp=u.plus(this.currentMeasure.AbsoluteTimestamp,this.currentVerticalContainerInMeasureTimestamp),this.currentVoiceEntryIndex=-1,void this.recursiveMove();this.currentVerticalContainerInMeasureTimestamp=new u,this.currentMeasure=void 0,this.currentVoiceEntries=void 0,this.endReached=!0}checkEntries(e){const t=this.CurrentVisibleVoiceEntries();if(t.length>0){if(!e)return!0;for(let e=0,i=t.length;e<i;++e)if(t[e].Notes[0].Pitch)return!0}return!1}getVisibleEntries(e,t){if(e.ParentVoice.Visible){let i=!1;for(const t of e.Notes){i=!0;break}if(!i&&this.SkipInvisibleNotes)return;t.push(e)}}getAudibleEntries(e,t){if(e.hasTie()){const t=e.Notes[0];if(void 0!==t.NoteTie&&t.NoteTie.StartNote!==t)return}e.ParentVoice.Audible&&t.push(e)}getScoreFollowingEntries(e,t){e.ParentVoice.Following&&e.ParentVoice.Parent.Following&&t.push(e)}getVoiceEntries(e){const t=[];for(const n of e.StaffEntries){var i,s;null!=n&&null!==(i=n.ParentStaff)&&void 0!==i&&null!==(s=i.ParentInstrument)&&void 0!==s&&s.Visible&&n.VoiceEntries[0]&&t.push(...n.VoiceEntries)}return t}}class I{constructor(e,t,i){this.hidden=!1,this.currentPageNumber=1,this.skipInvisibleNotes=!0,this.ScrollPosition="center",this.noteGraphicalId=0,this.activeMeasureNum=0,this.container=e,this.openSheetMusicDisplay=t,this.rules=this.openSheetMusicDisplay.EngravingRules,this.cursorOptions=i;let s=0;for(this.cursorElementId="cursorImg-0";document.getElementById(this.cursorElementId);)s++,this.cursorElementId=`cursorImg-${s}`;this.noteGraphicalId=0;const n=document.createElement("img");n.id=this.cursorElementId,n.style.position="absolute",!0===this.cursorOptions.follow?(this.wantedZIndex="-1",n.style.zIndex=this.wantedZIndex):(this.wantedZIndex="-2",n.style.zIndex=this.wantedZIndex),this.cursorElement=n,this.container.appendChild(n)}cursorPositionChanged(e,t){for(;this.iterator.currentTimeStamp.lt(e)&&!this.iterator.EndReached;)this.iterator.moveToNext();this.iterator.CurrentEnrolledTimestamp.gt(e)&&(this.iterator=new w(this.manager.MusicSheet,e)),this.updateWithTimestamp(t.PredictedPosition)}pauseOccurred(e){}selectionEndReached(e){}resetOccurred(e){this.reset()}notesPlaybackEventOccurred(e){}adjustToBackgroundColor(){let e;e=this.rules.PageBackgroundColor?"1":this.wantedZIndex,this.cursorElement.style.zIndex=e}init(e,t){this.manager=e,this.graphic=t,this.reset(),this.hidden=!1}show(){this.hidden=!1,this.update(),this.adjustToBackgroundColor()}resetIterator(){if(!this.openSheetMusicDisplay.Sheet||!this.openSheetMusicDisplay.Sheet.SourceMeasures)return;const e=this.openSheetMusicDisplay.Sheet.SourceMeasures.length-1;let t=this.rules.MinMeasureToDrawIndex;t=Math.min(t,e);let i=this.rules.MaxMeasureToDrawIndex;if(i=Math.min(i,e),this.openSheetMusicDisplay.Sheet&&(!this.openSheetMusicDisplay.Sheet.SelectionStart||this.openSheetMusicDisplay.Sheet.SelectionStart.WholeValue<t)&&this.openSheetMusicDisplay.Sheet.SourceMeasures.length,this.openSheetMusicDisplay.Sheet.SelectionStart=this.openSheetMusicDisplay.Sheet.SourceMeasures[t].AbsoluteTimestamp,this.openSheetMusicDisplay.Sheet&&this.openSheetMusicDisplay.Sheet.SourceMeasures.length>i){const e=this.openSheetMusicDisplay.Sheet.SourceMeasures[i];this.openSheetMusicDisplay.Sheet.SelectionEnd=u.plus(e.AbsoluteTimestamp,e.Duration)}this.iterator=this.manager.getIterator(),this.iterator.SkipInvisibleNotes=this.skipInvisibleNotes}getStaffEntryFromVoiceEntry(e){const t=e.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.measureListIndex,i=e.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;return this.graphic.findGraphicalStaffEntryFromMeasureList(i,t,e.ParentSourceStaffEntry)}updateWithTimestamp(e){const t=this.manager.absoluteEnrolledToSheetTimestamp(e),i=this.graphic.calculateXPositionFromTimestamp(t),s=i[0],n=i[1];this.updateCurrentPageFromSystem(n);const r=i[2];if(!r)return;const o=Math.max(r.parentMeasure.MeasureNumber,1);let a;for(const c of this.graphic.MeasureList[o-1])if(c){a=c;break}const l=this.graphic.calculateCursorPoints(s,n),h=l[0].y,u=l[1].y-h;if(a){if(this.updateWidthAndStyle(a.PositionAndShape,s,h,u),this.openSheetMusicDisplay.FollowCursor){const e=this.cursorElement.getBoundingClientRect().top;this.cursorElement.scrollIntoView({behavior:e<1e3?"smooth":"auto",block:this.ScrollPosition})}this.cursorElement.style.display=""}}update(){var e;if(this.hidden||void 0===this.hidden||null===this.hidden)return;this.updateCurrentPage();const t=this.Iterator;let i,s=t.CurrentVisibleVoiceEntries(),n=t.CurrentMeasureIndex,r=0,o=0,a=0;if(0!==s.length||t.FrontReached||t.EndReached||(t.moveToPrevious(),s=t.CurrentVisibleVoiceEntries(),t.moveToNext()),t.FrontReached&&0===s.length){t.moveToNext(),s=t.CurrentVisibleVoiceEntries();const e=this.findVisibleGraphicalMeasure(t.CurrentMeasureIndex);r=e.PositionAndShape.AbsolutePosition.x,i=e.ParentMusicSystem,t.moveToPrevious()}else if(t.EndReached||!t.CurrentVoiceEntries||0===s.length){t.moveToPrevious(),s=t.CurrentVisibleVoiceEntries(),n=t.CurrentMeasureIndex;const e=this.findVisibleGraphicalMeasure(t.CurrentMeasureIndex);r=e.PositionAndShape.AbsolutePosition.x+e.PositionAndShape.Size.width,i=e.ParentMusicSystem,t.moveToNext()}else if(t.CurrentMeasure.isReducedToMultiRest){const e=this.findVisibleGraphicalMeasure(t.CurrentMeasureIndex),s=e.parentSourceMeasure.multipleRestMeasures,n=t.CurrentMeasure.multipleRestMeasureNumber/(s+1),o=e.PositionAndShape.Size.width-e.beginInstructionsWidth;r=e.PositionAndShape.AbsolutePosition.x+e.beginInstructionsWidth+n*o,i=e.ParentMusicSystem}else{const e=s.map((e=>this.getStaffEntryFromVoiceEntry(e)));let t=e.sort(((e,t)=>{var i,s,n,r;return(null==e||null===(i=e.PositionAndShape)||void 0===i||null===(s=i.AbsolutePosition)||void 0===s?void 0:s.x)<=(null==t||null===(n=t.PositionAndShape)||void 0===n||null===(r=n.AbsolutePosition)||void 0===r?void 0:r.x)?-1:1}))[0];window.DYFirstTrackName&&(t=e.find((e=>e.sourceStaffEntry.ParentStaff.ParentInstrument.Name===window.DYFirstTrackName))),t&&(r=t.PositionAndShape.AbsolutePosition.x,i=t.parentMeasure.ParentMusicSystem)}if(null===(e=i)||void 0===e||!e.StaffLines[0])return;o=i.PositionAndShape.AbsolutePosition.y+i.StaffLines[0].PositionAndShape.RelativePosition.y;let l=i.PositionAndShape.AbsolutePosition.y;const h=i.StaffLines[i.StaffLines.length-1];h&&(l+=h.PositionAndShape.RelativePosition.y+h.StaffHeight),a=l-o;const u=this.findVisibleGraphicalMeasure(n);if(!u)return;const c=u.PositionAndShape;if(!this.activeMeasureNum||u.MeasureNumber===this.activeMeasureNum){if(this.updateWidthAndStyle(c,r,o,a),this.openSheetMusicDisplay.FollowCursor&&this.cursorOptions.follow)if(this.openSheetMusicDisplay.EngravingRules.RenderSingleHorizontalStaffline)this.cursorElement.scrollIntoView({behavior:"smooth",inline:"center"});else{const e=this.cursorElement.getBoundingClientRect().top;this.cursorElement.scrollIntoView({behavior:e<1e3?"smooth":"auto",block:"center"})}this.cursorElement.style.display=""}}findVisibleGraphicalMeasure(e){for(let t=0;t<this.graphic.NumberOfStaves;t++){const e=this.graphic.findGraphicalMeasure(this.iterator.CurrentMeasureIndex,t);if(null!=e&&e.ParentStaff.ParentInstrument.Visible)return e}}updateWidthAndStyle(e,t,i,s){var n;const r=this.cursorElement;let o=0,a=s;switch(this.cursorOptions.type){case 1:r.style.top=10*i*this.openSheetMusicDisplay.zoom+"px",r.style.left=10*(t-1.5)*this.openSheetMusicDisplay.zoom+"px",a=10*s*this.openSheetMusicDisplay.zoom,r.height=a,r.style.height=a+"px",o=5*this.openSheetMusicDisplay.zoom;break;case 2:r.style.top=10*(i-2.5)*this.openSheetMusicDisplay.zoom+"px",r.style.left=10*t*this.openSheetMusicDisplay.zoom+"px",a=15*this.openSheetMusicDisplay.zoom,r.height=a,r.style.height=a+"px",o=5*this.openSheetMusicDisplay.zoom;break;case 3:r.style.top=10*e.AbsolutePosition.y*this.openSheetMusicDisplay.zoom+"px",r.style.left=10*e.AbsolutePosition.x*this.openSheetMusicDisplay.zoom+"px",a=10*s*this.openSheetMusicDisplay.zoom,r.height=a,r.style.height=a+"px",o=10*e.Size.width*this.openSheetMusicDisplay.zoom;break;case 4:r.style.top=10*e.AbsolutePosition.y*this.openSheetMusicDisplay.zoom+"px",r.style.left=10*e.AbsolutePosition.x*this.openSheetMusicDisplay.zoom+"px",a=10*s*this.openSheetMusicDisplay.zoom,r.height=a,r.style.height=a+"px",o=10*(t-e.AbsolutePosition.x)*this.openSheetMusicDisplay.zoom;break;default:r.style.top=10*i*this.openSheetMusicDisplay.zoom+"px",r.style.left=10*(t-1.5)*this.openSheetMusicDisplay.zoom+"px",a=10*s*this.openSheetMusicDisplay.zoom,r.height=a,r.style.height=a+"px",o=30*this.openSheetMusicDisplay.zoom}null!==(n=window.GYM)&&void 0!==n&&n.multitrack&&(r.height=a+24,r.style.height=a+24+"px"),r.width=o,this.cursorOptionsRendered!==this.cursorOptions&&this.updateStyle(o,this.cursorOptions)}hide(){this.cursorElement.style.display="none",this.hidden=!0}previous(){this.iterator.moveToPreviousVisibleVoiceEntry(!1),this.update()}next(){this.Iterator.moveToNextVisibleVoiceEntry(!1),this.update()}reset(){this.resetIterator();const e=this.manager.getIterator(this.graphic.ParentMusicSheet.SelectionStart);this.updateWithTimestamp(e.CurrentEnrolledTimestamp)}updateStyle(e,t=void 0){void 0!==t&&(this.cursorOptions=t);const i=document.createElement("canvas");i.width=this.cursorElement.width,i.height=1;const s=i.getContext("2d");s.globalAlpha=this.cursorOptions.alpha;const n=s.createLinearGradient(0,0,this.cursorElement.width,0);switch(this.cursorOptions.type){case 1:case 2:case 3:case 4:n.addColorStop(1,this.cursorOptions.color);break;default:n.addColorStop(0,"white"),n.addColorStop(.2,this.cursorOptions.color),n.addColorStop(.8,this.cursorOptions.color),n.addColorStop(1,"white")}s.fillStyle=n,s.fillRect(0,0,e,1),this.cursorOptionsRendered={...this.cursorOptions},this.cursorElement.src=i.toDataURL("image/png")}get Iterator(){return this.iterator}get Hidden(){return this.hidden}VoicesUnderCursor(e){return this.Iterator.CurrentVisibleVoiceEntries(e)}NotesUnderCursor(e){const t=this.VoicesUnderCursor(e),i=[];return t.forEach((e=>{i.push.apply(i,e.Notes)})),i}GNotesUnderCursor(e){const t=this.VoicesUnderCursor(e),i=[];return t.forEach((e=>{i.push(...e.Notes.map((e=>this.rules.GNote(e))))})),i}updateCurrentPage(){let e=this.iterator.currentTimeStamp;e.RealValue<0&&(e=new u(0,0));for(const t of this.graphic.MusicPages)if(t.MusicSystems.last().GetSystemsLastTimeStamp().gt(e)){const e=t.PageNumber;return e!==this.currentPageNumber&&(this.container.removeChild(this.cursorElement),this.container=document.getElementById(this.rules.DYContainerId+e),this.container.appendChild(this.cursorElement)),this.currentPageNumber=e}return 1}get SkipInvisibleNotes(){return this.skipInvisibleNotes}set SkipInvisibleNotes(e){this.skipInvisibleNotes=e,this.iterator.SkipInvisibleNotes=e}get CursorOptions(){return this.cursorOptions}set CursorOptions(e){this.cursorOptions=e}updateCurrentPageFromSystem(e){if(null!=e&&e.Parent){const t=e.Parent.PageNumber;return t!==this.currentPageNumber&&(this.container.removeChild(this.cursorElement),this.container=document.getElementById(this.rules.DYContainerId+t),this.container.appendChild(this.cursorElement)),this.currentPageNumber=t}return 1}Dispose(){this.hide(),this.container.removeChild(this.cursorElement),this.rules=void 0,this.openSheetMusicDisplay=void 0,this.cursorOptions=void 0}}var A=(e=>(e.allon="allon",e.compact="compact",e.compacttight="compacttight",e.default="default",e.leadsheet="leadsheet",e.preview="preview",e.thumbnail="thumbnail",e))(A||{}),R=(e=>(e[e.Standard=0]="Standard",e[e.ThinLeft=1]="ThinLeft",e[e.ShortThinTopLeft=2]="ShortThinTopLeft",e[e.CurrentArea=3]="CurrentArea",e[e.CurrentAreaLeft=4]="CurrentAreaLeft",e))(R||{}),N=(e=>(e[e.Never=0]="Never",e[e.Always=1]="Always",e[e.Auto=2]="Auto",e))(N||{}),C=(e=>(e[e.No=0]="No",e[e.YesVisible=1]="YesVisible",e[e.YesInvisible=2]="YesInvisible",e))(C||{}),B=(e=>(e[e.SVG=0]="SVG",e[e.Canvas=1]="Canvas",e))(B||{}),D=(e=>(e[e.Plain=0]="Plain",e[e.WebGL=1]="WebGL",e))(D||{});class V{static OSMDOptionsStandard(){return{autoResize:!0,backend:"svg",drawingParameters:A.default}}static BackendTypeFromString(e){return e&&"canvas"===e.toLowerCase()?1:0}}class k{constructor(e){if(this.hasAttributes=!1,!e)throw new Error("IXmlElement: expected Element, got undefined");this.elem=e,this.name=e.nodeName.toLowerCase(),e.hasAttributes()&&(this.hasAttributes=!0,this.firstAttribute=e.attributes[0]),this.hasElements=e.hasChildNodes(),1===e.childNodes.length&&e.childNodes[0].nodeType===Node.TEXT_NODE?this.value=e.childNodes[0].nodeValue:this.value=""}attribute(e){return this.elem.attributes.getNamedItem(e)}attributes(){if(!this.attrs){const e=this.elem.attributes,t=[];for(let i=0;i<e.length;i+=1)t.push(e[i]);this.attrs=t}return this.attrs}element(e){const t=this.elem.childNodes;for(let i=0,s=t.length;i<s;i+=1){const s=t[i];if(s.nodeType===Node.ELEMENT_NODE&&s.nodeName.toLowerCase()===e)return new k(s)}}elements(e){const t=this.elem.childNodes,i=[],s=!e;s||(e=e.toLowerCase());for(let n=0;n<t.length;n+=1){const r=t[n];r.nodeType!==Node.ELEMENT_NODE||!s&&r.nodeName.toLowerCase()!==e||i.push(new k(r))}return i}combinedElement(e){const t=this.elem.childNodes;if(t.length>0){let i;for(let s=0,n=t.length;s<n;s+=1){const n=t[s];if(n.nodeType===Node.ELEMENT_NODE&&n.nodeName.toLowerCase()===e)if(i){const e=n.childNodes;for(let t=0,s=e.length;t<s;t+=1){const s=e[t];i.appendChild(s.cloneNode(!0))}}else i=n}if(i)return new k(i)}}}class F{constructor(e,t){this.staffEntries=[],this.absoluteTimestamp=t,this.staffEntries=new Array(e)}get Index(){return this.index}set Index(e){this.index=e}get AbsoluteTimestamp(){return this.absoluteTimestamp}get StaffEntries(){return this.staffEntries}set StaffEntries(e){this.staffEntries=e}static compareByTimestamp(e,t){const i=e.absoluteTimestamp.RealValue,s=t.absoluteTimestamp.RealValue;return i<s?-1:i>s?1:0}getFirstNonNullStaffEntry(){for(let e=0,t=this.staffEntries.length;e<t;++e){const t=this.staffEntries[e];if(t)return t}}}var O=(e=>(e[e.BaseWritingColor=0]="BaseWritingColor",e[e.FollowingCursor=1]="FollowingCursor",e[e.AlternativeFollowingCursor=2]="AlternativeFollowingCursor",e[e.PlaybackCursor=3]="PlaybackCursor",e[e.Highlighted=4]="Highlighted",e[e.ErrorUnderlay=5]="ErrorUnderlay",e[e.Selected=6]="Selected",e[e.SelectionSymbol=7]="SelectionSymbol",e[e.DebugColor1=8]="DebugColor1",e[e.DebugColor2=9]="DebugColor2",e[e.DebugColor3=10]="DebugColor3",e[e.SplitScreenDivision=11]="SplitScreenDivision",e[e.GreyTransparentOverlay=12]="GreyTransparentOverlay",e[e.MarkedArea1=13]="MarkedArea1",e[e.MarkedArea2=14]="MarkedArea2",e[e.MarkedArea3=15]="MarkedArea3",e[e.MarkedArea4=16]="MarkedArea4",e[e.MarkedArea5=17]="MarkedArea5",e[e.MarkedArea6=18]="MarkedArea6",e[e.MarkedArea7=19]="MarkedArea7",e[e.MarkedArea8=20]="MarkedArea8",e[e.MarkedArea9=21]="MarkedArea9",e[e.MarkedArea10=22]="MarkedArea10",e[e.Comment1=23]="Comment1",e[e.Comment2=24]="Comment2",e[e.Comment3=25]="Comment3",e[e.Comment4=26]="Comment4",e[e.Comment5=27]="Comment5",e[e.Comment6=28]="Comment6",e[e.Comment7=29]="Comment7",e[e.Comment8=30]="Comment8",e[e.Comment9=31]="Comment9",e[e.Comment10=32]="Comment10",e))(O||{});const _=new i;_.setValue(0,"Thistle"),_.setValue(1,"Aqua"),_.setValue(2,"Azure"),_.setValue(3,"Bisque"),_.setValue(4,"CadetBlue"),_.setValue(5,"DarkBlue"),_.setValue(6,"DarkGoldenRod"),_.setValue(7,"BlanchedAlmond"),_.setValue(8,"Chartreuse"),_.setValue(9,"DarkGreen"),_.setValue(10,"DarkOrange"),_.setValue(11,"FireBrick"),_.setValue(12,"DarkSalmon"),_.setValue(13,"DarkSeaGreen"),_.setValue(14,"DarkOrchid"),_.setValue(15,"Aquamarine"),_.setValue(16,"DarkKhaki"),_.setValue(17,"ForestGreen"),_.setValue(18,"AliceBlue"),_.setValue(19,"DeepPink"),_.setValue(20,"Coral"),_.setValue(21,"DarkOliveGreen"),_.setValue(22,"Chocolate"),_.setValue(23,"DodgerBlue"),_.setValue(24,"Blue"),_.setValue(25,"Beige"),_.setValue(26,"Crimson"),_.setValue(27,"Fuchsia"),_.setValue(28,"Brown"),_.setValue(29,"BlanchedAlmond"),_.setValue(30,"CornflowerBlue"),_.setValue(31,"Cornsilk"),_.setValue(32,"DarkGrey");var G=(e=>(e[e.Background=0]="Background",e[e.Highlight=1]="Highlight",e[e.MeasureError=2]="MeasureError",e[e.SelectionSymbol=3]="SelectionSymbol",e[e.Cursor=4]="Cursor",e[e.PSI_Debug=5]="PSI_Debug",e[e.Notes=6]="Notes",e[e.Comment=7]="Comment",e[e.Debug_above=8]="Debug_above",e))(G||{}),W=(e=>(e[e.Normal=0]="Normal",e[e.Selected=1]="Selected",e[e.Follow_Confirmed=2]="Follow_Confirmed",e[e.QFeedback_NotFound=3]="QFeedback_NotFound",e[e.QFeedback_OK=4]="QFeedback_OK",e[e.QFeedback_Perfect=5]="QFeedback_Perfect",e[e.Debug1=6]="Debug1",e[e.Debug2=7]="Debug2",e[e.Debug3=8]="Debug3",e))(W||{}),U=(e=>(e.C="#d82c6b",e.D="#F89D15",e.E="#FFE21A",e.F="#4dbd5c",e.G="#009D96",e.A="#43469d",e.B="#76429c",e.Rest="#000000",e))(U||{});class X{constructor(e,t,i=0,s=O.BaseWritingColor,n=void 0){this.start=e,this.end=t,this.width=i,this.styleId=s,this.colorHex=n}get Start(){return this.start}set Start(e){this.start=e}get End(){return this.end}set End(e){this.end=e}get Width(){return this.width}set Width(e){this.width=e}}class z{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}static get Empty(){return new z}static pointsAreEqual(e,t){return e.x===t.x&&e.y===t.y}ToString(){return"["+this.x+", "+this.y+"]"}}var H=(e=>(e[e.C=0]="C",e[e.D=2]="D",e[e.E=4]="E",e[e.F=5]="F",e[e.G=7]="G",e[e.A=9]="A",e[e.B=11]="B",e))(H||{}),Y=(e=>(e[e.SHARP=0]="SHARP",e[e.FLAT=1]="FLAT",e[e.NONE=2]="NONE",e[e.NATURAL=3]="NATURAL",e[e.DOUBLESHARP=4]="DOUBLESHARP",e[e.DOUBLEFLAT=5]="DOUBLEFLAT",e[e.TRIPLESHARP=6]="TRIPLESHARP",e[e.TRIPLEFLAT=7]="TRIPLEFLAT",e[e.QUARTERTONESHARP=8]="QUARTERTONESHARP",e[e.QUARTERTONEFLAT=9]="QUARTERTONEFLAT",e[e.SLASHFLAT=10]="SLASHFLAT",e[e.THREEQUARTERSSHARP=11]="THREEQUARTERSSHARP",e[e.THREEQUARTERSFLAT=12]="THREEQUARTERSFLAT",e[e.SLASHQUARTERSHARP=13]="SLASHQUARTERSHARP",e[e.SLASHSHARP=14]="SLASHSHARP",e[e.DOUBLESLASHFLAT=15]="DOUBLESLASHFLAT",e[e.SORI=16]="SORI",e[e.KORON=17]="KORON",e))(Y||{});const j=class{constructor(e,t,i,s=void 0,n=!1){this.accidental=2,this.fundamentalNote=e,this.octave=t,this.accidental=i,this.accidentalXml=s,this.halfTone=e+12*(t+j.octXmlDiff)+j.HalfTonesFromAccidental(i),n||(this.frequency=j.calcFrequency(this),this.nextFrequency=j.calcFrequency(this,"next"),this.prevFrequency=j.calcFrequency(this,"prev"))}static getNoteEnumString(e){switch(e){case 0:return"C";case 2:return"D";case 4:return"E";case 5:return"F";case 7:return"G";case 9:return"A";case 11:return"B";default:return""}}static lineShiftFromNoteEnum(e,t){if(0===t)return[e,0];const i=j.pitchEnumValues,s=i.indexOf(e);let n=0,r=(s+t)%i.length;return s+t>i.length-1&&(n=1),r<0&&(r=i.length+r,n=-1),[i[r],n]}static CalculateTransposedHalfTone(e,t){const i=e.fundamentalNote+e.AccidentalHalfTones+t;return j.WrapAroundCheck(i,12)}static WrapAroundCheck(e,t){let i=0;for(;e<0;)e+=t,i--;for(;e>=t;)e-=t,i++;return{overflow:i,halftone:e}}static calcFrequency(e,t){const i="musicScore"===window.DYProjectName?{"-2":[11,3],"-7":[12],"-9":[5],12:[33,34,35,37,38,2],24:[39]}:{"-2":[4,12,23],"-7":[13],"-9":[6],12:[5,116,55]};let s,n=0;if(e instanceof j){const t=e;n=t.octave-1,s=t.fundamentalNote-9+t.AccidentalHalfTones}else"number"==typeof e&&(s=e-57);const r=window.DYSubjectId;let o=0;if("COLEXIU"===window.DYEnvironment&&(i[12]=[120]),window.xmlNeedAdjustVoice)for(const l in i)if(Object.prototype.hasOwnProperty.call(i,l)&&i[l].includes(r)){o=parseFloat(l);break}let a=s+o;return"next"===t&&a++,"prev"===t&&a--,442*Math.pow(2,n)*Math.pow(2,a/12)}static calcFractionalKey(e){return Math.log(e/440)/Math.LN10*j.halftoneFactor+57}static fromFrequency(e){const t=j.calcFractionalKey(e)+.5,i=Math.floor(t/12)-j.octXmlDiff,s=Math.floor(t)%12;let n=s,r=2;return-1===this.pitchEnumValues.indexOf(n)&&(n=s-1,r=0),new j(n,i,r)}static fromHalftone(e){const t=Math.floor(e/12)-j.octXmlDiff,i=e%12;let s=i,n=2;return-1===this.pitchEnumValues.indexOf(s)&&(s=i-1,n=0),new j(s,t,n)}static ceiling(e){let t=e%=12;return-1===this.pitchEnumValues.indexOf(t)&&(t=e+1),t}static floor(e){let t=e%=12;return-1===this.pitchEnumValues.indexOf(t)&&(t=e-1),t}static HalfTonesFromAccidental(e){switch(e){case 2:case 3:return 0;case 0:return 1;case 1:return-1;case 4:return 2;case 5:return-2;case 6:return 3;case 7:return-3;case 8:return.5;case 9:return-.5;case 10:return-.51;case 11:return 1.5;case 12:return-1.5;case 13:return.0013;case 14:return.0014;case 15:return-.0015;case 16:return.0016;case 17:return.0017;default:throw new Error("Unhandled AccidentalEnum value")}}static AccidentalFromHalfTones(e){switch(e){case 0:return 2;case 1:return 0;case-1:return 1;case 2:return 4;case-2:return 5;case 3:return 6;case-3:return 7;case.5:return 8;case-.5:return 9;case 1.5:return 11;case-1.5:return 12;default:return e>0&&e<1?8:e<0&&e>-1?9:8}}static accidentalVexflow(e){let t;switch(e){case 3:t="n";break;case 1:t="b";break;case 0:t="#";break;case 4:t="##";break;case 6:t="###";break;case 5:t="bb";break;case 7:t="bbs";break;case 8:t="+";break;case 9:t="d";break;case 10:t="bs";break;case 11:t="++";break;case 12:t="db";break;case 13:t="+-";break;case 14:t="++-";break;case 15:t="bss";break;case 16:t="o";break;case 17:t="k"}return t}get AccidentalHalfTones(){return j.HalfTonesFromAccidental(this.accidental)}get Octave(){return this.octave}get FundamentalNote(){return this.fundamentalNote}get Accidental(){return this.accidental}get AccidentalXml(){return this.accidentalXml}get Frequency(){return this.frequency}static get OctaveXmlDifference(){return j.octXmlDiff}getHalfTone(){return this.halfTone}getTransposedPitch(e){if(e>12)throw new Error("rewrite this method to handle bigger octave changes or don't use is with bigger octave changes!");return e>0?this.getHigherPitchByTransposeFactor(e):e<0?this.getLowerPitchByTransposeFactor(-e):this}DoEnharmonicChange(){switch(this.accidental){case 1:case 5:this.fundamentalNote=this.getPreviousFundamentalNote(this.fundamentalNote),this.accidental=j.AccidentalFromHalfTones(this.halfTone-(this.fundamentalNote+12*(this.octave+j.octXmlDiff)));break;case 0:case 4:this.fundamentalNote=this.getNextFundamentalNote(this.fundamentalNote),this.accidental=j.AccidentalFromHalfTones(this.halfTone-(this.fundamentalNote+12*(this.octave+j.octXmlDiff)));break;default:return}}ToString(){let e=j.accidentalVexflow(this.accidental);return e||(e=""),"Key: "+j.getNoteEnumString(this.fundamentalNote)+e+", Note: "+this.fundamentalNote+", octave: "+this.octave.toString()}ToStringShort(e=0){let t=j.accidentalVexflow(this.accidental);t||(t="");const i=this.octave+e;return j.getNoteEnumString(this.fundamentalNote)+t+i}get ToStringShortGet(){return this.ToStringShort(0)}OperatorEquals(e){const t=this;return!(!t||!e)&&t.FundamentalNote===e.FundamentalNote&&t.Octave===e.Octave&&t.Accidental===e.Accidental}OperatorNotEqual(e){return!(this===e)}OperatorFundamentalGreaterThan(e){const t=this;return t.Octave===e.Octave?t.FundamentalNote>e.FundamentalNote:t.Octave>e.Octave}OperatorFundamentalLessThan(e){const t=this;return t.Octave===e.Octave?t.FundamentalNote<e.FundamentalNote:t.Octave<e.Octave}getHigherPitchByTransposeFactor(e){const t=j.pitchEnumValues.indexOf(this.fundamentalNote);let i,s=this.octave;return t+e>j.pitchEnumValues.length-1?(i=j.pitchEnumValues[t+e-j.pitchEnumValues.length],s++):i=j.pitchEnumValues[t+e],new j(i,s,2)}getLowerPitchByTransposeFactor(e){const t=j.pitchEnumValues.indexOf(this.fundamentalNote);let i,s=this.octave;return t-e<0?(i=j.pitchEnumValues[j.pitchEnumValues.length+t-e],s--):i=j.pitchEnumValues[t-e],new j(i,s,2)}getNextFundamentalNote(e){let t=j.pitchEnumValues.indexOf(e);return t=(t+1)%j.pitchEnumValues.length,j.pitchEnumValues[t]}getPreviousFundamentalNote(e){const t=j.pitchEnumValues.indexOf(e);return t>0?j.pitchEnumValues[t-1]:j.pitchEnumValues[j.pitchEnumValues.length-1]}};let K=j;K.pitchEnumValues=[0,2,4,5,7,9,11],K.halftoneFactor=12/(Math.LN2/Math.LN10),K.octXmlDiff=3;class J extends L{constructor(e=0,t=0,i=2){super(void 0),this.clefType=0,this.line=2,this.octaveOffset=0,this.line=i,this.clefType=e,this.octaveOffset=t,this.calcParameters()}static getDefaultClefFromMidiInstrument(e){switch(e){case 0:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 43:return new J(1,0,4);default:return new J(0,0,2)}}static getAllPossibleClefs(){const e=[];for(let t=0;t<=2;t++){const i=new J(0,t,2);e.push(i)}for(let t=-2;t<=0;t++){const i=new J(1,t,4);e.push(i)}return e}static isSupportedClef(e){switch(e){case 0:case 1:case 2:case 3:case 4:return!0;default:return!1}}get ClefType(){return this.clefType}set ClefType(e){this.clefType=e}get Line(){return this.line}set Line(e){this.line=e}get OctaveOffset(){return this.octaveOffset}set OctaveOffset(e){this.octaveOffset=e}get ClefPitch(){return this.clefPitch}set ClefPitch(e){this.clefPitch=e}get ReferenceCyPosition(){return this.referenceCyPosition}set ReferenceCyPosition(e){this.referenceCyPosition=e}Equals(e){return this===e||!(!this||!e)&&this.clefPitch===e.clefPitch&&this.Line===e.Line}NotEqual(e){return!this.Equals(e)}ToString(){return"ClefType: "+this.clefType}calcParameters(){switch(this.clefType){case 0:this.clefPitch=new K(H.G,1+this.octaveOffset,Y.NONE),this.referenceCyPosition=5-this.line+2;break;case 1:this.clefPitch=new K(H.F,0+this.octaveOffset,Y.NONE),this.referenceCyPosition=5-this.line+1.5;break;case 2:this.clefPitch=new K(H.C,1+this.octaveOffset,Y.NONE),this.referenceCyPosition=5-this.line;break;case 3:this.clefPitch=new K(H.C,2,Y.NONE),this.referenceCyPosition=2;break;case 4:this.clefPitch=new K(H.G,0,Y.NONE),this.referenceCyPosition=0;break;default:throw new y("clefType")}}}var q=(e=>(e[e.G=0]="G",e[e.F=1]="F",e[e.C=2]="C",e[e.percussion=3]="percussion",e[e.TAB=4]="TAB",e))(q||{}),$=(e=>(e[e.None=-1]="None",e[e.Acoustic_Grand_Piano=0]="Acoustic_Grand_Piano",e[e.Bright_Acoustic_Piano=1]="Bright_Acoustic_Piano",e[e.Electric_Grand_Piano=2]="Electric_Grand_Piano",e[e.Honky_tonk_Piano=3]="Honky_tonk_Piano",e[e.Electric_Piano_1=4]="Electric_Piano_1",e[e.Electric_Piano_2=5]="Electric_Piano_2",e[e.Harpsichord=6]="Harpsichord",e[e.Clavinet=7]="Clavinet",e[e.Celesta=8]="Celesta",e[e.Glockenspiel=9]="Glockenspiel",e[e.Music_Box=10]="Music_Box",e[e.Vibraphone=11]="Vibraphone",e[e.Marimba=12]="Marimba",e[e.Xylophone=13]="Xylophone",e[e.Tubular_Bells=14]="Tubular_Bells",e[e.Dulcimer=15]="Dulcimer",e[e.Drawbar_Organ=16]="Drawbar_Organ",e[e.Percussive_Organ=17]="Percussive_Organ",e[e.Rock_Organ=18]="Rock_Organ",e[e.Church_Organ=19]="Church_Organ",e[e.Reed_Organ=20]="Reed_Organ",e[e.Accordion=21]="Accordion",e[e.Harmonica=22]="Harmonica",e[e.Tango_Accordion=23]="Tango_Accordion",e[e.Acoustic_Guitar_nylon=24]="Acoustic_Guitar_nylon",e[e.Acoustic_Guitar_steel=25]="Acoustic_Guitar_steel",e[e.Electric_Guitar_jazz=26]="Electric_Guitar_jazz",e[e.Electric_Guitar_clean=27]="Electric_Guitar_clean",e[e.Electric_Guitar_muted=28]="Electric_Guitar_muted",e[e.Overdriven_Guitar=29]="Overdriven_Guitar",e[e.Distortion_Guitar=30]="Distortion_Guitar",e[e.Guitar_harmonics=31]="Guitar_harmonics",e[e.Acoustic_Bass=32]="Acoustic_Bass",e[e.Electric_Bass_finger=33]="Electric_Bass_finger",e[e.Electric_Bass_pick=34]="Electric_Bass_pick",e[e.Fretless_Bass=35]="Fretless_Bass",e[e.Slap_Bass_1=36]="Slap_Bass_1",e[e.Slap_Bass_2=37]="Slap_Bass_2",e[e.Synth_Bass_1=38]="Synth_Bass_1",e[e.Synth_Bass_2=39]="Synth_Bass_2",e[e.Violin=40]="Violin",e[e.Viola=41]="Viola",e[e.Cello=42]="Cello",e[e.Contrabass=43]="Contrabass",e[e.Tremolo_Strings=44]="Tremolo_Strings",e[e.Pizzicato_Strings=45]="Pizzicato_Strings",e[e.Orchestral_Harp=46]="Orchestral_Harp",e[e.Timpani=47]="Timpani",e[e.String_Ensemble_1=48]="String_Ensemble_1",e[e.String_Ensemble_2=49]="String_Ensemble_2",e[e.Synth_Strings_1=50]="Synth_Strings_1",e[e.Synth_Strings_2=51]="Synth_Strings_2",e[e.Choir_Aahs=52]="Choir_Aahs",e[e.Voice_Oohs=53]="Voice_Oohs",e[e.Synth_Voice=54]="Synth_Voice",e[e.Orchestra_Hit=55]="Orchestra_Hit",e[e.Trumpet=56]="Trumpet",e[e.Trombone=57]="Trombone",e[e.Tuba=58]="Tuba",e[e.Muted_Trumpet=59]="Muted_Trumpet",e[e.French_Horn=60]="French_Horn",e[e.Brass_Section=61]="Brass_Section",e[e.Synth_Brass_1=62]="Synth_Brass_1",e[e.Synth_Brass_2=63]="Synth_Brass_2",e[e.Soprano_Sax=64]="Soprano_Sax",e[e.Alto_Sax=65]="Alto_Sax",e[e.Tenor_Sax=66]="Tenor_Sax",e[e.Baritone_Sax=67]="Baritone_Sax",e[e.Oboe=68]="Oboe",e[e.English_Horn=69]="English_Horn",e[e.Bassoon=70]="Bassoon",e[e.Clarinet=71]="Clarinet",e[e.Piccolo=72]="Piccolo",e[e.Flute=73]="Flute",e[e.Recorder=74]="Recorder",e[e.Pan_Flute=75]="Pan_Flute",e[e.Blown_Bottle=76]="Blown_Bottle",e[e.Shakuhachi=77]="Shakuhachi",e[e.Whistle=78]="Whistle",e[e.Ocarina=79]="Ocarina",e[e.Lead_1_square=80]="Lead_1_square",e[e.Lead_2_sawtooth=81]="Lead_2_sawtooth",e[e.Lead_3_calliope=82]="Lead_3_calliope",e[e.Lead_4_chiff=83]="Lead_4_chiff",e[e.Lead_5_charang=84]="Lead_5_charang",e[e.Lead_6_voice=85]="Lead_6_voice",e[e.Lead_7_fifths=86]="Lead_7_fifths",e[e.Lead_8_bass_lead=87]="Lead_8_bass_lead",e[e.Pad_1_new_age=88]="Pad_1_new_age",e[e.Pad_2_warm=89]="Pad_2_warm",e[e.Pad_3_polysynth=90]="Pad_3_polysynth",e[e.Pad_4_choir=91]="Pad_4_choir",e[e.Pad_5_bowed=92]="Pad_5_bowed",e[e.Pad_6_metallic=93]="Pad_6_metallic",e[e.Pad_7_halo=94]="Pad_7_halo",e[e.Pad_8_sweep=95]="Pad_8_sweep",e[e.FX_1_rain=96]="FX_1_rain",e[e.FX_2_soundtrack=97]="FX_2_soundtrack",e[e.FX_3_crystal=98]="FX_3_crystal",e[e.FX_4_atmosphere=99]="FX_4_atmosphere",e[e.FX_5_brightness=100]="FX_5_brightness",e[e.FX_6_goblins=101]="FX_6_goblins",e[e.FX_7_echoes=102]="FX_7_echoes",e[e.FX_8_scifi=103]="FX_8_scifi",e[e.Sitar=104]="Sitar",e[e.Banjo=105]="Banjo",e[e.Shamisen=106]="Shamisen",e[e.Koto=107]="Koto",e[e.Kalimba=108]="Kalimba",e[e.Bag_pipe=109]="Bag_pipe",e[e.Fiddle=110]="Fiddle",e[e.Shanai=111]="Shanai",e[e.Tinkle_Bell=112]="Tinkle_Bell",e[e.Agogo=113]="Agogo",e[e.Steel_Drums=114]="Steel_Drums",e[e.Woodblock=115]="Woodblock",e[e.Taiko_Drum=116]="Taiko_Drum",e[e.Melodic_Tom=117]="Melodic_Tom",e[e.Synth_Drum=118]="Synth_Drum",e[e.Reverse_Cymbal=119]="Reverse_Cymbal",e[e.Guitar_Fret_Noise=120]="Guitar_Fret_Noise",e[e.Breath_Noise=121]="Breath_Noise",e[e.Seashore=122]="Seashore",e[e.Bird_Tweet=123]="Bird_Tweet",e[e.Telephone_Ring=124]="Telephone_Ring",e[e.Helicopter=125]="Helicopter",e[e.Applause=126]="Applause",e[e.Gunshot=127]="Gunshot",e[e.Percussion=128]="Percussion",e))($||{});const Q=class extends L{constructor(e=void 0,t=0,i=0){super(e),this.isTransposedBy=0,this.Key=t,this.keyTypeOriginal=t,this.mode=i,this.alteratedNotes=this.calcAlteratedNotes()}static copy(e){const t=new Q(e.parent,e.Key,e.Mode);return t.keyTypeOriginal=e.keyTypeOriginal,t}static getAllPossibleMajorKeyInstructions(){const e=[];for(let t=-7;t<7;t++){const i=new Q(void 0,t,0);e.push(i)}return e}get Key(){return this.keyType}set Key(e){this.keyType=e,this.alteratedNotes=this.calcAlteratedNotes()}get Mode(){return this.mode}set Mode(e){this.mode=e}get AlteratedNotes(){return this.alteratedNotes}calcAlteratedNotes(){const e=[];if(this.keyType>0)for(let t=0;t<this.keyType;t++)e.push(Q.sharpPositionList[t]);else if(this.keyType<0)for(let t=0;t<-this.keyType;t++)e.push(Q.flatPositionList[t]);return e}willAlterateNote(e){return this.alteratedNotes.indexOf(e)>=0}getAlterationForPitch(e){return this.keyType>0&&this.alteratedNotes.indexOf(e.FundamentalNote)<=this.keyType?Y.SHARP:this.keyType<0&&this.alteratedNotes.indexOf(e.FundamentalNote)<=Math.abs(this.keyType)?Y.FLAT:Y.NONE}ToString(){return"Key: "+this.keyType+this.mode}OperatorEquals(e){const t=this;return t===e||!(!t||!e)&&t.Key===e.Key&&t.Mode===e.Mode}OperatorNotEqual(e){return!this.OperatorEquals(e)}};let Z=Q;Z.sharpPositionList=[H.F,H.C,H.G,H.D,H.A,H.E,H.B],Z.flatPositionList=[H.B,H.E,H.A,H.D,H.G,H.C,H.F];var ee=(e=>(e[e.major=0]="major",e[e.minor=1]="minor",e[e.none=2]="none",e[e.dorian=3]="dorian",e[e.phrygian=4]="phrygian",e[e.lydian=5]="lydian",e[e.mixolydian=6]="mixolydian",e[e.aeolian=7]="aeolian",e[e.ionian=8]="ionian",e[e.locrian=9]="locrian",e))(ee||{});class te{constructor(e=0,t=0){this.width=e,this.height=t}}class ie{constructor(e,t,i,s){this.x=0,this.y=0,this.width=0,this.height=0,this.x=e,this.y=t,this.width=i,this.height=s}static createFromLocationAndSize(e,t){return new ie(e.x,e.y,t.width,t.height)}get Location(){return new z(this.x,this.y)}get Size(){return new te(this.width,this.height)}}class se{isInstanceOfClass(e){let t=this.constructor.prototype;for(;t;){if(e===t.constructor.name)return!0;t=t.__proto__}return!1}}class ne extends se{get PositionAndShape(){return this.boundingBox}set PositionAndShape(e){this.boundingBox=e}}class re extends ne{}class oe{constructor(e=void 0,t=void 0,i=!1){this.isSymbol=!1,this.relativePositionHasBeenSet=!1,this.xBordersHaveBeenSet=!1,this.yBordersHaveBeenSet=!1,this.absolutePosition=new z,this.relativePosition=new z,this.size=new te,this.marginSize=new te,this.upperLeftCorner=new z,this.upperLeftMarginCorner=new z,this.borderLeft=0,this.borderRight=0,this.borderTop=0,this.borderBottom=0,this.borderMarginLeft=0,this.borderMarginRight=0,this.borderMarginTop=0,this.borderMarginBottom=0,this.childElements=[],this.parent=t,this.dataObject=e,this.isSymbol=i,this.xBordersHaveBeenSet=!1,this.yBordersHaveBeenSet=!1,t&&(this.Parent=t)}get RelativePositionHasBeenSet(){return this.relativePositionHasBeenSet}get XBordersHaveBeenSet(){return this.xBordersHaveBeenSet}set XBordersHaveBeenSet(e){this.xBordersHaveBeenSet=e}get YBordersHaveBeenSet(){return this.yBordersHaveBeenSet}set YBordersHaveBeenSet(e){this.yBordersHaveBeenSet=e}get AbsolutePosition(){return this.absolutePosition}set AbsolutePosition(e){this.absolutePosition=e}get RelativePosition(){return this.relativePosition}set RelativePosition(e){this.relativePosition=e,this.relativePositionHasBeenSet=!0}get Size(){return this.size}set Size(e){this.size=e}get MarginSize(){return this.marginSize}get UpperLeftCorner(){return this.upperLeftCorner}get UpperLeftMarginCorner(){return this.upperLeftMarginCorner}get BorderLeft(){return this.borderLeft}set BorderLeft(e){this.borderLeft=e,this.calculateRectangle()}get BorderRight(){return this.borderRight}set BorderRight(e){this.borderRight=e,this.calculateRectangle()}get BorderTop(){return this.borderTop}set BorderTop(e){this.borderTop=e,this.calculateRectangle()}get BorderBottom(){return this.borderBottom}set BorderBottom(e){this.borderBottom=e,this.calculateRectangle()}get BorderMarginLeft(){return this.borderMarginLeft>this.borderLeft?this.borderLeft:this.borderMarginLeft}set BorderMarginLeft(e){this.borderMarginLeft=e,this.calculateMarginRectangle()}get BorderMarginRight(){return this.borderMarginRight<this.borderRight?this.borderRight:this.borderMarginRight}set BorderMarginRight(e){this.borderMarginRight=e,this.calculateMarginRectangle()}get BorderMarginTop(){return this.borderMarginTop>this.borderTop?this.borderTop:this.borderMarginTop}set BorderMarginTop(e){this.borderMarginTop=e,this.calculateMarginRectangle()}get BorderMarginBottom(){return this.borderMarginBottom<this.borderBottom?this.borderBottom:this.borderMarginBottom}set BorderMarginBottom(e){this.borderMarginBottom=e,this.calculateMarginRectangle()}get BoundingRectangle(){return this.boundingRectangle}get BoundingMarginRectangle(){return this.boundingMarginRectangle}get ChildElements(){return this.childElements}set ChildElements(e){this.childElements=e}get Parent(){return this.parent}set Parent(e){var t,i,n,r;if(this.parent){const e=this.parent.ChildElements.indexOf(this,0);e>-1&&this.parent.ChildElements.splice(e,1)}this.parent=e,(null===(t=this.parent)||void 0===t||null===(i=t.ChildElements)||void 0===i?void 0:i.indexOf(this))>-1?s.error("BoundingBox of "+this.dataObject.constructor.name+" already in children list of "+this.parent.dataObject.constructor.name+"'s BoundingBox"):null===(n=this.parent)||void 0===n||null===(r=n.ChildElements)||void 0===r||r.push(this)}get DataObject(){return this.dataObject}get Center(){return new z(this.RelativePosition.x+(this.BorderMarginRight+this.BorderMarginLeft),this.RelativePosition.y+(this.BorderMarginBottom+this.BorderMarginTop))}setAbsolutePositionFromParent(){this.parent?(this.absolutePosition.x=this.parent.AbsolutePosition.x+this.relativePosition.x,this.absolutePosition.y=this.parent.AbsolutePosition.y+this.relativePosition.y):this.absolutePosition=this.relativePosition}calculateAbsolutePosition(){this.absolutePosition.x=this.relativePosition.x,this.absolutePosition.y=this.relativePosition.y;let e=this.parent;for(;e;)this.absolutePosition.x+=e.relativePosition.x,this.absolutePosition.y+=e.relativePosition.y,e=e.parent}calculateAbsolutePositionsRecursiveWithoutTopelement(){this.absolutePosition.x=0,this.absolutePosition.y=0;for(let e=0,t=this.ChildElements.length;e<t;++e)this.ChildElements[e].calculateAbsolutePositionsRecursive(this.absolutePosition.x,this.absolutePosition.y)}calculateAbsolutePositionsRecursive(e,t){this.absolutePosition.x=this.relativePosition.x+e,this.absolutePosition.y=this.relativePosition.y+t;for(let i=0,s=this.ChildElements.length;i<s;++i)this.ChildElements[i].calculateAbsolutePositionsRecursive(this.absolutePosition.x,this.absolutePosition.y)}calculateAbsolutePositionsOfChildren(){for(let e=0,t=this.ChildElements.length;e<t;++e)this.ChildElements[e].calculateAbsolutePositionsRecursive(this.absolutePosition.x,this.absolutePosition.y)}calculateBoundingBox(e=[]){if(0===this.childElements.length)return;for(let h=0,u=this.ChildElements.length;h<u;++h){const t=this.ChildElements[h];let i=!0;for(const s of e){const e=t.DataObject;if(e.isInstanceOfClass&&e.isInstanceOfClass(s)){i=!1;break}}i&&t.calculateBoundingBox(e)}let t=Number.MAX_VALUE,i=Number.MIN_VALUE,s=Number.MAX_VALUE,n=Number.MIN_VALUE,r=Number.MAX_VALUE,o=Number.MIN_VALUE,a=Number.MAX_VALUE,l=Number.MIN_VALUE;this.isSymbol&&(t=this.borderLeft,i=this.borderRight,s=this.borderTop,n=this.borderBottom,r=this.borderMarginLeft,o=this.borderMarginRight,a=this.borderMarginTop,l=this.borderMarginBottom);for(let h=0,u=this.ChildElements.length;h<u;++h){const e=this.ChildElements[h];t=Math.min(t,e.relativePosition.x+e.borderLeft),i=Math.max(i,e.relativePosition.x+e.borderRight),s=Math.min(s,e.relativePosition.y+e.borderTop),n=Math.max(n,e.relativePosition.y+e.borderBottom),r=Math.min(r,e.relativePosition.x+e.borderMarginLeft),o=Math.max(o,e.relativePosition.x+e.borderMarginRight),a=Math.min(a,e.relativePosition.y+e.borderMarginTop),l=Math.max(l,e.relativePosition.y+e.borderMarginBottom)}this.borderLeft=t,this.borderRight=i,this.borderTop=s,this.borderBottom=n,this.borderMarginLeft=r,this.borderMarginRight=o,this.borderMarginTop=a,this.borderMarginBottom=l,this.calculateRectangle(),this.calculateMarginRectangle(),this.xBordersHaveBeenSet=!0,this.yBordersHaveBeenSet=!0}calculateTopBottomBorders(){if(0===this.childElements.length)return;for(let n=0,r=this.ChildElements.length;n<r;++n)this.ChildElements[n].calculateTopBottomBorders();let e=Number.MAX_VALUE,t=Number.MIN_VALUE,i=Number.MAX_VALUE,s=Number.MIN_VALUE;this.yBordersHaveBeenSet&&(e=this.borderTop,t=this.borderBottom,i=this.borderMarginTop,s=this.borderMarginBottom);for(let n=0,r=this.ChildElements.length;n<r;++n){const r=this.ChildElements[n];e=Math.min(e,r.relativePosition.y+r.borderTop),t=Math.max(t,r.relativePosition.y+r.borderBottom),i=Math.min(i,r.relativePosition.y+r.borderMarginTop),s=Math.max(s,r.relativePosition.y+r.borderMarginBottom)}this.borderTop=e,this.borderBottom=t,this.borderMarginTop=i,this.borderMarginBottom=s,this.calculateRectangle(),this.calculateMarginRectangle()}computeNonOverlappingPositionWithMargin(e,t,i){this.RelativePosition=new z(i.x,i.y),this.setAbsolutePositionFromParent();let s=0,n=!1;do{switch(t){case 0:case 1:s=this.relativePosition.x,e.calculateMarginPositionAlongDirection(this,t),n=Math.abs(s-this.relativePosition.x)>.001;break;case 2:case 3:s=this.relativePosition.y,e.calculateMarginPositionAlongDirection(this,t),n=Math.abs(s-this.relativePosition.y)>.001;break;default:throw new y("direction")}}while(n)}collisionDetection(e){const t=Math.min(this.AbsolutePosition.x+this.borderRight,e.absolutePosition.x+e.borderRight)-Math.max(this.AbsolutePosition.x+this.borderLeft,e.absolutePosition.x+e.borderLeft),i=Math.min(this.AbsolutePosition.y+this.borderBottom,e.absolutePosition.y+e.borderBottom)-Math.max(this.AbsolutePosition.y+this.borderTop,e.absolutePosition.y+e.borderTop);return t>0&&i>0}liesInsideBorders(e){const t=this.AbsolutePosition.x+this.borderLeft<=e.absolutePosition.x+e.borderLeft&&e.absolutePosition.x+e.borderLeft<=this.AbsolutePosition.x+this.borderRight,i=this.AbsolutePosition.x+this.borderLeft<=e.absolutePosition.x+e.borderRight&&e.absolutePosition.x+e.borderRight<=this.AbsolutePosition.x+this.borderRight;if(t&&i){const t=this.AbsolutePosition.y+this.borderTop<=e.absolutePosition.y+e.borderTop&&e.absolutePosition.y+e.borderTop<=this.AbsolutePosition.y+this.borderBottom,i=this.AbsolutePosition.y+this.borderTop<=e.absolutePosition.y+e.borderBottom&&e.absolutePosition.y+e.borderBottom<=this.AbsolutePosition.y+this.borderBottom;if(t&&i)return!0}return!1}pointLiesInsideBorders(e){return this.AbsolutePosition.x+this.borderLeft<=e.x&&e.x<=this.AbsolutePosition.x+this.borderRight&&this.AbsolutePosition.y+this.borderTop<=e.y&&e.y<=this.AbsolutePosition.y+this.borderBottom}marginCollisionDetection(e){const t=Math.min(this.AbsolutePosition.x+this.borderMarginRight,e.absolutePosition.x+e.borderMarginRight)-Math.max(this.AbsolutePosition.x+this.borderMarginLeft,e.absolutePosition.x+e.borderMarginLeft),i=Math.min(this.AbsolutePosition.y+this.borderMarginBottom,e.absolutePosition.y+e.borderMarginBottom)-Math.max(this.AbsolutePosition.y+this.borderMarginTop,e.absolutePosition.y+e.borderMarginTop);return t>0&&i>0}liesInsideMargins(e){const t=this.AbsolutePosition.x+this.borderMarginLeft<=e.absolutePosition.x+e.borderMarginLeft&&e.absolutePosition.x+e.borderMarginLeft<=this.AbsolutePosition.x+this.borderMarginRight,i=this.AbsolutePosition.x+this.borderMarginLeft<=e.absolutePosition.x+e.borderMarginRight&&e.absolutePosition.x+e.borderMarginRight<=this.AbsolutePosition.x+this.borderMarginRight;if(t&&i){const t=this.AbsolutePosition.y+this.borderMarginTop<=e.absolutePosition.y+e.borderMarginTop&&e.absolutePosition.y+e.borderMarginTop<=this.AbsolutePosition.y+this.borderMarginBottom,i=this.AbsolutePosition.y+this.borderMarginTop<=e.absolutePosition.y+e.borderMarginBottom&&e.absolutePosition.y+e.borderMarginBottom<=this.AbsolutePosition.y+this.borderMarginBottom;if(t&&i)return!0}return!1}pointLiesInsideMargins(e){return this.AbsolutePosition.x+this.borderMarginLeft<=e.x&&e.x<=this.AbsolutePosition.x+this.borderMarginRight&&this.AbsolutePosition.y+this.borderMarginTop<=e.y&&e.y<=this.AbsolutePosition.y+this.borderMarginBottom}computeNonOverlappingPosition(e,t,i){this.RelativePosition=new z(i.x,i.y),this.setAbsolutePositionFromParent();let s=0,n=!1;do{switch(t){case 0:case 1:s=this.relativePosition.x,e.calculatePositionAlongDirection(this,t),n=Math.abs(s-this.relativePosition.x)>1e-4;break;case 2:case 3:s=this.relativePosition.y,e.calculatePositionAlongDirection(this,t),n=Math.abs(s-this.relativePosition.y)>1e-4;break;default:throw new y("direction")}}while(n)}getClickedObjectOfType(e){const t=this.dataObject;if(this.pointLiesInsideBorders(e)&&t)return t;for(let i=0,s=this.childElements.length;i<s;++i){const t=this.childElements[i].getClickedObjectOfType(e);if(t)return t}}getClickedClickable(e){const t=this.dataObject;if(this.pointLiesInsideBorders(e)&&t&&t instanceof re)return t;for(let i=0,s=this.childElements.length;i<s;++i){const t=this.childElements[i].getClickedClickable(e);if(t&&t instanceof re)return t}}getObjectsInRegion(e,t=!0,i=ne.name){let s=[];for(const n of this.childElements)s=s.concat(n.getObjectsInRegion(e,t,i));return this.dataObject&&this.dataObject.isInstanceOfClass(i)&&(t?e.liesInsideBorders(this)&&s.push(this.dataObject):e.collisionDetection(this)&&s.push(this.dataObject)),s}calculateRectangle(){this.upperLeftCorner=new z(this.BorderLeft,this.BorderTop),this.size=new te(this.BorderRight-this.BorderLeft,this.BorderBottom-this.BorderTop),this.boundingRectangle=ie.createFromLocationAndSize(this.upperLeftCorner,this.size)}calculateMarginRectangle(){this.upperLeftMarginCorner=new z(this.BorderMarginLeft,this.BorderMarginTop),this.marginSize=new te(this.BorderMarginRight-this.BorderMarginLeft,this.BorderMarginBottom-this.BorderMarginTop),this.boundingMarginRectangle=ie.createFromLocationAndSize(this.upperLeftMarginCorner,this.marginSize)}calculateMarginPositionAlongDirection(e,t){if(this!==e){if(this.isSymbol&&this.marginCollisionDetection(e)){let i=0;switch(t){case 0:return i=this.absolutePosition.x+this.borderMarginLeft-(e.absolutePosition.x+e.borderMarginRight),e.relativePosition.x+=i,void(e.absolutePosition.x+=i);case 1:return i=this.absolutePosition.x+this.borderMarginRight-(e.absolutePosition.x+e.borderMarginLeft),e.relativePosition.x+=i,void(e.absolutePosition.x+=i);case 2:return i=this.absolutePosition.y+this.borderMarginTop-(e.absolutePosition.y+e.borderMarginBottom),e.relativePosition.y+=i,void(e.absolutePosition.y+=i);case 3:return i=this.absolutePosition.y+this.borderMarginBottom-(e.absolutePosition.y+e.borderMarginTop),e.relativePosition.y+=i,void(e.absolutePosition.y+=i);default:throw new y("direction")}}for(let i=0,s=this.ChildElements.length;i<s;++i)this.ChildElements[i].calculateMarginPositionAlongDirection(e,t)}}calculatePositionAlongDirection(e,t){if(this!==e){if(this.isSymbol&&this.collisionDetection(e)){let i;switch(t){case 0:return i=this.absolutePosition.x+this.borderLeft-(e.absolutePosition.x+e.borderRight),e.relativePosition.x+=i,void(e.absolutePosition.x+=i);case 1:return i=this.absolutePosition.x+this.borderRight-(e.absolutePosition.x+e.borderLeft),e.relativePosition.x+=i,void(e.absolutePosition.x+=i);case 2:return i=this.absolutePosition.y+this.borderTop-(e.absolutePosition.y+e.borderBottom),e.relativePosition.y+=i,void(e.absolutePosition.y+=i);case 3:return i=this.absolutePosition.y+this.borderBottom-(e.absolutePosition.y+e.borderTop),e.relativePosition.y+=i,void(e.absolutePosition.y+=i);default:throw new y("direction")}}for(let i=0,s=this.ChildElements.length;i<s;++i)this.ChildElements[i].calculatePositionAlongDirection(e,t)}}}var ae=(e=>(e[e.Left=0]="Left",e[e.Right=1]="Right",e[e.Up=2]="Up",e[e.Down=3]="Down",e[e.NotYetDefined=4]="NotYetDefined",e))(ae||{});Array.prototype.last||Object.defineProperty(Array.prototype,"last",{enumerable:!1,writable:!0,value:function(){return this[this.length-1]}}),Array.prototype.clear||Object.defineProperty(Array.prototype,"clear",{enumerable:!1,writable:!0,value:function(){this.length=0}}),Array.prototype.contains||Object.defineProperty(Array.prototype,"contains",{enumerable:!1,writable:!0,value:function(e){return-1!==this.indexOf(e)}});class le{static contains2(e,t){for(let i=0;i<e.length;i++)if(e[i]===t)return!0;return!1}static last(e){return e[e.length-1]}static flat(e){return[].concat(...e)}static removeDictElementIfTrue(e,t,i){const s=[];t.forEach((function(t,n){i(e,t,n)&&s.push(t)}));for(let n=0;n<s.length;n++)t.remove(s[n])}static getLastElement(e){return e[e.length-1]}static binarySearch(e,t,i,s=0,n=e.length-1){let r=1,o=-1;for(;s<=n&&(r=Math.floor((s+n)/2),r!==o);){const a=i(e[r],t);if(0===a)return r;a<0&&(s=r+1),0<a&&(n=r),o=r}return-r}}class he extends ne{constructor(e){super(),this.musicSystems=[],this.labels=[],this.parent=e,this.boundingBox=new oe(this,void 0)}get MusicSystems(){return this.musicSystems}set MusicSystems(e){this.musicSystems=e}get Labels(){return this.labels}set Labels(e){this.labels=e}get Parent(){return this.parent}set Parent(e){this.parent=e}get PageNumber(){return this.pageNumber}set PageNumber(e){this.pageNumber=e}setMusicPageAbsolutePosition(e,t){return new z(0,0)}}var ue=(e=>(e[e.Down=0]="Down",e[e.Right=1]="Right",e[e.RightDown=2]="RightDown",e))(ue||{}),ce=(e=>(e[e.LeftTop=0]="LeftTop",e[e.LeftCenter=1]="LeftCenter",e[e.LeftBottom=2]="LeftBottom",e[e.CenterTop=3]="CenterTop",e[e.CenterCenter=4]="CenterCenter",e[e.CenterBottom=5]="CenterBottom",e[e.RightTop=6]="RightTop",e[e.RightCenter=7]="RightCenter",e[e.RightBottom=8]="RightBottom",e))(ce||{});class de{static IsLeft(e){return 0===e||1===e||2===e}static IsCenterAligned(e){return 3===e||4===e||5===e}static IsRight(e){return 6===e||7===e||8===e}}var fe=(e=>(e[e.XML=0]="XML",e[e.AutoColoring=1]="AutoColoring",e[e.CustomColorSet=2]="CustomColorSet",e))(fe||{}),me=(e=>(e[e.Regular=0]="Regular",e[e.Bold=1]="Bold",e[e.Italic=2]="Italic",e[e.BoldItalic=3]="BoldItalic",e[e.Underlined=4]="Underlined",e))(me||{}),pe=(e=>(e[e.TimesNewRoman=0]="TimesNewRoman",e[e.Kokila=1]="Kokila",e[e.Gonville=2]="Gonville",e))(pe||{});const ge={0:"Times New Roman",1:"Kokila",2:"Gonville"};var Se=(e=>(e.SIMPLE="",e.HAMMERON="H",e.PULLOFF="P",e.SLIDE="S",e.TAPPING="T",e))(Se||{});class ye{constructor(e,t,i,s,n){this.rootPitch=e,this.chordKind=t,this.bassPitch=i,this.degrees=s,this.rules=n}get RootPitch(){return this.rootPitch}get ChordKind(){return this.chordKind}get BassPitch(){return this.bassPitch}get ChordDegrees(){return this.degrees}static calculateChordText(e,t,i){let s=e.RootPitch;if(yi.transposeCalculator&&(s=yi.transposeCalculator.transposePitch(e.RootPitch,i,t)),31===e.ChordKind)return e.getTextFromChordKindEnum(e.ChordKind);let n=K.getNoteEnumString(s.FundamentalNote);s.Accidental!==Y.NONE&&(n+=e.getTextForAccidental(s.Accidental));const r={adds:[],alts:[],subs:[]};for(const h of e.ChordDegrees)if(h){let t="";switch(h.alteration!==Y.NONE&&(t+=e.getTextForAccidental(h.alteration)),t+=h.value,h.text){case 0:r.adds.push(t);break;case 1:r.alts.push(t);break;case 2:r.subs.push(t)}}let o=e.getTextFromChordKindEnum(e.ChordKind);const a=["adds","alts","subs"],l=e.rules.CustomChords;for(const h of l){if(h.chordKind!==e.chordKind)continue;let t=!0;for(const e of a){for(const i of h.degrees[e]||[])if(r[e].indexOf(i)<0){t=!1;break}if(!t)break}if(t){for(const e of a)for(const t of h.degrees[e]||[])r[e].splice(r[e].indexOf(t),1);o=h.alternateName}}if(n+=o,r.adds.length>0&&(n+="("+r.adds.join(",")+")"),r.alts.length>0&&(n+="(alt "+r.alts.join(",")+")"),r.subs.length>0&&(n+="(omit "+r.subs.join(",")+")"),e.BassPitch){let s=e.BassPitch;yi.transposeCalculator&&(s=yi.transposeCalculator.transposePitch(e.BassPitch,i,t)),n+="/",n+=K.getNoteEnumString(s.FundamentalNote),n+=e.getTextForAccidental(s.Accidental)}return n}getTextForAccidental(e){const t=this.rules.ChordAccidentalTexts.getValue(e);return void 0!==t?t:""}getTextFromChordKindEnum(e){var t;return null!==(t=this.rules.ChordSymbolLabelTexts.getValue(e))&&void 0!==t?t:""}}class be{constructor(e,t,i){this.value=e,this.alteration=t,this.text=i}}class Me{constructor(e,t,i){this.alternateName=e,this.chordKind=t,this.degrees=i}static createCustomChord(e,t,i){return new Me(e,t,i)}static renameCustomChord(e,t,i){for(const s of i)s.alternateName===e&&(s.alternateName=t)}}var ve=(e=>(e[e.add=0]="add",e[e.alter=1]="alter",e[e.subtract=2]="subtract",e))(ve||{}),Pe=(e=>(e[e.major=0]="major",e[e.minor=1]="minor",e[e.augmented=2]="augmented",e[e.diminished=3]="diminished",e[e.dominant=4]="dominant",e[e.majorseventh=5]="majorseventh",e[e.minorseventh=6]="minorseventh",e[e.diminishedseventh=7]="diminishedseventh",e[e.augmentedseventh=8]="augmentedseventh",e[e.halfdiminished=9]="halfdiminished",e[e.majorminor=10]="majorminor",e[e.majorsixth=11]="majorsixth",e[e.minorsixth=12]="minorsixth",e[e.dominantninth=13]="dominantninth",e[e.majorninth=14]="majorninth",e[e.minorninth=15]="minorninth",e[e.dominant11th=16]="dominant11th",e[e.major11th=17]="major11th",e[e.minor11th=18]="minor11th",e[e.dominant13th=19]="dominant13th",e[e.major13th=20]="major13th",e[e.minor13th=21]="minor13th",e[e.suspendedsecond=22]="suspendedsecond",e[e.suspendedfourth=23]="suspendedfourth",e[e.Neapolitan=24]="Neapolitan",e[e.Italian=25]="Italian",e[e.French=26]="French",e[e.German=27]="German",e[e.pedal=28]="pedal",e[e.power=29]="power",e[e.Tristan=30]="Tristan",e[e.none=31]="none",e))(Pe||{});class Ee extends ne{constructor(e,t,i,s=void 0){super(),this.DrawnAccidental=Y.NONE,this.lineShift=0,this.sourceNote=e,this.parentVoiceEntry=t,this.PositionAndShape=new oe(this,t.PositionAndShape),this.graphicalNoteLength=s||e.Length,this.numberOfDots=this.calculateNumberOfNeededDots(this.graphicalNoteLength),this.rules=i,this.rules.addGraphicalNoteToNoteMap(e,this)}Transpose(e,t,i,s){let n=this.sourceNote.Pitch;return yi.transposeCalculator&&(n=yi.transposeCalculator.transposePitch(this.sourceNote.Pitch,e,i)),n}calculateNumberOfNeededDots(e){return this.sourceNote&&this.sourceNote.NoteTuplet?0:e.calculateNumberOfNeededDots()}get ParentMusicPage(){return this.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentMusicSystem.Parent}static FromNote(e,t){return t.NoteToGraphicalNoteMap.getValue(e.NoteToGraphicalNoteObjectId)}ToStringShort(e=0){var t;return null===(t=this.sourceNote)||void 0===t?void 0:t.ToStringShort(e)}get ToStringShortGet(){return this.ToStringShort(0)}}const Le=class{constructor(){this.DYSlursStartingAtSameStaffEntryYOffset=0,this.DYMinNoteWidth=0,this.DYWorkId=0,this.DYWorkSpecial=!1,this.DYContainerId="osmdCanvasPage",this.DYSVGContainerId="osmdSvgPage",this.DYMusicScoreType="staff",this.DYMusicScoreId="",this.DYCustomRepeatCount=0,this.DYIsSingleLine=!1,this.DYMusicClientType="",this.NoteDistances=[1,1,1.3,1.6,2,2.5,3,4],this.NoteDistancesScalingFactors=[1,2,4,8,16,32,64,128],this.DurationDistanceDict={},this.DurationScalingDistanceDict={},this.NoteToGraphicalNoteMapObjectCount=0,this.RenderCount=0,this.PlayAlreadyStartedNotesFromCursorPosition=!1,this.PlaybackSkipNotesSafetyInterval=.02,this.UseDefaultVoiceInteractionListener=!0,this.LimitCursorPositionToCurrentMeasure=!0,this.loadDefaultValues()}loadDefaultValues(){this.SamplingUnit=3*Le.unit,this.MpatMode=!0,this.SheetTitleHeight=4,this.SheetSubtitleHeight=2,this.SheetMinimumDistanceBetweenTitleAndSubtitle=1,this.SheetComposerHeight=2,this.SheetAuthorHeight=2,this.SheetCopyrightHeight=1.5,this.SheetCopyrightMargin=2,this.SheetComposerSubtitleUseLegacyParsing=!1,this.CompactMode=!1,this.PagePlacementEnum=ue.Down,this.PageHeight=100001,this.PageTopMargin=5,this.PageTopMarginNarrow=0,this.PageBottomMargin=5,this.PageLeftMargin=5,this.PageRightMargin=5,this.TitleTopDistance=5,this.TitleBottomDistance=1,this.StaffDistance=7,this.BetweenStaffDistance=5,this.MinimumStaffLineDistance=4,this.MinSkyBottomDistBetweenStaves=1,this.StaffHeight=4,this.TabStaffInterlineHeight=1.1111,this.BetweenStaffLinesDistance=Le.unit,this.SystemLeftMargin=0,this.SystemRightMargin=0,this.SystemLabelsRightMargin=2,this.SystemComposerDistance=2,this.SystemLyricistDistance=2,this.InstrumentLabelTextHeight=2,this.MinimumDistanceBetweenSystems=7,this.MinSkyBottomDistBetweenSystems=5,this.LastSystemMaxScalingFactor=1.4,this.AutoBeamNotes=!1,this.AutoBeamOptions={beam_middle_rests_only:!1,beam_rests:!1,maintain_stem_directions:!1},this.AutoBeamTabs=!1,this.BeamWidth=Le.unit/2,this.BeamSpaceWidth=Le.unit/3,this.BeamForwardLength=1.25*Le.unit,this.FlatBeams=!1,this.FlatBeamOffset=20,this.FlatBeamOffsetPerBeam=10,this.ClefLeftMargin=.5,this.ClefRightMargin=.75,this.PercussionOneLineCutoff=3,this.PercussionForceVoicesOneLineCutoff=1,this.PercussionUseXMLDisplayStep=!0,this.PercussionXMLDisplayStepNoteValueShift=0,this.PercussionOneLineXMLDisplayStepOctaveOffset=0,this.PercussionUseCajon2NoteSystem=!1,this.BetweenKeySymbolsDistance=.2,this.KeyRightMargin=.75,this.RhythmRightMargin=1.25,this.ShowRhythmAgainAfterPartEndOrFinalBarline=!0,this.NewPartAndSystemAfterFinalBarline=!1,this.InStaffClefScalingFactor=.8,this.DistanceBetweenNaturalAndSymbolWhenCancelling=.4,this.NoteHelperLinesOffset=.25,this.MeasureLeftMargin=.7,this.MeasureRightMargin=0,this.DistanceBetweenLastInstructionAndRepetitionBarline=1,this.ArpeggioDistance=.6,this.StaccatoShorteningFactor=2,this.IdealStemLength=3,this.StemNoteHeadBorderYOffset=.2,this.StemMargin=.2,this.StemMinLength=2.5,this.StemMaxLength=4.5,this.BeamSlopeMaxAngle=10,this.StemMinAllowedDistanceBetweenNoteHeadAndBeamLine=1,this.SetWantedStemDirectionByXml=!0,this.GraceNoteScalingFactor=.6,this.GraceNoteXOffset=.2,this.GraceNoteGroupXMargin=0,this.WedgeOpeningLength=1.2,this.WedgeMeasureEndOpeningLength=.75,this.WedgeMeasureBeginOpeningLength=.75,this.WedgePlacementAboveY=-1.5,this.WedgePlacementBelowY=1.5,this.WedgeHorizontalMargin=.6,this.WedgeVerticalMargin=.5,this.DistanceOffsetBetweenTwoHorizontallyCrossedWedges=.3,this.WedgeMinLength=2,this.WedgeEndDistanceBetweenTimestampsFactor=1.75,this.SoftAccentWedgePadding=.4,this.SoftAccentSizeFactor=.6,this.DistanceBetweenAdjacentDynamics=.75,this.TempoChangeMeasureValidity=4,this.TempoContinousFactor=.7,this.StaccatoScalingFactor=.8,this.BetweenDotsDistance=.8,this.OrnamentAccidentalScalingFactor=.65,this.ChordSymbolTextHeight=2,this.ChordSymbolTextAlignment=ce.LeftBottom,this.ChordSymbolRelativeXOffset=-1,this.ChordSymbolExtraXShiftForShortChordSymbols=.3,this.ChordSymbolExtraXShiftWidthThreshold=2,this.ChordSymbolXSpacing=1,this.ChordOverlapAllowedIntoNextMeasure=0,this.ChordSymbolYOffset=.1,this.ChordSymbolYPadding=0,this.ChordSymbolYAlignment=!0,this.ChordSymbolYAlignmentScope="staffline",this.ChordSymbolWholeMeasureRestXOffset=0,this.ChordSymbolWholeMeasureRestXOffsetMeasure1=-2,this.ChordAccidentalTexts=new i,this.resetChordAccidentalTexts(this.ChordAccidentalTexts,!1),this.ChordSymbolLabelTexts=new i,this.resetChordSymbolLabelTexts(this.ChordSymbolLabelTexts),this.CustomChords=[],this.resetChordNames(),this.RepetitionSymbolsYOffset=0,this.RepetitionEndInstructionXShiftAsPercentOfStaveWidth=.4,this.RehearsalMarkXOffsetDefault=10,this.RehearsalMarkXOffset=0,this.RehearsalMarkXOffsetSystemStartMeasure=-20,this.RehearsalMarkYOffsetDefault=-15,this.RehearsalMarkYOffset=0,this.RehearsalMarkFontSize=10,this.MeasureNumberLabelHeight=1.5*Le.unit,this.MeasureNumberLabelOffset=2,this.MeasureNumberLabelXOffset=-.5,this.TupletsRatioed=!1,this.TupletsBracketed=!1,this.TripletsBracketed=!1,this.TupletsBracketedUseXMLValue=!0,this.TupletNumberLabelHeight=1.5*Le.unit,this.TupletNumberYOffset=.5,this.TupletNumberLimitConsecutiveRepetitions=!0,this.TupletNumberMaxConsecutiveRepetitions=2,this.TupletNumberAlwaysDisableAfterFirstMax=!0,this.TupletNumberUseShowNoneXMLValue=!0,this.LabelMarginBorderFactor=.1,this.TupletVerticalLineLength=.5,this.TupletNumbersInTabs=!0,this.TabTupletYOffsetBottom=1,this.TabTupletYOffsetTop=-3.5,this.TabTupletYOffsetEffects=1.5,this.TabTupletsBracketed=!0,this.TabBeamsRendered=!0,this.TabKeySignatureRendered=!1,this.TabKeySignatureSpacingAdded=!0,this.TabTimeSignatureRendered=!1,this.TabTimeSignatureSpacingAdded=!0,this.TabFingeringsRendered=!1,this.SlurPlacementFromXML=!0,this.SlurPlacementAtStems=!1,this.SlurPlacementUseSkyBottomLine=!1,this.BezierCurveStepSize=1e3,this.calculateCurveParametersArrays(),this.TieGhostObjectWidth=.75,this.TieYPositionOffsetFactor=.3,this.MinimumNeededXspaceForTieGhostObject=1,this.TieHeightMinimum=.28,this.TieHeightMaximum=1.2,this.TieHeightInterpolationK=.0288,this.TieHeightInterpolationD=.136,this.SlurNoteHeadYOffset=.5,this.SlurEndArticulationYOffset=.8,this.SlurStartArticulationYOffsetOfArticulation=.5,this.SlurStemXOffset=.3,this.SlurSlopeMaxAngle=15,this.SlurTangentMinAngle=30,this.SlurTangentMaxAngle=80,this.SlurHeightFactor=1,this.SlurHeightFlattenLongSlursFactorByWidth=.24,this.SlurHeightFlattenLongSlursFactorByAngle=.36,this.SlurHeightFlattenLongSlursCutoffAngle=47,this.SlurHeightFlattenLongSlursCutoffWidth=16,this.SlursStartingAtSameStaffEntryYOffset=.8,this.SlurMaximumYControlPointDistance=void 0,this.GlissandoNoteOffset=.5,this.GlissandoStafflineStartMinimumWidth=1,this.GlissandoStafflineStartYDistanceToNote=.8,this.GlissandoStafflineEndOffset=1,this.GlissandoDefaultWidth=.1,this.RepetitionAllowFirstMeasureBeginningRepeatBarline=!1,this.RepetitionEndingLabelHeight=2,this.RepetitionEndingLabelXOffset=.5,this.RepetitionEndingLabelYOffset=.3,this.RepetitionEndingLineYLowerOffset=.5,this.RepetitionEndingLineYUpperOffset=.3,this.VoltaOffset=2.5,this.LyricsAlignmentStandard=ce.LeftBottom,this.LyricsHeight=2,this.LyricsYOffsetToStaffHeight=0,this.LyricsYMarginToBottomLine=.2,this.LyricsExtraXShiftForShortLyrics=.5,this.LyricsExtraXShiftForShortLyricsWidthThreshold=1.4,this.LyricsUseXPaddingForLongLyrics=!0,this.LyricsXPaddingFactorForLongLyrics=1,this.LyricsXPaddingWidthThreshold=1.7,this.LyricsXPaddingReductionForLongNotes=.7,this.LyricsXPaddingReductionForLastNoteInMeasure=1.2,this.LyricsXPaddingForLastNoteInMeasure=!0,this.VerticalBetweenLyricsDistance=2,this.HorizontalBetweenLyricsDistance=5,this.BetweenSyllableMaximumDistance=10,this.BetweenSyllableMinimumDistance=.5,this.LyricOverlapAllowedIntoNextMeasure=3.4,this.MinimumDistanceBetweenDashes=10,this.MaximumLyricsElongationFactor=2.5,this.TempoYSpacing=.5,this.InstantaneousTempoTextHeight=2.3,this.ContinuousDynamicTextHeight=2.3,this.UseEndOffsetForExpressions=!0,this.MoodTextHeight=2.3,this.UnknownTextHeight=2,this.ContinuousTempoTextHeight=2.3,this.DynamicExpressionMaxDistance=2,this.DynamicExpressionSpacer=.5,this.IgnoreRepeatedDynamics=!1,this.ExpressionsUseXMLColor=!0,this.VexFlowDefaultNotationFontScale=39,this.VexFlowDefaultTabFontScale=39,this.TremoloStrokeScale=1,this.TremoloYSpacingScale=1,this.TremoloBuzzRollThickness=.25,this.StemWidth=.15,this.StaffLineWidth=.1,this.StaffLineColor=void 0,this.LedgerLineWidth=1,this.LedgerLineStrokeStyle=void 0,this.LedgerLineColorDefault="#000000",this.WedgeLineWidth=.12,this.TupletLineWidth=.12,this.LyricUnderscoreLineWidth=.12,this.SystemThinLineWidth=.12,this.SystemBoldLineWidth=Le.unit/2,this.SystemRepetitionEndingLineWidth=.12,this.SystemDotWidth=Le.unit/2,this.DistanceBetweenVerticalSystemLines=.35,this.DistanceBetweenDotAndLine=.7,this.RepeatEndStartPadding=2,this.OctaveShiftLineWidth=.12,this.OctaveShiftVerticalLineLength=Le.unit,this.OctaveShiftOnWholeMeasureNoteUntilEndOfMeasure=!1,this.GraceLineWidth=this.StaffLineWidth*this.GraceNoteScalingFactor,this.MultipleRestMeasureDefaultWidth=4,this.MultipleRestMeasureAddKeySignature=!0,this.FixedMeasureWidth=!1,this.FixedMeasureWidthFixedValue=void 0,this.FixedMeasureWidthUseForPickupMeasures=!1,this.MinimumCrossedBeamDifferenceMargin=1e-4,this.SheetMaximumWidth=32767,this.VoiceSpacingMultiplierVexflow=1,this.VoiceSpacingAddendVexflow=5,this.PickupMeasureWidthMultiplier=1,this.PickupMeasureRepetitionSpacing=.8,this.PickupMeasureSpacingSingleNoteAddend=1.6,this.DisplacedNoteMargin=.1,this.MinNoteDistance=2,this.SubMeasureXSpacingThreshold=35,this.MeasureDynamicsMaxScalingFactor=2.5,this.WholeRestXShiftVexflow=-1.5,this.MetronomeMarksDrawn=!0,this.MetronomeMarkXShift=-6,this.MetronomeMarkYShift=-1,this.SoftmaxFactorVexFlow=15,this.StaggerSameWholeNotes=!0,this.AlignRests=N.Never,this.RestCollisionYPadding=0,this.FillEmptyMeasuresWithWholeRest=C.No,this.ArpeggiosGoAcrossVoices=!1,this.RenderArpeggios=!0,this.RenderSlurs=!0,this.RenderGlissandi=!0,this.ColoringMode=fe.XML,this.ColoringEnabled=!0,this.ColorStemsLikeNoteheads=!1,this.ColorBeams=!0,this.ColorFlags=!0,this.applyDefaultColorMusic("#000000"),this.DefaultColorCursor="#33e02f",this.DefaultFontFamily="Times New Roman",this.DefaultFontStyle=me.Regular,this.DefaultVexFlowNoteFont="gonville",this.MaxMeasureToDrawIndex=Number.MAX_VALUE,this.MaxMeasureToDrawNumber=Number.MAX_VALUE,this.MinMeasureToDrawIndex=0,this.MinMeasureToDrawNumber=0,this.MaxSystemToDrawNumber=Number.MAX_VALUE,this.MaxPageToDrawNumber=Number.MAX_VALUE,this.RenderComposer=!0,this.RenderTitle=!0,this.RenderSubtitle=!0,this.RenderLyricist=!0,this.RenderCopyright=!1,this.RenderPartNames=!0,this.RenderPartAbbreviations=!0,this.RenderSystemLabelsAfterFirstPage=!0,this.RenderFingerings=!0,this.RenderMeasureNumbers=!0,this.RenderMeasureNumbersOnlyAtSystemStart=!1,this.UseXMLMeasureNumbers=!0,this.RenderLyrics=!0,this.RenderChordSymbols=!0,this.RenderMultipleRestMeasures=!0,this.AutoGenerateMultipleRestMeasuresFromRestMeasures=!0,this.RenderRehearsalMarks=!0,this.RenderClefsAtBeginningOfStaffline=!0,this.RenderKeySignatures=!0,this.RenderTimeSignatures=!0,this.RenderPedals=!0,this.RenderWavyLines=!0,this.ArticulationPlacementFromXML=!0,this.BreathMarkDistance=.8,this.FingeringPosition=d.AboveOrBelow,this.FingeringPositionFromXML=!0,this.FingeringPositionGrace=d.Left,this.FingeringInsideStafflines=!1,this.FingeringLabelFontHeight=1.7,this.FingeringOffsetX=0,this.FingeringOffsetY=0,this.FingeringPaddingY=-.2,this.FingeringTextSize=1.5,this.RenderStringNumbersClassical=!0,this.StringNumberOffsetY=0,this.NewSystemAtXMLNewSystemAttribute=!1,this.NewPageAtXMLNewPageAttribute=!1,this.NewSystemAtXMLNewPageAttribute=!1,this.RestoreCursorAfterRerender=!0,this.StretchLastSystemLine=!1,this.IgnoreBracketsWords=!0,this.PlaceWordsInsideStafflineFromXml=!1,this.PlaceWordsInsideStafflineYOffset=.9,this.UseJustifiedBuilder=!0,this.PageFormat=Te.UndefinedPageFormat,this.PageBackgroundColor=void 0,this.UsePageBackgroundColorForTabNotes=!0,this.PerformanceMode=!1,this.RenderSingleHorizontalStaffline=!1,this.SpacingBetweenTextLines=0,this.NoteToGraphicalNoteMap=new i,this.NoteToGraphicalNoteMapObjectCount=0,this.SkyBottomLineBatchMinMeasures=5,this.SkyBottomLineWebGLMinMeasures=80,this.AlwaysSetPreferredSkyBottomLineBackendAutomatically=!0,this.DisableWebGLInFirefox=!0,this.DisableWebGLInSafariAndIOS=!0,this.setPreferredSkyBottomLineBackendAutomatically();try{this.MaxInstructionsConstValue=this.ClefLeftMargin+this.ClefRightMargin+this.KeyRightMargin+this.RhythmRightMargin+11}catch(e){s.info("EngravingRules()",e)}this.MpatMode&&(this.NewPartAndSystemAfterFinalBarline=!0)}setPreferredSkyBottomLineBackendAutomatically(e=-1){let t="",i="";var s,n,r,o;"object"==typeof globalThis&&(t=null!==(s=null===(n=globalThis.navigator)||void 0===n?void 0:n.vendor)&&void 0!==s?s:"",i=null!==(r=null===(o=globalThis.navigator)||void 0===o?void 0:o.userAgent)&&void 0!==r?r:"");let a=!1;(this.DisableWebGLInSafariAndIOS&&/apple/i.test(t)||this.DisableWebGLInFirefox&&i.includes("Firefox"))&&(a=!0),this.PreferredSkyBottomLineBatchCalculatorBackend=D.Plain,a||e>=this.SkyBottomLineWebGLMinMeasures&&(this.PreferredSkyBottomLineBatchCalculatorBackend=D.WebGL)}applyDefaultColorMusic(e){this.DefaultColorMusic=e,this.DefaultColorNotehead=e,this.DefaultColorRest=e,this.DefaultColorStem=e,this.DefaultColorLabel=e,this.DefaultColorLyrics=e,this.DefaultColorTitle=e,this.LedgerLineColorDefault=e}addGraphicalNoteToNoteMap(e,t){e.NoteToGraphicalNoteObjectId=this.NoteToGraphicalNoteMapObjectCount,this.NoteToGraphicalNoteMap.setValue(e.NoteToGraphicalNoteObjectId,t),this.NoteToGraphicalNoteMapObjectCount++}GNote(e){return Ee.FromNote(e,this)}clearMusicSheetObjects(){this.NoteToGraphicalNoteMap=new i,this.NoteToGraphicalNoteMapObjectCount=0}resetChordAccidentalTexts(e,t){e.setValue(Y.SHARP,t?"♯":"#"),e.setValue(Y.FLAT,t?"♭":"b"),e.setValue(Y.DOUBLEFLAT,t?"𝄫":"bb"),e.setValue(Y.DOUBLESHARP,t?"𝄪":"x")}setChordSymbolLabelText(e,t){this.ChordSymbolLabelTexts.setValue(e,t)}resetChordSymbolLabelTexts(e){return e.setValue(Pe.minor,"m"),e.setValue(Pe.augmented,"aug"),e.setValue(Pe.diminished,"dim"),e.setValue(Pe.dominant,"7"),e.setValue(Pe.majorseventh,"maj7"),e.setValue(Pe.minorseventh,"m7"),e.setValue(Pe.diminishedseventh,"dim7"),e.setValue(Pe.augmentedseventh,"aug7"),e.setValue(Pe.halfdiminished,`m7${this.ChordAccidentalTexts.getValue(Y.FLAT)}5`),e.setValue(Pe.majorminor,"m(maj7)"),e.setValue(Pe.majorsixth,"maj6"),e.setValue(Pe.minorsixth,"m6"),e.setValue(Pe.dominantninth,"9"),e.setValue(Pe.majorninth,"maj9"),e.setValue(Pe.minorninth,"m9"),e.setValue(Pe.dominant11th,"11"),e.setValue(Pe.major11th,"maj11"),e.setValue(Pe.minor11th,"m11"),e.setValue(Pe.dominant13th,"13"),e.setValue(Pe.major13th,"maj13"),e.setValue(Pe.minor13th,"m13"),e.setValue(Pe.suspendedsecond,"sus2"),e.setValue(Pe.suspendedfourth,"sus4"),e.setValue(Pe.power,"5"),e.setValue(Pe.none,"N.C."),e}addChordName(e,t,i,s,n){if(void 0!==Pe[t]){const r={adds:i,alts:s,subs:n};this.CustomChords.push(Me.createCustomChord(e,Pe[t],r))}}renameChord(e,t){Me.renameCustomChord(e,t,this.CustomChords)}resetChordNames(){const e=this.ChordAccidentalTexts.getValue(Y.SHARP),t=this.ChordAccidentalTexts.getValue(Y.FLAT);this.addChordName("alt","major",[`${e}5`,`${t}9`,`${e}9`],[`${t}5`],[]),this.addChordName("7alt","dominant",[`${e}5`,`${t}9`,`${e}9`],[`${t}5`],[]),this.addChordName("7sus4","dominant",["4"],[],["3"]),this.addChordName("7sus4","suspendedfourth",["7"],[],[]),this.addChordName("9sus4","dominantninth",["4"],[],["3"]),this.addChordName("9sus4","suspendedfourth",["9"],[],[]),this.addChordName("11sus4","dominant11th",["4"],[],["3"]),this.addChordName("11sus4","suspendedfourth",["11"],[],[]),this.addChordName("13sus4","dominant13th",["4"],[],["3"]),this.addChordName("13sus4","suspendedfourth",["13"],[],[]),this.addChordName("7sus2","dominant",["2"],[],["3"]),this.addChordName("7sus2","suspendedsecond",["7"],[],[]),this.addChordName(`m7${t}5`,"minorseventh",[],[`${t}5`],[]),this.addChordName("9sus2","dominantninth",["2"],[],["3"]),this.addChordName("9sus2","suspendedsecond",["9"],[],[]),this.addChordName("11sus2","dominant11th",["2"],[],["3"]),this.addChordName("11sus2","suspendedsecond",["11"],[],[]),this.addChordName("13sus2","dominant13th",["2"],[],["3"]),this.addChordName("13sus2","suspendedsecond",["13"],[],[]),this.addChordName("m(maj9)","majorminor",["9"],[],[]),this.addChordName("m(maj11)","majorminor",["11"],[],[]),this.addChordName("m(maj13)","majorminor",["13"],[],[]),this.addChordName("69","majorsixth",["9"],[],[]),this.addChordName("mi69","minorsixth",["9"],[],[])}calculateCurveParametersArrays(){this.TPower3=new Array(this.BezierCurveStepSize),this.OneMinusTPower3=new Array(this.BezierCurveStepSize),this.FactorOne=new Array(this.BezierCurveStepSize),this.FactorTwo=new Array(this.BezierCurveStepSize);for(let e=0;e<this.BezierCurveStepSize;e++){const t=e/this.BezierCurveStepSize;this.TPower3[e]=Math.pow(t,3),this.OneMinusTPower3[e]=Math.pow(1-t,3),this.FactorOne[e]=3*Math.pow(1-t,2)*t,this.FactorTwo[e]=3*(1-t)*Math.pow(t,2)}}};let xe=Le;xe.unit=1;class Te{constructor(e,t,i="noIdStringGiven"){this.width=e,this.height=t,this.idString=i}get aspectRatio(){return this.IsUndefined?0:this.width/this.height}get IsUndefined(){return void 0===this.width||void 0===this.height||0===this.height||0===this.width}static get UndefinedPageFormat(){return new Te(0,0)}Equals(e){return!!e&&e.width===this.width&&e.height===this.height}}class we extends ne{constructor(e,t,i){super(),this.parentVoiceEntry=e,this.parentStaffEntry=t,this.PositionAndShape=new oe(this,t?t.PositionAndShape:void 0,!0),this.notes=[],this.rules=i||(t?t.parentMeasure.parentSourceMeasure.Rules:new xe)}sort(){return this.notes.sort(((e,t)=>{var i,s,n,r;return(null!==(i=null===(s=t.sourceNote.Pitch)||void 0===s?void 0:s.getHalfTone())&&void 0!==i?i:0)-(null!==(n=null===(r=e.sourceNote.Pitch)||void 0===r?void 0:r.getHalfTone())&&void 0!==n?n:0)})),this.notes}sortForVexflow(){return this.notes.sort(((e,t)=>{var i,s,n;return(null!==(i=null===(s=e.sourceNote.Pitch)||void 0===s?void 0:s.getHalfTone())&&void 0!==i?i:0)-(null!==(n=t.sourceNote.Pitch.getHalfTone())&&void 0!==n?n:0)})),this.notes}color(){}}class Ie{constructor(e,t){this.musicPages=[],this.measureList=[],this.verticalGraphicalStaffEntryContainers=[],this.cursors=[],this.leadSheet=!1,this.musicSheet=e,this.numberOfStaves=this.musicSheet.Staves.length,this.calculator=t,this.calculator.initialize(this)}get ParentMusicSheet(){return this.musicSheet}get GetCalculator(){return this.calculator}get JianpuKeySignature(){return this.jianpuKeySignature}set JianpuKeySignature(e){this.jianpuKeySignature=e}get MusicPages(){return this.musicPages}set MusicPages(e){this.musicPages=e}get MeasureList(){return this.measureList}set MeasureList(e){this.measureList=e}get VerticalGraphicalStaffEntryContainers(){return this.verticalGraphicalStaffEntryContainers}set VerticalGraphicalStaffEntryContainers(e){this.verticalGraphicalStaffEntryContainers=e}get Title(){return this.title}set Title(e){this.title=e}get Subtitle(){return this.subtitle}set Subtitle(e){this.subtitle=e}get Composer(){return this.composer}set Composer(e){this.composer=e}get Lyricist(){return this.lyricist}set Lyricist(e){this.lyricist=e}get Copyright(){return this.copyright}set Copyright(e){this.copyright=e}get Cursors(){return this.cursors}get SelectionStartSymbol(){return this.selectionStartSymbol}get SelectionEndSymbol(){return this.selectionEndSymbol}get MinAllowedSystemWidth(){return this.minAllowedSystemWidth}set MinAllowedSystemWidth(e){this.minAllowedSystemWidth=e}get NumberOfStaves(){return this.numberOfStaves}get LeadSheet(){return this.leadSheet}set LeadSheet(e){this.leadSheet=e}static transformRelativeToAbsolutePosition(e){for(let t=0;t<e.MusicPages.length;t++){const i=e.MusicPages[t].setMusicPageAbsolutePosition(t,e.ParentMusicSheet.Rules);e.MusicPages[t].PositionAndShape.calculateAbsolutePositionsRecursive(i.x,i.y)}}Initialize(){this.verticalGraphicalStaffEntryContainers=[],this.musicPages=[],this.measureList=[]}reCalculate(){this.calculator.calculate()}EnforceRedrawOfMusicSystems(){for(let e=0,t=this.musicPages.length;e<t;++e){const t=this.musicPages[e];for(let e=0,i=t.MusicSystems.length;e<i;++e)t.MusicSystems[e].needsToBeRedrawn=!0}}getClickedObject(e){for(let t=0,i=this.MusicPages.length;t<i;++t)return this.MusicPages[t].PositionAndShape.getClickedObjectOfType(e)}findGraphicalMeasure(e,t){for(let s=e;s>=0;s--){var i;const e=null===(i=this.measureList[s])||void 0===i?void 0:i[t];if(e)return e}}findGraphicalMeasureByMeasureNumber(e,t){for(let i=e;i>=0;i--)if(this.MeasureList[i]){const s=this.MeasureList[i][t];if((null==s?void 0:s.MeasureNumber)===e)return s}}findGraphicalStaffEntryFromMeasureList(e,t,i){for(let s=t;s<this.measureList.length;s++){const t=this.measureList[s][e];if(t)for(let e=0,s=t.staffEntries.length;e<s;++e){const s=t.staffEntries[e];if(s.sourceStaffEntry===i)return s}}}findNextGraphicalStaffEntry(e,t,i){const s=i.parentMeasure,n=s.staffEntries.indexOf(i);if(n<s.staffEntries.length-1)return s.staffEntries[n+1];if(t<this.measureList.length-1){const i=this.measureList[t+1][e];if(i.staffEntries.length>0)return i.staffEntries[0]}}getFirstVisibleMeasuresListFromIndices(e,t){const i=[],s=this.measureList[0].length;for(let n=e;n<=t;n++)for(let e=0;e<s;e++)if(this.measureList[n][e].isVisible()){i.push(this.measureList[n][e]);break}return i}orderMeasuresByStaffLine(e){const t=[];let i=[];t.push(i);for(let s=0;s<e.length;s++)0===s?i.push(e[0]):(e[s].ParentStaffLine===e[s-1].ParentStaffLine||(-1===t.indexOf(i)&&t.push(i),i=[],t.push(i)),i.push(e[s]));return t}initializeActiveClefs(){const e=[],t=this.musicSheet.getFirstSourceMeasure();if(t)for(let i=0;i<t.CompleteNumberOfStaves;i++){let s=new J;if(t.FirstInstructionsStaffEntries[i])for(let e=0,n=t.FirstInstructionsStaffEntries[i].Instructions.length;e<n;++e){const n=t.FirstInstructionsStaffEntries[i].Instructions[e];n instanceof J&&(s=n)}e.push(s)}return e}GetMainKey(){const e=this.musicSheet.getFirstSourceMeasure();if(e)for(let t=0;t<e.CompleteNumberOfStaves;t++)for(let i=0,s=e.FirstInstructionsStaffEntries[t].Instructions.length;i<s;++i){const s=e.FirstInstructionsStaffEntries[t].Instructions[i];if(s instanceof Z)return s}}getOrCreateVerticalContainer(e){if(0===this.verticalGraphicalStaffEntryContainers.length||le.getLastElement(this.verticalGraphicalStaffEntryContainers).AbsoluteTimestamp.lt(e)){const t=new F(this.numberOfStaves,e);return this.verticalGraphicalStaffEntryContainers.push(t),t}for(let t=this.verticalGraphicalStaffEntryContainers.length-1;t>=0;t--){if(this.verticalGraphicalStaffEntryContainers[t].AbsoluteTimestamp.lt(e)){const i=new F(this.numberOfStaves,e);return this.verticalGraphicalStaffEntryContainers.splice(t+1,0,i),i}if(this.verticalGraphicalStaffEntryContainers[t].AbsoluteTimestamp.Equals(e))return this.verticalGraphicalStaffEntryContainers[t]}}GetVerticalContainerFromTimestamp(e,t=0){const i=le.binarySearch(this.verticalGraphicalStaffEntryContainers,new F(0,e),F.compareByTimestamp,t);if(i>=0)return this.verticalGraphicalStaffEntryContainers[i]}GetInterpolatedIndexInVerticalContainers(e){const t=this.verticalGraphicalStaffEntryContainers;if(1===t.length)return 0;let i,s,n=0,r=t.length-1;if(e.lte(t[t.length-1].AbsoluteTimestamp)){for(;r-n>1;){const i=Math.floor((r+n)/2);if(t[n].AbsoluteTimestamp.Equals(e)){r=n;break}if(t[r].AbsoluteTimestamp.Equals(e)){n=r;break}if(t[i].AbsoluteTimestamp.Equals(e))return this.verticalGraphicalStaffEntryContainers.indexOf(t[i]);e.lt(t[i].AbsoluteTimestamp)?r=i:n=i}if(n===r)return this.verticalGraphicalStaffEntryContainers.indexOf(t[n]);i=t[n].AbsoluteTimestamp,s=t[r].AbsoluteTimestamp}else i=t[t.length-1].AbsoluteTimestamp,s=u.plus(this.getLongestStaffEntryDuration(t.length-1),i),r=t.length;const o=s.RealValue-i.RealValue,a=r-(s.RealValue-e.RealValue)/o;return Math.min(a,this.verticalGraphicalStaffEntryContainers.length-1)}getVisibleStavesIndicesFromSourceMeasure(e){const t=[],i=[];for(let s=0,n=e.length;s<n;++s){const i=e[s].ParentStaff.ParentInstrument;-1===t.indexOf(i)&&t.push(i)}for(let s=0,n=t.length;s<n;++s){const e=t[s],n=this.musicSheet.getGlobalStaffIndexOfFirstStaff(e);for(let t=0;t<e.Staves.length;t++)i.push(n+t)}return i}getGraphicalMeasureFromSourceMeasureAndIndex(e,t){for(let s=0;s<this.measureList.length;s++){var i;if((null===(i=this.measureList[s][0])||void 0===i?void 0:i.parentSourceMeasure)===e)return this.measureList[s][t]}}getLastGraphicalMeasureFromIndex(e,t=!0){let i=this.measureList.length-1;t&&(i=Math.min(i,this.musicSheet.Rules.MaxMeasureToDrawIndex));let s=this.measureList[i][e];for(;!s&&i>=0;)s=this.measureList[--i][e];return this.measureList[i][e]}getMeasureIndex(e,t,i){for(t=0;t<this.measureList.length;t++)for(let i=0,s=this.measureList[t].length;i<s;++i)if(this.measureList[t][i]===e)return!0;return!1}GetNearestGraphicalObject(e,t=ne.name,i=5,s=20,n=5,r=void 0){const o=[];for(;0===o.length&&i<=s;){const s=new oe(void 0);s.BorderLeft=e.x-i,s.BorderTop=e.y-i,s.BorderRight=e.x+i,s.BorderBottom=e.y+i,s.AbsolutePosition=new z(e.x,e.y),s.calculateAbsolutePosition();for(let e=0,i=this.MusicPages.length;e<i;++e){const i=this.MusicPages[e].PositionAndShape.getObjectsInRegion(s,!1,t);if(i&&0!==i.length)for(let e=0,t=i.length;e<t;++e)r?r(i[e])&&o.push(i[e]):o.push(i[e])}i+=n}let a;for(let l=0,h=o.length;l<h;++l){const t=o[l];(void 0===a||this.CalculateDistance(t.PositionAndShape.AbsolutePosition,e)<this.CalculateDistance(a.PositionAndShape.AbsolutePosition,e))&&(a=t)}if(a)return a}GetNearestVoiceEntry(e){return this.GetNearestGraphicalObject(e,we.name,5,20,5,(e=>{var t;return void 0!==(null===(t=e.parentStaffEntry)||void 0===t?void 0:t.relInMeasureTimestamp)}))}GetNearestNote(e,t){const i=this.GetNearestVoiceEntry(e);if(!i)return;let s,n=Number.MAX_SAFE_INTEGER;for(const r of i.notes){const t=r.PositionAndShape.AbsolutePosition.y,i=Math.abs(r.PositionAndShape.AbsolutePosition.x-e.x),o=Math.abs(t-e.y);i+o<n&&(s=r,n=i+o)}return s}domToSvg(e){return this.domToSvgTransform(e,!0)}svgToDom(e){return this.domToSvgTransform(e,!1)}svgToOsmd(e){const t=new z(e.x,e.y);return t.x/=10,t.y/=10,t}domToSvgTransform(e,t){const i=this.drawer.Backends[0].getSvgElement(),s=i.createSVGPoint();s.x=e.x,s.y=e.y;let n=i.getScreenCTM();t&&(n=n.inverse());const r=s.matrixTransform(n);return new z(r.x,r.y)}GetClickableLabel(e){const t=new oe;t.BorderLeft=e.x-4,t.BorderTop=e.y-4,t.BorderRight=e.x+4,t.BorderBottom=e.y+4,t.AbsolutePosition=new z(0,0);for(let i=0,s=this.MusicPages.length;i<s;++i){const e=this.MusicPages[i].PositionAndShape.getObjectsInRegion(t);if(1===e.length)for(let t=0,i=e.length;t<i;++t)return e[t]}}GetNearestObject(e,t){const i=[],s=new oe(void 0);s.BorderLeft=e.x-10,s.BorderTop=e.y-10,s.BorderRight=e.x+10,s.BorderBottom=e.y+10,s.AbsolutePosition=new z(0,0);for(let r=0,o=this.MusicPages.length;r<o;++r){const e=this.MusicPages[r].PositionAndShape.getObjectsInRegion(s,!1,t);if(e&&0!==e.length)for(let t=0,s=e.length;t<s;++t){const s=e[t];i.push(s)}}let n;for(let r=0,o=i.length;r<o;++r){const t=i[r];(void 0===n||this.CalculateDistance(t.PositionAndShape.AbsolutePosition,e)<this.CalculateDistance(n.PositionAndShape.AbsolutePosition,e))&&(n=t)}if(n)return n}GetPossibleCommentAnchor(e){const t=this.GetNearestVoiceEntry(e);if(t)return t.parentStaffEntry.sourceStaffEntry}GetClickedObjectOfType(e){for(let t=0,i=this.musicPages.length;t<i;++t){const i=this.musicPages[t].PositionAndShape.getClickedObjectOfType(e);if(i)return i}}GetClickedClickable(e){for(let t=0,i=this.musicPages.length;t<i;++t){const i=this.musicPages[t].PositionAndShape.getClickedClickable(e);if(i&&i instanceof re)return i}}tryGetTimestampFromPosition(e){const t=this.GetClickedObjectOfType(e);if(t)return t.getAbsoluteTimestamp()}tryGetClickableLabel(e){try{return this.GetClickableLabel(e)}catch(t){s.info("GraphicalMusicSheet.tryGetClickableObject","positionOnMusicSheet: "+e,t)}}tryGetTimeStampFromPosition(e){try{const t=this.GetNearestVoiceEntry(e);if(!t)return;return t.parentStaffEntry.getAbsoluteTimestamp()}catch(t){s.info("GraphicalMusicSheet.tryGetTimeStampFromPosition","positionOnMusicSheet: "+e,t)}}getStaffEntry(e){const t=this.VerticalGraphicalStaffEntryContainers[e];let i;try{for(let e=0,s=t.StaffEntries.length;e<s;++e){const s=t.StaffEntries[e];s&&s.sourceStaffEntry.ParentStaff.ParentInstrument.Visible&&(i?s.PositionAndShape&&i.PositionAndShape&&i.PositionAndShape.RelativePosition.x>s.PositionAndShape.RelativePosition.x&&(i=s):i=s)}}catch(n){s.info("GraphicalMusicSheet.getStaffEntry",n)}return i}GetPreviousVisibleContainerIndex(e){for(let t=e-1;t>=0;t--){const e=this.verticalGraphicalStaffEntryContainers[t].StaffEntries;for(let i=0,s=e.length;i<s;++i){const s=e[i];if(s&&s.sourceStaffEntry.ParentStaff.ParentInstrument.Visible)return t}}return-1}GetNextVisibleContainerIndex(e){for(let t=e+1;t<this.verticalGraphicalStaffEntryContainers.length;++t){const e=this.verticalGraphicalStaffEntryContainers[t].StaffEntries;for(let i=0,s=e.length;i<s;++i){const s=e[i];if(s&&s.sourceStaffEntry.ParentStaff.ParentInstrument.Visible)return t}}return-1}findClosestLeftStaffEntry(e,t){let i,s=Math.floor(e);s=Math.min(this.VerticalGraphicalStaffEntryContainers.length-1,s);for(let n=s;n>=0;n--)if(i=this.getStaffEntry(n),i){if(!t)return i;if(i.sourceStaffEntry.ParentStaff.ParentInstrument.Visible)return i}}findClosestRightStaffEntry(e,t){let i;for(let s=Math.max(0,Math.ceil(e));s<this.VerticalGraphicalStaffEntryContainers.length;s++)if(i=this.getStaffEntry(s),i){if(!t)return i;if(i.sourceStaffEntry.ParentStaff.ParentInstrument.Visible)return i}}calculateCursorLineAtTimestamp(e,t){const i=this.calculateXPositionFromTimestamp(e),s=i[0],n=i[1];if(!n||0===n.StaffLines.length)return;const r=n.PositionAndShape.AbsolutePosition.y,o=le.last(n.StaffLines).PositionAndShape.RelativePosition.y+4;return new X(new z(s,r),new z(s,r+o),3,t)}calculateXPositionFromTimestamp(e){let t;const i=this.GetInterpolatedIndexInVerticalContainers(e),s=this.findClosestLeftStaffEntry(i,!0),n=this.findClosestRightStaffEntry(i,!0),r=e.RealValue;if(!s&&!n)return[0,void 0,void 0];let o;var a,l;let h;var c,d;let f;if(o=s?null===(a=s.parentMeasure.ParentStaffLine)||void 0===a?void 0:a.ParentMusicSystem:null===(l=n.parentMeasure.ParentStaffLine)||void 0===l?void 0:l.ParentMusicSystem,h=n?null===(c=n.parentMeasure.ParentStaffLine)||void 0===c?void 0:c.ParentMusicSystem:null===(d=s.parentMeasure.ParentStaffLine)||void 0===d?void 0:d.ParentMusicSystem,o===h){var m;let e,i,a;t=o;let l=0;if(s)if(n){i=s.PositionAndShape.AbsolutePosition.x,a=n.PositionAndShape.AbsolutePosition.x,f=s.parentMeasure.parentSourceMeasure,e=s===n?0:(r-s.getAbsoluteTimestamp().RealValue)/(n.getAbsoluteTimestamp().RealValue-s.getAbsoluteTimestamp().RealValue);const t=s.parentMeasure,o=s.parentMeasure.parentSourceMeasure.multipleRestMeasures,h=t.MeasureNumber/(o+1),u=t.PositionAndShape.Size.width-t.beginInstructionsWidth;l=t.PositionAndShape.AbsolutePosition.x+t.beginInstructionsWidth+h*u}else i=s.PositionAndShape.AbsolutePosition.x,a=t.GetRightBorderAbsoluteXPosition(),f=s.parentMeasure.parentSourceMeasure,e=(r-s.getAbsoluteTimestamp().RealValue)/(u.plus(f.AbsoluteTimestamp,f.Duration).RealValue-s.getAbsoluteTimestamp().RealValue);else i=a=n.PositionAndShape.AbsolutePosition.x,e=0;e=Math.min(1,Math.max(0,e));let h=a;return null!==(m=f)&&void 0!==m&&m.Rules.LimitCursorPositionToCurrentMeasure&&(h=Math.min(s.parentMeasure.PositionAndShape.AbsolutePosition.x+s.parentMeasure.PositionAndShape.BorderRight,h)),l&&1===s.parentMeasure.MeasureNumber?[l,t,s]:[i+e*(h-i),t,s]}{const e=n.parentMeasure.parentSourceMeasure.AbsoluteTimestamp.RealValue;let i,a;if(r<e&&o.StaffLines[0]){t=o;const n=s.PositionAndShape.AbsolutePosition.x,l=t.GetRightBorderAbsoluteXPosition();i=(r-s.getAbsoluteTimestamp().RealValue)/(e-s.getAbsoluteTimestamp().RealValue),i=Math.min(1,Math.max(0,i)),a=n+i*(l-n)}else{t=h;const s=n.PositionAndShape.AbsolutePosition.x,o=t.GetLeftBorderAbsoluteXPosition();i=(r-e)/(n.getAbsoluteTimestamp().RealValue-e),i=Math.min(1,Math.max(0,i)),a=o+i*(s-o)}return[a,t,s]}}calculateCursorPoints(e,t){if(void 0===t||0===t.StaffLines.length)return[new z,new z];const i=t.PositionAndShape.AbsolutePosition.y,s=t.StaffLines.last(),n=s.PositionAndShape.RelativePosition.y+s.StaffHeight;return[new z(e,i),new z(e,i+n)]}GetNumberOfVisibleInstruments(){let e=0;for(let t=0,i=this.musicSheet.Instruments.length;t<i;++t)!0===this.musicSheet.Instruments[t].Visible&&e++;return e}GetNumberOfFollowedInstruments(){let e=0;for(let t=0,i=this.musicSheet.Instruments.length;t<i;++t)!0===this.musicSheet.Instruments[t].Following&&e++;return e}GetGraphicalFromSourceStaffEntry(e){var t;if(null===(t=e.VerticalContainerParent.ParentMeasure)||void 0===t||!t.VerticalMeasureList)return;const i=e.VerticalContainerParent.ParentMeasure.VerticalMeasureList[e.ParentStaff.idInMusicSheet];return null==i?void 0:i.findGraphicalStaffEntryFromTimestamp(e.Timestamp)}CalculateDistance(e,t){const i=e.x-t.x,s=e.y-t.y;return i*i+s*s}getLongestStaffEntryDuration(e){let t=new u(0,1);for(const i of this.verticalGraphicalStaffEntryContainers[e].StaffEntries){if(!i)continue;const e=i.findStaffEntryMaxNoteLength();t.lt(e)&&(t=e)}return t}}class Ae{constructor(e,t,i,s,n,r){this.slurs=[],this.playbackInstrumentId=void 0,this.notehead=void 0,this.printObject=!0,this.voiceEntry=e,this.parentStaffEntry=t,this.length=i,this.pitch=s,this.sourceMeasure=n,this.isRestFlag=null!=r&&r,this.noteTremoloType="",this.glissandoType="",this.slideType="",this.halfTone=s?s.getHalfTone():0}get NoteAsString(){return this.pitch.toString()}ToStringShort(e=0){var t;return!this.Pitch||this.isRest()?"rest":null===(t=this.Pitch)||void 0===t?void 0:t.ToStringShort(e)}get ToStringShortGet(){return this.ToStringShort(0)}get TremoloType(){return this.noteTremoloType}set TremoloType(e){this.noteTremoloType=e}get ParentVoiceEntry(){return this.voiceEntry}set ParentVoiceEntry(e){this.voiceEntry=e}get ParentStaffEntry(){return this.parentStaffEntry}get ParentStaff(){return this.parentStaffEntry.ParentStaff}get Length(){return this.length}set PlaybackNote(e){this.playbackNote=e}get PlaybackNote(){return this.playbackNote}set Length(e){this.length=e}get SourceMeasure(){return this.sourceMeasure}get TypeLength(){return this.typeLength}set TypeLength(e){this.typeLength=e}get NoteTypeXml(){return this.noteTypeXml}set NoteTypeXml(e){this.noteTypeXml=e}get NormalNotes(){return this.normalNotes}set NormalNotes(e){this.normalNotes=e}get Pitch(){return this.pitch}get NoteBeam(){return this.beam}set NoteBeam(e){this.beam=e}set Notehead(e){this.notehead=e}get Notehead(){return this.notehead}get NoteTuplet(){return this.tuplet}set NoteTuplet(e){this.tuplet=e}get NoteGlissando(){return this.glissando}set NoteGlissando(e){this.glissando=e}get NoteTie(){return this.tie}set NoteTie(e){this.tie=e}get NoteSlurs(){return this.slurs}set NoteSlurs(e){this.slurs=e}get PlaybackInstrumentId(){return this.playbackInstrumentId}set PlaybackInstrumentId(e){this.playbackInstrumentId=e}get PrintObject(){return this.printObject}set PrintObject(e){this.printObject=e}get Arpeggio(){return this.arpeggio}set Arpeggio(e){this.arpeggio=e}get IsCueNote(){return this.isCueNote}set IsCueNote(e){this.isCueNote=e}get StemDirectionXml(){return this.stemDirectionXml}set StemDirectionXml(e){this.stemDirectionXml=e}get TremoloStrokes(){var e;return null===(e=this.TremoloInfo)||void 0===e?void 0:e.tremoloStrokes}get StemColorXml(){return this.stemColorXml}set StemColorXml(e){this.stemColorXml=e}get NoteheadColorXml(){return this.noteheadColorXml}set NoteheadColorXml(e){this.noteheadColorXml=e}get NoteheadColor(){return this.noteheadColor}set NoteheadColor(e){this.noteheadColor=e}get NoteheadColorCurrentlyRendered(){return this.noteheadColorCurrentlyRendered}set NoteheadColorCurrentlyRendered(e){this.noteheadColorCurrentlyRendered=e}isRest(){return this.isRestFlag}isWholeRest(){return this.isRest()&&this.Length.RealValue===this.sourceMeasure.ActiveTimeSignature.RealValue}isWholeMeasureNote(){return this.Length.RealValue===this.sourceMeasure.ActiveTimeSignature.RealValue}ToString(){return this.pitch?this.Pitch.ToString()+", length: "+this.length.toString():"rest note, length: "+this.length.toString()}getAbsoluteTimestamp(){return u.plus(this.voiceEntry.Timestamp,this.sourceMeasure.AbsoluteTimestamp)}isDuplicateSlur(e){for(let t=0,i=this.slurs.length;t<i;++t){const i=this.slurs[t];if(void 0!==i.StartNote&&void 0!==i.EndNote&&void 0!==e.StartNote&&e.StartNote===i.StartNote&&i.EndNote===this&&e.PlacementXml===i.PlacementXml)return!0}return!1}hasTabEffects(){return!1}}class Re extends ne{constructor(e=void 0,t=void 0,i=void 0){super(),this.hasOnlyRests=!1,this.measureNumber=-1,this.ShowTimeSignature=!0,this.ShowKeySignature=!0,this.isTabMeasure=!1,this.parentStaff=e,this.parentSourceMeasure=t,this.parentStaffLine=i,i?(this.parentStaff=i.ParentStaff,this.PositionAndShape=new oe(this,i.PositionAndShape)):this.PositionAndShape=new oe(this),this.PositionAndShape.BorderBottom=4,this.parentSourceMeasure&&(this.measureNumber=this.parentSourceMeasure.MeasureNumber),this.staffEntries=[]}get ParentStaff(){return this.parentStaff}get ParentMusicSystem(){return this.parentMusicSystem}set ParentMusicSystem(e){this.parentMusicSystem=e}get MeasureNumber(){return this.measureNumber}get FirstInstructionStaffEntry(){return this.firstInstructionStaffEntry}set FirstInstructionStaffEntry(e){this.firstInstructionStaffEntry=e}get LastInstructionStaffEntry(){return this.lastInstructionStaffEntry}set LastInstructionStaffEntry(e){this.lastInstructionStaffEntry=e}get ParentStaffLine(){return this.parentStaffLine}set ParentStaffLine(e){this.parentStaffLine=e,this.parentStaffLine&&(this.PositionAndShape.Parent=this.parentStaffLine.PositionAndShape)}resetLayout(){throw new Error("not implemented")}getLineWidth(e){throw new Error("not implemented")}addClefAtBegin(e){throw new Error("not implemented")}addKeyAtBegin(e,t,i){throw new Error("not implemented")}addRhythmAtBegin(e,t){throw new Error("not implemented")}addClefAtEnd(e,t=!0){throw new Error("not implemented")}setPositionInStaffline(e){this.PositionAndShape.RelativePosition=new z(e,0)}setWidth(e){this.PositionAndShape.BorderRight=e}layoutSymbols(){throw new Error("not implemented")}findGraphicalStaffEntryFromTimestamp(e){for(let i=0,s=this.staffEntries.length;i<s;++i){var t;const s=this.staffEntries[i];if(null!==(t=s.relInMeasureTimestamp)&&void 0!==t&&t.Equals(e))return s}}findGraphicalStaffEntryFromVerticalContainerTimestamp(e){for(let t=0,i=this.staffEntries.length;t<i;++t){const i=this.staffEntries[t];if(i.sourceStaffEntry.VerticalContainerParent.getAbsoluteTimestamp().Equals(e))return i}}hasSameDurationWithSourceMeasureParent(){const e=new u(0,1);for(let t=0,i=this.staffEntries.length;t<i;++t){const i=this.staffEntries[t];e.Add(i.findStaffEntryMinNoteLength())}return e.Equals(this.parentSourceMeasure.Duration)}hasMultipleVoices(){if(0===this.staffEntries.length)return!1;const e=[];for(let t=0,i=this.staffEntries.length;t<i;++t){const i=this.staffEntries[t];for(let t=0,s=i.sourceStaffEntry.VoiceEntries.length;t<s;++t){const s=i.sourceStaffEntry.VoiceEntries[t];e.indexOf(s.ParentVoice)<0&&e.push(s.ParentVoice)}}return e.length>1}isVisible(){return this.ParentStaff.ParentInstrument.Visible}getGraphicalMeasureDurationFromStaffEntries(){let e=new u(0,1);const t=[];for(let i=0,s=this.staffEntries.length;i<s;++i){const e=this.staffEntries[i];for(let i=0,s=e.sourceStaffEntry.VoiceEntries.length;i<s;++i){const s=e.sourceStaffEntry.VoiceEntries[i];t.indexOf(s.ParentVoice)<0&&t.push(s.ParentVoice)}}for(let i=0,s=t.length;i<s;++i){const s=t[i],n=new u(0,1);for(const e of this.staffEntries)for(const t of e.graphicalVoiceEntries)t.parentVoiceEntry.ParentVoice===s&&t.notes.length>0&&n.Add(t.notes[0].graphicalNoteLength);e.lt(n)&&(e=u.createFromFraction(n))}return e}addGraphicalStaffEntry(e){this.staffEntries.push(e)}addGraphicalStaffEntryAtTimestamp(e){if(e)if(0===this.staffEntries.length||this.staffEntries[this.staffEntries.length-1].relInMeasureTimestamp.lt(e.relInMeasureTimestamp))this.staffEntries.push(e);else for(let t=this.staffEntries.length-1;t>=0;t--){if(this.staffEntries[t].relInMeasureTimestamp.lt(e.relInMeasureTimestamp)){this.staffEntries.splice(t+1,0,e);break}0===t&&this.staffEntries.splice(t,0,e)}}isPianoRightHand(){return this.isUpperStaffOfInstrument()}isPianoLeftHand(){return this.isLowerStaffOfInstrument()}isUpperStaffOfInstrument(){return 1===this.parentStaff.ParentInstrument.Staves.length||this.ParentStaff===this.parentStaff.ParentInstrument.Staves[0]}isLowerStaffOfInstrument(){return 1!==this.parentStaff.ParentInstrument.Staves.length&&this.ParentStaff===this.ParentStaff.ParentInstrument.Staves.last()}beginsWithLineRepetition(){const e=this.parentSourceMeasure;return!!e&&e.beginsWithLineRepetition()}endsWithLineRepetition(){const e=this.parentSourceMeasure;return!!e&&e.endsWithLineRepetition()}beginsWithWordRepetition(){const e=this.parentSourceMeasure;return!!e&&e.beginsWithWordRepetition()}endsWithWordRepetition(){const e=this.parentSourceMeasure;return!!e&&e.endsWithWordRepetition()}getTransposedHalftones(){return this.parentStaff.ParentInstrument.GetMusicSheet.Transpose+this.parentStaff.ParentInstrument.Transpose}}var Ne=(e=>(e[e.SingleThin=0]="SingleThin",e[e.DoubleThin=1]="DoubleThin",e[e.ThinBold=2]="ThinBold",e[e.BoldThinDots=3]="BoldThinDots",e[e.DotsThinBold=4]="DotsThinBold",e[e.DotsBoldBoldDots=5]="DotsBoldBoldDots",e[e.None=6]="None",e[e.Dotted=7]="Dotted",e[e.Dashed=8]="Dashed",e[e.Bold=9]="Bold",e[e.BoldThin=10]="BoldThin",e[e.DoubleBold=11]="DoubleBold",e[e.Tick=12]="Tick",e[e.Short=13]="Short",e))(Ne||{});class Ce{static xmlBarlineStyleToSystemLinesEnum(e){return"regular"===e?0:"dotted"===e?7:"dashed"===e?8:"heavy"===e?9:"light-light"===e?1:"light-heavy"===e?2:"heavy-light"===e?10:"heavy-heavy"===e?11:"tick"===e?12:"short"===e?13:"none"===e?6:0}}class Be{constructor(){this.matrix=[];for(let e=0;e<2;e++){this.matrix[e]=[];for(let t=0;t<2;t++)this.matrix[e][t]=0}}static getRotationMatrix(e){const t=new Be,i=Math.cos(e),s=Math.sin(e);return t.matrix[0][0]=i,t.matrix[0][1]=-s,t.matrix[1][0]=s,t.matrix[1][1]=i,t}scalarMultiplication(e){for(let t=0;t<2;t++)for(let i=0;i<2;i++)this.matrix[t][i]*=e}getTransposeMatrix(){const e=new Be;for(let t=0;t<2;t++)for(let i=0;i<2;i++)e.matrix[t][i]=this.matrix[i][t];return e}vectorMultiplication(e){const t=new z;return t.x=e.x*this.matrix[0][0]+e.y*this.matrix[0][1],t.y=e.x*this.matrix[1][0]+e.y*this.matrix[1][1],t}}class De{constructor(){this.measureErrors={},this.errors=[],this.tempErrors=[]}finalizeMeasure(e){let t=this.measureErrors[e];t||(t=[]),this.measureErrors[e]=t.concat(this.tempErrors),this.tempErrors=[]}pushMeasureError(e){this.tempErrors.push(e)}push(e){this.errors.push(e)}}class Ve{constructor(e,t=7){this.parentVoiceEntry=e,this.type=t,this.notes=[]}addNote(e){this.notes.push(e),e.Arpeggio=this}}var ke=(e=>(e[e.BRUSH_DOWN=1]="BRUSH_DOWN",e[e.BRUSH_UP=2]="BRUSH_UP",e[e.ROLL_DOWN=3]="ROLL_DOWN",e[e.ROLL_UP=4]="ROLL_UP",e[e.RASQUEDO_DOWN=5]="RASQUEDO_DOWN",e[e.RASQUEDO_UP=6]="RASQUEDO_UP",e[e.ARPEGGIO_DIRECTIONLESS=7]="ARPEGGIO_DIRECTIONLESS",e))(ke||{});class Fe{constructor(e=1,t=0){this.notes=[],this.extendedNoteList=[],this.BeamNumberOffsetToXML=0,this.AutoGenerated=!1,this.BeamNumber=e,this.BeamNumberOffsetToXML=t}get Notes(){return this.notes}set Notes(e){this.notes=e}get ExtendedNoteList(){return this.extendedNoteList}set ExtendedNoteList(e){this.extendedNoteList=e}addNoteToBeam(e){e&&(e.NoteBeam=this,this.notes.push(e),this.extendedNoteList.push(e))}}class Oe{constructor(e){this.notes=[],this.XMLNumber=1,this.AddNote(e),this.StartNote=e,this.Direction=ae.NotYetDefined}get Notes(){return this.notes}get Duration(){const e=new u;for(const t of this.notes)e.Add(t.Length);return e}get Pitch(){return this.StartNote.Pitch}AddNote(e){this.notes.push(e),e.NoteGlissando=this,2===this.notes.length&&(this.notes[0].Pitch.getHalfTone()<this.notes[1].Pitch.getHalfTone()?this.Direction=ae.Up:this.Direction=ae.Down)}}class _e{constructor(e,t){this.voiceEntries=[],this.volume=1,this.parent=e,this.visible=!0,this.audible=!0,this.following=!0,this.voiceId=t,this.uniqueVoiceId="I:"+this.parent.Id+" V: "+this.voiceId}get VoiceEntries(){return this.voiceEntries}get Parent(){return this.parent}get Visible(){return this.visible}set Visible(e){this.visible=e}get Audible(){return this.audible}set Audible(e){this.audible=e}get Following(){return this.following}set Following(e){this.following=e}get Solo(){return this.solo}set Solo(e){this.solo=e}get VoiceId(){return this.voiceId}get Volume(){return this.volume}set Volume(e){this.volume=e}toString(){return this.uniqueVoiceId}}class Ge extends _e{constructor(e,t,i){super(e,t),this.master=i}get Master(){return this.master}}class We{constructor(e,t,i=void 0){this.sourceNote=e,this.setShapeFromXml(t,i)}setShapeFromXml(e,t=void 0){this.shape=We.ShapeTypeXmlToShape(e);let i=t;void 0===i&&(this.sourceNote?i=this.sourceNote.Length.Denominator>2:(s.warn("notehead: sourceNote and filledXmlAttribute undefined."),i=!0)),this.filled=i}get SourceNote(){return this.sourceNote}get Shape(){return this.shape}get Filled(){return this.filled}static ShapeTypeXmlToShape(e){switch(e.toLowerCase()){case"normal":return 2;case"x":return 8;case"slash":return 4;case"diamond":return 1;case"square":case"la":return 5;case"do":case"triangle":return 6;case"inverted triangle":return 7;case"rectangle":return 3;case"circle-x":return 0;default:return s.info("unsupported/unhandled xml notehead '"+e+"'. Using normal notehead."),2}}}var Ue=(e=>(e[e.CIRCLEX=0]="CIRCLEX",e[e.DIAMOND=1]="DIAMOND",e[e.NORMAL=2]="NORMAL",e[e.RECTANGLE=3]="RECTANGLE",e[e.SLASH=4]="SLASH",e[e.SQUARE=5]="SQUARE",e[e.TRIANGLE=6]="TRIANGLE",e[e.TRIANGLE_INVERTED=7]="TRIANGLE_INVERTED",e[e.X=8]="X",e))(Ue||{});class Xe{static translateText(e,t){if(!this.defaultTextTranslation)return t}}var ze=(e=>(e[e.UNDEFINED=0]="UNDEFINED",e[e._1024th=1]="_1024th",e[e._512th=2]="_512th",e[e._256th=3]="_256th",e[e._128th=4]="_128th",e[e._64th=5]="_64th",e[e._32nd=6]="_32nd",e[e._16th=7]="_16th",e[e.EIGTH=8]="EIGTH",e[e.QUARTER=9]="QUARTER",e[e.HALF=10]="HALF",e[e.WHOLE=11]="WHOLE",e[e.BREVE=12]="BREVE",e[e.LONG=13]="LONG",e[e.MAXIMA=14]="MAXIMA",e))(ze||{});class He{static NoteTypeToString(e){return this.NoteTypeXmlValues[e]}static StringToNoteType(e){const t=this.NoteTypeXmlValues.indexOf(e);return-1!==t?t:0}static getNoteDurationFromType(e){switch(e){case"1024th":return new u(1,1024);case"512th":return new u(1,512);case"256th":return new u(1,256);case"128th":return new u(1,128);case"64th":return new u(1,64);case"32th":case"32nd":return new u(1,32);case"16th":return new u(1,16);case"eighth":return new u(1,8);case"quarter":return new u(1,4);case"half":return new u(1,2);case"whole":return new u(1,1);case"breve":return new u(2,1);case"long":return new u(4,1);case"maxima":return new u(8,1);default:{const e=Xe.translateText("ReaderErrorMessages/NoteDurationError","Invalid note duration.");throw new S(e)}}}}He.NoteTypeXmlValues=["","1024th","512th","256th","128th","64th","32nd","16th","eigth","quarter","half","whole","breve","long","maxima"];class Ye{constructor(e){this.placement=d.Above,this.accidentalAbove=Y.NONE,this.accidentalBelow=Y.NONE,this.ornament=e}get GetOrnament(){return this.ornament}get AccidentalAbove(){return this.accidentalAbove}set AccidentalAbove(e){this.accidentalAbove=e}get AccidentalBelow(){return this.accidentalBelow}set AccidentalBelow(e){this.accidentalBelow=e}}var je=(e=>(e[e.Trill=0]="Trill",e[e.Turn=1]="Turn",e[e.InvertedTurn=2]="InvertedTurn",e[e.DelayedTurn=3]="DelayedTurn",e[e.DelayedInvertedTurn=4]="DelayedInvertedTurn",e[e.Mordent=5]="Mordent",e[e.InvertedMordent=6]="InvertedMordent",e))(je||{});class Ke{constructor(e,t,i){this.staffEntries=[],this.comments=[],this.timestamp=t,this.staffEntries=new Array(i),this.parentMeasure=e}$get$(e){return this.staffEntries[e]}$set$(e,t){this.staffEntries[e]=t}get Timestamp(){return this.timestamp}set Timestamp(e){this.timestamp=e}get StaffEntries(){return this.staffEntries}set StaffEntries(e){this.staffEntries=e}get Comments(){return this.comments}set Comments(e){this.comments=e}get ParentMeasure(){return this.parentMeasure}set ParentMeasure(e){this.parentMeasure=e}getAbsoluteTimestamp(){return u.plus(this.timestamp,this.parentMeasure.AbsoluteTimestamp)}}class Je{constructor(e,t){this.voiceEntries=[],this.instructions=[],this.chordSymbolContainers=[],this.verticalContainerParent=e,this.parentStaff=t}get ParentStaff(){return this.parentStaff}get VerticalContainerParent(){return this.verticalContainerParent}get Timestamp(){if(this.VerticalContainerParent)return this.VerticalContainerParent.Timestamp}get AbsoluteTimestamp(){if(this.VerticalContainerParent)return u.plus(this.VerticalContainerParent.ParentMeasure.AbsoluteTimestamp,this.VerticalContainerParent.Timestamp)}get VoiceEntries(){return this.voiceEntries}set VoiceEntries(e){this.voiceEntries=e}get Link(){return this.staffEntryLink}set Link(e){this.staffEntryLink=e}get Instructions(){return this.instructions}set Instructions(e){this.instructions=e}get ChordContainers(){return this.chordSymbolContainers}set ChordContainers(e){this.chordSymbolContainers=e}removeAllInstructionsOfTypeClefInstruction(){let e=0,t=0;for(;e<this.instructions.length;)this.instructions[e]instanceof J?(this.instructions.splice(e,1),t++):e++;return t}removeFirstInstructionOfTypeClefInstruction(){for(let e=0;e<this.instructions.length;e++)if(this.instructions[e]instanceof J)return this.instructions.splice(e,1),!0;return!1}removeAllInstructionsOfTypeKeyInstruction(){let e=0,t=0;for(;e<this.instructions.length;)this.instructions[e]instanceof Z?(this.instructions.splice(e,1),t++):e++;return t}removeFirstInstructionOfTypeKeyInstruction(){for(let e=0;e<this.instructions.length;e++)if(this.instructions[e]instanceof Z)return this.instructions.splice(e,1),!0;return!1}removeAllInstructionsOfTypeRhythmInstruction(){let e=0,t=0;for(;e<this.instructions.length;)this.instructions[e]instanceof x?(this.instructions.splice(e,1),t++):e++;return t}removeFirstInstructionOfTypeRhythmInstruction(){for(let e=0;e<this.instructions.length;e++)if(this.instructions[e]instanceof x)return this.instructions.splice(e,1),!0;return!1}calculateMinNoteLength(){let e=new u(Number.MAX_VALUE,1);for(let t=0,i=this.VoiceEntries.length;t<i;++t){const i=this.VoiceEntries[t];for(let t=0,s=i.Notes.length;t<s;++t){const s=i.Notes[t];s.Length.lt(e)&&(e=s.Length)}}return e}calculateMaxNoteLength(e=!0){let t=new u(0,1);for(let i=0,s=this.VoiceEntries.length;i<s;++i){const s=this.VoiceEntries[i];for(let i=0,n=s.Notes.length;i<n;++i){const n=s.Notes[i];if(e&&n.NoteTie){const e=u.createFromFraction(n.Length);let i=!1;for(const t of n.NoteTie.Notes)t!==n?i&&e.Add(t.Length):i=!0;t.lt(e)&&(t=e)}else t.lt(n.Length)&&(t=n.Length)}}return t}hasNotes(){for(let e=0,t=this.VoiceEntries.length;e<t;++e)if(this.VoiceEntries[e].Notes.length>0)return!0;return!1}hasTie(){for(let e=0,t=this.VoiceEntries.length;e<t;++e)if(this.VoiceEntries[e].hasTie())return!0;return!1}findLinkedNotes(e){for(let t=0,i=this.voiceEntries.length;t<i;++t){const i=this.voiceEntries[t];for(let t=0,s=i.Notes.length;t<s;++t){const s=i.Notes[t];s.ParentStaffEntry===this&&e.push(s)}}}get hasOnlyRests(){for(const e of this.voiceEntries)for(const t of e.Notes)if(!t.isRest())return!1;return!0}}class qe{static Compare(e,t){if(void 0!==e.parentRepetition&&t.parentRepetition){if(1===e.alignment&&1===t.alignment){if(e.parentRepetition.StartIndex<t.parentRepetition.StartIndex)return 1;if(e.parentRepetition.StartIndex>t.parentRepetition.StartIndex)return-1}if(0===e.alignment&&0===t.alignment){if(e.parentRepetition.EndIndex<t.parentRepetition.EndIndex)return 1;if(e.parentRepetition.EndIndex>t.parentRepetition.EndIndex)return-1}}return 0}}class $e{constructor(e,t,i=1,s=void 0,n=void 0,r){this.endingIndices=void 0,this.measureIndex=e,n&&(this.endingIndices=n.slice()),this.type=t,r&&(this.originalVal=r),this.alignment=i,this.parentRepetition=s}CompareTo(e){const t=e;if(this.measureIndex>t.measureIndex)return 1;if(this.measureIndex<t.measureIndex)return-1;if(0===this.alignment){if(1===t.alignment)return-1;switch(this.type){case 3:return 1;case 0:return 3===t.type?-1:1;case 12:case 13:return 12===t.type?1:-1}}else{if(0===t.alignment)return 1;switch(this.type){case 3:return-1;case 6:case 7:return 3===t.type?1:-1;case 1:switch(t.type){case 3:case 6:case 7:return 1}return-1;case 8:case 9:case 10:case 11:case 4:case 5:case 2:return 1}}return 0}equals(e){if(this.measureIndex!==e.measureIndex||this.type!==e.type||this.alignment!==e.alignment)return!1;if(this.endingIndices===e.endingIndices)return!0;if(!this.endingIndices||!e.endingIndices||this.endingIndices.length!==e.endingIndices.length)return!1;for(let t=0;t<this.endingIndices.length;t++)if(this.endingIndices[t]!==e.endingIndices[t])return!1;return!0}}var Qe=(e=>(e[e.StartLine=0]="StartLine",e[e.ForwardJump=1]="ForwardJump",e[e.BackJumpLine=2]="BackJumpLine",e[e.Ending=3]="Ending",e[e.DaCapo=4]="DaCapo",e[e.DalSegno=5]="DalSegno",e[e.Fine=6]="Fine",e[e.ToCoda=7]="ToCoda",e[e.DalSegnoAlFine=8]="DalSegnoAlFine",e[e.DaCapoAlFine=9]="DaCapoAlFine",e[e.DalSegnoAlCoda=10]="DalSegnoAlCoda",e[e.DaCapoAlCoda=11]="DaCapoAlCoda",e[e.Coda=12]="Coda",e[e.Segno=13]="Segno",e[e.None=14]="None",e))(Qe||{}),Ze=(e=>(e[e.Begin=0]="Begin",e[e.End=1]="End",e))(Ze||{});let et=null;class tt{constructor(e,t){this.printNewSystemXml=!1,this.printNewPageXml=!1,this.IsSystemStartMeasure=!1,this.WidthFactor=1,this.hasLyrics=!1,this.hasMoodExpressions=!1,this.CompoundTempo="",this.allRests=!1,this.isReducedToMultiRest=!1,this.multipleRestMeasureNumber=0,this.staffLinkedExpressions=[],this.tempoExpressions=[],this.verticalSourceStaffEntryContainers=[],this.graphicalMeasureErrors=[],this.firstRepetitionInstructions=[],this.lastRepetitionInstructions=[],this.metronomeNoteIndex=0,this.WasRendered=!1,this.completeNumberOfStaves=e,this.implicitMeasure=!1,this.hasEndLine=!1,this.endingBarStyleXml="",this.endingBarStyleEnum=Ne.SingleThin,this.firstInstructionsStaffEntries=new Array(e),this.lastInstructionsStaffEntries=new Array(e),this.rules=t,this.TempoInBPM=0;for(let i=0;i<e;i++)this.graphicalMeasureErrors.push(!1),this.staffLinkedExpressions.push([])}get MeasureNumber(){return this.measureNumber}set MeasureNumber(e){this.measureNumber=e}getPrintedMeasureNumber(){return this.rules.UseXMLMeasureNumbers&&Number.isInteger(this.MeasureNumberXML)?(this.MeasureNumberPrinted=this.MeasureNumberXML,this.MeasureNumberPrinted):(this.MeasureNumberPrinted=this.MeasureNumber,this.MeasureNumberPrinted)}get AbsoluteTimestamp(){return this.absoluteTimestamp}set AbsoluteTimestamp(e){this.absoluteTimestamp=e}get CompleteNumberOfStaves(){return this.completeNumberOfStaves}get Duration(){return this.duration}set Duration(e){this.duration=e}get ActiveTimeSignature(){return this.activeTimeSignature}set ActiveTimeSignature(e){this.activeTimeSignature=e}get ImplicitMeasure(){return this.implicitMeasure}set ImplicitMeasure(e){this.implicitMeasure=e}get HasEndLine(){return this.hasEndLine}set HasEndLine(e){this.hasEndLine=e}get StaffLinkedExpressions(){return this.staffLinkedExpressions}get TempoExpressions(){return this.tempoExpressions}get VerticalSourceStaffEntryContainers(){return this.verticalSourceStaffEntryContainers}get FirstInstructionsStaffEntries(){return this.firstInstructionsStaffEntries}get LastInstructionsStaffEntries(){return this.lastInstructionsStaffEntries}get FirstRepetitionInstructions(){return this.firstRepetitionInstructions}get LastRepetitionInstructions(){return this.lastRepetitionInstructions}getErrorInMeasure(e){return this.graphicalMeasureErrors[e]}setErrorInGraphicalMeasure(e,t){this.graphicalMeasureErrors[e]=t}getNextMeasure(e){return e[this.measureListIndex+1]}getPreviousMeasure(e){if(this.measureListIndex>1)return e[this.measureListIndex-1]}get Rules(){return this.rules}get VerticalMeasureList(){return this.verticalMeasureList}set VerticalMeasureList(e){this.verticalMeasureList=e}get TempoInBPM(){return this.tempoInBPM}set TempoInBPM(e){this.tempoInBPM=e}findOrCreateStaffEntry(e,t,i){let s,n;for(const o of this.verticalSourceStaffEntryContainers)if(o.Timestamp.Equals(e)){n=o;break}if(n)return n.StaffEntries[t]?s=n.StaffEntries[t]:(s=new Je(n,i),n.StaffEntries[t]=s),{createdNewContainer:!1,staffEntry:s};const r=this.verticalSourceStaffEntryContainers[this.verticalSourceStaffEntryContainers.length-1];if(0===this.verticalSourceStaffEntryContainers.length||r.Timestamp.lt(e)){const n=new Ke(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.push(n),s=new Je(n,i),n.StaffEntries[t]=s}else for(let o=this.verticalSourceStaffEntryContainers.length-1;o>=0;o--){if(this.verticalSourceStaffEntryContainers[o].Timestamp.lt(e)){const n=new Ke(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.splice(o+1,0,n),s=new Je(n,i),n.StaffEntries[t]=s;break}if(0===o){const n=new Ke(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.splice(o,0,n),s=new Je(n,i),n.StaffEntries[t]=s;break}}return{createdNewContainer:!0,staffEntry:s}}findOrCreateVoiceEntry(e,t){let i,s=!1;for(const n of e.VoiceEntries)if(n.ParentVoice===t){i=n;break}return i||(i=new ut(e.Timestamp,t,e),s=!0),{createdVoiceEntry:s,voiceEntry:i}}getPreviousSourceStaffEntryFromIndex(e,t){for(let i=t-1;i>=0;i--)if(this.verticalSourceStaffEntryContainers[i][e])return this.verticalSourceStaffEntryContainers[i][e]}getVerticalContainerIndexByTimestamp(e){for(let t=0,i=this.VerticalSourceStaffEntryContainers.length;t<i;++t)if(this.VerticalSourceStaffEntryContainers[t].Timestamp.Equals(e))return t;return-1}getVerticalContainerByTimestamp(e){for(let t=0,i=this.VerticalSourceStaffEntryContainers.length;t<i;++t){const i=this.VerticalSourceStaffEntryContainers[t];if(i.Timestamp.Equals(e))return i}}checkForEmptyVerticalContainer(e){let t=0;for(let i=0;i<this.completeNumberOfStaves;i++)this.verticalSourceStaffEntryContainers[e][i]||t++;t===this.completeNumberOfStaves&&this.verticalSourceStaffEntryContainers.splice(e,1)}reverseCheck(e,t){let i=new u(0,1);const s=[];for(let n=0;n<e.Instruments.length;n++){let t=new u(0,1);const i=e.getGlobalStaffIndexOfFirstStaff(e.Instruments[n]);for(let s=0;s<e.Instruments[n].Staves.length;s++){const e=this.getLastSourceStaffEntryForInstrument(i+s);if(void 0!==e&&!e.hasTie())for(let n=this.verticalSourceStaffEntryContainers.indexOf(e.VerticalContainerParent)-1;n>=0;n--){const e=this.verticalSourceStaffEntryContainers[n][i+s];if(void 0!==e&&e.hasTie()&&t.lt(u.plus(e.Timestamp,e.calculateMaxNoteLength()))){t=u.plus(e.Timestamp,e.calculateMaxNoteLength());break}}}s.push(t)}for(let n=0,r=s.length;n<r;++n){const e=s[n];i.lt(e)&&(i=e)}return u.max(i,t)}calculateInstrumentsDuration(e,t){const i=[];for(let s=0;s<e.Instruments.length;s++){let n=new u(0,1);const r=e.getGlobalStaffIndexOfFirstStaff(e.Instruments[s]);for(let t=0;t<e.Instruments[s].Staves.length;t++){const e=this.getLastSourceStaffEntryForInstrument(r+t);void 0!==e&&e.Timestamp&&n.lt(u.plus(e.Timestamp,e.calculateMaxNoteLength()))&&(n=u.plus(e.Timestamp,e.calculateMaxNoteLength()))}n.lt(t[s])&&(n=t[s]),i.push(n)}return i}getEntriesPerStaff(e){const t=[];for(const i of this.VerticalSourceStaffEntryContainers){const s=i.StaffEntries[e];s&&t.push(s)}return t}hasBeginInstructions(){for(let e=0,t=this.FirstInstructionsStaffEntries.length;e<t;e++){const t=this.FirstInstructionsStaffEntries[e];if(void 0!==t&&t.Instructions.length>0)return!0}return!1}beginsWithLineRepetition(){for(let e=0,t=this.FirstRepetitionInstructions.length;e<t;++e){const t=this.FirstRepetitionInstructions[e];if(t.type===Qe.StartLine)return!0;if(void 0!==t.parentRepetition&&t===t.parentRepetition.startMarker&&!t.parentRepetition.FromWords)return!0}return!1}endsWithLineRepetition(){for(let e=0,t=this.LastRepetitionInstructions.length;e<t;++e){const t=this.LastRepetitionInstructions[e];if(t.type===Qe.BackJumpLine)return!0;const i=t.parentRepetition;if(i&&!i.FromWords)for(let e=0,s=i.BackwardJumpInstructions.length;e<s;++e)if(t===i.BackwardJumpInstructions[e])return!0}return!1}beginsWithWordRepetition(){for(let e=0,t=this.FirstRepetitionInstructions.length;e<t;++e){const t=this.FirstRepetitionInstructions[e];if(void 0!==t.parentRepetition&&t===t.parentRepetition.startMarker&&t.parentRepetition.FromWords)return!0}return!1}endsWithWordRepetition(){for(let e=0,t=this.LastRepetitionInstructions.length;e<t;++e){const t=this.LastRepetitionInstructions[e],i=t.parentRepetition;if(i&&i.FromWords){for(let e=0,s=i.BackwardJumpInstructions.length;e<s;++e)if(t===i.BackwardJumpInstructions[e])return!0;if(t===i.forwardJumpInstruction)return!0}}return!1}beginsRepetitionEnding(){for(const e of this.FirstRepetitionInstructions)if(e.type===Qe.Ending&&e.alignment===Ze.Begin)return!0;return!1}endsRepetitionEnding(){for(const e of this.LastRepetitionInstructions)if(e.type===Qe.Ending&&e.alignment===Ze.End)return!0;return!1}getKeyInstruction(e){if(this.FirstInstructionsStaffEntries[e]){const t=this.FirstInstructionsStaffEntries[e];for(let e=0,i=t.Instructions.length;e<i;++e){const i=t.Instructions[e];if(i instanceof Z)return i}}}getLastSourceStaffEntryForInstrument(e,t=!0){let i;for(let s=this.verticalSourceStaffEntryContainers.length-1;s>=0;s--)if(i=this.verticalSourceStaffEntryContainers[s].StaffEntries[e],i&&(!t||i.VoiceEntries.length>0))return i}canBeReducedToMultiRest(){var e,t,i,s,n,r,o,a;if(this.firstRepetitionInstructions.length>0||this.lastRepetitionInstructions.length>0)return!1;let l=!0,h=!1;for(const u of this.verticalSourceStaffEntryContainers)if(u)for(const e of u.StaffEntries)if(e&&e.ParentStaff.ParentInstrument.Visible){if(e.ChordContainers.length>0)return!1;e.ParentStaff.hasLyrics&&(h=!0);for(const t of e.VoiceEntries){for(const e of t.Notes)if(!e.isRest()){l=!1;break}if(!l)break}}if(!l||h||this.hasMoodExpressions||this.tempoExpressions.length>0)return!1;for(const u of this.staffLinkedExpressions)if(u.length>0)return!1;for(const u of this.lastInstructionsStaffEntries)for(let e=0,t=null==u?void 0:u.Instructions.length;e<t;++e)if(u.Instructions[e]instanceof J)return!1;return!et||(null===(e=et)||void 0===e||null===(t=e.ActiveTimeSignature)||void 0===t?void 0:t.Numerator)===(null===(i=this.ActiveTimeSignature)||void 0===i?void 0:i.Numerator)&&(null===(s=et)||void 0===s||null===(n=s.ActiveTimeSignature)||void 0===n?void 0:n.Denominator)===(null===(r=this.ActiveTimeSignature)||void 0===r?void 0:r.Denominator)?(et=this,(null===(o=this.Duration)||void 0===o?void 0:o.RealValue)===(null===(a=this.ActiveTimeSignature)||void 0===a?void 0:a.RealValue)):(et=this,!1)}}class it{constructor(e,t){this.isTab=!1,this.voices=[],this.volume=1,this.stafflineCount=5,this.hasLyrics=!1,this.openTieDict={},this.parentInstrument=e,this.id=t,this.audible=!0,this.following=!0}get ParentInstrument(){return this.parentInstrument}set ParentInstrument(e){this.parentInstrument=e}get Voices(){return this.voices}get Solo(){return this.solo}set Solo(e){this.solo=e}get Id(){return this.id}get Volume(){return this.volume}set Volume(e){this.volume=e}get StafflineCount(){return this.stafflineCount}set StafflineCount(e){this.stafflineCount=e}toString(){return"Staff "+this.idInMusicSheet.toString()}}class st{constructor(e){this.linkStaffEntries=[],this.voiceEntry=e}get GetVoiceEntry(){return this.voiceEntry}get LinkStaffEntries(){return this.linkStaffEntries}set LinkStaffEntries(e){this.linkStaffEntries=e}}class nt{constructor(e,t){this.notes=[],this.TieNumber=1,this.TieDirection=d.NotYetDefined,this.NoteIndexToTieDirection={},this.AddNote(e),this.type=t}getTieDirection(e){if(!e)return this.TieDirection;for(let t=0;t<this.Notes.length;t++)if(this.Notes[t]===e){const e=this.NoteIndexToTieDirection[t];return e||this.TieDirection}return s.debug("tie.getTieDuration note not in tie.Notes"),this.TieDirection}get Notes(){return this.notes}get Type(){return this.type}get StartNote(){return this.notes[0]}get Duration(){const e=new u;for(const t of this.notes)e.Add(t.Length);return e}get Pitch(){return this.StartNote.Pitch}AddNote(e){this.notes.push(e),e.NoteTie=this}}class rt{constructor(e,t=!1){this.PlacementFromXml=!1,this.RenderTupletNumber=!0,this.notes=[],this.fractions=[],this.tupletLabelNumber=e,this.bracket=t}shouldBeBracketed(e,t,i,s=!1,n=!1){if(s)return n;if(e&&void 0!==this.BracketedXmlValue)return this.BracketedXmlValue;const r=this.Notes[0][0].NoteBeam;if(!r)return!0;for(const o of this.Notes)if(o[0].NoteBeam!==r)return!0;return this.Bracket||3===this.TupletLabelNumber&&i||3!==this.TupletLabelNumber&&t}get TupletLabelNumber(){return this.tupletLabelNumber}set TupletLabelNumber(e){this.tupletLabelNumber=e}get Notes(){return this.notes}set Notes(e){this.notes=e}get Fractions(){return this.fractions}set Fractions(e){this.fractions=e}get Bracket(){return this.bracket}set Bracket(e){this.bracket=e}getNoteIndex(e){for(let t=this.notes.length-1;t>=0;t--)for(let i=0;i<this.notes[t].length;i++)if(e===this.notes[t][i])return t;return 0}}var ot=(e=>(e[e.Fingering=0]="Fingering",e[e.String=1]="String",e))(ot||{});class at{}class lt{constructor(e,t){if(this.parentEntry=e,this.parentNote=t,this.ParentNote.PlaybackNote=this,this.Length=this.ParentNote.Length,void 0!==t.Pitch){const e=this.ParentNote.ParentStaff.ParentInstrument.MidiInstrumentId===$.Percussion;this.MidiKey=e?lt.noteToMidiDrumKey(t):t.Pitch.getHalfTone()+12}else this.MidiKey=0}setLength(){void 0!==this.ParentNote.NoteTie&&this.ParentNote.NoteTie.StartNote===this.ParentNote&&(this.Length=this.ParentNote.NoteTie.Duration)}get ParentEntry(){return this.parentEntry}get ParentNote(){return this.parentNote}static noteToMidiDrumKey(e){var t;const i=e.Pitch.getHalfTone()-12,s=null===(t=e.Notehead)||void 0===t?void 0:t.Shape;switch(e.Pitch.Octave){case 1:switch(e.Pitch.FundamentalNote){case H.D:return 44;case H.E:return 35;case H.F:return 36;case H.G:return 41;case H.A:return 43;case H.B:return s===Ue.TRIANGLE?54:47;default:return i}case 2:switch(e.Pitch.FundamentalNote){case H.C:return s===Ue.X?37:38;case H.D:return s===Ue.X?59:48;case H.E:switch(s){case Ue.X:return 42;case Ue.CIRCLEX:return 46;case Ue.TRIANGLE:return 56;default:return 50}case H.F:return s===Ue.DIAMOND?53:51;case H.G:switch(s){case Ue.CIRCLEX:case Ue.DIAMOND:return 46;default:return 42}case H.A:return 49;case H.B:return 57;default:return i}case 3:return e.Pitch.FundamentalNote===H.C?s===Ue.CIRCLEX?52:55:i;default:return i}}}class ht{constructor(e){this.notes=[],this.TimestampShift=new u,this.parentVoiceEntry=e;for(const t of e.Notes)this.Notes.push(new lt(this,t))}get ParentVoiceEntry(){return this.parentVoiceEntry}get Notes(){return this.notes}get Length(){if(this.Notes.length>0)return this.Notes[0].Length}set Length(e){for(const t of this.Notes)t.Length=e}get HasNotes(){return this.Notes.length>0}}class ut{constructor(e,t,s,n=!0,r=!1,o=!1,a=!1){if(this.notes=[],this.graceVoiceEntriesBefore=[],this.graceVoiceEntriesAfter=[],this.articulations=[],this.playbackEntries=[],this.technicalInstructions=[],this.lyricsEntries=new i,this.wantedStemDirection=-1,this.stemDirectionXml=-1,this.stemDirection=-1,this.timestamp=e,this.parentVoice=t,this.parentSourceStaffEntry=s,this.isGrace=r,this.graceAfterMainNote=!1,this.graceNoteSlash=o,this.graceSlur=a,r||t.VoiceEntries.push(this),n&&void 0!==s){const e=s.VoiceEntries;-1===e.indexOf(this)&&e.push(this)}this.mainPlaybackEntry=new ht(this),this.PlaybackEntries.push(this.mainPlaybackEntry)}get ParentSourceStaffEntry(){return this.parentSourceStaffEntry}get ParentVoice(){return this.parentVoice}get Timestamp(){return this.timestamp}set Timestamp(e){this.timestamp=e}get Notes(){return this.notes}addNote(e){this.notes.push(e),e.isRest()||void 0!==e.NoteTie&&e.NoteTie.StartNote!==e||this.MainPlaybackEntry.Notes.push(new lt(this.MainPlaybackEntry,e))}get GraceVoiceEntriesBefore(){return this.graceVoiceEntriesBefore}set GraceVoiceEntriesBefore(e){this.graceVoiceEntriesBefore=e;for(const t of this.graceVoiceEntriesBefore)t.parentSourceStaffEntry=this.ParentSourceStaffEntry}get GraceVoiceEntriesAfter(){return this.graceVoiceEntriesAfter}set GraceVoiceEntriesAfter(e){this.graceVoiceEntriesAfter=e;for(const t of this.graceVoiceEntriesAfter)t.parentSourceStaffEntry=this.ParentSourceStaffEntry}get IsGrace(){return this.isGrace}set IsGrace(e){this.isGrace=e}get GraceAfterMainNote(){return this.graceAfterMainNote}set GraceAfterMainNote(e){this.graceAfterMainNote=e}get GraceNoteSlash(){return this.graceNoteSlash}set GraceNoteSlash(e){this.graceNoteSlash=e}get GraceSlur(){return this.graceSlur}set GraceSlur(e){this.graceSlur=e}get Articulations(){return this.articulations}get PlaybackEntries(){return this.playbackEntries}get Fermata(){return this.fermata}get MainPlaybackEntry(){return this.mainPlaybackEntry}set MainPlaybackEntry(e){this.mainPlaybackEntry=e}removeMainPlaybackEntry(){void 0!==this.mainPlaybackEntry&&this.removePlaybackEntry(this.mainPlaybackEntry)}removePlaybackEntry(e){this.mainPlaybackEntry===e&&(this.mainPlaybackEntry=void 0);const t=this.playbackEntries.indexOf(e);t>-1&&this.playbackEntries.splice(t,1)}set Articulations(e){this.articulations=e}get TechnicalInstructions(){return this.technicalInstructions}get LyricsEntries(){return this.lyricsEntries}get Arpeggio(){return this.arpeggio}set Arpeggio(e){this.arpeggio=e}get OrnamentContainer(){return this.ornamentContainer}set OrnamentContainer(e){this.ornamentContainer=e}set WantedStemDirection(e){this.wantedStemDirection=e}get WantedStemDirection(){return this.wantedStemDirection}set StemDirectionXml(e){this.stemDirectionXml=e}get StemDirectionXml(){return this.stemDirectionXml}set StemDirection(e){this.stemDirection=e}get StemDirection(){return this.stemDirection}get StemColorXml(){return this.stemColorXml}set StemColorXml(e){this.stemColorXml=e}get StemColor(){return this.stemColor}set StemColor(e){this.stemColor=e}get VolumeModifier(){return this.volumeModifier}set VolumeModifier(e){this.volumeModifier=e}get DurationModifier(){return this.durationModifier}set DurationModifier(e){this.durationModifier=e}hasArticulation(e){for(const t of this.articulations)if(t.Equals(e))return!0;return!1}static isSupportedArticulation(e){switch(e){case 0:case 1:case 2: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 27:return!0;default:return!1}}hasTie(){for(let e=0,t=this.Notes.length;e<t;++e)if(this.Notes[e].NoteTie)return!0;return!1}hasSlur(){for(let e=0,t=this.Notes.length;e<t;++e)if(this.Notes[e].NoteSlurs.length>0)return!0;return!1}isStaccato(){for(const e of this.Articulations)if(6===e.articulationEnum)return!0;return!1}isAccent(){for(const e of this.Articulations)if(0===e.articulationEnum||1===e.articulationEnum)return!0;return!1}getVerseNumberForLyricEntry(e){let t="1";return this.lyricsEntries.forEach(((i,s)=>{e===s&&(t=i)})),t}}var ct=(e=>(e[e.accent=0]="accent",e[e.strongaccent=1]="strongaccent",e[e.softaccent=2]="softaccent",e[e.marcatoup=3]="marcatoup",e[e.marcatodown=4]="marcatodown",e[e.invertedstrongaccent=5]="invertedstrongaccent",e[e.staccato=6]="staccato",e[e.staccatissimo=7]="staccatissimo",e[e.spiccato=8]="spiccato",e[e.tenuto=9]="tenuto",e[e.fermata=10]="fermata",e[e.invertedfermata=11]="invertedfermata",e[e.breathmark=12]="breathmark",e[e.caesura=13]="caesura",e[e.lefthandpizzicato=14]="lefthandpizzicato",e[e.naturalharmonic=15]="naturalharmonic",e[e.snappizzicato=16]="snappizzicato",e[e.upbow=17]="upbow",e[e.downbow=18]="downbow",e[e.scoop=19]="scoop",e[e.plop=20]="plop",e[e.doit=21]="doit",e[e.falloff=22]="falloff",e[e.stress=23]="stress",e[e.unstress=24]="unstress",e[e.detachedlegato=25]="detachedlegato",e[e.otherarticulation=26]="otherarticulation",e[e.bend=27]="bend",e))(ct||{}),dt=(e=>(e[e.Undefined=-1]="Undefined",e[e.Up=0]="Up",e[e.Down=1]="Down",e[e.None=2]="None",e[e.Double=3]="Double",e))(dt||{}),ft=(e=>(e[e.MeasureBegin=0]="MeasureBegin",e[e.MeasureEnd=1]="MeasureEnd",e))(ft||{});class mt extends re{constructor(e,t,i,s,n=void 0){super(),this.CenteringXShift=0,this.label=e,this.boundingBox=new oe(this,n),this.label.fontHeight=t,this.label.textAlignment=i,this.rules=s,this.rules.MpatMode&&"TRIO"===this.label.text&&(this.label.fontFamily="Arial")}get Label(){return this.label}toString(){return`${this.label.text} (${this.boundingBox.RelativePosition.x},${this.boundingBox.RelativePosition.y})`}setLabelPositionAndShapeBorders(){var e,t;if(""===this.Label.text.trim())return;this.TextLines=[];const i=null!==(e=null===(t=this.rules)||void 0===t?void 0:t.LabelMarginBorderFactor)&&void 0!==e?e:.1,s=this.Label.text.split(/[\n\r]+/g),n=s.length;let r=0;for(let l=0;l<n;l++){const e=s[l].trim();if(!e||""===e)continue;const t=yi.TextMeasurer.computeTextWidthToHeightRatio(e,this.Label.font,this.Label.fontStyle,this.label.fontFamily),i=this.Label.fontHeight*t;r=Math.max(r,i);const n=void 0!==this.Label.trackIndex?{text:e,xOffset:0,width:i,trackIndex:this.Label.trackIndex}:{text:e,xOffset:0,width:i};this.TextLines.push(n)}for(const l of this.TextLines){let e=0;switch(this.Label.textAlignment){case ce.RightBottom:case ce.RightCenter:case ce.RightTop:e=r-l.width;break;case ce.CenterBottom:case ce.CenterCenter:case ce.CenterTop:e=(r-l.width)/2}l.xOffset=e}let o=this.Label.fontHeight*n;this.rules.SpacingBetweenTextLines>0&&this.TextLines.length>1&&(o+=this.rules.SpacingBetweenTextLines*n/10);const a=this.PositionAndShape;switch(this.Label.textAlignment){case ce.CenterBottom:a.BorderTop=-o,a.BorderLeft=-r/2,a.BorderBottom=0,a.BorderRight=r/2;break;case ce.CenterCenter:a.BorderTop=-o/2,a.BorderLeft=-r/2,a.BorderBottom=o/2,a.BorderRight=r/2;break;case ce.CenterTop:a.BorderTop=0,a.BorderLeft=-r/2,a.BorderBottom=o,a.BorderRight=r/2;break;case ce.LeftBottom:a.BorderTop=-o,a.BorderLeft=0,a.BorderBottom=0,a.BorderRight=r;break;case ce.LeftCenter:a.BorderTop=-o/2,a.BorderLeft=0,a.BorderBottom=o/2,a.BorderRight=r;break;case ce.LeftTop:a.BorderTop=0,a.BorderLeft=0,a.BorderBottom=o,a.BorderRight=r;break;case ce.RightBottom:a.BorderTop=-o,a.BorderLeft=-r,a.BorderBottom=0,a.BorderRight=0;break;case ce.RightCenter:a.BorderTop=-o/2,a.BorderLeft=-r,a.BorderBottom=o/2,a.BorderRight=0;break;case ce.RightTop:a.BorderTop=0,a.BorderLeft=-r,a.BorderBottom=o,a.BorderRight=0}a.BorderMarginTop=a.BorderTop-o*i,a.BorderMarginLeft=a.BorderLeft-o*i,a.BorderMarginBottom=a.BorderBottom+o*i,a.BorderMarginRight=a.BorderRight+o*i}}class pt{constructor(e="",t=ce.CenterBottom,i=void 0,s=!0){this.IsCreditLabel=!1,this.isLyricText=!1,this.isNotRender=!1,this.text=e,this.print=s,this.textAlignment=t,this.font=i,this.fontFamily=void 0}set font(e){this.fontEnumValue=e,this.fontFamily=ge[e]}get font(){return this.fontEnumValue}ToString(){return this.text}}const gt={Grava:40,Largo:46,Lento:52,Adagio:56,Larghetto:60,Andante:66,Anderato:69,Andantino:69,Moderato:88,Allegretto:108,"Allegro Moderato":108,Allegro:132,Vivace:152,Vivo:160,Vivacissimo:168,Presto:184,Prestissimo:208},St=["纯律","纯律结束"],yt=["跳过下一个","b","#","§","º","X"],bt=["poco rit.","rall.","rit.","accel.","molto rit.","molto rall","lentando","poco accel.","calando","molto allargando","allargando","stringendo","poco a poco rit.","rit. poco a poco","Ritardando","Ritenuto","accelerate","poco a poco accel."],Mt="结束范围速度",vt=(e("G","a tempo"),[Mt]),Pt="速度 ",Et="仅文本速度 ";function Lt(e){return 0===e.indexOf(Pt)}function xt(e){return 0===e.indexOf(Et)}function Tt(e){return[...Object.keys(gt),...St,...vt,...yt].map((e=>e.trim().toLocaleUpperCase())).includes(e.toLocaleUpperCase().trim())}function wt(e){return[ce.CenterTop,ce.RightTop].includes(e)}var It=(e=>(e[e.Unused_first_Symbol=0]="Unused_first_Symbol",e[e.BLACK_HEAD=1]="BLACK_HEAD",e[e.UPWARDS_TAIL=2]="UPWARDS_TAIL",e[e.DOWNWARDS_TAIL=3]="DOWNWARDS_TAIL",e[e.UPWARDS_DOUBLE_TAIL=4]="UPWARDS_DOUBLE_TAIL",e[e.DOWNWARDS_DOUBLE_TAIL=5]="DOWNWARDS_DOUBLE_TAIL",e[e.UPWARDS_TRIPLE_TAIL=6]="UPWARDS_TRIPLE_TAIL",e[e.DOWNWARDS_TRIPLE_TAIL=7]="DOWNWARDS_TRIPLE_TAIL",e[e.UPWARDS_QUAD_TAIL=8]="UPWARDS_QUAD_TAIL",e[e.DOWNWARDS_QUAD_TAIL=9]="DOWNWARDS_QUAD_TAIL",e[e.ROUND_HEAD=10]="ROUND_HEAD",e[e.WHITE_HEAD=11]="WHITE_HEAD",e[e.G_CLEF=12]="G_CLEF",e[e.F_CLEF=13]="F_CLEF",e[e.C_CLEF=14]="C_CLEF",e[e.BREVE=15]="BREVE",e[e.BREVE_REST=16]="BREVE_REST",e[e.COMMON_TIME=17]="COMMON_TIME",e[e.CUT_TIME=18]="CUT_TIME",e[e.WHOLE_REST=19]="WHOLE_REST",e[e.HALF_REST=20]="HALF_REST",e[e.QUARTER_REST=21]="QUARTER_REST",e[e.EIGHTH_REST=22]="EIGHTH_REST",e[e.SIXTEENTH_REST=23]="SIXTEENTH_REST",e[e.THIRTYSECOND_REST=24]="THIRTYSECOND_REST",e[e.SIXTYFOURTH_REST=25]="SIXTYFOURTH_REST",e[e.FLAT=26]="FLAT",e[e.SHARP=27]="SHARP",e[e.NATURAL=28]="NATURAL",e[e.DOUBLE_FLAT=29]="DOUBLE_FLAT",e[e.DOUBLE_SHARP=30]="DOUBLE_SHARP",e[e.ZERO=31]="ZERO",e[e.ONE=32]="ONE",e[e.TWO=33]="TWO",e[e.THREE=34]="THREE",e[e.FOUR=35]="FOUR",e[e.FIVE=36]="FIVE",e[e.SIX=37]="SIX",e[e.SEVEN=38]="SEVEN",e[e.EIGHT=39]="EIGHT",e[e.NINE=40]="NINE",e[e.DOT=41]="DOT",e[e.FERMATA=42]="FERMATA",e[e.INVERTED_FERMATA=43]="INVERTED_FERMATA",e[e.SPICCATO=44]="SPICCATO",e[e.TENUTO=45]="TENUTO",e[e.MARCATO=46]="MARCATO",e[e.MARCATISSIMO=47]="MARCATISSIMO",e[e.INVERTED_MARCATISSIMO=48]="INVERTED_MARCATISSIMO",e[e.P=49]="P",e[e.F=50]="F",e[e.S=51]="S",e[e.Z=52]="Z",e[e.M=53]="M",e[e.R=54]="R",e[e.SEGNO=55]="SEGNO",e[e.CODA=56]="CODA",e[e.DRUM_CLEF=57]="DRUM_CLEF",e[e.G_CLEF_SUB8=58]="G_CLEF_SUB8",e[e.G_CLEF_SUPER8=59]="G_CLEF_SUPER8",e[e.G_CLEF_SUB15=60]="G_CLEF_SUB15",e[e.G_CLEF_SUPER15=61]="G_CLEF_SUPER15",e[e.F_CLEF_SUB8=62]="F_CLEF_SUB8",e[e.F_CLEF_SUPER8=63]="F_CLEF_SUPER8",e[e.F_CLEF_SUB15=64]="F_CLEF_SUB15",e[e.F_CLEF_SUPER15=65]="F_CLEF_SUPER15",e[e.DOWN_BOW=66]="DOWN_BOW",e[e.MORDENT=67]="MORDENT",e[e.INVERTED_MORDENT=68]="INVERTED_MORDENT",e[e.TURN=69]="TURN",e[e.INVERTED_TURN=70]="INVERTED_TURN",e[e.LEFTHAND_PIZZICATO=71]="LEFTHAND_PIZZICATO",e[e.RELEASE_PED=72]="RELEASE_PED",e[e.ENGAGE_PED=73]="ENGAGE_PED",e[e.VA8=74]="VA8",e[e.VB8=75]="VB8",e[e.TRILL=76]="TRILL",e[e.MA15=77]="MA15",e[e.MB15=78]="MB15",e[e.HIGH=79]="HIGH",e[e.PLAY=80]="PLAY",e[e.MIC=81]="MIC",e[e.SNAP_PIZZICATO=82]="SNAP_PIZZICATO",e[e.NATURAL_HARMONIC=83]="NATURAL_HARMONIC",e[e.EditPen=84]="EditPen",e[e.PEDAL_BRACKET=85]="PEDAL_BRACKET",e[e.PEDAL_MIXED=86]="PEDAL_MIXED",e[e.PEDAL_SYMBOL=87]="PEDAL_SYMBOL",e))(It||{}),At=(e=>(e[e.Normal=0]="Normal",e[e.Disabled=1]="Disabled",e[e.Selected=2]="Selected",e[e.Clickable=3]="Clickable",e[e.PlaybackSymbols=4]="PlaybackSymbols",e[e.FollowSymbols=5]="FollowSymbols",e[e.QFeedbackNotFound=6]="QFeedbackNotFound",e[e.QFeedbackOk=7]="QFeedbackOk",e[e.QFeedbackPerfect=8]="QFeedbackPerfect",e[e.Debug1=9]="Debug1",e[e.Debug2=10]="Debug2",e[e.Debug3=11]="Debug3",e))(At||{}),Rt=(e=>(e[e.Following=0]="Following",e[e.Midi=1]="Midi",e[e.Manual=2]="Manual",e))(Rt||{});class Nt{}class Ct{constructor(e,t){this.drawableBoundingBoxElement="None",this.skyLineVisible=!1,this.bottomLineVisible=!1,this.needSpecialArrTs=[],this.phonicScoreMode=Rt.Manual,this.textMeasurer=e,this.splitScreenLineColor=-1,this.drawingParameters=t,this.rules=t.Rules}set Mode(e){this.phonicScoreMode=e}drawSheet(e){if(this.graphicalMusicSheet=e,this.rules=e.ParentMusicSheet.Rules,this.drawSplitScreenLine(),this.drawingParameters.drawCursors)for(const i of e.Cursors){if(!i)continue;const e=new oe(i);e.AbsolutePosition=i.Start,e.BorderBottom=i.End.y-i.Start.y,e.BorderRight=i.Width/2,e.BorderLeft=-i.Width/2,this.isVisible(e)&&this.drawLineAsVerticalRectangle(i,G.Cursor)}this.drawingParameters.drawScrollIndicator&&this.drawScrollIndicator();const t=Math.min(this.graphicalMusicSheet.MusicPages.length,this.rules.MaxPageToDrawNumber);for(let i=0;i<t;i++){const e=this.graphicalMusicSheet.MusicPages[i];this.drawPage(e)}}drawLineAsHorizontalRectangle(e,t){let i=new ie(e.Start.x,e.End.y-e.Width/2,e.End.x-e.Start.x,e.Width);i=this.applyScreenTransformationForRect(i),this.renderRectangle(i,t,e.styleId,e.colorHex)}drawLineAsVerticalRectangle(e,t){const i=e.Start,s=e.Width;let n=new ie(i.x-s/2,i.y,s,e.End.y-i.y);n=this.applyScreenTransformationForRect(n),this.renderRectangle(n,t,e.styleId)}drawLineAsHorizontalRectangleWithOffset(e,t,i){const s=new z(e.Start.x+t.x,e.Start.y+t.y),n=new z(e.End.x+t.x,e.End.y+t.y),r=e.Width;let o=new ie(s.x,n.y-r/2,n.x-s.x,r);o=this.applyScreenTransformationForRect(o),this.renderRectangle(o,i,e.styleId)}drawLineAsVerticalRectangleWithOffset(e,t,i){const s=new z(e.Start.x+t.x,e.Start.y+t.y),n=new z(e.End.x+t.x,e.End.y+t.y),r=e.Width;let o=new ie(s.x,s.y,r,n.y-s.y);o=this.applyScreenTransformationForRect(o),this.renderRectangle(o,i,e.styleId)}drawRectangle(e,t){const i=e.PositionAndShape;let s=new ie(i.AbsolutePosition.x,i.AbsolutePosition.y,i.BorderRight,i.BorderBottom);s=this.applyScreenTransformationForRect(s),this.renderRectangle(s,t,e.style)}drawLabel(e,t,i){var s,n,r;const o=this.graphicalMusicSheet.GetNearestNote(e.PositionAndShape.AbsolutePosition);if(!this.isVisible(e.PositionAndShape))return;const a=e.Label;if(""===a.text.trim())return;const l=this.calculateLabel(e),h=this.applyScreenTransformation(e.PositionAndShape.AbsolutePosition),u=e.PositionAndShape.Parent.DataObject;if(this.rules.MetronomeMarksDrawn&&1===(null==u||null===(s=u.measures)||void 0===s||null===(n=s[0])||void 0===n?void 0:n.MeasureNumber)&&0===(null==u||null===(r=u.ParentMusicSystem)||void 0===r?void 0:r.Id)&&wt(e.Label.textAlignment)&&(l.ScreenPosition.y-=10),","===a.text){var c,d,f;let t=0;const i=(null===(c=this.graphicalMusicSheet)||void 0===c||null===(d=c.MusicPages)||void 0===d||null===(f=d[0])||void 0===f?void 0:f.MusicSystems)||[];let s;try{for(let n=0;n<i.length;n++){const r=i[n];if(e.PositionAndShape.AbsolutePosition.x<10){e.PositionAndShape.AbsolutePosition.x;const i=this.graphicalMusicSheet.MeasureList[o.sourceNote.SourceMeasure.MeasureNumber-2];i&&i[0]&&(s=i[0],t=s.PositionAndShape.AbsolutePosition.y-s.PositionAndShape.Size.height/2);break}if(r.PositionAndShape.AbsolutePosition.y-10<e.PositionAndShape.AbsolutePosition.y&&e.PositionAndShape.AbsolutePosition.y<r.PositionAndShape.AbsolutePosition.y+10){var m,p;const t=(null==r?void 0:r.GraphicalMeasures.map((e=>e[0])).filter(Boolean))||[],i=[];let n=!1;for(let r=0;r<t.length;r++){var g,S,y;const o=t[r];if(1===(null===(g=o.vfVoices)||void 0===g||null===(S=g[1])||void 0===S||null===(y=S.tickables)||void 0===y?void 0:y.length)&&o.PositionAndShape.AbsolutePosition.x<e.PositionAndShape.AbsolutePosition.x&&e.PositionAndShape.AbsolutePosition.x<o.PositionAndShape.AbsolutePosition.x+o.PositionAndShape.Size.width){s=o,n=!0;break}const a=o.PositionAndShape.AbsolutePosition.x+o.PositionAndShape.Size.width,l=e.PositionAndShape.AbsolutePosition.x;a-15<l&&l<a+15&&i.push({measure:o,x:Math.abs(l-a)})}if(n)break;s=null===(m=i.sort(((e,t)=>e.x-t.x)))||void 0===m||null===(p=m[0])||void 0===p?void 0:p.measure;break}}}catch(w){}let n=0;var b,M;if(s)n=(null===(b=s.stave)||void 0===b?void 0:b.end_x)||0;else n=(null===(M=o.sourceNote.SourceMeasure.VerticalMeasureList[0])||void 0===M?void 0:M.getVFStave()).end_x;const r=0;l.ScreenPosition.x=n,l.ScreenPosition.y=0===t?10*(e.PositionAndShape.Parent.AbsolutePosition.y-3-r):10*t}const v=["C","G","D","A","E","B","F#","C#","G#","F","Bb","Eb","Ab","Db","Gb","Cb","Fb","D#","A#","E#"];v.includes(a.text)&&(l.ScreenPosition.y=10*(e.PositionAndShape.Parent.AbsolutePosition.y+e.PositionAndShape.Parent.BorderTop+e.PositionAndShape.Parent.BorderMarginTop)),["play","listen"].includes(a.text.toLocaleLowerCase())&&a.textAlignment===ce.LeftBottom&&(l.ScreenPosition.y=10*(e.PositionAndShape.Parent.AbsolutePosition.y-1+e.PositionAndShape.Parent.BorderBottom));const P=["ffp","p-f","sfzp","szf","sffzp"];for(let I=0;I<P.length;I++){const e=P[I].replace(/ /g,""),t=a.text.replace(/ /g,"");if(t.toLocaleLowerCase()===e.toLocaleLowerCase()||t.includes(e)){a.fontStyle=3,"sfzp"===a.text&&(a.fontHeight=2.3);break}}const E=e.PositionAndShape.Size.width/2*10;if(h.x-E<e.PositionAndShape.RelativePosition.x&&(l.ScreenPosition.x=10*(e.PositionAndShape.RelativePosition.x+this.rules.PageLeftMargin)),!Tt(e.Label.text||"")||v.includes(a.text)||e.Label.isLyricText||(e.Label.fontHeight=0),this.rules.MetronomeMarksDrawn&&e.Label.fontHeight>0&&(wt(e.Label.textAlignment)||[ce.CenterBottom].includes(e.Label.textAlignment))){let t=-1,i=!1;for(const s of(null==u?void 0:u.AbstractExpressions)||[]){var L,x;if(s.Label===e?t=null==s||null===(x=s.parentMeasure)||void 0===x?void 0:x.measureListIndex:null!==(L=s.expression)&&void 0!==L&&L.TempoInBpm&&(i=s.expression.TempoInBpm>0),i&&t>-1){l.ScreenPosition.y-=40;break}}}const T=!/^\d+$/.test(e.Label.text);(!i&&!e.Label.isNotRender||T)&&this.renderLabel(e,t,l)}calculateLabel(e){const t=new Nt,i=e.Label;t.ScreenPosition=this.applyScreenTransformation(e.PositionAndShape.AbsolutePosition),t.FontHeightInPixel=this.calculatePixelDistance(i.fontHeight);const s=this.calculatePixelDistance(e.PositionAndShape.Size.width);switch(t.BitmapWidth=Math.ceil(s),t.BitmapHeight=e.TextLines?Math.ceil(t.FontHeightInPixel*(.2+e.TextLines.length)):10,i.textAlignment){case ce.LeftTop:break;case ce.LeftCenter:t.ScreenPosition.y-=t.BitmapHeight/2;break;case ce.LeftBottom:t.ScreenPosition.y-=t.BitmapHeight;break;case ce.CenterTop:t.ScreenPosition.x-=t.BitmapWidth/2;break;case ce.CenterCenter:t.ScreenPosition.x-=t.BitmapWidth/2,t.ScreenPosition.y-=t.BitmapHeight/2;break;case ce.CenterBottom:t.ScreenPosition.x-=t.BitmapWidth/2,t.ScreenPosition.y-=t.BitmapHeight,"筒音作5"===i.text&&"jianpu"===this.rules.DYMusicScoreType&&(t.ScreenPosition.x=80);break;case ce.RightTop:t.ScreenPosition.x-=t.BitmapWidth;break;case ce.RightCenter:t.ScreenPosition.x-=t.BitmapWidth,t.ScreenPosition.y-=t.BitmapHeight/2;break;case ce.RightBottom:t.ScreenPosition.x-=t.BitmapWidth,t.ScreenPosition.y-=t.BitmapHeight;break;default:throw new y("")}const n=e.PositionAndShape.Parent.DataObject,r=[1,3,7,9,15,20,22,24,28,30,36,41];var o,a;this.rules.DYMusicScoreId&&"1722157850347765762"===this.rules.DYMusicScoreId&&("."===i.text&&(t.ScreenPosition.x=142,t.ScreenPosition.y=134),"T"===i.text&&(this.needSpecialArrTs.push(t),1===(null==n||null===(o=n.measures)||void 0===o||null===(a=o[0])||void 0===a?void 0:a.MeasureNumber)?t.ScreenPosition.y+=20:t.ScreenPosition.y-=20));for(let l in this.needSpecialArrTs)r.includes(Number(l))&&(this.needSpecialArrTs[l].ScreenPosition.x-=20);return t}applyScreenTransformations(e){const t=[];for(const i of e)t.push(this.applyScreenTransformation(i));return t}drawSplitScreenLine(){}renderRectangle(e,t,i,s=void 0,n=1){throw new Error("not implemented")}drawScrollIndicator(){}drawSelectionStartSymbol(e){}drawSelectionEndSymbol(e){}renderLabel(e,t,i){throw new Error("not implemented")}renderSystemToScreen(e,t,i){}drawSkyLine(e){}drawBottomLine(e){}drawInstrumentBrace(e,t){}drawGroupBracket(e,t){}isVisible(e){return!0}drawMusicSystem(e){const t=this.getSystemAbsBoundingRect(e),i=this.getSytemBoundingBoxInPixels(t);this.drawMusicSystemComponents(e,i,t)}getSytemBoundingBoxInPixels(e){const t=this.applyScreenTransformationForRect(e);return t.x=Math.round(t.x),t.y=Math.round(t.y),t}getSystemAbsBoundingRect(e){const t=e.PositionAndShape.BoundingRectangle;return new ie(e.PositionAndShape.AbsolutePosition.x+e.PositionAndShape.BorderLeft-1,e.PositionAndShape.AbsolutePosition.y+e.PositionAndShape.BorderTop-1,t.width+6,t.height+2)}drawMusicSystemComponents(e,t,i){const s=this.graphicalMusicSheet.SelectionStartSymbol,n=this.graphicalMusicSheet.SelectionEndSymbol;this.drawingParameters.drawSelectionStartSymbol&&void 0!==s&&this.isVisible(s.PositionAndShape)&&this.drawSelectionStartSymbol(s),this.drawingParameters.drawSelectionEndSymbol&&void 0!==n&&this.isVisible(n.PositionAndShape)&&this.drawSelectionEndSymbol(n);for(const a of e.StaffLines)this.drawStaffLine(a),this.rules.RenderLyrics&&(a.LyricsDashes.length>0&&this.drawDashes(a.LyricsDashes),a.LyricLines.length>0&&this.drawLyricLines(a.LyricLines,a));for(const a of e.SystemLines)this.drawSystemLineObject(a);if(this.rules.RenderSystemLabelsAfterFirstPage||e.Parent===e.Parent.Parent.MusicPages[0])for(const a of e.Labels)a.SVGNode=this.drawLabel(a,G.Notes);const r=this.graphicalMusicSheet.ParentMusicSheet.Instruments,o=r.filter((e=>e.Visible)).length;for(const a of e.InstrumentBrackets)this.drawInstrumentBrace(a,e);if(r.length>0)if(o>1)for(const a of e.GroupBrackets)this.drawGroupBracket(a,e);else for(const a of e.GroupBrackets)a.Visible=!1;if(!this.leadSheet)for(const a of e.MeasureNumberLabels)a.SVGNode=this.drawLabel(a,G.Notes);for(const a of e.StaffLines)this.drawStaffLineSymbols(a);this.drawingParameters.drawMarkedAreas&&this.drawMarkedAreas(e)}activateSystemRendering(e,t,i,s){return!0}drawSystemLineObject(e){}drawStaffLine(e){for(const t of e.Measures)this.drawMeasure(t),t.parentSourceMeasure&&(t.parentSourceMeasure.WasRendered=!0);this.rules.RenderLyrics&&e.LyricsDashes.length>0&&this.drawDashes(e.LyricsDashes),this.drawOctaveShifts(e),this.drawPedals(e),this.drawWavyLines(e),this.drawExpressions(e),this.skyLineVisible&&this.drawSkyLine(e),this.bottomLineVisible&&this.drawBottomLine(e)}drawLyricLines(e,t){t.LyricLines.forEach((e=>{e.Start.y+=t.PositionAndShape.AbsolutePosition.y,e.End.y+=t.PositionAndShape.AbsolutePosition.y,e.Start.x+=t.PositionAndShape.AbsolutePosition.x,e.End.x+=t.PositionAndShape.AbsolutePosition.x,this.drawGraphicalLine(e,this.rules.LyricUnderscoreLineWidth,e.colorHex)}))}drawExpressions(e){}drawGraphicalLine(e,t,i="black"){return this.drawLine(e.Start,e.End,i,t)}drawLine(e,t,i="#FF0000FF",s){}drawDashes(e){e.forEach((e=>{var t;e.SVGNode=this.drawLabel(e,G.Notes),null===(t=e.SVGNode)||void 0===t||t.classList.add("dash")}))}drawOctaveShifts(e){}drawStaffLines(e){if(e.StaffLines){const t=e.PositionAndShape.AbsolutePosition;for(let i=0;i<5;i++)this.drawLineAsHorizontalRectangleWithOffset(e.StaffLines[i],t,G.Notes)}}drawSymbol(e,t,i,s=1,n=G.Notes){}get leadSheet(){return this.graphicalMusicSheet.LeadSheet}set leadSheet(e){this.graphicalMusicSheet.LeadSheet=e}drawPage(e){if(this.isVisible(e.PositionAndShape)){for(const t of e.MusicSystems)this.isVisible(t.PositionAndShape)&&this.drawMusicSystem(t);if(e===e.Parent.MusicPages[0])for(const t of e.Labels)t.SVGNode=this.drawLabel(t,G.Notes);this.drawableBoundingBoxElement&&this.drawBoundingBoxes(e.PositionAndShape,0,this.drawableBoundingBoxElement)}}drawBoundingBoxes(e,t=0,i="all"){const s=e.DataObject.constructor.name;let n=!1;"all"===i&&(n=!0),(n||s===i)&&this.drawBoundingBox(e,void 0,!0,s,t),t++,e.ChildElements.forEach((e=>this.drawBoundingBoxes(e,t,i)))}drawBoundingBox(e,t=void 0,i=!1,s=void 0,n=0){let r=new ie(e.AbsolutePosition.x+e.BorderMarginLeft,e.AbsolutePosition.y+e.BorderMarginTop,e.BorderMarginRight-e.BorderMarginLeft,e.BorderMarginBottom-e.BorderMarginTop);i&&(this.drawLineAsHorizontalRectangle(new X(new z(e.AbsolutePosition.x-1,e.AbsolutePosition.y),new z(e.AbsolutePosition.x+1,e.AbsolutePosition.y),.1,O.BaseWritingColor,t),n-1),this.drawLineAsVerticalRectangle(new X(new z(e.AbsolutePosition.x,e.AbsolutePosition.y-1),new z(e.AbsolutePosition.x,e.AbsolutePosition.y+1),.1,O.BaseWritingColor,t),n-1)),r=this.applyScreenTransformationForRect(r);const o=this.renderRectangle(r,G.Background,n,t,.5);if(s){const e=new pt(s),t=new Nt;t.BitmapWidth=r.width,t.BitmapHeight=r.height,t.FontHeightInPixel=r.height,t.ScreenPosition=new z(r.x,r.y+12),this.renderLabel(new mt(e,.8,ce.CenterCenter,this.rules),n,t)}return o}drawMarkedAreas(e){for(const t of e.GraphicalMarkedAreas)t&&(t.systemRectangle&&this.drawRectangle(t.systemRectangle,G.Background),t.settings&&(t.settings.SVGNode=this.drawLabel(t.settings,G.Comment)),t.labelRectangle&&this.drawRectangle(t.labelRectangle,G.Background),t.label&&(t.label.SVGNode=this.drawLabel(t.label,G.Comment)))}drawStaffLineSymbols(e){const t=e.ParentStaff.ParentInstrument,i=e.PositionAndShape.AbsolutePosition.x,s=e.PositionAndShape.AbsolutePosition.y+2,n=e.PositionAndShape.BorderRight;t.highlight&&this.drawingParameters.drawHighlights&&this.drawLineAsHorizontalRectangle(new X(new z(i,s),new z(i+n,s),4,O.Highlighted),G.Highlight);let r=At.Disabled,o=It.PLAY,a=this.drawingParameters.drawActivitySymbols;switch(this.phonicScoreMode){case Rt.Midi:o=It.PLAY,this.midiPlaybackAvailable&&e.ParentStaff.audible&&(r=At.PlaybackSymbols);break;case Rt.Following:o=It.MIC,e.ParentStaff.following&&(r=At.FollowSymbols);break;default:a=!1}if(a){const e=new z(i+n+2,s);this.drawSymbol(o,r,e)}if(this.drawingParameters.drawErrors)for(const l of e.Measures){const e=l.PositionAndShape,t=e.AbsolutePosition.x,i=e.AbsolutePosition.y+2;l.hasError&&this.graphicalMusicSheet.ParentMusicSheet.DrawErroneousMeasures&&this.drawLineAsHorizontalRectangle(new X(new z(t,i),new z(t+e.BorderRight,i),4,O.ErrorUnderlay),G.MeasureError)}}}class Bt{constructor(e){this.fontSize=20,this.fontSizeStandard=this.fontSize;const t=document.createElement("canvas");this.context=t.getContext("2d"),this.rules=e}computeTextWidthToHeightRatio(e,t,i,s=void 0,n=this.fontSize){return this.context.font=Jt.font(n,i,t,this.rules,s),this.context.measureText(e).width/n}setFontSize(e=this.fontSizeStandard){return this.fontSize=e,e}}class Dt extends ne{constructor(e,t,i){super(),this.expression=t,this.parentMeasure=i,this.boundingBox=new oe(this,e.PositionAndShape),this.parentStaffLine=e,this.parentStaffLine.AbstractExpressions.push(this),this.rules=e.ParentMusicSystem.rules}get Label(){return this.label}get ParentStaffLine(){return this.parentStaffLine}get SourceExpression(){return this.expression}get Placement(){return this.expression.Placement}}class Vt extends Dt{constructor(e,t){super(t.PositionAndShape.Parent.DataObject,e,e.parentMeasure),this.label=t}get GraphicalLabel(){return this.label}updateSkyBottomLine(){}}class kt extends Dt{constructor(e,t,i){super(t,e,i.parentSourceMeasure),this.mInstantaneousDynamicExpression=e,this.mMeasure=i}updateSkyBottomLine(){const e=this.parentStaffLine.SkyBottomLineCalculator,t=this.PositionAndShape.RelativePosition.x+this.PositionAndShape.BorderMarginLeft,i=this.PositionAndShape.RelativePosition.x+this.PositionAndShape.BorderMarginRight;let n=0;switch(this.Placement){case d.Above:n=this.PositionAndShape.RelativePosition.y+this.PositionAndShape.BorderMarginTop,e.updateSkyLineInRange(t,i,n);break;case d.Below:n=this.PositionAndShape.RelativePosition.y+this.PositionAndShape.BorderMarginBottom,e.updateBottomLineInRange(t,i,n);break;default:s.error("Placement for GraphicalInstantaneousDynamicExpression is unknown")}}}class Ft extends Dt{constructor(e,t,i){super(t,e,i),this.lines=[],this.isSplittedPart=!1,this.notToBeRemoved=!1}get StartMeasure(){return this.startMeasure}set StartMeasure(e){this.startMeasure=e}get EndMeasure(){return this.endMeasure}set EndMeasure(e){this.endMeasure=e}get EndStaffLine(){return this.endMeasure?this.endMeasure.ParentStaffLine:void 0}get IsSplittedPart(){return this.isSplittedPart}set IsSplittedPart(e){this.isSplittedPart=e}get IsVerbal(){return this.ContinuousDynamic.Label&&this.ContinuousDynamic.Label.length>0}get NotToBeRemoved(){return this.notToBeRemoved}set NotToBeRemoved(e){this.notToBeRemoved=e}get Lines(){return this.lines}get ContinuousDynamic(){return this.SourceExpression}updateSkyBottomLine(){const e=this.parentStaffLine.SkyBottomLineCalculator,t=this.IsVerbal?this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginLeft:0,i=this.IsVerbal?this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginRight:0;var n;switch(!this.IsSoftAccent&&!this.IsVerbal&&this.lines.length<2&&s.warn("Not enough lines for SkyBottomLine calculation"),this.IsVerbal||this.ContinuousDynamic.DynamicType!==p.crescendo&&this.ContinuousDynamic.DynamicType!==p.diminuendo&&s.warn("GraphicalContinuousDynamicExpression.updateSkyBottomLine(): unhandled continuous dynamic type. start measure: "+(null===(n=this.startMeasure)||void 0===n?void 0:n.MeasureNumber)),this.Placement){case d.Above:if(this.IsSoftAccent)e.updateSkyLineWithWedge(this.lines[0].Start,this.lines[0].End),e.updateSkyLineWithWedge(this.lines[2].End,this.lines[2].Start),e.updateSkyLineWithLine(this.lines[0].End,this.lines[2].End,this.lines[0].End.y);else if(this.IsVerbal){const s=this.label.PositionAndShape.BorderMarginTop+this.label.PositionAndShape.RelativePosition.y;e.updateSkyLineInRange(t,i,s)}else this.ContinuousDynamic.DynamicType===p.crescendo?e.updateSkyLineWithWedge(this.lines[0].Start,this.lines[0].End):this.ContinuousDynamic.DynamicType===p.diminuendo&&e.updateSkyLineWithWedge(this.lines[0].End,this.lines[0].Start);break;case d.Below:if(this.IsVerbal){const s=this.label.PositionAndShape.BorderMarginBottom+this.label.PositionAndShape.RelativePosition.y;e.updateBottomLineInRange(t,i,s)}else this.ContinuousDynamic.DynamicType===p.crescendo?e.updateBottomLineWithWedge(this.lines[1].Start,this.lines[1].End):this.ContinuousDynamic.DynamicType===p.diminuendo&&e.updateBottomLineWithWedge(this.lines[1].End,this.lines[1].Start);break;default:s.error("Placement for GraphicalContinuousDynamicExpression is unknown")}}createCrescendoLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeLineWidth){const r=new z(e,i),o=new z(t,i-s/2),a=new z(t,i+s/2);this.addWedgeLines(r,o,a,n)}createFirstHalfCrescendoLines(e,t,i,s=this.rules.WedgeMeasureEndOpeningLength,n=this.rules.WedgeLineWidth){const r=new z(e,i),o=new z(t,i-s/2),a=new z(t,i+s/2);this.addWedgeLines(r,o,a,n)}createSecondHalfCrescendoLines(e,t,i,s=this.rules.WedgeMeasureBeginOpeningLength,n=this.rules.WedgeOpeningLength,r=this.rules.WedgeLineWidth){const o=new z(e,i-s/2),a=new z(e,i+s/2),l=new z(t,i-n/2),h=new z(t,i+n/2);this.addDoubleLines(o,l,a,h,r)}recalculateCrescendoLines(e,t,i){const s=Math.abs(this.lines[0].Start.y-this.lines[1].Start.y)>1e-4;this.lines.clear(),s?this.createSecondHalfCrescendoLines(e,t,i):this.isSplittedPart?this.createFirstHalfCrescendoLines(e,t,i):this.createCrescendoLines(e,t,i)}createDiminuendoLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeLineWidth){const r=new z(e,i-s/2),o=new z(e,i+s/2),a=new z(t,i);this.addWedgeLines(a,r,o,n)}createFirstHalfDiminuendoLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeMeasureEndOpeningLength,r=this.rules.WedgeLineWidth){const o=new z(e,i-s/2),a=new z(e,i+s/2),l=new z(t,i-n/2),h=new z(t,i+n/2);this.addDoubleLines(o,l,a,h,r)}createSecondHalfDiminuendoLines(e,t,i,s=this.rules.WedgeMeasureBeginOpeningLength,n=this.rules.WedgeLineWidth){const r=new z(e,i-s/2),o=new z(e,i+s/2),a=new z(t,i);this.addWedgeLines(a,r,o,n)}recalculateDiminuendoLines(e,t,i){const s=Math.abs(this.lines[0].End.y-this.lines[1].End.y)>1e-4;this.lines.clear(),s?this.createFirstHalfDiminuendoLines(e,t,i):this.isSplittedPart?this.createSecondHalfDiminuendoLines(e,t,i):this.createDiminuendoLines(e,t,i)}createFirstHalfLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeMeasureEndOpeningLength,r=this.rules.WedgeLineWidth){this.ContinuousDynamic.DynamicType===p.crescendo?this.createFirstHalfCrescendoLines(e,t,i,n,r):this.ContinuousDynamic.DynamicType===p.diminuendo&&this.createFirstHalfDiminuendoLines(e,t,i,s,n,r)}createSecondHalfLines(e,t,i,s=this.rules.WedgeMeasureBeginOpeningLength,n=this.rules.WedgeOpeningLength,r=this.rules.WedgeLineWidth){this.ContinuousDynamic.DynamicType===p.crescendo?this.createSecondHalfCrescendoLines(e,t,i,s,n,r):this.ContinuousDynamic.DynamicType===p.diminuendo&&this.createSecondHalfDiminuendoLines(e,t,i,s,r)}createLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeLineWidth){this.ContinuousDynamic.DynamicType===p.crescendo?this.createCrescendoLines(e,t,i,s,n):this.ContinuousDynamic.DynamicType===p.diminuendo&&this.createDiminuendoLines(e,t,i,s,n)}calcPsi(){this.IsVerbal?this.PositionAndShape.calculateBoundingBox():(this.PositionAndShape.RelativePosition=this.lines[0].Start,this.PositionAndShape.BorderMarginTop=this.lines[0].End.y-this.lines[0].Start.y,this.PositionAndShape.BorderMarginBottom=this.lines[1].End.y-this.lines[1].Start.y,this.PositionAndShape.Center.y=(this.PositionAndShape.BorderMarginTop+this.PositionAndShape.BorderMarginBottom)/2,this.IsSoftAccent?(this.PositionAndShape.BorderMarginLeft=0,this.PositionAndShape.BorderMarginRight=this.lines[3].Start.x-this.lines[0].Start.x):this.ContinuousDynamic.DynamicType===p.crescendo?(this.PositionAndShape.BorderMarginLeft=0,this.PositionAndShape.BorderMarginRight=this.lines[0].End.x-this.lines[0].Start.x):(this.PositionAndShape.BorderMarginLeft=this.lines[0].End.x-this.lines[0].Start.x,this.PositionAndShape.BorderMarginRight=0))}cleanUp(){this.lines.clear()}shiftYPosition(e){this.IsVerbal?(this.PositionAndShape.RelativePosition.y+=e,this.PositionAndShape.calculateBoundingBox()):(this.lines[0].Start.y+=e,this.lines[0].End.y+=e,this.lines[1].End.y+=e)}squeeze(e){this.IsVerbal||Math.abs(this.lines[0].End.x-this.lines[0].Start.x)<Math.abs(e)||(this.ContinuousDynamic.DynamicType===p.crescendo?e>0?this.lines[0].Start.x+=e:(this.lines[0].End.x+=e,this.lines[1].End.x+=e):e<0?this.lines[0].Start.x+=e:(this.lines[0].End.x+=e,this.lines[1].End.x+=e),this.calcPsi())}addWedgeLines(e,t,i,s){const n=new X(e,t,s),r=new X(e,i,s);this.rules.DefaultColorMusic&&(n.colorHex=this.rules.DefaultColorMusic,r.colorHex=this.rules.DefaultColorMusic),this.lines.push(n),this.lines.push(r)}addDoubleLines(e,t,i,s,n){const r=new X(e,t,n),o=new X(i,s,n);this.rules.DefaultColorMusic&&(r.colorHex=this.rules.DefaultColorMusic,o.colorHex=this.rules.DefaultColorMusic),this.lines.push(r),this.lines.push(o)}}class Ot{constructor(e=A.default,t){this.drawCursors=!0,this.drawTitle=!0,this.drawSubtitle=!0,this.drawLyricist=!0,this.drawComposer=!0,this.drawCopyright=!1,this.drawCredits=!0,this.drawPartNames=!0,this.fingeringPosition=d.Left,this.drawHiddenNotes=!1,this.rules=t,this.rules||(this.rules=new xe),this.DrawingParametersEnum=e}set DrawingParametersEnum(e){switch(this.drawingParametersEnum=e,e){case A.allon:this.setForAllOn();break;case A.thumbnail:this.setForThumbnail();break;case A.leadsheet:this.setForLeadsheet();break;case A.compact:this.setForCompactMode();break;case A.compacttight:this.setForCompactTightMode();break;case A.default:default:this.setForDefault()}}get DrawingParametersEnum(){return this.drawingParametersEnum}setForAllOn(){this.drawHighlights=!0,this.drawErrors=!0,this.drawSelectionStartSymbol=!0,this.drawSelectionEndSymbol=!0,this.drawCursors=!0,this.drawActivitySymbols=!0,this.drawScrollIndicator=!0,this.drawAnnotations=!0,this.drawComments=!0,this.drawMarkedAreas=!0,this.DrawTitle=!0,this.DrawSubtitle=!0,this.DrawComposer=!0,this.DrawLyricist=!0,this.drawCredits=!0,this.DrawPartNames=!0,this.drawHiddenNotes=!0,this.rules.CompactMode=!1}setForDefault(){this.rules.loadDefaultValues(),this.setForAllOn(),this.drawHiddenNotes=!1}setForThumbnail(){this.drawHighlights=!1,this.drawErrors=!1,this.drawSelectionStartSymbol=!1,this.drawSelectionStartSymbol=!1,this.drawCursors=!1,this.drawActivitySymbols=!1,this.drawScrollIndicator=!1,this.drawAnnotations=!0,this.drawComments=!0,this.drawMarkedAreas=!0,this.drawHiddenNotes=!1}setForCompactMode(){this.rules.CompactMode=!0,this.DrawCredits=!1,this.drawHiddenNotes=!1}setForCompactTightMode(){this.setForCompactMode(),this.DrawPartNames=!1,this.rules.VoiceSpacingMultiplierVexflow=.65,this.rules.VoiceSpacingAddendVexflow=2,this.rules.MinSkyBottomDistBetweenStaves=1,this.rules.MinSkyBottomDistBetweenSystems=1,this.rules.BetweenStaffDistance=2.5,this.rules.StaffDistance=3.5,this.rules.MinimumDistanceBetweenSystems=1,this.rules.PageBottomMargin=0,this.rules.PageLeftMargin=2,this.rules.PageRightMargin=2}setForLeadsheet(){this.drawHighlights=!1,this.drawErrors=!1,this.drawSelectionStartSymbol=!0,this.drawSelectionEndSymbol=!0,this.drawCursors=!0,this.drawActivitySymbols=!1,this.drawScrollIndicator=!0,this.drawAnnotations=!0,this.drawComments=!0,this.drawMarkedAreas=!0}get DrawCredits(){return this.drawCredits}set DrawCredits(e){this.drawCredits=e,this.DrawComposer=e,this.DrawTitle=e,this.DrawSubtitle=e,this.DrawLyricist=e,this.DrawCopyright=e}get DrawTitle(){return this.drawTitle}set DrawTitle(e){this.drawTitle=e,this.rules.RenderTitle=e,e||(this.DrawSubtitle=!1)}get DrawSubtitle(){return this.drawSubtitle}set DrawSubtitle(e){this.drawSubtitle=e,this.rules.RenderSubtitle=e,e&&(this.DrawTitle=!0)}get DrawComposer(){return this.drawComposer}set DrawComposer(e){this.drawComposer=e,this.rules.RenderComposer=e}get DrawLyricist(){return this.drawLyricist}set DrawLyricist(e){this.drawLyricist=e,this.rules.RenderLyricist=e}get DrawCopyright(){return this.drawCopyright}set DrawCopyright(e){this.drawCopyright=e,this.rules.RenderCopyright=e}get DrawPartNames(){return this.drawPartNames}set DrawPartNames(e){this.drawPartNames=e,this.rules.RenderPartNames=e,this.rules.RenderPartNames||(this.rules.RenderPartAbbreviations=!1)}get FingeringPosition(){return this.fingeringPosition}set FingeringPosition(e){this.fingeringPosition=e,this.rules.FingeringPosition=e}get Rules(){return this.rules}set Rules(e){this.rules=e}}class _t extends Dt{constructor(e,t,i,s,n=void 0){super(e,new c(i),s),this.label=t,this.sourceMultiExpression=n}updateSkyBottomLine(){const e=this.parentStaffLine.SkyBottomLineCalculator,t=this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginLeft,i=this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginRight;switch(this.Placement){case d.Above:const n=this.label.PositionAndShape.BorderMarginTop+this.label.PositionAndShape.RelativePosition.y;e.updateSkyLineInRange(t,i,n);break;case d.Below:const r=this.label.PositionAndShape.BorderMarginBottom+this.label.PositionAndShape.RelativePosition.y;e.updateBottomLineInRange(t,i,r);break;default:s.error("Placement for GraphicalUnknownExpression is unknown")}}}const Gt=n.Flow;class Wt{getInnerElement(){return this.inner}getCanvas(){return this.canvas}getRenderElement(){let e=this.canvas;return this.getVexflowBackendType()===Gt.Renderer.Backends.CANVAS&&(e=this.inner),e}getRenderer(){return this.renderer}removeAllChildrenFromContainer(e){for(;0!==e.children.length;)e.removeChild(e.children.item(0))}removeFromContainer(e){const t=this.getRenderElement();for(let i=0;i<e.children.length;i++)if(e.children.item(i)===t){e.removeChild(t);break}}resize(e,t){this.renderer.resize(e,t),this.width=e,this.height=t}}const Ut=n.Flow;class Xt extends Wt{constructor(e){super(),this.rules=e,this.textId=0}getVexflowBackendType(){return Ut.Renderer.Backends.SVG}getOSMDBackendType(){return B.SVG}getCanvasSize(){var e;return null===(e=document.getElementById("osmdCanvasPage"+this.graphicalMusicPage.PageNumber))||void 0===e?void 0:e.offsetHeight}initialize(e,t,i=void 0){this.zoom=t,this.canvas=document.createElement("div"),i||(i=this.graphicalMusicPage?this.graphicalMusicPage.PageNumber.toString():"1"),this.canvas.id="osmdCanvasPage"+i,this.inner=this.canvas,this.inner.style.position="relative",this.canvas.style.zIndex="0",e.appendChild(this.inner),this.renderer=new n.Flow.Renderer(this.canvas,this.getVexflowBackendType()),this.ctx=this.renderer.getContext(),this.ctx.svg.id="osmdSvgPage"+i}getContext(){return this.ctx}getSvgElement(){return this.ctx.svg}removeNode(e){var t;const i=null===(t=this.ctx)||void 0===t?void 0:t.svg;if(!i)return!1;try{i.removeChild(e)}catch(n){return s.error(n),!1}return!0}free(){const e=this.ctx.svg;for(;e.lastChild;)e.removeChild(e.lastChild)}clear(){this.ctx&&(this.free(),this.rules.PageBackgroundColor&&(this.ctx.svg.style["background-color"]=this.rules.PageBackgroundColor))}scale(e){this.ctx.scale(e,e)}translate(e,t){}renderText(e,t,i,s,n,r,o=void 0,a=void 0,l,h){this.ctx.save();const u=this.ctx.openGroup("text");void 0!==l&&(u.setAttribute("class",`vf-lyric lyric${l}`),u.setAttribute("lyricIndex",h)),o&&(this.ctx.attributes.fill=o,this.ctx.attributes.stroke=o);let c=a;a&&"default"!==a||(c=this.rules.DefaultFontFamily),this.ctx.setFont(c,e,Jt.fontStyle(t)),this.ctx.attributes["font-size"]=`${e}px`,this.ctx.state["font-size"]=`${e}px`;let d="normal",f="normal";switch(t){case me.Bold:d="bold";break;case me.Italic:f="italic";break;case me.BoldItalic:d="bold",f="italic";break;default:d="normal"}return this.ctx.attributes["font-weight"]=d,this.ctx.state["font-weight"]=d,this.ctx.attributes["font-style"]=f,this.ctx.state["font-style"]=f,this.ctx.fillText(s,r.x,r.y+n),this.ctx.closeGroup(),this.ctx.restore(),u}renderRectangle(e,t,i,s=1){this.ctx.save();const n=this.ctx.openGroup("rect");return this.ctx.attributes.fill=i||Jt.style(t),this.ctx.attributes["fill-opacity"]=s,this.ctx.fillRect(e.x,e.y,e.width,e.height),this.ctx.restore(),this.ctx.attributes["fill-opacity"]=1,this.ctx.closeGroup(),n}renderLine(e,t,i="#FF0000FF",s=2,n){this.ctx.save();const r=this.ctx.openGroup("line",n);return this.ctx.beginPath(),this.ctx.moveTo(e.x,e.y),this.ctx.lineTo(t.x,t.y),this.ctx.attributes.stroke=i,this.ctx.lineWidth=s,this.ctx.stroke(),this.ctx.closeGroup(),this.ctx.restore(),r}renderCurve(e){if(this.rules.DYIsSingleLine){const t=Math.max(...e.map((e=>e.y))),i=Math.min(...e.map((e=>e.y)));if(t-i>100){const i=t-100;e.forEach((e=>{t-e.y>100&&(e.y=i)}))}}const t=this.ctx.openGroup("curve");return this.ctx.beginPath(),this.ctx.moveTo(e[0].x,e[0].y),this.ctx.bezierCurveTo(e[1].x,e[1].y,e[2].x,e[2].y,e[3].x,e[3].y),this.ctx.lineTo(e[7].x,e[7].y),this.ctx.bezierCurveTo(e[6].x,e[6].y,e[5].x,e[5].y,e[4].x,e[4].y),this.ctx.lineTo(e[0].x,e[0].y),this.ctx.closePath(),this.ctx.fill(),this.ctx.closeGroup(),t}renderPath(e,t=!0,i){const s=this.ctx.openGroup("path",i);let n;this.ctx.beginPath();for(const r of e)n?this.ctx.lineTo(r.x,r.y):(this.ctx.moveTo(r.x,r.y),n=r);return this.ctx.closePath(),t?this.ctx.fill():this.ctx.stroke(),this.ctx.stroke(),this.ctx.closeGroup(),s}export(){const e=this.ctx.svg.cloneNode(!0),t=document.implementation.createDocumentType("svg","-//W3C//DTD SVG 1.1//EN","http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"),i=document.implementation.createDocument("http://www.w3.org/2000/svg","svg",t);i.replaceChild(e,i.documentElement);const s=(new XMLSerializer).serializeToString(i),n=document.createElement("a");n.href="data:image/svg+xml; charset=utf8, "+encodeURIComponent(s.replace(/></g,">\n\r<")),n.download="opensheetmusicdisplay_download.svg",n.innerHTML=window.location.href+"/download",document.body.appendChild(n)}}const zt=10;class Ht extends Ct{constructor(e=new Ot){super(new Bt(e.Rules),e),this.backends=[],this.zoom=1,this.pageIdx=0,this.getDotId=(e,t)=>t?String(e.Label.PositionAndShape.RelativePosition[t]):String(e.Label.PositionAndShape.RelativePosition.x)+String(e.Label.PositionAndShape.RelativePosition.y),this.hasDot=(e,t,i,s)=>{const n=t||Object.values(s);for(const r of n){if(i)return e.x===r.x&&e.y===r.y;if(e.x===r.x)return!0}return!1}}get Zoom(){return this.zoom}get Backends(){return this.backends}initializeBackendForPage(e){this.backend=this.backends[e.PageNumber-1]}drawSheet(e){var t,i,s;"gonville"===this.rules.DefaultVexFlowNoteFont&&(n.Flow.DEFAULT_FONT_STACK=[null===(t=n.Flow.Fonts)||void 0===t?void 0:t.Gonville,null===(i=n.Flow.Fonts)||void 0===i?void 0:i.Bravura,null===(s=n.Flow.Fonts)||void 0===s?void 0:s.Custom]),n.Flow.STAVE_LINE_THICKNESS=this.rules.StaffLineWidth*zt,n.Flow.STEM_WIDTH=this.rules.StemWidth*zt,n.Flow.DEFAULT_NOTATION_FONT_SCALE=this.rules.VexFlowDefaultNotationFontScale,n.Flow.DEFAULT_TAB_FONT_SCALE=this.rules.VexFlowDefaultTabFontScale,this.pageIdx=0;for(const n of e.MusicPages){if(n.PageNumber>this.rules.MaxPageToDrawNumber)break;const e=this.backends[this.pageIdx];e.graphicalMusicPage=n,e.scale(this.zoom),this.pageIdx+=1}this.pageIdx=0,this.backend=this.backends[0],super.drawSheet(e)}drawPage(e){e&&(this.backend=this.backends[e.PageNumber-1],super.drawPage(e),this.pageIdx+=1)}clear(){for(const e of this.backends)e.clear()}setZoom(e){this.zoom=e}calculatePixelDistance(e){return e*zt}drawStaffLine(e){const t=this.backend.getContext().openGroup();t&&t.classList.add("staffline"),super.drawStaffLine(e);const i=e.PositionAndShape.AbsolutePosition;this.rules.RenderSlurs&&this.drawSlurs(e,i),this.backend.getContext().closeGroup(),this.rules.RenderGlissandi&&this.drawGlissandi(e,i)}drawSlurs(e,t){var i;const s=null===(i=window.GYM)||void 0===i?void 0:i.vfcurveItem;for(let l=0;l<e.GraphicalSlurs.length;l++){const i=e.GraphicalSlurs[l];if(!i.slur.isCrossed()){if(s&&s.length)try{const e=s.find(((e,t)=>(!e.index||e.index===l)&&e.MeasureNumberXML==i.staffEntries[i.staffEntries.length-1].parentMeasure.MeasureNumber));var n,r,o;e&&(i.bezierEndControlPt.y+=null!=e&&null!==(n=e.bezierEndControlPt)&&void 0!==n&&n.y?e.bezierEndControlPt.y:0,i.bezierEndPt.y+=null!=e&&null!==(r=e.bezierEndPt)&&void 0!==r&&r.y?e.bezierEndPt.y:0,i.bezierStartControlPt.y+=null!=e&&null!==(o=e.bezierStartControlPt)&&void 0!==o&&o.y?e.bezierStartControlPt.y:0)}catch(a){}this.drawSlur(i,t)}}}drawGlissandi(e,t){for(const i of e.GraphicalGlissandi)this.drawGlissando(i,t)}drawGlissando(e,t){if(e.StaffLine.ParentStaff.isTab||e.calculateLine(this.rules),e.Line){const i=new z(e.Line.Start.x+t.x,e.Line.Start.y),s=new z(e.Line.End.x+t.x,e.Line.End.y);e.Line.SVGElement=this.drawLine(i,s,e.Color,e.Width)}else{const t=e.vfTie;if(t){const e=this.backend.getContext();t.setContext(e),t.draw()}}}drawSlur(e,t){const i=[];let s,n,r,o;"jianpu"===this.rules.DYMusicScoreType?((e.placement>0||e.bezierStartPt.y>0)&&(e.bezierStartPt.y=-.8,e.bezierStartControlPt.y=-2.5),s=new z(e.bezierStartPt.x+t.x,e.bezierStartPt.y+t.y),n=new z(e.bezierStartControlPt.x+t.x,e.bezierStartControlPt.y+t.y),r=new z(e.bezierEndControlPt.x+t.x,e.bezierStartControlPt.y+t.y),o=new z(e.bezierEndPt.x+t.x,e.bezierStartPt.y+t.y)):(s=new z(e.bezierStartPt.x+t.x,e.bezierStartPt.y+t.y),n=new z(e.bezierStartControlPt.x+t.x,e.bezierStartControlPt.y+t.y),r=new z(e.bezierEndControlPt.x+t.x,e.bezierEndControlPt.y+t.y),o=new z(e.bezierEndPt.x+t.x,e.bezierEndPt.y+t.y)),i.push(this.applyScreenTransformation(s)),i.push(this.applyScreenTransformation(n)),i.push(this.applyScreenTransformation(r)),i.push(this.applyScreenTransformation(o)),e.placement===d.Above?(s.y-=.05,n.y-=.3,r.y-=.3,o.y-=.05):(s.y+=.05,n.y+=.3,r.y+=.3,o.y+=.05),i.push(this.applyScreenTransformation(s)),i.push(this.applyScreenTransformation(n)),i.push(this.applyScreenTransformation(r)),i.push(this.applyScreenTransformation(o)),e.SVGElement=this.backend.renderCurve(i)}drawMeasure(e){e.setAbsoluteCoordinates(e.PositionAndShape.AbsolutePosition.x*zt,e.PositionAndShape.AbsolutePosition.y*zt);const t=this.backend.getContext();try{e.draw(t)}catch(n){s.warn("VexFlowMusicSheetDrawer.drawMeasure",n)}let i=0;for(const s of e.staffEntries)this.drawStaffEntry(s),i=this.drawBuzzRolls(s,i)}drawBuzzRolls(e,t){for(const n of e.graphicalVoiceEntries)for(const e of n.notes){var i;if(null!==(i=e.sourceNote.TremoloInfo)&&void 0!==i&&i.tremoloUnmeasured){var s;const i=this.rules.TremoloBuzzRollThickness,n=.9,r=.5,o=e;let a,l;const h=o.vfnote[0].getStemDirection();let u;if(this.backend instanceof Xt&&(u=o.getStemSVG()),void 0!==(null===(s=u)||void 0===s?void 0:s.getBbox)){const e=u.getBBox();a=new z(e.x/10,e.y/10),l=e.height/10}else l=o.vfnote[0].getStemLength()/10,a=new z(o.vfnote[0].getStem().x_begin/10,o.vfnote[0].getStem().y_top/10),1===h&&(a.y-=l);let c=a.y+l/3;o.vfnote[0].getBeamCount()>1&&(c=a.y+l/2,-1===h&&(c-=r+.2));const d=a.x-.5,f=c,m=[],p=[new z(0,-i),new z(n-i,0),new z(-n+i,-r),new z(0,-i),new z(n,0),new z(0,i),new z(-n+i,0),new z(n-i,r),new z(0,i),new z(-n,0)];let g=new z(d,f);m.push(g);for(const e of p)g=m.last(),m.push(new z(g.x+e.x,g.y-e.y));this.DrawPath(m,o.ParentMusicPage,!0,`buzzRoll${t}`),t++}}return t}drawLine(e,t,i="#000000FF",s=.2){return e=this.applyScreenTransformation(e),t=this.applyScreenTransformation(t),this.backend.renderLine(e,t,i,s*zt)}DrawOverlayLine(e,t,i,s="#FF0000FF",n=.2,r){if(!i.PageNumber||i.PageNumber>this.backends.length||i.PageNumber<1)return;const o=i.PageNumber-1,a=this.backends[o];return e=this.applyScreenTransformation(e),t=this.applyScreenTransformation(t),r||(r=`overlayLine ${e.x}/${e.y}`),a.renderLine(e,t,s,n*zt,r)}DrawPath(e,t,i=!0,s){const n=t.PageNumber-1,r=this.backends[n],o=[];for(const a of e)o.push(this.applyScreenTransformation(a));return r.renderPath(o,i,s)}drawSkyLine(e){const t=e.PositionAndShape.AbsolutePosition,i=e.PositionAndShape.Size.width;this.drawSampledLine(e.SkyLine,t,i)}drawBottomLine(e){const t=new z(e.PositionAndShape.AbsolutePosition.x,e.PositionAndShape.AbsolutePosition.y),i=e.PositionAndShape.Size.width;this.drawSampledLine(e.BottomLine,t,i,"#0000FFFF")}drawSampledLine(e,t,i,s="#FF0000FF"){const n=[];let r=0;for(let a=0;a<e.length;a++)e[a]!==r&&(n.push(a),r=e[a]);const o=t;if(n.length>0){const t=this.rules.SamplingUnit;let r,a,l=new z(o.x,o.y),h=new z(n[0]/t+o.x,o.y);this.drawLine(l,h,s),e[0]>=0&&(r=new z(n[0]/t+o.x,o.y),a=new z(n[0]/t+o.x,o.y+e[n[0]]),this.drawLine(r,a,s));for(let i=1;i<n.length;i++)l=new z(n[i-1]/t+o.x,o.y+e[n[i-1]]),h=new z(n[i]/t+o.x,o.y+e[n[i-1]]),this.drawLine(l,h,s),r=new z(n[i]/t+o.x,o.y+e[n[i-1]]),a=new z(n[i]/t+o.x,o.y+e[n[i]]),this.drawLine(r,a,s);n[n.length-1]<e.length?(l=new z(n[n.length-1]/t+o.x,o.y+e[n[n.length-1]]),h=new z(o.x+i,o.y+e[n[n.length-1]]),this.drawLine(l,h,s)):(l=new z(n[n.length-1]/t+o.x,o.y),h=new z(o.x+i,o.y),this.drawLine(l,h,s))}else{const e=new z(o.x,o.y),t=new z(o.x+i,o.y);this.drawLine(e,t,s)}}drawStaffEntry(e){if(e.FingeringEntries.length>0)for(const t of e.FingeringEntries)t.SVGNode=this.drawLabel(t,G.Notes);if(void 0!==e.graphicalChordContainers&&e.graphicalChordContainers.length>0)for(const t of e.graphicalChordContainers){const e=t.GraphicalLabel;e.SVGNode=this.drawLabel(e,G.Notes)}this.rules.RenderLyrics&&e.LyricsEntries.length>0&&this.drawLyrics(e.LyricsEntries,G.Notes)}drawLyrics(e,t){e.forEach((e=>{var i;const s=e.GraphicalLabel;s.Label.colorDefault=this.rules.DefaultColorLyrics,s.SVGNode=this.drawLabel(s,t),null===(i=s.SVGNode)||void 0===i||i.classList.add("lyrics")}))}drawInstrumentBrace(e,t){e.draw(this.backend.getContext())}drawGroupBracket(e,t){e.draw(this.backend.getContext())}drawOctaveShifts(e){for(const i of e.OctaveShifts)if(i){const e=i,n=this.backend.getContext(),r=e.getTextBracket();this.rules.DefaultColorMusic&&(r.render_options.color=this.rules.DefaultColorMusic),r.setContext(n);try{r.draw()}catch(t){s.warn(t)}}}drawPedals(e){for(const t of e.Pedals)if(t){const e=t,i=this.backend.getContext(),s=e.getPedalMarking();s.render_options.color=this.rules.DefaultColorMusic,s.setContext(i),s.draw()}}drawWavyLines(e){for(const t of e.WavyLines)if(t){const e=t,i=this.backend.getContext(),s=e.getVibratoBracket();s.setContext(i),s.draw()}}getMaxExpressionsYAndDots(e){const t=[];let i=0;for(const h of e.measures)t.push(h.measureNumber);const s={},n={},r={};for(const h of e.AbstractExpressions)if(h instanceof _t&&t.includes(h.parentMeasure.MeasureNumber)){const e=this.getDotId(h),t=this.getDotId(h,"x");n[e]||(n[e]=[]),r[t]||(r[t]=[]),this.hasDot(h.Label.PositionAndShape.RelativePosition,n[e],!0)||(n[e].push(h.Label.PositionAndShape.RelativePosition),r[t].push(h.Label.PositionAndShape.RelativePosition)),s[e]=h.Label.PositionAndShape.RelativePosition}let o=0;for(const h of e.AbstractExpressions){var a;const e=null===(a=h.parentMeasure)||void 0===a?void 0:a.MeasureNumber;if(h instanceof _t&&t.includes(e)){var l;const t=null===(l=h.parentMeasure.verticalMeasureList[0])||void 0===l?void 0:l.stave,s=(null==t?void 0:t.end_x)-(null==t?void 0:t.x),n=this.getDotId(h,"x");if(1===(r[n]||[]).length&&o!==e){const e=h.Label.PositionAndShape.AbsolutePosition.y;i=0===i?e:Math.min(i,e)}1!==(r[n]||[]).length&&s/10<h.Label.PositionAndShape.MarginSize.width&&(o=e+1)}}return{maxY:i,dots:s,dotsPoint:n,dotsPointByX:r}}drawExpressions(e){const t={},i=[],{maxY:n,dotsPointByX:r}=this.getMaxExpressionsYAndDots(e);for(const o of e.AbstractExpressions)if(o instanceof kt)this.drawInstantaneousDynamic(o);else if(o instanceof Vt){const e=o.GraphicalLabel;e.SVGNode=this.drawLabel(e,G.Notes)}else if(o instanceof Ft)this.drawContinuousDynamic(o);else if(o instanceof _t){const e=this.getDotId(o),s=this.getDotId(o,"x");if(1===(r[s]||[]).length);else{const r=o.Label.PositionAndShape.AbsolutePosition.y;t[s]?i.includes(e)||0===t[s]||(o.Label.PositionAndShape.AbsolutePosition.y=r-1):(t[s]=-Math.abs(n-r),o.Label.PositionAndShape.AbsolutePosition.y=r+t[s]),i.push(e)}const a=o.Label;a.SVGNode=this.drawLabel(a,G.Notes)}else s.warn("Unkown type of expression!")}drawInstantaneousDynamic(e){var t,i,s;const n=(null==e||null===(t=e.mMeasure)||void 0===t||null===(i=t.stave)||void 0===i||null===(s=i.modifiers)||void 0===s?void 0:s.some((e=>{var t;return"StaveSection"===(null==e||null===(t=e.attrs)||void 0===t?void 0:t.type)&&(null==e?void 0:e.section)>0&&isFinite(null==e?void 0:e.section)})))||!1,r=e.Label;r.SVGNode=this.drawLabel(r,G.Notes,n)}drawContinuousDynamic(e){if(e.IsVerbal){const t=e.Label;t.SVGNode=this.drawLabel(t,G.Notes)}else{var t;try{if(2===e.Lines.length&&Math.abs(e.Lines[0].Start.x-e.Lines[1].Start.x)>Number.EPSILON){let t=Math.min(...e.Lines.map((e=>e.Start.x))),i=Math.min(...e.Lines.map((e=>e.Start.y)));e.Lines[0].Start.x=t,e.Lines[1].Start.x=t,e.Lines[0].Start.y=i+this.rules.WedgeOpeningLength/2,e.Lines[1].Start.y=i+2*this.rules.WedgeOpeningLength,e.Lines[0].End.y+=this.rules.WedgeOpeningLength/2,e.Lines[1].End.y+=this.rules.WedgeOpeningLength}}catch(s){}const n=this.backend.getContext(),r=n.openGroup("lineGroup");null!=e&&null!==(t=e.parentMeasure)&&void 0!==t&&t.MeasureNumberXML&&(null==r||r.setAttribute("data-mnum",String(e.parentMeasure.MeasureNumberXML)));for(const t of e.Lines){var i;const s=new z(e.ParentStaffLine.PositionAndShape.AbsolutePosition.x+t.Start.x,e.ParentStaffLine.PositionAndShape.AbsolutePosition.y+t.Start.y),n=new z(e.ParentStaffLine.PositionAndShape.AbsolutePosition.x+t.End.x,e.ParentStaffLine.PositionAndShape.AbsolutePosition.y+t.End.y);t.SVGElement=this.drawLine(s,n,null!==(i=t.colorHex)&&void 0!==i?i:"#000000",t.Width)}n.closeGroup()}}renderLabel(e,t,i){return this._renderLabel(e,i)}_renderLabel(e,t){if(!e.Label.print)return;const i=e.Label.fontHeight*zt,{font:s}=e.Label;let n;this.rules.ColoringEnabled&&(n=e.Label.colorDefault,e.ColorXML&&(n=e.ColorXML),e.Label.color&&(n=e.Label.color.toString()),n||(n=this.rules.DefaultColorLabel));let r,{fontStyle:o,fontFamily:a}=e.Label;o||(o=this.rules.DefaultFontStyle),a||(a=this.rules.DefaultFontFamily);for(let c=0;c<(null===(l=e.TextLines)||void 0===l?void 0:l.length);c++){var l,h,u;const a=e.TextLines[c],d=this.calculatePixelDistance(a.xOffset),f=new z(t.ScreenPosition.x+d,t.ScreenPosition.y),m=this.backend.renderText(i,o,s,a.text,t.FontHeightInPixel,f,n,e.Label.fontFamily,null===(h=e.Label)||void 0===h?void 0:h.lyricExtendNoteId,null===(u=e.Label)||void 0===u?void 0:u.lyricVerseNumber);void 0!==a.trackIndex&&m.setAttribute("data-trackIdx",a.trackIndex),r?r.appendChild(m):r=m,t.ScreenPosition.y=t.ScreenPosition.y+t.FontHeightInPixel,e.TextLines.length>1&&(t.ScreenPosition.y+=this.rules.SpacingBetweenTextLines)}return r}renderRectangle(e,t,i,s,n){return this.backend.renderRectangle(e,i,s,n)}applyScreenTransformation(e){return new z(e.x*zt,e.y*zt)}applyScreenTransformationForRect(e){return new ie(e.x*zt,e.y*zt,e.width*zt,e.height*zt)}}class Yt extends Ae{constructor(e,t,i,s,n,r,o,a){super(e,t,i,s,n),this.stringNumberTab=r,this.fretNumber=o,this.bendArray=a}get StringNumberTab(){return this.stringNumberTab}get FretNumber(){return this.fretNumber}get BendArray(){return this.bendArray}hasTabEffects(){var e;return(null===(e=this.bendArray)||void 0===e?void 0:e.length)>0}}const jt=n.Flow,Kt=class{static durations(e,t){const i=[],s=e.clone();for(;s.RealValue>1e-4;){const e=s.RealValue;if(e>=2)i.push("1/2"),s.Sub(new u(2,1));else if(e>=1)i.push("w"),s.Sub(new u(1,1));else if(e<1&&e>=.5){if(t&&e>.5)return["w"];i.push("h"),s.Sub(new u(1,2))}else if(e<.5&&e>=.25){if(t&&e>.25)return["h"];i.push("q"),s.Sub(new u(1,4))}else if(e<.25&&e>=.125){if(t&&e>.125)return["q"];i.push("8"),s.Sub(new u(1,8))}else if(e<.125&&e>=.0625){if(t&&e>.0625)return["8"];i.push("16"),s.Sub(new u(1,16))}else if(e<.0625&&e>=.03125){if(t&&e>.03125)return["16"];i.push("32"),s.Sub(new u(1,32))}else if(e<.03125&&e>=.015625){if(t&&e>.015625)return["32"];i.push("64"),s.Sub(new u(1,64))}else{if(t)return["64"];i.push("128"),s.Sub(new u(1,128))}}return i}static pitch(e,t,i,s=void 0,n=void 0){let r=n;void 0===n&&(r=3),t&&void 0===n&&(r=0,i.ClefType===q.F&&(r=2),i.ClefType===q.C&&(r=2));const o=H[e.FundamentalNote].toLowerCase(),a=K.accidentalVexflow(e.Accidental),l=e.Octave-i.OctaveOffset+r;let h="";return s&&(h=this.NoteHeadCode(s)),[o+"n/"+l+h,a,i]}static restToNotePitch(e,t){let i=e.Octave;switch(t){case q.C:case q.F:i+=2;case q.G:}return new K(e.FundamentalNote,i,Y.NONE)}static NoteHeadCode(e){const t=e.Filled?"2":"1";switch(e.Shape){case Ue.NORMAL:return"";case Ue.DIAMOND:return"/D"+t;case Ue.TRIANGLE:return"/T"+t;case Ue.TRIANGLE_INVERTED:return"/TI";case Ue.X:return"/X"+t;case Ue.CIRCLEX:return"/X3";case Ue.RECTANGLE:return"/R"+t;case Ue.SQUARE:return"/S"+t;case Ue.SLASH:default:return""}}static GhostNotes(e){const t=[],i=Kt.durations(e,!1);for(const s of i)t.push(new jt.GhostNote({duration:s}));return t}static StaveNote(e){var t,i,s;e.sortForVexflow();const n=e.notes,o=e.parentStaffEntry.parentMeasure.parentSourceMeasure.Rules,a=n[0];let l,h=[];const c=[],d=a.graphicalNoteLength,f=void 0!==a.sourceNote.NoteTuplet;let m,p=Kt.durations(d,f)[0];Kt.idx+=1,void 0!==a.sourceNote.TypeLength&&a.sourceNote.TypeLength!==d&&0!==a.sourceNote.TypeLength.RealValue&&(p=Kt.durations(a.sourceNote.TypeLength,f)[0],a.numberOfDots=a.sourceNote.DotsXml);let g,S,y=a.numberOfDots,b=!1,M=0,v=!1;for(const r of n){var P,E;if(y<r.numberOfDots&&(y=r.numberOfDots),r.sourceNote.isRest()){if(v=!0,r.sourceNote.Pitch){h=[r.vfpitch[0]];break}{var L;h=["b/4"];const e=null===(L=r.parentVoiceEntry)||void 0===L?void 0:L.parentVoiceEntry;if(e){var x;const t=null===(x=r.parentVoiceEntry)||void 0===x?void 0:x.parentStaffEntry.parentMeasure.staffEntries;let i,s,n=-1;for(let r=0;r<t.length;r++){var T;if((null===(T=t[r])||void 0===T?void 0:T.graphicalVoiceEntries[0].parentVoiceEntry)===e){n=r;break}}var w,I,A,R;if(n>=1&&t.length-1>=n+1&&(i=null===(w=t[n-1])||void 0===w||null===(I=w.graphicalVoiceEntries[0])||void 0===I?void 0:I.parentVoiceEntry,s=null===(A=t[n+1])||void 0===A||null===(R=A.graphicalVoiceEntries[0])||void 0===R?void 0:R.parentVoiceEntry,i&&s)){var N;const e=i.Notes[0],t=s.Notes[0];if(null!==(N=e.NoteBeam)&&void 0!==N&&N.Notes.includes(t)&&1!==t.ParentStaffEntry.ParentStaff.StafflineCount){const e=i.Notes.last().Pitch,t=r.Clef(),s=Kt.pitch(Kt.restToNotePitch(e.getTransposedPitch(-2),t.ClefType),!1,t);4===e.FundamentalNote&&(h=[s[0]])}}}}if((r.sourceNote.IsWholeMeasureRest||d.RealValue===r.sourceNote.SourceMeasure.ActiveTimeSignature.RealValue)&&(h="staff"===o.DYMusicScoreType?["d/5"]:["R/5"],p="w",y=0,b=!0,M=o.WholeRestXShiftVexflow*zt),[...r.sourceNote.ParentStaff.Voices].filter((e=>1!=(null==e?void 0:e.VoiceId))).length){const e=r.parentVoiceEntry.parentStaffEntry.graphicalVoiceEntries,t=r.parentVoiceEntry.parentVoiceEntry.ParentVoice.VoiceId;let i,s;for(const n of e)for(const e of n.notes){if(e===r||e.sourceNote.isRest()||!e.sourceNote.PrintObject){r.lineShift=-2;continue}const n=e.parentVoiceEntry.parentVoiceEntry.WantedStemDirection,a=1===t||5===t,l=a?1:-1,h=e.sourceNote.Pitch.getHalfTone();(!i||1===l&&h>i||-1===l&&h<i)&&(i=h,s=0,a&&n===dt.Up?s+=7:a||n!==dt.Down?s+=a?1:2:s+=7,p.includes("8")||n===dt.Up&&-1===l&&(s+=1),e.sourceNote.NoteBeam&&(s+=1),p.includes("w")&&(s=3.5),s+=.5*Math.ceil(o.RestCollisionYPadding),s*=l,r.lineShift=s)}if(i>0){let e=3;const t=r.Clef();switch(t.ClefType){case q.F:e=5;break;case q.C:e=4}g=K.fromHalftone(i),h=[Kt.pitch(g,!0,t,void 0,e)[0]]}}break}r.sourceNote.Notehead&&(r.sourceNote.Notehead.Shape,Ue.SLASH);const e=r.vfpitch;if(null!==(P=e[2])&&void 0!==P&&null!==(E=P.Parent)&&void 0!==E&&E.Instructions)for(let t=0,i=e[2].Parent.Instructions.length;t<i;++t){const i=e[2].Parent.Instructions[t];i instanceof Z&&(l=i)}h.push(e[0]),c.push(e[1]),m||(m=Kt.Clef(e[2]).type),"percussion"===m&&r.sourceNote.ParentStaff.StafflineCount}if(!m)try{const t=Kt.Clef(e.notes[0].clef);"percussion"===(null==t?void 0:t.type)&&e.notes[0].sourceNote.ParentStaff.StafflineCount}catch(U){}for(let r=0,u=y;r<u;++r)p+="d";1===n.length&&(null===(t=n[0].sourceNote.Notehead)||void 0===t?void 0:t.Shape)===Ue.SLASH&&(p+="s"),v&&(p+="r");const C={align_center:b,auto_stem:!1,clef:m,duration:p,keys:h,stem_direction:1,slash:e.GraceSlash,note_size:20,DYMusicScoreType:o.DYMusicScoreType,keyString:Kt.keySignature(l)},B=e.notes[0].sourceNote;if(B.IsCueNote&&(C.glyph_font_scale=jt.DEFAULT_NOTATION_FONT_SCALE*jt.GraceNote.SCALE,C.stroke_px=jt.GraceNote.LEDGER_LINE_OFFSET),e.parentVoiceEntry.IsGrace||e.notes[0].sourceNote.IsCueNote)"jianpu"===o.DYMusicScoreType?(C.ornament=!0,S=new r(C)):S=new jt.GraceNote(C);else{S="jianpu"===o.DYMusicScoreType?new r(C):new jt.StaveNote(C),S.stagger_same_whole_notes=o.StaggerSameWholeNotes;const t=e.parentStaffEntry.LyricsEntries;let i=!0,s=0;if(t.length>0&&o.RenderLyrics&&o.LyricsUseXPaddingForLongLyrics){const t=e.parentStaffEntry.parentMeasure,n=[];for(let i=t.staffEntries.indexOf(e.parentStaffEntry)+1;i<t.staffEntries.length;i++){const e=t.staffEntries[i];e.graphicalVoiceEntries[0]&&n.push(e)}let r,o=e.parentStaffEntry.relInMeasureTimestamp.clone();for(const a of n){const t=a.relInMeasureTimestamp.clone();if(r=u.minus(t,e.parentVoiceEntry.Timestamp),r.RealValue>.25){i=!1;break}if(a.LyricsEntries.length>0)break;s+=32*u.minus(t,o).RealValue,o=t}}if(o.RenderLyrics&&o.LyricsUseXPaddingForLongLyrics&&t.length>0&&i){let i=!1,r=0;for(const e of n)if(e.sourceNote.Length.RealValue<=.125){i=!0;break}let a=!1;for(const n of t){const t=o.LyricsXPaddingWidthThreshold;let l=n.GraphicalLabel.PositionAndShape.Size.width;if(n.hasDashFromLyricWord()&&(l+=.5),l>t){r+=l-t;const n=e.parentStaffEntry,h=n.parentMeasure.staffEntries,u=h.indexOf(n)===h.length-1;u&&(s+=o.LyricsXPaddingReductionForLastNoteInMeasure),i||(s+=o.LyricsXPaddingReductionForLongNotes),!o.LyricsXPaddingForLastNoteInMeasure&&u||l>t+s&&(a=!0,r-=s);break}}a&&(S.paddingRight=10*o.LyricsXPaddingFactorForLongLyrics*r)}}const D=e.notes[0].lineShift;if(0!==D&&(S.getKeyProps()[0].line+=D),n.length>1)for(let r=0;r<n.length;r++){var V;(null===(V=n[r].sourceNote.Notehead)||void 0===V?void 0:V.Shape)===Ue.SLASH&&(S.note_heads[r].note_type="s")}var k,F;(null===(i=window.GYM)||void 0===i?void 0:i.isDrumset)&&e.notes[0].sourceNote.isRest()&&(null===(k=e.notes[0].sourceNote.ParentStaffEntry)||void 0===k||null===(F=k.VoiceEntries)||void 0===F?void 0:F.length)>1&&1==e.notes[0].sourceNote.ParentVoiceEntry.ParentVoice.VoiceId&&(S.getKeyProps()[0].line=4.5);const O=null===(s=window.GYM)||void 0===s?void 0:s.customBassDrum;if(O&&S.isRest()&&("q"===S.getDuration()&&(S.getKeyProps()[0].line=O),"h"===S.getDuration()&&(S.getKeyProps()[0].line=O-1)),S.getKeyProps().forEach((({line:t},i)=>e.notes[i].staffLine=t)),(o.LedgerLineWidth||o.LedgerLineStrokeStyle)&&(S.ledgerLineStyle||(S.ledgerLineStyle={}),o.LedgerLineWidth&&(S.ledgerLineStyle.lineWidth=o.LedgerLineWidth),o.LedgerLineStrokeStyle&&(S.ledgerLineStyle.strokeStyle=o.LedgerLineStrokeStyle)),o.ColoringEnabled){const t=o.DefaultColorStem;let i=e.parentVoiceEntry.StemColor;!i&&t&&(i=t);const s={fillStyle:i,strokeStyle:i};i&&(S.setStemStyle(s),S.flag&&o.ColorFlags&&S.setFlagStyle(s))}if(S.x_shift=M,e.parentVoiceEntry.IsGrace&&e.notes[0].sourceNote.NoteBeam&&(e.parentVoiceEntry.WantedStemDirection=e.notes[0].sourceNote.NoteBeam.Notes[0].ParentVoiceEntry.WantedStemDirection),e.parentVoiceEntry){var _;let t=e.parentVoiceEntry.WantedStemDirection;const i=(null===(_=window.GYM)||void 0===_?void 0:_.stemDirectionNote)||[],s=null==i?void 0:i.find((t=>t.id===e.notes[0].sourceNote.NoteToGraphicalNoteObjectId));switch(s&&"number"==typeof(null==s?void 0:s.direction)&&(t=s.direction),t){case dt.Up:S.setStemDirection(jt.Stem.UP),e.parentVoiceEntry.StemDirection=dt.Up;break;case dt.Down:S.setStemDirection(jt.Stem.DOWN),e.parentVoiceEntry.StemDirection=dt.Down}}for(let r=0,u=n.length;r<u;r+=1){if(n[r].setIndex(S,r),c[r]){if("###"===c[r]){S.addAccidental(r,new jt.Accidental("##")),S.addAccidental(r,new jt.Accidental("#"));continue}if("bbs"===c[r]){S.addAccidental(r,new jt.Accidental("bb")),S.addAccidental(r,new jt.Accidental("b"));continue}S.addAccidental(r,new jt.Accidental(c[r]))}const e=n[r].sourceNote.TremoloStrokes,t=n[r].sourceNote.TremoloType;if(e>0&&"single"===t){const t=new jt.Tremolo(e);t.extra_stroke_scale=o.TremoloStrokeScale,t.y_spacing_scale=o.TremoloYSpacingScale,S&&"w"===S.duration&&S.stem.setExtension(-9),S.addModifier(r,t)}if(e>0&&"start"===t&&this.noteTremoloList.push(S),e>0&&"stop"===t){if(this.noteTremoloList.push(S),this.noteTremoloList.filter((e=>"w"===e.duration)).length===this.noteTremoloList.length)try{var G;if(this.noteTremoloList[0].keyProps&&this.noteTremoloList[1].keyProps)null===(G=(this.noteTremoloList[0].keyProps[0].line>this.noteTremoloList[1].keyProps[0].line?this.noteTremoloList[1]:this.noteTremoloList[0]).stem)||void 0===G||G.setResetHeight(30)}catch(U){console.error("设置都是全音符,stem的高度失败")}const t=new jt.Tremolo(e,[...this.noteTremoloList]);t.extra_stroke_scale=1.2,t.y_spacing_scale=1.2,t.x_shift=-30,S.addModifier(r,t),this.noteTremoloList=[]}this.glissandoList.length&&(S.setVibrato(this.glissandoList[0].vfnote[0]),this.glissandoList=[]),"start"===n[r].sourceNote.glissandoType&&this.glissandoList.push(n[r])}if(this.slideNote){try{S.setSlideNote(this.slideNote)}catch(U){console.error(U)}this.slideNote=null}if("start"===e.notes[0].sourceNote.slideType&&(this.slideNote=S),.25===B.Length.RealValue&&B.Notehead&&!1===B.Notehead.Filled){const e=S.getKeyProps();for(let t=0;t<e.length;t++)e[t].code="v81"}for(let r=0,u=y;r<u;++r)S.addDotToAll();if(h.length>1){var W;let e=S.getKeyProps().filter((e=>!e.code&&e.line>3));(null===(W=window.GYM)||void 0===W?void 0:W.stemDirectionNote)||e.length!==h.length||S.setStemDirection(-1)}"jianpu"===o.DYMusicScoreType&&window&&window.sett&&window.sett.keySignature&&S.addAccidental(0,new jt.Accidental("#"));try{const e=["b","#","§","º","X"],t={b:"b","#":"#","§":"n","º":"bb",X:"##"};for(const i of n){const s=i.sourceNote.voiceEntry.Timestamp;for(const n of i.sourceNote.SourceMeasure.StaffLinkedExpressions)for(const i of n){const n=u.Equal(s,i.Timestamp),r=i.EntriesList.map((e=>e.label)).filter((t=>e.includes(t))).map((e=>t[e]));if(n){for(const e of r)e&&S.addAnnotation(0,new jt.Annotation(e));break}}}}catch(U){}return S}static generateArticulations(e,t,i){if(e&&"GhostNote"!==e.getAttribute("type"))for(const h of t.sourceNote.ParentVoiceEntry.Articulations){let u,c=jt.Modifier.Position.ABOVE;e.getStemDirection()===jt.Stem.UP&&(c=jt.Modifier.Position.BELOW);const f=h.articulationEnum;switch(i.ArticulationPlacementFromXML&&(h.placement===d.Above?c=jt.Modifier.Position.ABOVE:h.placement===d.Below&&(c=jt.Modifier.Position.BELOW)),f){case ct.accent:{u=new jt.Articulation("a>");const e=t.sourceNote.NoteSlurs;for(const s of e)s.StartNote===t.sourceNote&&(s.PlacementXml===d.Above?u.setYShift(10*-i.SlurStartArticulationYOffsetOfArticulation):s.PlacementXml===d.Below&&u.setYShift(10*i.SlurStartArticulationYOffsetOfArticulation));break}case ct.breathmark:u=new jt.Articulation("abr"),h.placement===d.Above&&(c=jt.Modifier.Position.ABOVE),u.breathMarkDistance=i.BreathMarkDistance;break;case ct.downbow:u=new jt.Articulation("am"),void 0===h.placement&&(c=jt.Modifier.Position.ABOVE,h.placement=d.Above);break;case ct.fermata:u=new jt.Articulation("a@a"),c=jt.Modifier.Position.ABOVE,h.placement=d.Above;break;case ct.marcatodown:u=new jt.Articulation("a|");break;case ct.marcatoup:u=new jt.Articulation("a^"),c=jt.Modifier.Position.ABOVE;break;case ct.invertedfermata:{const e=t.sourceNote.ParentVoiceEntry;if(e!==t.sourceNote.ParentVoiceEntry.ParentSourceStaffEntry.VoiceEntries.last()){e.Articulations=e.Articulations.slice(e.Articulations.indexOf(h)),e.ParentSourceStaffEntry.VoiceEntries.last().Articulations.push(h);continue}u=new jt.Articulation("a@u"),c=jt.Modifier.Position.BELOW,h.placement=d.Below;break}case ct.lefthandpizzicato:u=new jt.Articulation("a+");break;case ct.naturalharmonic:u=new jt.Articulation("ah");break;case ct.snappizzicato:u=new jt.Articulation("ao");break;case ct.staccatissimo:u=new jt.Articulation("av");break;case ct.staccato:u=new jt.Articulation("a.");break;case ct.tenuto:u=new jt.Articulation("a-");break;case ct.upbow:u=new jt.Articulation("a|"),void 0===h.placement&&(c=jt.Modifier.Position.ABOVE,h.placement=d.Above);break;case ct.strongaccent:u=new jt.Articulation("a^")}if(u){var s,n,r,o,a,l;if(!e.hasStem()&&!e.isRest()&&f==ct.accent&&e.getLineNumber()>=3&&(c=jt.Modifier.Position.ABOVE,null!=e&&null!==(r=e.modifiers)&&void 0!==r&&null!==(o=r.filter((e=>["TREMOLO"].includes(e.getCategory().toLocaleUpperCase()))))&&void 0!==o&&o.length&&u.setYShift(-16)),f===ct.strongaccent)c=jt.Modifier.Position.ABOVE,(null===(a=window.GYM)||void 0===a?void 0:a.customArtPosition)&&(1===e.getStemDirection()?c=jt.Modifier.Position.ABOVE:(c=jt.Modifier.Position.BELOW,u=new jt.Articulation("a|")));if((null===(s=window.GYM)||void 0===s?void 0:s.customAccentItem)&&f===ct.accent&&(c=jt.Modifier.Position.ABOVE),!(null===(n=window.GYM)||void 0===n?void 0:n.customLefthandpizzicatoItem)||f!==ct.lefthandpizzicato&&f!==ct.naturalharmonic||(c=jt.Modifier.Position.ABOVE),f===ct.tenuto&&"w"===e.getDuration())(null===(l=window.GYM)||void 0===l?void 0:l.customTenutoItem)&&(c=jt.Modifier.Position.ABOVE);f===ct.tenuto&&"jianpu"===i.DYMusicScoreType&&(c=jt.Modifier.Position.ABOVE,u.setYShift(-15),u.setXShift(3)),f===ct.staccatissimo&&"jianpu"===i.DYMusicScoreType&&(c=jt.Modifier.Position.ABOVE),u.setPosition(c),e.addModifier(0,u)}}}static generateOrnaments(e,t){let i,n=jt.Modifier.Position.ABOVE;switch(t.placement===d.Below&&(n=jt.Modifier.Position.BELOW),t.GetOrnament){case je.DelayedInvertedTurn:i=new jt.Ornament("turn_inverted"),i.setDelayed(!0);break;case je.DelayedTurn:i=new jt.Ornament("turn"),i.setDelayed(!0);break;case je.InvertedMordent:i=new jt.Ornament("mordent"),i.setDelayed(!1);break;case je.InvertedTurn:i=new jt.Ornament("turn_inverted"),i.setDelayed(!1);break;case je.Mordent:i=new jt.Ornament("mordent_inverted"),i.setDelayed(!1);break;case je.Trill:i=new jt.Ornament("tr"),i.setDelayed(!1);break;case je.Turn:i=new jt.Ornament("turn"),i.setDelayed(!1);break;default:return void s.warn("unhandled OrnamentEnum type: "+t.GetOrnament)}i&&(t.AccidentalBelow!==Y.NONE&&i.setLowerAccidental(K.accidentalVexflow(t.AccidentalBelow)),t.AccidentalAbove!==Y.NONE&&i.setUpperAccidental(K.accidentalVexflow(t.AccidentalAbove)),i.setPosition(n),e.addModifier(0,i))}static StrokeTypeFromArpeggioType(e){switch(e){case ke.ARPEGGIO_DIRECTIONLESS:return jt.Stroke.Type.ARPEGGIO_DIRECTIONLESS;case ke.BRUSH_DOWN:return jt.Stroke.Type.BRUSH_UP;case ke.BRUSH_UP:return jt.Stroke.Type.BRUSH_DOWN;case ke.RASQUEDO_DOWN:return jt.Stroke.Type.RASQUEDO_UP;case ke.RASQUEDO_UP:return jt.Stroke.Type.RASQUEDO_DOWN;case ke.ROLL_DOWN:return jt.Stroke.Type.ROLL_UP;case ke.ROLL_UP:return jt.Stroke.Type.ROLL_DOWN;default:return jt.Stroke.Type.ARPEGGIO_DIRECTIONLESS}}static CreateTabNote(e){const t=[],i=e.notes.reverse(),n=[],r=e.notes[0].graphicalNoteLength,o=void 0!==e.notes[0].sourceNote.NoteTuplet;let a=Kt.durations(r,o)[0],l=0;for(const c of e.notes){const i=c.sourceNote;let r={str:i.StringNumberTab,fret:i.FretNumber};c.sourceNote instanceof Yt||(s.info(`invalid tab note: ${c.sourceNote.Pitch.ToString()} in measure ${e.parentStaffEntry.parentMeasure.MeasureNumber}, likely missing XML string+fret number.`),r={str:1,fret:0}),t.push(r),i.BendArray&&i.BendArray.forEach((function(e){let t;const i=e.bendalter-r.fret;t=i>1?"Full":1===i?"1/2":"1/4","up"===e.direction?n.push({type:jt.Bend.UP,text:t,width:10}):n.push({type:jt.Bend.DOWN,text:t,width:10})})),l<c.numberOfDots&&(l=c.numberOfDots)}for(let s=0,c=l;s<c;++s)a+="d";const h=new jt.TabNote({duration:a,positions:t}),u=e.parentStaffEntry.parentMeasure.parentSourceMeasure.Rules;u.UsePageBackgroundColorForTabNotes&&(h.BackgroundColor=u.PageBackgroundColor);for(let s=0,c=i.length;s<c;s+=1)i[s].setIndex(h,s);return n.forEach((function(e){e.type===jt.Bend.UP?h.addModifier(new jt.Bend(e.text,!1)):h.addModifier(new jt.Bend(e.text,!0))})),h}static Clef(e,t="default"){let i,n;switch("default"!==t&&"small"!==t&&(s.warn(`Invalid VexFlow clef size "${t}" specified. Using "default".`),t="default"),e.ClefType){case q.G:switch(e.Line){case 1:i="french";break;case 2:i="treble";break;default:i="treble",s.error(`Clef ${q[e.ClefType]} on line ${e.Line} not supported by VexFlow. Using default value "${i}".`)}break;case q.F:switch(e.Line){case 4:i="bass";break;case 3:i="baritone-f";break;case 5:i="subbass";break;default:i="bass",s.error(`Clef ${q[e.ClefType]} on line ${e.Line} not supported by VexFlow. Using default value "${i}".`)}break;case q.C:switch(e.Line){case 3:i="alto";break;case 4:i="tenor";break;case 1:i="soprano";break;case 2:i="mezzo-soprano";break;default:i="alto",s.error(`Clef ${q[e.ClefType]} on line ${e.Line} not supported by VexFlow. Using default value "${i}".`)}break;case q.percussion:i="percussion";break;case q.TAB:i="treble";break;default:s.info("bad clef type: "+e.ClefType),i="treble"}return 1===e.OctaveOffset&&"bass"!==i?n="8va":-1===e.OctaveOffset&&(n="8vb"),{type:i,size:t,annotation:n}}static TimeSignature(e){let t;switch(e.SymbolEnum){case T.NONE:t=e.Rhythm.Numerator+"/"+e.Rhythm.Denominator;break;case T.COMMON:t="C";break;case T.CUT:t="C|"}return new jt.TimeSignature(t)}static keySignature(e){if(!e)return;let t;switch(e.Mode){case ee.minor:t=Kt.minorMap[e.Key]+"m";break;case ee.major:case ee.none:t=Kt.majorMap[e.Key];break;default:t="C"}return t}static line(e,t){switch(e){case Ne.SingleThin:return t===ft.MeasureBegin?jt.StaveConnector.type.SINGLE:jt.StaveConnector.type.SINGLE_RIGHT;case Ne.DoubleThin:return jt.StaveConnector.type.THIN_DOUBLE;case Ne.ThinBold:return jt.StaveConnector.type.BOLD_DOUBLE_RIGHT;case Ne.BoldThinDots:return jt.StaveConnector.type.BOLD_DOUBLE_LEFT;case Ne.DotsThinBold:case Ne.DotsBoldBoldDots:return jt.StaveConnector.type.BOLD_DOUBLE_RIGHT;case Ne.None:return jt.StaveConnector.type.NONE}}static font(e,t=me.Regular,i=pe.TimesNewRoman,s,n=void 0){let r="normal",o="normal",a=`'${s.DefaultFontFamily}'`;switch(t){case me.Bold:o="bold";break;case me.Italic:r="italic";break;case me.BoldItalic:r="italic",o="bold";case me.Underlined:}return pe.Kokila,n&&"default"!==n&&(a=`'${n}'`),r+" "+o+" "+Math.floor(e)+"px "+a}static fontStyle(e){switch(e){case me.Bold:return"bold";case me.Italic:return"italic";case me.BoldItalic:return"italic bold";default:return"normal"}}static style(e){return _.getValue(e)}};let Jt=Kt;Jt.majorMap={"-1":"F","-2":"Bb","-3":"Eb","-4":"Ab","-5":"Db","-6":"Gb","-7":"Cb","-8":"Fb",0:"C",1:"G",2:"D",3:"A",4:"E",5:"B",6:"F#",7:"C#",8:"G#"},Jt.minorMap={"-1":"D","-2":"G","-3":"C","-4":"F","-5":"Bb","-6":"Eb","-7":"Ab","-8":"Db",0:"A",1:"E",2:"B",3:"F#",4:"C#",5:"G#",6:"D#",7:"A#",8:"E#"},Jt.noteTremoloList=[],Jt.glissandoList=[],Jt.slideNote=null,Jt.idx=0;class qt{constructor(e,t){this.numberXml=1,this.setOctaveShiftValue(e,t)}get Type(){return this.octaveValue}set Type(e){this.octaveValue=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get ParentStartMultiExpression(){return this.startMultiExpression}set ParentStartMultiExpression(e){this.startMultiExpression=e}get ParentEndMultiExpression(){return this.endMultiExpression}set ParentEndMultiExpression(e){this.endMultiExpression=e}setOctaveShiftValue(e,t){this.octaveValue=1===t&&"down"===e?0:1===t&&"up"===e?1:2===t&&"down"===e?2:2===t&&"up"===e?3:4}static getPitchFromOctaveShift(e,t){if(!e)return;let i=e.Octave;switch(t){case 0:i-=1;break;case 1:i+=1;break;case 2:i-=2;break;case 3:i+=2;break;default:i+=0}return new K(e.FundamentalNote,i,e.Accidental)}}var $t=(e=>(e[e.VA8=0]="VA8",e[e.VB8=1]="VB8",e[e.MA15=2]="MA15",e[e.MB15=3]="MB15",e[e.NONE=4]="NONE",e))($t||{});class Qt extends c{constructor(e,t,i,s){super(t),this.label=e,this.staffNumber=i,this.parentMultiTempoExpression=s}get Label(){return this.label}set Label(e){this.label=e}get Placement(){return this.placement}set Placement(e){this.placement=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get ParentMultiTempoExpression(){return this.parentMultiTempoExpression}static isStringInStringList(e,t){for(const i of e)if(Qt.stringContainsSeparatedWord(t.toLowerCase().trim(),i.toLowerCase().trim()))return!0;return!1}static stringContainsSeparatedWord(e,t){return e===t||-1!==e.indexOf(" "+t)||-1!==e.indexOf(t+" ")}}const Zt=class extends Qt{constructor(e,t,i,s,n,r=!1){super(e,t,i,n),this.isMetronomeMark=r,this.setTempoAndTempoType(s)}static getDefaultValueForTempoType(e){switch(e){case 1:return 20;case 2:return 30;case 3:return 48;case 4:return 52;case 5:return 63;case 6:return 70;case 7:return 75;case 8:return 88;case 9:return 92;case 10:return 96;case 11:return 106;case 12:return 112;case 13:return 118;case 14:return 130;case 15:return 140;case 16:return 155;case 17:return 170;case 18:return 184;case 19:return 200;default:throw new y("tempoEnum")}}static isInputStringInstantaneousTempo(e){return!!e&&(Zt.isStringInStringList(Zt.listInstantaneousTempoLarghissimo,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoGrave,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoLento,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoLargo,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoLarghetto,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAdagio,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAdagietto,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAndanteModerato,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAndante,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAndantino,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoModerato,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAllegretto,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAllegroModerato,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAllegro,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoVivace,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoVivacissimo,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoAllegrissimo,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoPresto,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoPrestissimo,e)||Zt.isStringInStringList(Zt.listInstantaneousTempoChangesGeneral,e))}get Label(){return this.label}set Label(e){this.label=e}get Placement(){return this.placement}set Placement(e){this.placement=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get Enum(){return this.tempoEnum}get TempoInBpm(){return this.tempoInBpm}set TempoInBpm(e){this.tempoInBpm=e}get ParentMultiTempoExpression(){return this.parentMultiTempoExpression}getAbsoluteTimestamp(){return u.plus(this.ParentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp,this.ParentMultiTempoExpression.Timestamp)}getAbsoluteFloatTimestamp(){return u.plus(this.ParentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp,this.ParentMultiTempoExpression.Timestamp).RealValue}setTempoAndTempoType(e){return this.label?Zt.isStringInStringList(Zt.listInstantaneousTempoLarghissimo,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(1)),this.tempoInBpm=e,void(this.tempoEnum=1)):Zt.isStringInStringList(Zt.listInstantaneousTempoGrave,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(2)),this.tempoInBpm=e,void(this.tempoEnum=2)):Zt.isStringInStringList(Zt.listInstantaneousTempoLento,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(3)),this.tempoInBpm=e,void(this.tempoEnum=3)):Zt.isStringInStringList(Zt.listInstantaneousTempoLargo,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(4)),this.tempoInBpm=e,void(this.tempoEnum=4)):Zt.isStringInStringList(Zt.listInstantaneousTempoLarghetto,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(5)),this.tempoInBpm=e,void(this.tempoEnum=5)):Zt.isStringInStringList(Zt.listInstantaneousTempoAdagio,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(6)),this.tempoInBpm=e,void(this.tempoEnum=6)):Zt.isStringInStringList(Zt.listInstantaneousTempoAdagietto,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(7)),this.tempoInBpm=e,void(this.tempoEnum=7)):Zt.isStringInStringList(Zt.listInstantaneousTempoAndanteModerato,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(8)),this.tempoInBpm=e,void(this.tempoEnum=8)):Zt.isStringInStringList(Zt.listInstantaneousTempoAndante,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(9)),this.tempoInBpm=e,void(this.tempoEnum=9)):Zt.isStringInStringList(Zt.listInstantaneousTempoAndantino,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(10)),this.tempoInBpm=e,void(this.tempoEnum=10)):Zt.isStringInStringList(Zt.listInstantaneousTempoModerato,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(11)),this.tempoInBpm=e,void(this.tempoEnum=11)):Zt.isStringInStringList(Zt.listInstantaneousTempoAllegretto,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(12)),this.tempoInBpm=e,void(this.tempoEnum=12)):Zt.isStringInStringList(Zt.listInstantaneousTempoAllegroModerato,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(13)),this.tempoInBpm=e,void(this.tempoEnum=13)):Zt.isStringInStringList(Zt.listInstantaneousTempoAllegro,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(14)),this.tempoInBpm=e,void(this.tempoEnum=14)):Zt.isStringInStringList(Zt.listInstantaneousTempoVivace,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(15)),this.tempoInBpm=e,void(this.tempoEnum=15)):Zt.isStringInStringList(Zt.listInstantaneousTempoVivacissimo,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(16)),this.tempoInBpm=e,void(this.tempoEnum=16)):Zt.isStringInStringList(Zt.listInstantaneousTempoAllegrissimo,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(17)),this.tempoInBpm=e,void(this.tempoEnum=17)):Zt.isStringInStringList(Zt.listInstantaneousTempoPresto,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(18)),this.tempoInBpm=e,void(this.tempoEnum=18)):Zt.isStringInStringList(Zt.listInstantaneousTempoPrestissimo,this.label)?(0===e&&(e=Zt.getDefaultValueForTempoType(19)),this.tempoInBpm=e,void(this.tempoEnum=19)):Zt.isStringInStringList(Zt.listInstantaneousTempoAddons,this.label)?(this.tempoInBpm=0,void(this.tempoEnum=21)):Zt.isStringInStringList(Zt.listInstantaneousTempoChangesGeneral,this.label)?(this.tempoInBpm=0,void(this.tempoEnum=22)):void 0:(this.tempoInBpm=e,void(this.tempoEnum=23))}};let ei=Zt;ei.listInstantaneousTempoLarghissimo=["Larghissimo","Sehr breit","very, very slow"],ei.listInstantaneousTempoGrave=["Grave","Schwer","slow and solemn"],ei.listInstantaneousTempoLento=["Lento","Lent","Langsam","slowly"],ei.listInstantaneousTempoLargo=["Largo","Breit","broadly"],ei.listInstantaneousTempoLarghetto=["Larghetto","Etwas breit","rather broadly"],ei.listInstantaneousTempoAdagio=["Adagio","Langsam","Ruhig","slow and stately"],ei.listInstantaneousTempoAdagietto=["Adagietto","Ziemlich ruhig","Ziemlich langsam","rather slow"],ei.listInstantaneousTempoAndanteModerato=["Andante moderato"],ei.listInstantaneousTempoAndante=["Andante","Gehend","Schreitend","at a walking pace"],ei.listInstantaneousTempoAndantino=["Andantino","Maestoso"],ei.listInstantaneousTempoModerato=["Moderato","Mäßig","Modéré","moderately"],ei.listInstantaneousTempoAllegretto=["Allegretto","Animato","fast"],ei.listInstantaneousTempoAllegroModerato=["Allegro moderato"],ei.listInstantaneousTempoAllegro=["Allegro","Rapide","Vite","Rasch","Schnell","Fröhlich"],ei.listInstantaneousTempoVivace=["Vivace","Allegro Assai","Lebhaft","Lebendig","lively and fast"],ei.listInstantaneousTempoVivacissimo=["Vivacissimo","Sehr lebhaft","Sehr lebendig"],ei.listInstantaneousTempoAllegrissimo=["Allegrissimo","very fast"],ei.listInstantaneousTempoPresto=["Presto","Sehr schnell","Geschwind"],ei.listInstantaneousTempoPrestissimo=["Prestissimo","äußerst schnell"],ei.listInstantaneousTempoChangesGeneral=["tempo primo","a tempo","tempo i","rubato","doppio movimento","rallentando","ritardando","ritard.","rit.","ritard","rall...","accelerando","accel","molto allargando","allargando","stringendo","poco a poco rit.","rit. poco a poco","Ritardando","Ritenuto","accelerate","poco a poco accel."],ei.listInstantaneousTempoAddons=["assai","amoroso","cantabile","con brio","con dolore","con espressione","con fuoco","con moto","con spirito","spiritoso","espressivo","giocoso","giusto","grazioso","lesto","lugubre","maestoso","ma non troppo","marcato","molto","morendo","mosso","non tanto","piu","un poco","poco","quasi","risoluto","scherzando","sostenuto","teneramente","tempo giusto","tranquillo","sehr","lieblich","liebevoll","mit Leidenschaft","mit Liebe","amourös","gesanglich","mit Schwung","mit Feuer","mit Schmerz","mit Ausdruck","mit Bewegung","geistvoll","ausdrucksvoll","freudig","verspielt","angemessen","graziös","mit Grazie","flink","behände","traurig","klagend","majestätisch","aber nicht zu sehr","markant","gemäßigt","viel","sehr","ersterbend","bewegt","nicht zu sehr","mehr","ein wenig","gleichsam","entschlossen","zupackend","heiter","nachdrücklich","getragen","gewichtig","zart","zärtlich","im angemessenen Zeitmaß","ruhig","ein wenig","alla marcia","ad libitum","alla breve"];var ti=(e=>(e[e.none=0]="none",e[e.larghissimo=1]="larghissimo",e[e.grave=2]="grave",e[e.lento=3]="lento",e[e.largo=4]="largo",e[e.larghetto=5]="larghetto",e[e.adagio=6]="adagio",e[e.adagietto=7]="adagietto",e[e.andanteModerato=8]="andanteModerato",e[e.andante=9]="andante",e[e.andantino=10]="andantino",e[e.moderato=11]="moderato",e[e.allegretto=12]="allegretto",e[e.allegroModerato=13]="allegroModerato",e[e.allegro=14]="allegro",e[e.vivace=15]="vivace",e[e.vivacissimo=16]="vivacissimo",e[e.allegrissimo=17]="allegrissimo",e[e.presto=18]="presto",e[e.prestissimo=19]="prestissimo",e[e.lastRealTempo=20]="lastRealTempo",e[e.addon=21]="addon",e[e.changes=22]="changes",e[e.metronomeMark=23]="metronomeMark",e))(ti||{});const ii=class extends c{constructor(e,t,i){super(t),this.label=e,this.staffNumber=i,this.setMoodType()}static isInputStringMood(e){return!!e&&(ii.isStringInStringList(ii.listMoodAffettuoso,e)||ii.isStringInStringList(ii.listMoodAgitato,e)||ii.isStringInStringList(ii.listMoodAnimato,e)||ii.isStringInStringList(ii.listMoodAppassionato,e)||ii.isStringInStringList(ii.listMoodBrillante,e)||ii.isStringInStringList(ii.listMoodCantabile,e)||ii.isStringInStringList(ii.listMoodDolce,e)||ii.isStringInStringList(ii.listMoodEnergico,e)||ii.isStringInStringList(ii.listMoodEroico,e)||ii.isStringInStringList(ii.listMoodEspressivo,e)||ii.isStringInStringList(ii.listMoodFurioso,e)||ii.isStringInStringList(ii.listMoodGiocoso,e)||ii.isStringInStringList(ii.listMoodGioioso,e)||ii.isStringInStringList(ii.listMoodGrandioso,e)||ii.isStringInStringList(ii.listMoodGrazioso,e)||ii.isStringInStringList(ii.listMoodLacrimoso,e)||ii.isStringInStringList(ii.listMoodLeggiero,e)||ii.isStringInStringList(ii.listMoodMaestoso,e)||ii.isStringInStringList(ii.listMoodMalinconico,e)||ii.isStringInStringList(ii.listMoodMarcato,e)||ii.isStringInStringList(ii.listMoodMarziale,e)||ii.isStringInStringList(ii.listMoodMesto,e)||ii.isStringInStringList(ii.listMoodMorendo,e)||ii.isStringInStringList(ii.listMoodNobilmente,e)||ii.isStringInStringList(ii.listMoodPatetico,e)||ii.isStringInStringList(ii.listMoodPesante,e)||ii.isStringInStringList(ii.listMoodSaltando,e)||ii.isStringInStringList(ii.listMoodSautille,e)||ii.isStringInStringList(ii.listMoodScherzando,e)||ii.isStringInStringList(ii.listMoodSostenuto,e)||ii.isStringInStringList(ii.listMoodSpiccato,e)||ii.isStringInStringList(ii.listMoodTenerezza,e)||ii.isStringInStringList(ii.listMoodTranquillamente,e)||ii.isStringInStringList(ii.listMoodTrionfante,e))}get Label(){return this.label}set Label(e){this.label=e}get Mood(){return this.moodType}set Mood(e){this.moodType=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get Placement(){return this.placement}set Placement(e){this.placement=e}setMoodType(){ii.isStringInStringList(ii.listMoodAffettuoso,this.label)?this.moodType=0:ii.isStringInStringList(ii.listMoodAgitato,this.label)?this.moodType=1:ii.isStringInStringList(ii.listMoodAnimato,this.label)?this.moodType=3:ii.isStringInStringList(ii.listMoodAppassionato,this.label)?this.moodType=2:ii.isStringInStringList(ii.listMoodBrillante,this.label)?this.moodType=4:ii.isStringInStringList(ii.listMoodCantabile,this.label)?this.moodType=5:ii.isStringInStringList(ii.listMoodDolce,this.label)?this.moodType=6:ii.isStringInStringList(ii.listMoodEnergico,this.label)?this.moodType=7:ii.isStringInStringList(ii.listMoodEroico,this.label)?this.moodType=8:ii.isStringInStringList(ii.listMoodEspressivo,this.label)?this.moodType=9:ii.isStringInStringList(ii.listMoodFurioso,this.label)?this.moodType=10:ii.isStringInStringList(ii.listMoodGiocoso,this.label)?this.moodType=11:ii.isStringInStringList(ii.listMoodGioioso,this.label)?this.moodType=12:ii.isStringInStringList(ii.listMoodGrandioso,this.label)?this.moodType=14:ii.isStringInStringList(ii.listMoodGrazioso,this.label)?this.moodType=15:ii.isStringInStringList(ii.listMoodLacrimoso,this.label)?this.moodType=13:ii.isStringInStringList(ii.listMoodLeggiero,this.label)?this.moodType=16:ii.isStringInStringList(ii.listMoodMaestoso,this.label)?this.moodType=17:ii.isStringInStringList(ii.listMoodMalinconico,this.label)?this.moodType=18:ii.isStringInStringList(ii.listMoodMarcato,this.label)?this.moodType=19:ii.isStringInStringList(ii.listMoodMarziale,this.label)?this.moodType=20:ii.isStringInStringList(ii.listMoodMesto,this.label)?this.moodType=21:ii.isStringInStringList(ii.listMoodMorendo,this.label)?this.moodType=22:ii.isStringInStringList(ii.listMoodNobilmente,this.label)?this.moodType=23:ii.isStringInStringList(ii.listMoodPatetico,this.label)?this.moodType=24:ii.isStringInStringList(ii.listMoodPesante,this.label)?this.moodType=25:ii.isStringInStringList(ii.listMoodSaltando,this.label)?this.moodType=27:ii.isStringInStringList(ii.listMoodSautille,this.label)?this.moodType=26:ii.isStringInStringList(ii.listMoodScherzando,this.label)?this.moodType=28:ii.isStringInStringList(ii.listMoodSostenuto,this.label)?this.moodType=29:ii.isStringInStringList(ii.listMoodSpiccato,this.label)?this.moodType=30:ii.isStringInStringList(ii.listMoodTenerezza,this.label)?this.moodType=31:ii.isStringInStringList(ii.listMoodTranquillamente,this.label)?this.moodType=32:ii.isStringInStringList(ii.listMoodTrionfante,this.label)&&(this.moodType=33)}};let si=ii;si.listMoodAffettuoso=["affettuoso"],si.listMoodAgitato=["agitato"],si.listMoodAppassionato=["appassionato"],si.listMoodAnimato=["animato","lively"],si.listMoodBrillante=["brillante"],si.listMoodCantabile=["cantabile"],si.listMoodDolce=["dolce"],si.listMoodEnergico=["energico"],si.listMoodEroico=["eroico"],si.listMoodEspressivo=["espressivo"],si.listMoodFurioso=["furioso"],si.listMoodGiocoso=["giocoso"],si.listMoodGioioso=["gioioso"],si.listMoodLacrimoso=["lacrimoso"],si.listMoodGrandioso=["grandioso"],si.listMoodGrazioso=["grazioso"],si.listMoodLeggiero=["leggiero"],si.listMoodMaestoso=["maestoso"],si.listMoodMalinconico=["malinconico"],si.listMoodMarcato=["marcato"],si.listMoodMarziale=["marziale"],si.listMoodMesto=["mesto"],si.listMoodMorendo=["morendo"],si.listMoodNobilmente=["nobilmente"],si.listMoodPatetico=["patetico"],si.listMoodPesante=["pesante"],si.listMoodSautille=["sautille"],si.listMoodSaltando=["saltando"],si.listMoodScherzando=["scherzando"],si.listMoodSostenuto=["sostenuto"],si.listMoodSpiccato=["spiccato"],si.listMoodTenerezza=["tenerezza"],si.listMoodTranquillamente=["tranquillamente"],si.listMoodTrionfante=["trionfante"];class ni extends c{constructor(e,t,i,s){super(t),this.label=e,this.staffNumber=s,void 0===i&&(i=ce.LeftBottom),this.textAlignment=i}get Label(){return this.label}get Placement(){return this.placement}set Placement(e){this.placement=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get TextAlignment(){return this.textAlignment}}class ri{constructor(e,t){this.unknownList=[],this.moodList=[],this.expressions=[],this.sourceMeasure=e,this.timestamp=t}get SourceMeasureParent(){return this.sourceMeasure}set SourceMeasureParent(e){this.sourceMeasure=e}get StaffNumber(){return this.staffNumber}set StaffNumber(e){this.staffNumber=e}get Timestamp(){return this.timestamp}set Timestamp(e){this.timestamp=e}get AbsoluteTimestamp(){return u.plus(this.timestamp,this.sourceMeasure.AbsoluteTimestamp)}get InstantaneousDynamic(){return this.instantaneousDynamic}set InstantaneousDynamic(e){this.instantaneousDynamic=e}get EndingContinuousDynamic(){return this.endingContinuousDynamic}set EndingContinuousDynamic(e){this.endingContinuousDynamic=e}get StartingContinuousDynamic(){return this.startingContinuousDynamic}set StartingContinuousDynamic(e){this.startingContinuousDynamic=e}get MoodList(){return this.moodList}get UnknownList(){return this.unknownList}get EntriesList(){return this.expressions}get OctaveShiftStart(){return this.octaveShiftStart}set OctaveShiftStart(e){this.octaveShiftStart=e}get OctaveShiftEnd(){return this.octaveShiftEnd}set OctaveShiftEnd(e){this.octaveShiftEnd=e}get CombinedExpressionsText(){return this.combinedExpressionsText}set CombinedExpressionsText(e){this.combinedExpressionsText=e}getPlacementOfFirstEntry(){let e=d.Above;return this.expressions.length>0&&(this.expressions[0].expression instanceof v||this.expressions[0].expression instanceof m||this.expressions[0].expression instanceof si||this.expressions[0].expression instanceof ni)&&(e=this.expressions[0].expression.Placement),e}getFontstyleOfFirstEntry(){let e=me.Regular;if(this.expressions.length>0)if(this.expressions[0].expression instanceof m)e=me.Italic;else if(this.expressions[0].expression instanceof si)e=me.Italic;else if(this.expressions[0].expression instanceof ni){var t;e=null!==(t=this.expressions[0].expression.fontStyle)&&void 0!==t?t:me.Regular}return e}addExpression(e,t){e instanceof v?(this.instantaneousDynamic&&this.removeExpressionFromEntryList(this.InstantaneousDynamic),this.instantaneousDynamic=e,this.instantaneousDynamic.ParentMultiExpression=this):e instanceof m?this.startingContinuousDynamic=e:e instanceof si?this.moodList.push(e):e instanceof ni&&this.unknownList.push(e),this.addExpressionToEntryList(e,t)}CompareTo(e){return this.Timestamp.RealValue>e.Timestamp.RealValue?1:this.Timestamp.RealValue<e.Timestamp.RealValue?-1:0}addExpressionToEntryList(e,t){const i=new oi;i.prefix=t,i.expression=e,i.label=e instanceof m||e instanceof si||e instanceof ni?e.Label:"",this.expressions.push(i)}removeExpressionFromEntryList(e){for(let t=0,i=this.expressions.length;t<i;++t)if(this.expressions[t].expression===e){this.expressions.splice(t,1);break}}}class oi{}const ai=class extends Qt{constructor(e,t,i,s){super(e,t,i,s),this.setTempoType()}static isInputStringContinuousTempo(e){return!!e&&(ai.isStringInStringList(ai.listContinuousTempoFaster,e)||ai.isStringInStringList(ai.listContinuousTempoSlower,e))}static isIncreasingTempo(e){return e<=4}static isDecreasingTempo(e){return e>=5&&e<=12}get TempoType(){return this.tempoType}set TempoType(e){this.tempoType=e}get StartTempo(){return this.startTempo}set StartTempo(e){this.startTempo=e}get EndTempo(){return this.endTempo}set EndTempo(e){this.endTempo=e}get AbsoluteEndTimestamp(){return this.absoluteEndTimestamp}set AbsoluteEndTimestamp(e){this.absoluteEndTimestamp=e}get AbsoluteTimestamp(){return this.ParentMultiTempoExpression.AbsoluteTimestamp}getAbsoluteFloatTimestamp(){return this.ParentMultiTempoExpression.AbsoluteTimestamp.RealValue}getInterpolatedTempo(e){const t=u.plus(this.parentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp,this.parentMultiTempoExpression.Timestamp);if(e.lt(t))return-1;if(this.absoluteEndTimestamp.lt(e))return-2;const i=u.minus(e,t).RealValue/u.minus(this.absoluteEndTimestamp,t).RealValue;return Math.max(0,Math.min(250,this.startTempo+(this.endTempo-this.startTempo)*i))}setTempoType(){ai.isStringInStringList(ai.listContinuousTempoFaster,this.label)?this.tempoType=0:ai.isStringInStringList(ai.listContinuousTempoSlower,this.label)&&(this.tempoType=9)}};let li=ai;li.listContinuousTempoFaster=["accelerando","piu mosso","poco piu","stretto","stringendo","accelerate","poco a poco accel."],li.listContinuousTempoSlower=["poco meno","meno mosso","piu lento","calando","allargando","molto allargando","rallentando","ritardando","ritenuto","ritard.","ritard","rit.","rit","riten.","riten","poco a poco rit.","rit. poco a poco","Ritardando","Ritenuto"];class hi{constructor(e,t){this.expressions=[],this.sourceMeasure=e,this.timestamp=t}get Timestamp(){return this.timestamp}get AbsoluteTimestamp(){return u.plus(this.sourceMeasure.AbsoluteTimestamp,this.timestamp)}get SourceMeasureParent(){return this.sourceMeasure}set SourceMeasureParent(e){this.sourceMeasure=e}get InstantaneousTempo(){return this.instantaneousTempo}get ContinuousTempo(){return this.continuousTempo}get EntriesList(){return this.expressions}get CombinedExpressionsText(){return this.combinedExpressionsText}set CombinedExpressionsText(e){this.combinedExpressionsText=e}getPlacementOfFirstEntry(){let e=d.Above;return this.expressions.length>0&&(this.expressions[0].Expression instanceof ei||this.expressions[0].Expression instanceof li)&&(e=this.expressions[0].Expression.Placement),e}getFontstyleOfFirstEntry(){let e=me.Regular;return this.expressions[0].Expression instanceof ei?e=me.Bold:this.expressions[0].Expression instanceof li&&(e=me.Italic),e}addExpression(e,t){if(this.checkIfAlreadyExists(e))return;e instanceof ei?this.instantaneousTempo=e:e instanceof li&&(this.continuousTempo=e);const i=new ui;i.prefix=t,i.Expression=e,i.label=e.Label,this.expressions.push(i)}CompareTo(e){return this.Timestamp.RealValue>e.Timestamp.RealValue?1:this.Timestamp.RealValue<e.Timestamp.RealValue?-1:0}checkIfAlreadyExists(e){for(const t of this.expressions)if(t.label===e.Label)return!0;return!1}}class ui{get Expression(){return this.expression}set Expression(e){this.expression=e}}class ci extends c{constructor(e,t){super(t),this.label=e}}class di{constructor(){this.musicSystems=[],this.globalSystemIndex=0,this.leadSheet=!1}initialize(e,t,i){this.leadSheet=e.LeadSheet,this.graphicalMusicSheet=e,this.rules=this.graphicalMusicSheet.ParentMusicSheet.Rules,this.measureList=t,this.numberOfVisibleStaffLines=i,this.activeRhythm=new Array(this.numberOfVisibleStaffLines),this.activeKeys=new Array(this.numberOfVisibleStaffLines),this.activeClefs=new Array(this.numberOfVisibleStaffLines),this.initializeActiveInstructions(this.measureList[0])}buildMusicSystems(){const e=this.getFullPageSystemWidth();let t=!1;this.measureListIndex=0,this.currentSystemParams=new fi,this.currentSystemParams.currentSystem=this.initMusicSystem();let i=0,s=0;for(;this.measureListIndex<this.measureList.length;){var n,r;const l=this.measureList[this.measureListIndex];if(!l||!l[0]){this.measureListIndex++;continue}for(let e=0,t=l.length;e<t;++e)l[e].resetLayout();const h=l[0].parentSourceMeasure,u=!this.rules.DYIsSingleLine&&h.HasEndLine,c=u&&this.rules.NewPartAndSystemAfterFinalBarline,d=this.currentSystemParams.IsSystemStartMeasure();h.IsSystemStartMeasure=d;const f=h===this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();let m=this.rules.MeasureLeftMargin,p=0;const g=this.getMeasureStartLine();if(m+=this.getLineWidth(l[0],g,d),!this.leadSheet){let e=!1;t&&this.rules.ShowRhythmAgainAfterPartEndOrFinalBarline&&(e=!0),m+=this.addBeginInstructions(l,d,f||e),p+=this.addEndInstructions(l)}let S=0;for(let e=0;e<this.numberOfVisibleStaffLines;e++)S=Math.max(S,l[e].minimumStaffEntriesWidth);const y=this.getMeasureEndLine();p+=this.getLineWidth(l[0],y,d);let b,M=this.rules.MeasureLeftMargin;if(this.measureListIndex+1<this.measureList.length){var o,a;const e=this.measureList[this.measureListIndex+1];b=null===(o=e[0])||void 0===o?void 0:o.parentSourceMeasure,null!==(a=b)&&void 0!==a&&a.hasBeginInstructions()&&(M+=this.addBeginInstructions(e,!1,!1))}let v=m+p+S;null!==(n=l[0])&&void 0!==n&&null!==(r=n.parentSourceMeasure)&&void 0!==r&&r.multipleRestMeasures&&(v=this.rules.MultipleRestMeasureDefaultWidth);const P=this.currentSystemParams.currentWidth+v+M<e;0===i&&(i=Math.abs(Math.floor((e-m-p-M)/(v-m))),i=i%2==0?i:i-1,i<1&&(i=1));const E=this.rules.NewPageAtXMLNewPageAttribute&&h.printNewPageXml,L=E||this.rules.NewSystemAtXMLNewPageAttribute&&h.printNewPageXml||this.rules.NewSystemAtXMLNewSystemAttribute&&h.printNewSystemXml;if((d||P&&!L)&&(this.rules.DYWorkSpecial||s<i)){if(this.addMeasureToSystem(l,g,y,v,m,S,p),this.updateActiveClefs(h,l),this.measureListIndex++,c){if(this.rules.MaxSystemToDrawNumber===this.musicSystems.length)return this.finalizeCurrentSystem(l,!this.rules.StretchLastSystemLine,!1),this.musicSystems;this.finalizeCurrentAndCreateNewSystem(l,!this.rules.StretchLastSystemLine,!1)}t=u}else{if(s=0,this.rules.MaxSystemToDrawNumber===this.musicSystems.length)return this.finalizeCurrentSystem(l,!1,!0,E),this.musicSystems;this.finalizeCurrentAndCreateNewSystem(l,!1,!0,E)}}if(this.currentSystemParams.systemMeasures.length>0){if(this.rules.MaxSystemToDrawNumber===this.musicSystems.length)return this.finalizeCurrentSystem(this.measureList[this.measureList.length-1],!this.rules.StretchLastSystemLine,!1),this.musicSystems;this.finalizeCurrentAndCreateNewSystem(this.measureList[this.measureList.length-1],!this.rules.StretchLastSystemLine,!1)}return this.musicSystems}calculateSystemYLayout(){for(const e of this.musicSystems)this.optimizeDistanceBetweenStaffLines(e);this.calculateMusicSystemsRelativePositions()}setMeasureWidth(e,t,i,s){for(let n=0,r=e.length;n<r;++n){const r=e[n];r.setWidth(t),i>0&&(r.beginInstructionsWidth=i),s>0&&(r.endInstructionsWidth=s)}}finalizeCurrentAndCreateNewSystem(e,t=!1,i=!0,s=!1){this.finalizeCurrentSystem(e,t,i,s),this.currentSystemParams=new fi,void 0!==e&&this.measureListIndex<this.measureList.length&&(this.currentSystemParams.currentSystem=this.initMusicSystem())}finalizeCurrentSystem(e,t=!1,i=!0,s=!1){this.currentSystemParams.currentSystem.breaksPage=s,this.adaptRepetitionLineWithIfNeeded(),void 0!==e&&i&&this.checkAndCreateExtraInstructionMeasure(e),this.stretchMusicSystem(t)}adaptRepetitionLineWithIfNeeded(){const e=this.currentSystemParams.systemMeasures;if(e.length>=1){const t=this.currentSystemParams.currentSystem.GraphicalMeasures[this.currentSystemParams.currentSystem.GraphicalMeasures.length-1];let i=0;const s=e[e.length-1];s.endLine===Ne.DotsBoldBoldDots&&(s.endLine=Ne.DotsThinBold,i=t[0].getLineWidth(Ne.DotsBoldBoldDots)/2-t[0].getLineWidth(Ne.DotsThinBold)),this.currentSystemParams.currentSystemFixWidth-=i;for(let e=0,n=t.length;e<n;++e)t[e].endInstructionsWidth-=i}}addMeasureToSystem(e,t,i,s,n,r,o){this.currentSystemParams.systemMeasures.push({beginLine:t,endLine:i}),this.setMeasureWidth(e,s,n,o),this.addStaveMeasuresToSystem(e),this.currentSystemParams.currentWidth+=s,this.currentSystemParams.currentSystemFixWidth+=n+o,this.currentSystemParams.currentSystemVarWidth+=r,this.currentSystemParams.systemMeasureIndex++}initMusicSystem(){const e=yi.symbolFactory.createMusicSystem(this.globalSystemIndex++,this.rules);return this.musicSystems.push(e),this.layoutSystemStaves(e),e.createMusicSystemLabel(this.rules.InstrumentLabelTextHeight,this.rules.SystemLabelsRightMargin,this.rules.LabelMarginBorderFactor,1===this.musicSystems.length),e}getFullPageSystemWidth(){return this.graphicalMusicSheet.ParentMusicSheet.pageWidth-this.rules.PageLeftMargin-this.rules.PageRightMargin-this.rules.SystemLeftMargin-this.rules.SystemRightMargin}layoutSystemStaves(e){const t=this.getFullPageSystemWidth(),i=e.PositionAndShape;i.BorderLeft=0,i.BorderRight=t,i.BorderTop=0;const s=[],n=this.graphicalMusicSheet.ParentMusicSheet.Instruments;for(let a=0,l=n.length;a<l;++a){const e=n[a];if(e.Visible&&0!==e.Voices.length)for(let t=0,i=e.Staves.length;t<i;++t){const i=e.Staves[t];s.push(i)}}let r=!1;if(this.leadSheet)for(let a=0,l=s.length;a<l;++a)if(s[a].ParentInstrument.LyricVersesNumbers.length>1){r=!0;break}let o=0;for(let a=0;a<s.length;a++)if(this.addStaffLineToMusicSystem(e,o,s[a]),o+=this.rules.StaffHeight,a+1<s.length){let e=0;e=this.leadSheet&&!r?2.5:s[a].ParentInstrument===s[a+1].ParentInstrument?this.rules.BetweenStaffDistance:this.rules.StaffDistance,o+=e}i.BorderBottom=o}addStaffLineToMusicSystem(e,t,i){if(e){const s=yi.symbolFactory.createStaffLine(e,i);e.StaffLines.push(s);const n=s.PositionAndShape,r=new z;r.x=0,n.BorderRight=e.PositionAndShape.Size.width,r.y=t,n.RelativePosition=r,n.BorderLeft=0,n.BorderTop=0,n.BorderBottom=this.rules.StaffHeight;for(let e=0;e<5;e++){const t=new z;t.x=0,t.y=e*this.rules.StaffHeight/4;const i=new z;i.x=s.PositionAndShape.Size.width,i.y=e*this.rules.StaffHeight/4,this.leadSheet&&(t.y=i.y=0),s.StaffLines[e]=new X(t,i,this.rules.StaffLineWidth)}}}initializeActiveInstructions(e){const t=this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();if(t){this.visibleStaffIndices=this.graphicalMusicSheet.getVisibleStavesIndicesFromSourceMeasure(e);for(let e=0,i=this.visibleStaffIndices.length;e<i;e++){const i=this.visibleStaffIndices[e],s=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(t,i);this.activeClefs[e]=t.FirstInstructionsStaffEntries[i].Instructions[0],s.InitiallyActiveClef=this.activeClefs[e];const n=t.FirstInstructionsStaffEntries[i].Instructions[1];if(n){let t=Z.copy(n);t=this.transposeKeyInstruction(t,s),this.activeKeys[e]=t}const r=t.FirstInstructionsStaffEntries[i].Instructions[2];this.activeRhythm[e]=r}}}transposeKeyInstruction(e,t){const i=t.getTransposedHalftones();return i!==e.isTransposedBy&&t.ParentStaff.ParentInstrument.MidiInstrumentId!==$.Percussion&&void 0!==yi.transposeCalculator&&yi.transposeCalculator.transposeKey(e,i),e}addBeginInstructions(e,t,i){var s;const n=e.length;if(0===n)return 0;let r=0;const o=e[0].parentSourceMeasure,a=[];for(let l=0;l<n;++l){const s=e[l];s&&a.push(s.getVFStave());const n=this.visibleStaffIndices[l],h=o.FirstInstructionsStaffEntries[n],u=this.AddInstructionsAtMeasureBegin(h,s,l,i,t);r=Math.max(r,u)}return(null===(s=a[0])||void 0===s?void 0:s.formatBegModifiers)&&a[0].formatBegModifiers(a),r}addEndInstructions(e){const t=e.length;if(0===t)return 0;let i=.5;const s=e[0].parentSourceMeasure;for(let n=0;n<t;n++){const t=e[n],r=this.visibleStaffIndices[n],o=s.LastInstructionsStaffEntries[r],a=this.addInstructionsAtMeasureEnd(o,t,e);i=Math.max(i,a)}return i}AddInstructionsAtMeasureBegin(e,t,i,s,n){var r,o;let a,l,h,u=0;if(e)for(let v=0,P=e.Instructions.length;v<P;++v){const t=e.Instructions[v];t instanceof J?a=t:t instanceof Z?l=t:t instanceof x&&(h=t)}t.InitiallyActiveClef=null!==(r=a)&&void 0!==r?r:this.activeClefs[i];const c=null===(o=window.GYM)||void 0===o?void 0:o.multitrack;var d;n&&(a||(a=this.activeClefs[i]),l||(l=Z.copy(this.activeKeys[i])),!c||!l||null!==(d=l.AlteratedNotes)&&void 0!==d&&d.length||(l=Z.copy(this.activeKeys[0]),l.PrintObject=!1),s&&!h&&(h=this.activeRhythm[i]));let f=!1,m=!1,p=!1;if(a?(t.addClefAtBegin(a),f=!0):a=this.activeClefs[i],l){l=this.transposeKeyInstruction(l,t);const e=n?void 0:this.activeKeys[i];if(t.addKeyAtBegin(l,e,a),c&&!l.PrintObject)try{var g,S,y;null===(g=t.stave)||void 0===g||null===(S=g.getModifiers(void 0,"keysignatures"))||void 0===S||null===(y=S[0])||void 0===y||y.setDrawState(!1)}catch(M){}m=!0}if(void 0!==h&&h.PrintObject&&this.rules.RenderTimeSignatures){let e=!0;const s=t.MeasureNumber-1-this.rules.MinMeasureToDrawIndex;if(t.MeasureNumber-1>=0&&this.measureList[s]){var b;const t=null===(b=this.measureList[s][0])||void 0===b?void 0:b.parentSourceMeasure;null!=t&&t.ImplicitMeasure&&null!=t&&t.RhythmPrinted&&(e=!1)}e&&(t.addRhythmAtBegin(h,i),t.parentSourceMeasure.RhythmPrinted=h,p=!0)}return(f||m||p)&&(u+=t.beginInstructionsWidth,p&&(u+=this.rules.RhythmRightMargin)),u}addInstructionsAtMeasureEnd(e,t,i){if(!e||!e.Instructions||0===e.Instructions.length)return 0;for(let s=0,n=e.Instructions.length;s<n;++s){const n=e.Instructions[s];if(n instanceof J){const e=n;t.addClefAtEnd(e);for(const s of i)s!==t&&s.addClefAtEnd(e,!1)}}return this.rules.MeasureRightMargin+t.endInstructionsWidth}updateActiveClefs(e,t){for(let i=0,s=t.length;i<s;i++){const t=this.visibleStaffIndices[i],s=e.FirstInstructionsStaffEntries[t];if(s)for(let e=0,o=s.Instructions.length;e<o;++e){const t=s.Instructions[e];t instanceof J?this.activeClefs[i]=t:t instanceof Z?this.activeKeys[i]=t:t instanceof x&&(this.activeRhythm[i]=t)}const n=e.getEntriesPerStaff(t);for(let e=0,o=n.length;e<o;++e){const t=n[e];if(t.Instructions)for(let e=0,s=t.Instructions.length;e<s;++e){const s=t.Instructions[e];s instanceof J&&(this.activeClefs[i]=s)}}const r=e.LastInstructionsStaffEntries[t];if(r){const e=r.Instructions;for(let t=0,s=e.length;t<s;++t){const s=e[t];s instanceof J&&(this.activeClefs[i]=s)}}}}checkAndCreateExtraInstructionMeasure(e){const t=e[0].parentSourceMeasure.FirstInstructionsStaffEntries,i=[];for(let n=0,r=e.length;n<r;++n){const s=e[n];i.push(t[s.ParentStaff.idInMusicSheet])}let s=0;for(let n=0,r=i.length;n<r;++n){const e=i[n];if(!e)continue;const t=e.Instructions;let r,o;for(let i=0,s=t.length;i<s;++i){const e=t[i];e instanceof Z&&e.Key!==this.activeKeys[n].Key&&(r=e),e instanceof x&&e!==this.activeRhythm[n]&&(o=e)}if(void 0!==r||o){const e=this.addExtraInstructionMeasure(n,r,o);s=Math.max(s,e)}}s>0&&(this.currentSystemParams.systemMeasures.push({beginLine:Ne.None,endLine:Ne.None}),this.currentSystemParams.currentWidth+=s,this.currentSystemParams.currentSystemFixWidth+=s)}addExtraInstructionMeasure(e,t,i){const s=this.currentSystemParams.currentSystem,n=yi.symbolFactory.createExtraGraphicalMeasure(s.StaffLines[e]);t&&n.addKeyAtBegin(t,this.activeKeys[e],this.activeClefs[e]),void 0!==i&&i.PrintObject&&n.addRhythmAtBegin(i),n.PositionAndShape.BorderLeft=0,n.PositionAndShape.BorderTop=0,n.PositionAndShape.BorderBottom=this.rules.StaffHeight;const r=this.rules.MeasureLeftMargin+n.beginInstructionsWidth+this.rules.MeasureRightMargin;return n.PositionAndShape.BorderRight=r,s.StaffLines[e].Measures.push(n),r}addStaveMeasuresToSystem(e){if(e[0]){const t=[];for(let s=0;s<e.length;s++)t.push(e[s]);const i=this.currentSystemParams.currentSystem;for(let e=0;e<this.numberOfVisibleStaffLines;e++){const s=t[e];i.StaffLines[e].Measures.push(s),s.ParentStaffLine=i.StaffLines[e]}i.AddGraphicalMeasures(t)}}getMeasureStartLine(){if(this.thisMeasureBeginsLineRepetition()){const e=0===this.measureListIndex;if(e&&this.rules.RepetitionAllowFirstMeasureBeginningRepeatBarline)return Ne.BoldThinDots;const t=this.currentSystemParams.IsSystemStartMeasure();if(this.previousMeasureEndsLineRepetition()&&!t)return Ne.DotsBoldBoldDots;if(!e)return Ne.BoldThinDots}return Ne.None}getMeasureEndLine(){let e;try{if(e=this.measureList[this.measureListIndex][0].parentSourceMeasure,this.rules.RenderMultipleRestMeasures&&e.multipleRestMeasures>1){const t=Math.min(this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length-1,e.measureListIndex+e.multipleRestMeasures-1);e=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[t]}}finally{}const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures,i=t[this.measureListIndex];let s=!1;var n,r;return i.allRests&&(s=null===(n=t[this.measureListIndex+i.multipleRestMeasures-1])||void 0===n||null===(r=n.endsWithLineRepetition)||void 0===r?void 0:r.call(n)),this.nextMeasureBeginsLineRepetition()&&this.thisMeasureEndsLineRepetition()?Ne.DotsBoldBoldDots:this.thisMeasureEndsLineRepetition()||s?Ne.DotsThinBold:this.nextMeasureHasKeyInstructionChange()||this.thisMeasureEndsWordRepetition()||this.nextMeasureBeginsWordRepetition()?Ne.DoubleThin:e&&void 0!==e.endingBarStyleEnum?e.endingBarStyleEnum:Ne.SingleThin}getLineWidth(e,t,i){let s=e.getLineWidth(t);return t===Ne.DotsBoldBoldDots&&(s/=2),i&&t===Ne.BoldThinDots&&(s+=this.rules.DistanceBetweenLastInstructionAndRepetitionBarline),s}previousMeasureEndsLineRepetition(){if(0===this.measureListIndex)return!1;for(let e=0,t=this.measureList[this.measureListIndex-1].length;e<t;++e)if(this.measureList[this.measureListIndex-1][e].endsWithLineRepetition())return!0;return!1}thisMeasureBeginsLineRepetition(){for(let e=0,t=this.measureList[this.measureListIndex].length;e<t;++e)if(this.measureList[this.measureListIndex][e].beginsWithLineRepetition())return!0;return!1}nextMeasureBeginsLineRepetition(){const e=this.measureListIndex+1;if(e>=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length||!this.measureList[e])return!1;for(let t=0,i=this.measureList[e].length;t<i;++t)if(this.measureList[e][t].beginsWithLineRepetition())return!0;return!1}thisMeasureEndsLineRepetition(){for(let t=0,i=this.measureList[this.measureListIndex].length;t<i;++t){var e;const i=this.measureList[this.measureListIndex][t];if(i.endsWithLineRepetition())return!0;if(null!==(e=i.parentSourceMeasure)&&void 0!==e&&e.isReducedToMultiRest){const e=this.graphicalMusicSheet.ParentMusicSheet;let t=i.parentSourceMeasure;const s=e.SourceMeasures.indexOf(t);let n=t.multipleRestMeasureNumber;for(let i=s+1;i<e.SourceMeasures.length;i++){const s=e.SourceMeasures[i];if(!(s.multipleRestMeasureNumber>=n))break;t=s,n=s.multipleRestMeasureNumber}return t.endsWithLineRepetition()}}return!1}nextMeasureBeginsWordRepetition(){const e=this.measureListIndex+1;if(e>=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length||e>this.measureList.length-1)return!1;for(let t=0,i=this.measureList[e].length;t<i;++t)if(this.measureList[e][t].beginsWithWordRepetition())return!0;return!1}thisMeasureEndsWordRepetition(){for(let e=0,t=this.measureList[this.measureListIndex].length;e<t;++e)if(this.measureList[this.measureListIndex][e].endsWithWordRepetition())return!0;return!1}nextMeasureHasKeyInstructionChange(){return void 0!==this.getNextMeasureKeyInstruction()}getNextMeasureKeyInstruction(){if(this.measureListIndex<this.measureList.length-1)for(let t=0;t<this.measureList[this.measureListIndex].length;t++){var e;const i=null===(e=this.measureList[this.measureListIndex+1][t])||void 0===e?void 0:e.parentSourceMeasure;if(!i)return;return i.getKeyInstruction(this.visibleStaffIndices[t])}}calculateXScalingFactor(e,t){return Math.abs(t-0)<1e-5||Math.abs(e-0)<1e-5?1:(this.currentSystemParams.currentSystem.StaffLines[0].PositionAndShape.Size.width-e)/t}stretchMusicSystem(e){let t=this.calculateXScalingFactor(this.currentSystemParams.currentSystemFixWidth,this.currentSystemParams.currentSystemVarWidth);e&&(t=Math.min(t,this.rules.LastSystemMaxScalingFactor));const i=this.currentSystemParams.currentSystem;for(let s=0,n=i.StaffLines.length;s<n;++s){const e=i.StaffLines[s];let n=0;for(let s=0;s<e.Measures.length;s++){const r=e.Measures[s];r.setPositionInStaffline(n);const o=r.beginInstructionsWidth;if(r.setWidth(o+r.minimumStaffEntriesWidth*t+r.endInstructionsWidth),s<this.currentSystemParams.systemMeasures.length){const e=this.currentSystemParams.systemMeasures[s].beginLine,t=r.getLineWidth(Ne.BoldThinDots);if(e===Ne.BoldThinDots){let o=n;0===s&&(o=n+r.beginInstructionsWidth-t),i.createVerticalLineForMeasure(o,t,e,ft.MeasureBegin,s,r)}}if(r.staffEntriesScaleFactor=t,r.layoutSymbols(),!(s+1<this.currentSystemParams.systemMeasures.length&&this.currentSystemParams.systemMeasures[s+1].beginLine===Ne.BoldThinDots)){let e=Ne.SingleThin;s<this.currentSystemParams.systemMeasures.length&&(e=this.currentSystemParams.systemMeasures[s].endLine);const t=r.getLineWidth(e);let n=r.PositionAndShape.RelativePosition.x+r.PositionAndShape.BorderRight-t;e===Ne.DotsBoldBoldDots&&(n-=t/2),i.createVerticalLineForMeasure(n,t,e,ft.MeasureEnd,s,r)}n=r.PositionAndShape.RelativePosition.x+r.PositionAndShape.BorderRight}}e&&this.decreaseMusicSystemBorders()}decreaseMusicSystemBorders(){const e=this.currentSystemParams.currentSystem,t=le.last(e.StaffLines[0].Measures).PositionAndShape,i=t.RelativePosition.x+t.Size.width;for(let s=0,n=e.StaffLines.length;s<n;++s){const t=e.StaffLines[s];t.PositionAndShape.BorderRight=i;for(let e=0,s=t.StaffLines.length;e<s;++e){const s=t.StaffLines[e];s.End=new z(i,s.End.y)}}e.PositionAndShape.BorderRight=i+this.currentSystemParams.maxLabelLength+this.rules.SystemLabelsRightMargin}updateStaffLinesRelativePosition(e,t,i){for(let s=t;s<e.StaffLines.length;s++)e.StaffLines[s].PositionAndShape.RelativePosition.y=i;e.PositionAndShape.BorderBottom+=i}createMusicPage(){const e=new he(this.graphicalMusicSheet);return this.graphicalMusicSheet.MusicPages.push(e),e.PageNumber=this.graphicalMusicSheet.MusicPages.length,e.PositionAndShape.BorderLeft=0,e.PositionAndShape.BorderRight=this.graphicalMusicSheet.ParentMusicSheet.pageWidth,e.PositionAndShape.BorderTop=0,e.PositionAndShape.BorderBottom=this.rules.PageHeight,e.PositionAndShape.RelativePosition=new z(0,0),e}addSystemToPage(e,t){e.MusicSystems.push(t),t.Parent=e}optimizeDistanceBetweenStaffLines(e){if(!e.checkStaffEntriesForStaffEntryLink())for(let s=0;s<e.StaffLines.length-1;s++){const t=e.StaffLines[s].BottomLine,i=e.StaffLines[s+1].SkyLine;let n=0;for(let e=0;e<t.length;e++){const s=t[e],r=Math.max(0,e-6),o=Math.min(i.length-1,e+6);let a=0;for(let e=r;e<=o;e++)a=Math.min(a,i[e]);const l=s-a;n=Math.max(l,n)}n+=this.rules.MinSkyBottomDistBetweenStaves,n=Math.max(n,this.rules.StaffHeight+this.rules.MinimumStaffLineDistance);const r=n+e.StaffLines[s].PositionAndShape.RelativePosition.y;this.updateStaffLinesRelativePosition(e,s+1,r)}const t=e.StaffLines[0];e.PositionAndShape.BorderTop=t.PositionAndShape.RelativePosition.y+t.PositionAndShape.BorderTop;const i=e.StaffLines[e.StaffLines.length-1];e.PositionAndShape.BorderBottom=i.PositionAndShape.RelativePosition.y+i.PositionAndShape.BorderBottom}hasExpressionCounts(e){let t=0,i=!1;for(const n of e.GraphicalMeasures)for(const e of n){for(const t of e.parentSourceMeasure.TempoExpressions){var s;if((null===(s=t.InstantaneousTempo)||void 0===s?void 0:s.Enum)===ti.metronomeMark){i=!0;break}}for(const i of e.parentSourceMeasure.StaffLinkedExpressions)t+=i.length}return{TempoCount:i?1:0,OtherCount:t}}calculateMusicSystemsRelativePositions(){let e=this.createMusicPage(),t=0,i=this.musicSystems[0],s=0,n=0;if(this.musicSystems.length>1)for(let a=1;a<this.musicSystems.length;a++){const e=this.musicSystems[a-1],t=this.musicSystems[a];let i=this.findRequiredDistanceWithSkyBottomLine(e,t);i>n&&(n=i)}for(let a=0;a<this.musicSystems.length;a++)if(i=this.musicSystems[a],0===e.MusicSystems.length){this.addSystemToPage(e,i),t=this.rules.CompactMode?this.rules.PageTopMarginNarrow:this.rules.PageTopMargin,1===this.graphicalMusicSheet.MusicPages.length&&this.rules.RenderTitle&&(t+=this.rules.TitleTopDistance+this.rules.SheetTitleHeight+this.rules.TitleBottomDistance);const n=new z(this.rules.PageLeftMargin+this.rules.SystemLeftMargin,t);i.PositionAndShape.RelativePosition=n,t+i.PositionAndShape.BorderBottom>this.rules.PageHeight-this.rules.PageBottomMargin&&(s++,s<=4&&(e.PageNumber,i.GraphicalMeasures[0][0].MeasureNumber))}else{var r,o;const s=this.musicSystems[a-1],l=s.StaffLines[s.StaffLines.length-1],h=l.PositionAndShape;let u=this.findRequiredDistanceWithSkyBottomLine(s,i);u=Math.max(n,u),u+=this.rules.MinSkyBottomDistBetweenSystems,"GYM"===(null===(r=window)||void 0===r||null===(o=r.appName)||void 0===o?void 0:o.toLocaleUpperCase())&&(u=u<16?16:u);const c=this.hasExpressionCounts(i);c.TempoCount>0&&this.rules.MetronomeMarksDrawn&&(u+=2),c.OtherCount>0&&this.rules.MetronomeMarksDrawn&&(u+=2),u=Math.max(u,this.rules.MinimumDistanceBetweenSystems+l.StaffHeight);const d=t+h.RelativePosition.y+u,f=d+i.PositionAndShape.BorderMarginBottom;if(this.rules.NewPageAtXMLNewPageAttribute&&s.breaksPage||!(f<this.rules.PageHeight-this.rules.PageBottomMargin)){e=this.createMusicPage(),a-=1;continue}{this.addSystemToPage(e,i),t=d;const s=new z(this.rules.PageLeftMargin+this.rules.SystemLeftMargin,t);i.PositionAndShape.RelativePosition=s}}s>0&&e.PageNumber}findRequiredDistanceWithSkyBottomLine(e,t){const i=e.StaffLines[e.StaffLines.length-1],s=t.StaffLines[0],n=i.BottomLine,r=s.SkyLine,o=i.PositionAndShape,a=s.PositionAndShape,l=1/this.rules.SamplingUnit;let h=0;for(let u=0;u<n.length;u++){const e=n[u],t=u+Math.round((o.RelativePosition.x-a.RelativePosition.x)*l);if(t<0)continue;if(t>=r.length)break;const i=Math.max(0,t-6),s=Math.min(r.length-1,t+6);let c=0;for(let n=i;n<=s;n++)c=Math.min(c,r[n]);const d=e-c;h=Math.max(d,h)}return 0===h&&(h=o.BorderBottom-a.BorderTop),h}}class fi{constructor(){this.systemMeasures=[],this.systemMeasureIndex=0,this.currentWidth=0,this.currentSystemFixWidth=0,this.currentSystemVarWidth=0,this.maxLabelLength=0}IsSystemStartMeasure(){return 0===this.systemMeasureIndex}}class mi{constructor(e,t,i){this.getOpenOctaveShift=e,this.getAbsoluteStartTimestamp=t,this.getAbsoluteEndTimestamp=i}}class pi{constructor(){this.keySignatureNoteAlterationsDict=new i,this.currentAlterationsComparedToKeyInstructionList=[],this.currentInMeasureNoteAlterationsDict=new i}get ActiveKeyInstruction(){return this.activeKeyInstruction}set ActiveKeyInstruction(e){this.activeKeyInstruction=e,this.reactOnKeyInstructionChange()}doCalculationsAtEndOfMeasure(){this.currentInMeasureNoteAlterationsDict.clear(),this.currentAlterationsComparedToKeyInstructionList.clear();for(const e of this.keySignatureNoteAlterationsDict.keys())this.currentInMeasureNoteAlterationsDict.setValue(e,this.keySignatureNoteAlterationsDict.getValue(e))}checkAccidental(e,t){if(!t)return;const i=t.FundamentalNote+12*t.Octave,s=this.currentAlterationsComparedToKeyInstructionList.indexOf(i)>=0;if(this.currentInMeasureNoteAlterationsDict.containsKey(i)){if(s&&this.currentAlterationsComparedToKeyInstructionList.splice(this.currentAlterationsComparedToKeyInstructionList.indexOf(i),1),this.currentInMeasureNoteAlterationsDict.getValue(i)!==t.AccidentalHalfTones){this.keySignatureNoteAlterationsDict.containsKey(i)&&this.keySignatureNoteAlterationsDict.getValue(i)!==t.AccidentalHalfTones?(this.currentAlterationsComparedToKeyInstructionList.push(i),this.currentInMeasureNoteAlterationsDict.setValue(i,t.AccidentalHalfTones)):t.Accidental!==Y.NONE&&this.currentInMeasureNoteAlterationsDict.remove(i);const s=this.currentInMeasureNoteAlterationsDict.getValue(i);if(t.Accidental===Y.NONE&&(t=.5===Math.abs(s)?new K(t.FundamentalNote,t.Octave,Y.NONE):new K(t.FundamentalNote,t.Octave,Y.NATURAL)),this.isAlterAmbiguousAccidental(t.Accidental)&&!t.AccidentalXml)return;yi.symbolFactory.addGraphicalAccidental(e,t)}}else if(t.Accidental!==Y.NONE){if(s||this.currentAlterationsComparedToKeyInstructionList.push(i),this.currentInMeasureNoteAlterationsDict.setValue(i,t.AccidentalHalfTones),this.isAlterAmbiguousAccidental(t.Accidental)&&!t.AccidentalXml)return;yi.symbolFactory.addGraphicalAccidental(e,t)}else s&&(t=new K(t.FundamentalNote,t.Octave,Y.NATURAL),this.currentAlterationsComparedToKeyInstructionList.splice(this.currentAlterationsComparedToKeyInstructionList.indexOf(i),1),yi.symbolFactory.addGraphicalAccidental(e,t))}isAlterAmbiguousAccidental(e){return e===Y.SLASHFLAT||e===Y.QUARTERTONEFLAT}reactOnKeyInstructionChange(){const e=this.activeKeyInstruction.AlteratedNotes;let t;t=this.activeKeyInstruction.Key>0?Y.SHARP:Y.FLAT,this.keySignatureNoteAlterationsDict.clear(),this.currentAlterationsComparedToKeyInstructionList.length=0;for(let i=-9;i<9;i++)for(let s=0;s<e.length;s++)this.keySignatureNoteAlterationsDict.setValue(e[s]+12*i,K.HalfTonesFromAccidental(t));this.doCalculationsAtEndOfMeasure()}}class gi extends di{buildMusicSystems(){this.currentSystemParams=new fi;const e=[];let t=0,i=-1;for(let u=0,c=this.measureList.length;u<c;++u){this.measureListIndex=u;const s=this.measureList[u];if(!s||!s[0])continue;for(let e=0,t=s.length;e<t;++e)s[e].resetLayout();const n=s[0].parentSourceMeasure,r=this.rules.NewPageAtXMLNewPageAttribute&&n.printNewPageXml;(this.rules.NewSystemAtXMLNewSystemAttribute&&n.printNewSystemXml||r)&&u>0?(i=u-1,e.push({startIndex:t,endIndex:i}),t=u):n.HasEndLine&&this.rules.NewPartAndSystemAfterFinalBarline&&(i=u,e.push({startIndex:t,endIndex:i}),t=u+1)}t<this.measureList.length&&i<t&&e.push({startIndex:t,endIndex:this.measureList.length-1});const s=[];let n=[];const r=[],o=[];for(const u of e){let e=0;for(let s=u.startIndex;s<=u.endIndex;++s){this.measureListIndex=s;const t=this.measureList[s];if(!t||!t[0]){r.push(0),o.push(0);continue}for(let e=0,s=t.length;e<s;++e)t[e].resetLayout();const i=t[0].parentSourceMeasure===this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();let n=this.rules.MeasureLeftMargin,a=0;const l=this.getMeasureStartLine();n+=this.getLineWidth(t[0],l,!1),this.leadSheet||(n+=this.addBeginInstructions(t,!1,i),a+=this.addEndInstructions(t));let h=0;for(let e=0;e<this.numberOfVisibleStaffLines;e++)h=Math.max(h,t[e].minimumStaffEntriesWidth);const u=this.getMeasureEndLine();a+=this.getLineWidth(t[0],u,!1);const c=n+a+h;r.push(c),o.push(e+c/2),e+=c}const t=e,i=this.getFullPageSystemWidth()-8,c=Math.ceil(t/i)*i/t;let d=1,f=0,m=0,p=0;for(let g=u.startIndex;g<=u.endIndex;++g){var a,l;const e=o[g];if(0===e)continue;const t=r[g],u=r[g+1]||0;let S=e*c/i;m+=t;const y=(null===(a=window)||void 0===a?void 0:a.appName)||"";if("GYM"===(null==y?void 0:y.toLocaleUpperCase())||null!==(l=window)&&void 0!==l&&l.customSectionAmount){var h;let e=null===(h=window.GYM)||void 0===h?void 0:h.wrapNum;e=Number(e)>0?Number(e):6,p===e||m+u>i&&p%2==0?(n.push(p),m=t,p=1):p++}else m>i?(n.push(p),m=t,p=1):p++;S=t>i?g+1:Math.ceil(S),d===S?f+=1:(s.push(f),d=S,f=1)}s.push(f),n.push(p),n=n.filter(Boolean)}return n.length>1&&1===n[n.length-1]&&(n[n.length-2]=n[n.length-2]-1,n[n.length-1]=n[n.length-1]+1),this.buildPreparedMusicSystems(n)}buildPreparedMusicSystems(e){let t=!1;this.currentSystemParams=new fi,this.currentSystemParams.currentSystem=this.initMusicSystem();for(let i=0,s=this.measureList.length;i<s;++i){this.measureListIndex=i;const s=this.measureList[i];if(!s||!s[0])continue;const n=this.rules.NewPageAtXMLNewPageAttribute&&s[0].parentSourceMeasure.printNewPageXml;this.currentSystemParams.currentSystem.GraphicalMeasures.length===e[this.musicSystems.length-1]&&this.finalizeCurrentAndCreateNewSystem(s,!1,!t,n);for(let e=0,t=s.length;e<t;++e)s[e].resetLayout();const r=s[0].parentSourceMeasure,o=r.HasEndLine,a=this.currentSystemParams.IsSystemStartMeasure(),l=r===this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();let h=this.rules.MeasureLeftMargin,u=0;const c=this.getMeasureStartLine();if(h+=this.getLineWidth(s[0],c,a),!this.leadSheet){let e=!1;t&&this.rules.ShowRhythmAgainAfterPartEndOrFinalBarline&&(e=!0),h+=this.addBeginInstructions(s,a,l||e),u+=this.addEndInstructions(s)}let d=0;for(let e=0;e<this.numberOfVisibleStaffLines;e++)d=Math.max(d,s[e].minimumStaffEntriesWidth);const f=this.getMeasureEndLine();u+=this.getLineWidth(s[0],f,a);const m=h+u+d;this.addMeasureToSystem(s,c,f,m,h,d,u),this.updateActiveClefs(r,s),t=o}return this.finalizeCurrentAndCreateNewSystem(void 0,!1,!1),this.musicSystems}}let Si={};class yi{constructor(){this.staffEntriesWithGraphicalTies=[],this.staffEntriesWithOrnaments=[],this.staffEntriesWithChordSymbols=[],this.staffLinesWithLyricWords=[],this.graphicalLyricWords=[],this.abstractNotImplementedErrorMessage="abstract, not implemented",this.specialTrackNames=["tom-toms"],this.dynamicExpressionMap=new Map}static get TextMeasurer(){return yi.textMeasurer}static set TextMeasurer(e){yi.textMeasurer=e}get leadSheet(){return this.graphicalMusicSheet.LeadSheet}static setMeasuresMinStaffEntriesWidth(e,t){for(let i=0,s=e.length;i<s;++i){const s=e[i];s&&(s.minimumStaffEntriesWidth=t)}}initialize(e){this.graphicalMusicSheet=e,this.rules=e.ParentMusicSheet.Rules,this.rules.clearMusicSheetObjects(),this.prepareGraphicalMusicSheet()}prepareGraphicalMusicSheet(){const e=this.graphicalMusicSheet.ParentMusicSheet;this.staffEntriesWithGraphicalTies=[],this.staffEntriesWithOrnaments=[],this.staffEntriesWithChordSymbols=[],this.staffLinesWithLyricWords=[],this.graphicalMusicSheet.Initialize();const t=this.graphicalMusicSheet.MeasureList,i=this.createAccidentalCalculators(),s=this.graphicalMusicSheet.initializeActiveClefs(),n=[],r=e.getCompleteNumberOfStaves(),o=[];for(let l=0;l<r;l++)o.push(void 0);for(let l=0,h=e.SourceMeasures.length;l<h;++l){const r=e.SourceMeasures[l],a=this.createGraphicalMeasuresForSourceMeasure(r,i,n,o,s);if(t.push(a),r.multipleRestMeasures>0&&this.rules.RenderMultipleRestMeasures){r.isReducedToMultiRest=!0,r.multipleRestMeasureNumber=1;const i=r.multipleRestMeasures-1;l+=i;for(let s=1;s<=i;s++){const i=e.SourceMeasures.indexOf(r)+s;if(i>=e.SourceMeasures.length)break;const n=e.SourceMeasures[i];n.multipleRestMeasureNumber=s+1,n.isReducedToMultiRest=!0,t.push([void 0])}}}if(this.rules.AutoGenerateMultipleRestMeasuresFromRestMeasures&&this.rules.RenderMultipleRestMeasures){let r,a=0;for(let l=0,h=e.SourceMeasures.length;l<h;++l){const h=e.SourceMeasures[l];if(!h.isReducedToMultiRest&&h.canBeReducedToMultiRest())if(a>0){r.isReducedToMultiRest=!0,r.multipleRestMeasureNumber=1,a++,h.multipleRestMeasureNumber=a,h.isReducedToMultiRest=!0;for(let e=0;e<t[l].length;e++)t[l][e]=void 0}else r=h,a=1;else if(a>1){r.multipleRestMeasures=a;const e=this.createGraphicalMeasuresForSourceMeasure(r,i,n,o,s);t[r.measureListIndex]=e,a=0,r=void 0}else a=0,r=void 0}if(a>1){r.multipleRestMeasures=a,r.isReducedToMultiRest=!0;const e=this.createGraphicalMeasuresForSourceMeasure(r,i,n,o,s);t[r.measureListIndex]=e,a=0,r=void 0}}const a=s.map((e=>e.ClefType===q.percussion));this.handleStaffEntries(a),this.calculateVerticalContainersList(),this.setIndicesToVerticalGraphicalContainers()}calculate(){this.musicSystems=[],this.clearSystemsAndMeasures(),this.clearRecreatedObjects(),this.createGraphicalTies(),this.calculateSheetLabelBoundingBoxes(),this.calculateXLayout(this.graphicalMusicSheet,this.maxInstrNameLabelLength()),this.graphicalMusicSheet.MusicPages.length=0,this.calculateMusicSystems(),Ie.transformRelativeToAbsolutePosition(this.graphicalMusicSheet)}calculateXLayout(e,t){if(this.graphicalMusicSheet.MeasureList.length>0){let e,t=0,s=1;for(let i=0;i<this.graphicalMusicSheet.MeasureList.length;i++){e=this.graphicalMusicSheet.MeasureList[i];let n=this.calculateMeasureXLayout(e);n=this.calculateMeasureWidthFromStaffEntries(e,n),n>t&&(t=n);const r=this.graphicalMusicSheet.ParentMusicSheet.MeasureWidthFactor;for(const t of e)if(null!=t&&t.parentSourceMeasure.WidthFactor){s=t.parentSourceMeasure.WidthFactor;break}n*=r*s,yi.setMeasuresMinStaffEntriesWidth(e,n)}if(this.rules.FixedMeasureWidth){let s=t;this.rules.FixedMeasureWidthFixedValue&&(s=this.rules.FixedMeasureWidthFixedValue);for(let t=0;t<this.graphicalMusicSheet.MeasureList.length;t++){var i;e=this.graphicalMusicSheet.MeasureList[t],!this.rules.FixedMeasureWidthUseForPickupMeasures&&null!==(i=e[0])&&void 0!==i&&i.parentSourceMeasure.ImplicitMeasure||yi.setMeasuresMinStaffEntriesWidth(e,s)}}}}calculateMeasureWidthFromStaffEntries(e,t){throw new Error(this.abstractNotImplementedErrorMessage)}formatMeasures(){throw new Error(this.abstractNotImplementedErrorMessage)}calculateMeasureXLayout(e){throw new Error(this.abstractNotImplementedErrorMessage)}initGraphicalMeasuresCreation(){throw new Error(this.abstractNotImplementedErrorMessage)}handleBeam(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}handleTiedGraphicalNote(e,t,i,s,n,r,o,a){throw new Error(this.abstractNotImplementedErrorMessage)}handleVoiceEntryLyrics(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}handleVoiceEntryOrnaments(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}handleVoiceEntryArticulations(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}handleVoiceEntryTechnicalInstructions(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}handleTuplet(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}layoutVoiceEntry(e,t,i,s){throw new Error(this.abstractNotImplementedErrorMessage)}layoutStaffEntry(e){throw new Error(this.abstractNotImplementedErrorMessage)}createGraphicalTie(e,t,i,s,n){throw new Error(this.abstractNotImplementedErrorMessage)}updateStaffLineBorders(e){throw new Error(this.abstractNotImplementedErrorMessage)}calculateMeasureNumberPlacement(e){const t=e.StaffLines[0];if(!t||!t.Measures[0])return void s.warn("calculateMeasureNumberPlacement: measure undefined for system.Id "+e.Id);let i=t.Measures[0].MeasureNumber,n=0;for(let s=0;s<t.Measures.length;s++){const r=t.Measures[s];let o=this.rules.RenderMeasureNumbersOnlyAtSystemStart&&s>1;if(1===s&&t.Measures[0].parentSourceMeasure.ImplicitMeasure&&(o=!1),o)return;0!==r.MeasureNumber&&1!==r.MeasureNumber||(i=r.MeasureNumber),n=r!==t.Measures[0]&&this.rules.MeasureNumberLabelXOffset?this.rules.MeasureNumberLabelXOffset:0;const a=this.rules.UseXMLMeasureNumbers&&1===r.MeasureNumber&&1!==r.parentSourceMeasure.getPrintedMeasureNumber();((r.MeasureNumber===i||r.MeasureNumber>=i+this.rules.MeasureNumberLabelOffset)&&!r.parentSourceMeasure.ImplicitMeasure||a)&&((1!==r.MeasureNumber||1===r.MeasureNumber&&r!==t.Measures[0]||a)&&this.calculateSingleMeasureNumberPlacement(r,t,e,n),i=r.MeasureNumber)}}calculateSingleMeasureNumberPlacement(e,t,i,s=0){var n,r,o,a;const l=/^\d+$/.test((null==e||null===(n=e.parentSourceMeasure)||void 0===n||null===(r=n.rehearsalExpression)||void 0===r?void 0:r.label)||"")||(null==e||null===(o=e.stave)||void 0===o||null===(a=o.modifiers)||void 0===a?void 0:a.some((e=>{var t;return"StaveSection"===(null==e||null===(t=e.attrs)||void 0===t?void 0:t.type)&&(null==e?void 0:e.section)>0&&isFinite(null==e?void 0:e.section)})))||!1,h=e.parentSourceMeasure.getPrintedMeasureNumber().toString(),u=new pt(h);u.isNotRender=l;const c=new mt(u,this.rules.MeasureNumberLabelHeight,ce.LeftBottom,this.rules),d=t.SkyBottomLineCalculator;c.setLabelPositionAndShapeBorders(),c.PositionAndShape.Parent=i.PositionAndShape;const f=t.PositionAndShape.RelativePosition.x+e.PositionAndShape.RelativePosition.x-c.PositionAndShape.BorderMarginLeft+s;let m,p=f,g=f-c.PositionAndShape.BorderLeft+c.PositionAndShape.BorderRight;p-=t.PositionAndShape.RelativePosition.x,g-=t.PositionAndShape.RelativePosition.x;const S=p+.5,y=g-.5,b=d.getSkyLineMinInRange(S,y);if(e===t.Measures[0]){let t=0;if(i.GroupBrackets.length>0)for(const e of i.GroupBrackets)t=Math.min(t,e.PositionAndShape.BorderTop);else e.ParentStaff.ParentInstrument.Parent&&(t=-1);m=Math.min(b,t)}else m=b;m=Math.min(0,m),c.PositionAndShape.RelativePosition=new z(f,m),i.MeasureNumberLabels.push(c)}calculateMeasureNumberSkyline(e){const t=e.StaffLines[0];for(const i of e.MeasureNumberLabels){let e=i.PositionAndShape.RelativePosition.x,s=e-i.PositionAndShape.BorderLeft+i.PositionAndShape.BorderRight;e-=t.PositionAndShape.RelativePosition.x,s-=t.PositionAndShape.RelativePosition.x,t.SkyBottomLineCalculator.updateSkyLineInRange(e,s,i.PositionAndShape.RelativePosition.y+i.PositionAndShape.BorderMarginTop)}}layoutGraphicalTie(e,t,i){throw new Error(this.abstractNotImplementedErrorMessage)}calculateSingleStaffLineLyricsPosition(e,t){let i=0,s=this.rules.StaffHeight;const n=new Map,r=[],o=e.SkyBottomLineCalculator;let a=e.Measures.length;for(let h=0;h<a;++h){const t=e.Measures[h],a=t.PositionAndShape.RelativePosition,l=t.staffEntries.length;for(let e=0;e<l;++e){const l=t.staffEntries[e],h=l.LyricsEntries.length;for(let e=0;e<h;++e){const t=l.LyricsEntries[e].LyricsEntry;n[t.VerseNumber]=t.IsChorus}if(h>0){r.push(l),i=Math.max(i,l.LyricsEntries.length);const e=l.PositionAndShape.RelativePosition.x+a.x;let t=Number.MAX_VALUE,n=Number.MIN_VALUE;for(let i=0;i<l.LyricsEntries.length;i++){const s=l.LyricsEntries[i].GraphicalLabel;t=Math.min(t,e+s.PositionAndShape.BorderMarginLeft),n=Math.max(n,e+s.PositionAndShape.BorderMarginRight)}const h=o.getBottomLineMaxInRange(t,n);s=Math.max(s,h+this.rules.LyricsYMarginToBottomLine)}}}let l=0;a=r.length;for(const h of r){const e=[];let i=!0;for(let t=0;t<h.LyricsEntries.length;t++)i&&(i=h.LyricsEntries[t].LyricsEntry.IsChorus);for(const s of t)n[s]===i&&e.push(s);for(let t=0;t<h.LyricsEntries.length;t++){const i=h.LyricsEntries[t],n=i.GraphicalLabel,r=i.LyricsEntry.VerseNumber,o=e.indexOf(r),a=s+this.rules.LyricsHeight+this.rules.VerticalBetweenLyricsDistance+this.rules.LyricsYOffsetToStaffHeight+(this.rules.VerticalBetweenLyricsDistance+this.rules.LyricsHeight)*o,u=n.PositionAndShape.RelativePosition.x;n.PositionAndShape.RelativePosition=new z(u,a),n.Label.fontStyle=i.LyricsEntry.FontStyle,l=Math.max(l,a)}}if(r.length>0){const t=e.PositionAndShape.Size.width;let i=r[0].PositionAndShape.RelativePosition.x+r[0].PositionAndShape.BorderMarginLeft+r[0].parentMeasure.PositionAndShape.RelativePosition.x;i=i>t?t:i,o.updateBottomLineInRange(i,t,l)}return r}calculateLyricsExtendsAndDashes(e){for(let t=0,i=e.length;t<i;++t){const i=e[t];for(let e=0;e<i.LyricsEntries.length;e++){const t=i.LyricsEntries[e];t.ParentLyricWord&&t.ParentLyricWord.GraphicalLyricsEntries[t.ParentLyricWord.GraphicalLyricsEntries.length-1]!==t&&this.calculateSingleLyricWord(t),t.LyricsEntry.extend&&this.calculateLyricExtend(t)}}}calculateSingleOctaveShift(e,t,i,s){throw new Error(this.abstractNotImplementedErrorMessage)}calculateWordRepetitionInstruction(e,t){throw new Error(this.abstractNotImplementedErrorMessage)}calculateMoodAndUnknownExpression(e,t,i){var n;const r=e.AbsoluteTimestamp,o=this.graphicalMusicSheet.MeasureList[t];let a=new z;const l=null===(n=e.UnknownList[0])||void 0===n?void 0:n.defaultYXml;if(e.MoodList.length>0||e.UnknownList.length>0){var h;let t="";for(let i=0,s=e.EntriesList.length;i<s;++i){const s=e.EntriesList[i];""!==s.prefix&&(t+=""===t?s.prefix:" "+s.prefix),t+=""===t?s.label:" "+s.label}const n=o[i].ParentStaffLine;if(!n)return void s.debug("MusicSheetCalculator.calculateMoodAndUnknownExpression: staffLine undefined. Returning.");a=this.getRelativePositionInStaffLineFromTimestamp(r,i,n,null==n?void 0:n.isPartOfMultiStaffInstrument()),Math.abs(a.x-0)<1e-4&&(a.x=o[i].beginInstructionsWidth+this.rules.RhythmRightMargin);const u=this.rules.UnknownTextHeight,c=e.getPlacementOfFirstEntry(),d=this.calculateLabel(n,a,t,e.getFontstyleOfFirstEntry(),c,u);if(this.rules.PlaceWordsInsideStafflineFromXml&&l<0&&l>-50){let e=l/10;e+=this.rules.PlaceWordsInsideStafflineYOffset,d.PositionAndShape.RelativePosition.y=e}new _t(n,d,c,null===(h=o[i])||void 0===h?void 0:h.parentSourceMeasure,e)}}clearRecreatedObjects(){for(let e=0,t=this.staffEntriesWithGraphicalTies.length;e<t;++e)this.staffEntriesWithGraphicalTies[e].GraphicalTies.length=0;this.staffEntriesWithGraphicalTies.length=0}handleStaffEntryLink(e,t){s.debug("handleStaffEntryLink not implemented")}calculateMusicSystems(){if(!this.graphicalMusicSheet.MeasureList)return;const e=this.graphicalMusicSheet.MeasureList;if(!e)return;this.rules.MinMeasureToDrawIndex>e.length-1&&(s.debug("minimum measure to draw index out of range. resetting min measure index to limit."),this.rules.MinMeasureToDrawIndex=e.length-1);const t=[];for(let s=this.rules.MinMeasureToDrawIndex,o=e.length;s<o&&s<=this.rules.MaxMeasureToDrawIndex;++s){const i=[];for(let t=0,n=e[s].length;t<n;++t){const n=e[s][t];if(null!=n&&n.isVisible()&&(i.push(n),this.rules.ColoringEnabled))for(const e of n.staffEntries)for(const t of e.graphicalVoiceEntries)t.color()}t.push(i)}let i,n=0;for(let s=0,o=t.length;s<o;++s){const e=t[s];n=Math.max(e.length,n);break}if(0===n)return;const r=e.length;if(i=!this.rules.UseJustifiedBuilder||1===r||this.rules.RenderSingleHorizontalStaffline?new di:new gi,i.initialize(this.graphicalMusicSheet,t,n),this.musicSystems=i.buildMusicSystems(),this.formatMeasures(),this.leadSheet||(this.optimizeRestPlacement(),this.calculateStaffEntryArticulationMarks(),this.rules.RenderSlurs&&this.calculateTieCurves()),this.calculateSkyBottomLines(),this.calculateTupletNumbers(),this.rules.RenderMeasureNumbers)for(let s=0,o=this.musicSystems.length;s<o;++s){const e=this.musicSystems[s];this.calculateMeasureNumberPlacement(e)}if(this.rules.RenderFingerings&&this.calculateFingerings(),!this.leadSheet&&this.rules.RenderSlurs&&this.calculateSlurs(),this.calculateGlissandi(),this.rules.RenderMeasureNumbers)for(let s=0,o=this.musicSystems.length;s<o;++s){const e=this.musicSystems[s];this.calculateMeasureNumberSkyline(e)}this.leadSheet||this.calculateOrnaments(),this.calculateChordSymbols(),this.leadSheet||(this.calculateDynamicExpressions(),this.calculateMoodAndUnknownExpressions(),this.calculateExpressionAlignements(),this.calculateOctaveShifts(),this.rules.RenderPedals&&this.calculatePedals(),this.rules.RenderWavyLines&&this.calculateWavyLines(),this.calculateWordRepetitionInstructions()),this.calculateRepetitionEndings(),this.leadSheet||this.calculateTempoExpressions(),this.calculateRehearsalMarks(),this.calculateLyricsPosition();for(let s=0,o=this.musicSystems.length;s<o;++s){const e=this.musicSystems[s];for(let t=0,i=e.StaffLines.length;t<i;++t){const i=e.StaffLines[t];this.updateStaffLineBorders(i)}}i.calculateSystemYLayout(),this.calculateMarkedAreas();for(let s=0,o=this.graphicalMusicSheet.MusicPages.length;s<o;++s){const e=this.graphicalMusicSheet.MusicPages[s];for(let i=0,n=e.MusicSystems.length;i<n;++i){const t=0===s&&0===i,n=e.MusicSystems[i];n.setMusicSystemLabelsYPosition(),this.leadSheet?n===n.Parent.MusicSystems[0]&&n.createSystemLeftLine(this.rules.SystemThinLineWidth,this.rules.SystemLabelsRightMargin,t):(n.setYPositionsToVerticalLineObjectsAndCreateLines(this.rules),n.createSystemLeftLine(this.rules.SystemThinLineWidth,this.rules.SystemLabelsRightMargin,t),n.createInstrumentBrackets(this.graphicalMusicSheet.ParentMusicSheet.Instruments,this.rules.StaffHeight),n.createGroupBrackets(this.graphicalMusicSheet.ParentMusicSheet.InstrumentalGroups,this.rules.StaffHeight,0),n.alignBeginInstructions()),n.calculateBorders(this.rules)}const t=e.MusicSystems[0].PositionAndShape.BorderTop;for(let i=0,s=e.MusicSystems.length;i<s;++i){const s=e.MusicSystems[i];s.PositionAndShape.RelativePosition=new z(s.PositionAndShape.RelativePosition.x,s.PositionAndShape.RelativePosition.y-t)}e.PositionAndShape.calculateTopBottomBorders(),e===this.graphicalMusicSheet.MusicPages[0]&&this.calculatePageLabels(e),e.PositionAndShape.calculateTopBottomBorders()}}calculateMarkedAreas(){}calculateChordSymbols(){for(const e of this.musicSystems)for(const t of e.StaffLines){const i=t.SkyBottomLineCalculator;let s=Number.MAX_SAFE_INTEGER;if(this.rules.ChordSymbolYAlignment&&"staffline"===this.rules.ChordSymbolYAlignmentScope){const e=[];for(const i of t.Measures)e.push(...i.staffEntries);s=this.calculateAlignedChordSymbolsOffset(e,i)}for(let n=0;n<t.Measures.length;n++){const r=t.Measures[n];let o;this.rules.ChordSymbolYAlignment&&"measure"===this.rules.ChordSymbolYAlignmentScope&&(s=this.calculateAlignedChordSymbolsOffset(r.staffEntries,i));for(const t of r.staffEntries)if(t.graphicalChordContainers&&0!==t.graphicalChordContainers.length)for(let a=0;a<t.graphicalChordContainers.length;a++){const l=t.graphicalChordContainers[a];if(0===t.graphicalVoiceEntries.length&&t.relInMeasureTimestamp.RealValue>0){let e=0;0===r.staffEntries[0].relInMeasureTimestamp.RealValue&&(e=r.staffEntries[0].PositionAndShape.RelativePosition.x,1===r.MeasureNumber&&(e+=this.rules.ChordSymbolWholeMeasureRestXOffsetMeasure1));let i=e+(r.PositionAndShape.Size.width-r.endInstructionsWidth-e)*(t.relInMeasureTimestamp.RealValue/r.parentSourceMeasure.Duration.RealValue)+l.PositionAndShape.BorderMarginLeft;o&&(i=Math.max(i,o.PositionAndShape.RelativePosition.x+o.GraphicalLabel.PositionAndShape.Size.width+this.rules.ChordSymbolXSpacing)),l.PositionAndShape.RelativePosition.x=i,l.PositionAndShape.Parent=r.staffEntries[0].PositionAndShape.Parent}const h=l.PositionAndShape,u=h.Parent;if(u.DataObject instanceof Re&&0===t.relInMeasureTimestamp.RealValue&&(h.RelativePosition.x=Math.max(r.beginInstructionsWidth,h.RelativePosition.x),1===r.MeasureNumber&&h.RelativePosition.x>3&&(h.RelativePosition.x+=this.rules.ChordSymbolWholeMeasureRestXOffsetMeasure1)),0===t.PositionAndShape.RelativePosition.x){const i=e.GraphicalMeasures[n];for(const e of i){let i=!1;for(const s of e.staffEntries)if(s.relInMeasureTimestamp===t.relInMeasureTimestamp&&0!==s.PositionAndShape.RelativePosition.x){h.RelativePosition.x=s.PositionAndShape.RelativePosition.x,i=!0;break}if(i)break}}const c=h.BorderMarginLeft+u.AbsolutePosition.x+h.RelativePosition.x,d=h.BorderMarginRight+u.AbsolutePosition.x+h.RelativePosition.x;(!this.rules.ChordSymbolYAlignment||s>0)&&(s=i.getSkyLineMinInRange(c,d));let f=0;0===a?(f+=this.rules.ChordSymbolYOffset,f+=.1):f+=this.rules.ChordSymbolYPadding,f*=-1;const m=l.GraphicalLabel;m.PositionAndShape.RelativePosition.y=s+f,m.setLabelPositionAndShapeBorders(),m.PositionAndShape.calculateBoundingBox(),i.updateSkyLineInRange(c,d,s+m.PositionAndShape.BorderMarginTop),o=l}}}}calculateAlignedChordSymbolsOffset(e,t){let i=Number.MAX_SAFE_INTEGER;for(const s of e)for(const e of s.graphicalChordContainers){const s=e.PositionAndShape,n=s.Parent;let r=s.BorderMarginLeft+n.AbsolutePosition.x,o=s.BorderMarginRight+n.AbsolutePosition.x;n.DataObject instanceof Re&&(r+=n.DataObject.beginInstructionsWidth,o+=n.DataObject.beginInstructionsWidth),i=Math.min(i,t.getSkyLineMinInRange(r,o))}return i}layoutMeasureWithWholeRest(e,t,i){}layoutBeams(e){}layoutArticulationMarks(e,t,i){}layoutOrnament(e,t,i){}calculateRestNotePlacementWithinGraphicalBeam(e,t,i,s,n){}calculateTupletNumbers(){if(!this.rules.TupletNumberLimitConsecutiveRepetitions)return;let e,t,i,n=-1,r=0;const o={};for(const a of this.graphicalMusicSheet.ParentMusicSheet.Instruments)for(const l of a.Voices){r=0,o[l.VoiceId]={};for(const a of l.VoiceEntries)if(a.Notes.length>0){const h=a.Notes[0];if(!h.NoteTuplet||h.NoteTuplet.shouldBeBracketed(this.rules.TupletsBracketedUseXMLValue,this.rules.TupletsBracketed,this.rules.TripletsBracketed)){n=-1,r=0,t=void 0,e=void 0;continue}if(h.NoteTuplet===i)continue;let u=h.TypeLength;if(u||(s.warn("note missing TypeLength"),u=h.NoteTuplet.Fractions[0]),h.NoteTuplet!==t&&o[l.VoiceId][h.NoteTuplet.TupletLabelNumber]&&o[l.VoiceId][h.NoteTuplet.TupletLabelNumber][u.RealValue]){h.NoteTuplet.RenderTupletNumber=!1,i=h.NoteTuplet;continue}h.NoteTuplet.TupletLabelNumber===n&&u.Equals(e)&&!h.NoteTuplet.Bracket||(n=h.NoteTuplet.TupletLabelNumber,e=u,r=0),t=h.NoteTuplet,r++,r<=this.rules.TupletNumberMaxConsecutiveRepetitions&&(h.NoteTuplet.RenderTupletNumber=!0),r>this.rules.TupletNumberMaxConsecutiveRepetitions&&(h.NoteTuplet.RenderTupletNumber=!1,this.rules.TupletNumberAlwaysDisableAfterFirstMax&&(o[l.VoiceId][n]||(o[l.VoiceId][n]={}),o[l.VoiceId][n][u.RealValue]=!0)),i=t}}}calculateSlurs(){}calculateGlissandi(){}calculateDynamicExpressionsForMultiExpression(e,t,i){}calculateGraphicalVerbalContinuousDynamic(e,t){const i=e.Label,s=t.x+i.PositionAndShape.BorderMarginLeft,n=t.x+i.PositionAndShape.BorderMarginRight,r=e.ContinuousDynamic.Placement,o=e.ParentStaffLine.SkyBottomLineCalculator;let a;r===d.Below?(a=o.getBottomLineMaxInRange(s,n),i.PositionAndShape.RelativePosition=new z(t.x,a-i.PositionAndShape.BorderMarginTop)):(a=o.getSkyLineMinInRange(s,n),i.PositionAndShape.RelativePosition=new z(t.x,a-i.PositionAndShape.BorderMarginBottom))}calculateGraphicalContinuousDynamic(e,t){const i=e.IsSoftAccent,n=e.ParentStaffLine.ParentStaff.idInMusicSheet,r=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(e.ContinuousDynamic.EndMultiExpression.SourceMeasureParent,n);if(!r)return void s.warn("MusicSheetCalculator.calculateGraphicalContinuousDynamic: No endMeasure found");e.EndMeasure=r;const o=e.ParentStaffLine,a=r.ParentStaffLine,l=a&&o===a;let h=!1;a?h=null==a?void 0:a.isPartOfMultiStaffInstrument():o&&(h=null==o?void 0:o.isPartOfMultiStaffInstrument());const c=u.createFromFraction(e.ContinuousDynamic.EndMultiExpression.AbsoluteTimestamp),f=this.graphicalMusicSheet.GetVerticalContainerFromTimestamp(c),m=f.getFirstNonNullStaffEntry().parentMeasure,g=m.PositionAndShape.AbsolutePosition.x+m.PositionAndShape.BorderRight;let S=new u(0,0,0);for(const s of f.StaffEntries){var y;const e=null==s||null===(y=s.sourceStaffEntry)||void 0===y?void 0:y.calculateMaxNoteLength(!1);null!=e&&e.gt(S)&&(S=e)}const b=!i&&e.ContinuousDynamic.DynamicType===p.diminuendo,M=this.getRelativePositionInStaffLineFromTimestamp(c,n,a,h,0,b),v=u.plus(c,S).clone();e.ContinuousDynamic.EndMultiExpression.EndOffsetFraction&&this.rules.UseEndOffsetForExpressions&&v.Add(e.ContinuousDynamic.EndMultiExpression.EndOffsetFraction);const P=this.getRelativePositionInStaffLineFromTimestamp(v,n,a,h,0,e.ContinuousDynamic.DynamicType===p.diminuendo),E=this.rules.SoftAccentWedgePadding,L=f.getFirstNonNullStaffEntry().PositionAndShape.Size.width,x=this.rules.SoftAccentSizeFactor;i?(t.x-=L/2*x+E,M.x=t.x+L/2*x):P.x>M.x&&P.x<g?M.x+=(P.x-M.x)/this.rules.WedgeEndDistanceBetweenTimestampsFactor:M.x=g-this.rules.WedgeHorizontalMargin;const T=this.dynamicExpressionMap.get(e.ContinuousDynamic.StartMultiExpression.AbsoluteTimestamp.RealValue);T&&T.DataObject.ParentStaffLine===o&&(t.x=T.RelativePosition.x+this.rules.WedgeHorizontalMargin,t.x+=T.BorderMarginRight);const w=o.ParentMusicSystem,I=w.StaffLines.indexOf(o),A=o.SkyBottomLineCalculator;let R=e.ContinuousDynamic.Placement;const N=e.ContinuousDynamic.DynamicType;let C;0!==N&&1!==N||(R=1),l&&M.x-t.x<this.rules.WedgeMinLength&&!i&&(M.x=t.x+this.rules.WedgeMinLength);const B=t.x;let D=a.Measures[0].beginInstructionsWidth-this.rules.WedgeHorizontalMargin-2,V=0,k=0;const F=[];if(l)V=M.x;else{V=o.PositionAndShape.Size.width,k=M.x;const t=[o,a],i=e.StartMeasure;let s=i,l=0,h=i.parentSourceMeasure.measureListIndex;for(;s!==r&&l<1e3;){const i=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[h],r=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(i,n);if(r){s=r;const i=s.ParentStaffLine;if(!t.includes(i)){t.push(i);const s=new Ft(e.ContinuousDynamic,i,i.Measures[0].parentSourceMeasure);s.IsSplittedPart=!0,F.push(s)}}h++,l++}C=new Ft(e.ContinuousDynamic,a,r.parentSourceMeasure),C.IsSplittedPart=!0,e.IsSplittedPart=!0}i&&(D=M.x+E,k=D+L/2*x);let O=0,_=0;if(R===d.Below){let e=0;if(I<w.StaffLines.length-1&&(e=I+1),e>I){const t=w.StaffLines[e].PositionAndShape.RelativePosition.y-o.PositionAndShape.RelativePosition.y-this.rules.StaffHeight;O=this.rules.StaffHeight+t/2}else O=this.rules.WedgePlacementBelowY;O-=this.rules.WedgeOpeningLength/2,l||(_=O);let t=A.getBottomLineMaxInRange(B,V);if(t>O&&(O=t),I<w.StaffLines.length-1){const e=o.findClosestStaffEntry(V),t=o.findClosestStaffEntry(B);t&&e&&t.parentVerticalContainer}l||(t=a.SkyBottomLineCalculator.getBottomLineMaxInRange(D,k),t>_&&(_=t),_+=this.rules.WedgeOpeningLength/2,_+=this.rules.WedgeVerticalMargin),O+=this.rules.WedgeOpeningLength/2,O+=this.rules.WedgeVerticalMargin}else if(R===d.Above){if(1===o.ParentStaff.ParentInstrument.Staves.length)O=this.rules.WedgePlacementAboveY;else{let e=0;I>0&&(e=I-1);const t=w.StaffLines[e];O=-(o.PositionAndShape.RelativePosition.y-t.PositionAndShape.RelativePosition.y-this.rules.StaffHeight)/2}O+=this.rules.WedgeOpeningLength/2,l||(_=O);let e=A.getSkyLineMinInRange(B,V);if(e<O&&(O=e),o.ParentStaff.ParentInstrument.Staves.length>1&&I>0){const e=o.findClosestStaffEntry(B),t=o.findClosestStaffEntry(V);e&&t&&e.parentVerticalContainer}l||(e=a.SkyBottomLineCalculator.getSkyLineMinInRange(D,k),e<_&&(_=e),_-=this.rules.WedgeOpeningLength/2),O-=this.rules.WedgeOpeningLength/2,O-=this.rules.WedgeVerticalMargin,l||(_-=this.rules.WedgeVerticalMargin)}if(e.Lines.clear(),i)e.createFirstHalfCrescendoLines(B,V,O),e.createSecondHalfDiminuendoLines(D,k,O),e.calcPsi();else if(l&&!i)e.createLines(B,V,O),e.calcPsi();else{e.createFirstHalfLines(B,V,O),e.calcPsi();for(let t=0;t<F.length;t++){const i=F[t],s=i.ParentStaffLine;let n=_;if(R===d.Below){const e=a.SkyBottomLineCalculator.getBottomLineMaxInRange(D,V);e>n&&(n=e),n+=this.rules.WedgeOpeningLength/2,n+=this.rules.WedgeVerticalMargin}else if(R===d.Above){const e=s.SkyBottomLineCalculator.getSkyLineMinInRange(D,k);e<_&&(n=e),n-=this.rules.WedgeOpeningLength/2}e.ContinuousDynamic.DynamicType===p.crescendo?i.createSecondHalfCrescendoLines(0,s.PositionAndShape.Size.width,n):i.createFirstHalfDiminuendoLines(0,s.PositionAndShape.Size.width,n),i.calcPsi()}C.createSecondHalfLines(D,k,_),C.calcPsi()}this.dynamicExpressionMap.set(c.RealValue,e.PositionAndShape)}calculateGraphicalInstantaneousDynamicExpression(e,t,i){const s=e.ParentStaffLine;if(!s)return;const n=t.x+e.PositionAndShape.BorderMarginLeft,r=t.x+e.PositionAndShape.BorderMarginRight,o=s.SkyBottomLineCalculator;let a=0;if(e.Placement===d.Above){const i=o.getSkyLineMinInRange(n,r);if(s.isPartOfMultiStaffInstrument()&&s.ParentStaff!==s.ParentStaff.ParentInstrument.Staves[0]){const t=s.ParentMusicSystem.StaffLines[s.ParentMusicSystem.StaffLines.indexOf(s)-1],n=s.PositionAndShape.RelativePosition.y-t.PositionAndShape.RelativePosition.y-this.rules.StaffHeight;a=i>-n/2?-n/2:i-e.PositionAndShape.BorderMarginBottom}else a=i-e.PositionAndShape.BorderMarginBottom;e.PositionAndShape.RelativePosition=new z(t.x,a)}else if(e.Placement===d.Below){const i=o.getBottomLineMaxInRange(n,r),l=s.ParentStaff.ParentInstrument.Staves[s.ParentStaff.ParentInstrument.Staves.length-1];if(s.isPartOfMultiStaffInstrument()&&s.ParentStaff!==l){const t=s.ParentMusicSystem.StaffLines[s.ParentMusicSystem.StaffLines.indexOf(s)+1].PositionAndShape.RelativePosition.y-s.PositionAndShape.RelativePosition.y-this.rules.StaffHeight;a=i+e.PositionAndShape.BorderMarginBottom<this.rules.StaffHeight+t/2?this.rules.StaffHeight+t/2:i-e.PositionAndShape.BorderMarginTop}else a=i-e.PositionAndShape.BorderMarginTop;e.PositionAndShape.RelativePosition=new z(t.x,a)}e.updateSkyBottomLine()}calcGraphicalRepetitionEndingsRecursively(e){}layoutSingleRepetitionEnding(e,t,i,s,n,r){}calculateLabel(e,t,i,s,n,r,o=ce.CenterBottom,a=0){const l=new pt(i,o);l.fontStyle=s,l.fontHeight=r;const h=new mt(l,r,l.textAlignment,this.rules,e.PositionAndShape),u=1.1;n===d.Below&&(h.Label.textAlignment=ce.LeftTop),h.setLabelPositionAndShapeBorders(),h.PositionAndShape.BorderMarginBottom*=u,h.PositionAndShape.BorderMarginTop*=u,h.PositionAndShape.BorderMarginLeft*=u,h.PositionAndShape.BorderMarginRight*=u;let c,f=t.x+h.PositionAndShape.BorderMarginLeft,m=t.x+h.PositionAndShape.BorderMarginRight;m>e.PositionAndShape.Size.width&&(m=e.PositionAndShape.Size.width-this.rules.MeasureRightMargin,f=m-h.PositionAndShape.MarginSize.width,t.x=f-h.PositionAndShape.BorderMarginLeft);const p=e.SkyBottomLineCalculator;return c=n===d.Below?p.getBottomLineMaxInRange(f,m)+a:p.getSkyLineMinInRange(f,m)-a,h.PositionAndShape.RelativePosition=new z(t.x,c),n===d.Below?p.updateBottomLineInRange(f,m,h.PositionAndShape.BorderMarginBottom+c):p.updateSkyLineInRange(f,m,h.PositionAndShape.BorderMarginTop+c),h}calculateTempoExpressionsForMultiTempoExpression(e,t,i,n){Si={};const r=u.plus(e.AbsoluteTimestamp,t.Timestamp),o=this.graphicalMusicSheet.MeasureList[i];let a=new z;if(t.ContinuousTempo||t.InstantaneousTempo){if(this.rules.MinMeasureToDrawIndex>0)return;if(!o[0])return;let l=o[0].ParentStaffLine,h=o[0].PositionAndShape.RelativePosition.x,u=0;for(let e=0;e<o.length;e++)if(o[e].ParentStaffLine&&0!==o[e].ParentStaffLine.Measures.length&&o[e].ParentStaffLine.Measures.length>0){l=o[e].ParentStaffLine,h=o[e].PositionAndShape.RelativePosition.x,u=e;break}if(a=this.getRelativePositionInStaffLineFromTimestamp(r,u,l,l.isPartOfMultiStaffInstrument(),h),t.EntriesList.length>0&&t.EntriesList[0].Expression instanceof ei&&(t.EntriesList[0].Expression.Placement=d.Above,l.Measures[0].staffEntries.length>0&&0===Math.abs(a.x-l.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x)&&l.ParentMusicSystem===this.musicSystems[0])){const e=l.Measures[0].FirstInstructionStaffEntry;if(e){const t=e.GraphicalInstructions.last();a.x=t.PositionAndShape.RelativePosition.x}this.rules.CompactMode&&(a.x=l.PositionAndShape.RelativePosition.x+l.Measures[0].PositionAndShape.RelativePosition.x)}for(const r of t.EntriesList){let o=ce.CenterBottom;this.rules.CompactMode&&(o=ce.LeftBottom);const h=this.calculateLabel(l,a,r.label,t.getFontstyleOfFirstEntry(),r.Expression.Placement,this.rules.UnknownTextHeight,o,this.rules.TempoYSpacing);if(r.Expression.ColorXML&&this.rules.ExpressionsUseXMLColor&&(h.ColorXML=r.Expression.ColorXML),r.Expression instanceof ei){for(const e of l.AbstractExpressions)e instanceof Vt&&(e.SourceExpression.Label,r.Expression.Label);new Vt(r.Expression,h).ParentStaffLine||s.warn("Adding staffline didn't work"),r.Expression.Enum===ti.metronomeMark&&(Si[i]=r.Expression)}else r.Expression;if(n===e.TempoExpressions.length-1)for(const e of Object.values(Si))this.createMetronomeMark(e,i);else if(r.Expression instanceof li){for(const e of l.AbstractExpressions)e instanceof Vt&&(e.SourceExpression.Label,r.Expression.Label);l.AbstractExpressions.push(new Vt(r.Expression,h))}}}}createMetronomeMark(e,t){throw new Error(this.abstractNotImplementedErrorMessage)}graphicalMeasureCreatedCalculations(e){}clearSystemsAndMeasures(){for(let e=0,t=this.graphicalMusicSheet.MusicPages.length;e<t;++e){const t=this.graphicalMusicSheet.MusicPages[e];for(let e=0,i=t.MusicSystems.length;e<i;++e){const i=t.MusicSystems[e];for(let e=0,t=i.StaffLines.length;e<t;++e){const t=i.StaffLines[e];for(let e=0,i=t.Measures.length;e<i;++e){const i=t.Measures[e];if(i.FirstInstructionStaffEntry){const e=i.PositionAndShape.ChildElements.indexOf(i.FirstInstructionStaffEntry.PositionAndShape);e>-1&&i.PositionAndShape.ChildElements.splice(e,1),i.FirstInstructionStaffEntry=void 0,i.beginInstructionsWidth=0}if(i.LastInstructionStaffEntry){const e=i.PositionAndShape.ChildElements.indexOf(i.LastInstructionStaffEntry.PositionAndShape);e>-1&&i.PositionAndShape.ChildElements.splice(e,1),i.LastInstructionStaffEntry=void 0,i.endInstructionsWidth=0}}t.Measures=[],t.PositionAndShape.ChildElements=[]}i.StaffLines.length=0,i.PositionAndShape.ChildElements=[]}t.MusicSystems=[],t.PositionAndShape.ChildElements=[]}this.graphicalMusicSheet.MusicPages=[]}handleVoiceEntry(e,t,i,s,n,r,o,a,l,h=void 0,u=void 0){e.StemDirectionXml!==dt.Undefined&&this.rules.SetWantedStemDirectionByXml&&void 0!==e.StemDirectionXml?e.WantedStemDirection=e.StemDirectionXml:this.calculateStemDirectionFromVoices(e);const c=t.findOrCreateGraphicalVoiceEntry(e);c.octaveShiftValue=a;const d=t.tabStaffEntry;let f;d&&(f=d.findOrCreateGraphicalVoiceEntry(e));for(let m=0,p=e.Notes.length;m<p;++m){const s=e.Notes[m];if(!s)continue;if(void 0!==u&&void 0!==u.Link&&void 0!==h&&h.indexOf(s)>-1)continue;let l;if(e.IsGrace?l=yi.symbolFactory.createGraceNote(s,c,n,this.rules,a):(l=yi.symbolFactory.createNote(s,c,n,a,this.rules,void 0),yi.stafflineNoteCalculator.trackNote(l)),s.Pitch&&this.checkNoteForAccidental(l,i,n,a),this.resetYPositionForLeadSheet(l.PositionAndShape),t.addGraphicalNoteToListAtCorrectYPosition(c,l),l.PositionAndShape.calculateBoundingBox(),this.leadSheet||(void 0!==s.NoteBeam&&s.PrintObject&&(s instanceof Yt&&!this.rules.TabBeamsRendered||this.handleBeam(l,s.NoteBeam,o)),void 0!==s.NoteTuplet&&s.PrintObject&&this.handleTuplet(l,s.NoteTuplet,r)),f){const e=yi.symbolFactory.createNote(s,f,n,a,this.rules,void 0);d.addGraphicalNoteToListAtCorrectYPosition(f,e),e.PositionAndShape.calculateBoundingBox(),this.leadSheet||s.NoteTuplet&&this.handleTuplet(e,s.NoteTuplet,r)}}return e.Articulations.length>0&&this.handleVoiceEntryArticulations(e.Articulations,e,t),e.TechnicalInstructions.length>0&&this.handleVoiceEntryTechnicalInstructions(e.TechnicalInstructions,e,t),e.LyricsEntries.size()>0&&this.handleVoiceEntryLyrics(e,t,s),e.OrnamentContainer&&this.handleVoiceEntryOrnaments(e.OrnamentContainer,e,t),a}resetYPositionForLeadSheet(e){this.leadSheet&&(e.RelativePosition=new z(e.RelativePosition.x,0))}layoutVoiceEntries(e,t){if(e.PositionAndShape.RelativePosition=new z(0,0),!this.leadSheet)for(const i of e.graphicalVoiceEntries){const t=i.notes;if(0===t.length)continue;const s=t[0].sourceNote.ParentVoiceEntry,n=void 0!==t[0].sourceNote.Pitch;this.layoutVoiceEntry(s,t,e,n)}}maxInstrNameLabelLength(){let e=0;for(const i of this.graphicalMusicSheet.ParentMusicSheet.Instruments){var t;if(null!==(t=i.NameLabel)&&void 0!==t&&t.print&&i.Voices.length>0&&i.Voices[0].Visible){let t=i.NameLabel;this.rules.RenderPartNames||(t=new pt("",t.textAlignment,t.font));const s=new mt(t,this.rules.InstrumentLabelTextHeight,ce.LeftCenter,this.rules);s.setLabelPositionAndShapeBorders(),e=Math.max(e,s.PositionAndShape.MarginSize.width)}}return this.rules.RenderPartNames?e:0}calculateSheetLabelBoundingBoxes(){var e;const t=this.graphicalMusicSheet.ParentMusicSheet,i=this.rules.DefaultColorTitle;if(void 0!==t.Title&&this.rules.RenderTitle){const e=new mt(t.Title,this.rules.SheetTitleHeight,ce.CenterBottom,this.rules);e.Label.IsCreditLabel=!0,e.Label.colorDefault=i,this.graphicalMusicSheet.Title=e,e.setLabelPositionAndShapeBorders()}else this.rules.RenderTitle||(this.graphicalMusicSheet.Title=void 0);if(void 0!==t.Subtitle&&this.rules.RenderSubtitle){const e=new mt(t.Subtitle,this.rules.SheetSubtitleHeight,ce.CenterCenter,this.rules);e.Label.IsCreditLabel=!0,e.Label.colorDefault=i,this.graphicalMusicSheet.Subtitle=e,e.setLabelPositionAndShapeBorders()}else this.rules.RenderSubtitle||(this.graphicalMusicSheet.Subtitle=void 0);if(void 0!==t.Composer&&this.rules.RenderComposer){const e=new mt(t.Composer,this.rules.SheetComposerHeight,ce.RightCenter,this.rules);e.Label.IsCreditLabel=!0,e.Label.colorDefault=i,this.graphicalMusicSheet.Composer=e,e.setLabelPositionAndShapeBorders()}else this.rules.RenderComposer||(this.graphicalMusicSheet.Composer=void 0);if(void 0!==t.Lyricist&&this.rules.RenderLyricist){const e=new mt(t.Lyricist,this.rules.SheetAuthorHeight,ce.RightCenter,this.rules);e.Label.IsCreditLabel=!0,e.Label.colorDefault=i,this.graphicalMusicSheet.Lyricist=e,e.setLabelPositionAndShapeBorders()}else this.rules.RenderLyricist||(this.graphicalMusicSheet.Lyricist=void 0);if(void 0!==t.Copyright&&this.rules.RenderCopyright){const e=new mt(t.Copyright,this.rules.SheetCopyrightHeight,ce.CenterBottom,this.rules);e.Label.IsCreditLabel=!0,e.Label.colorDefault=i,this.graphicalMusicSheet.Copyright=e,e.setLabelPositionAndShapeBorders()}else this.rules.RenderCopyright||(this.graphicalMusicSheet.Copyright=void 0);const s=null===(e=this.graphicalMusicSheet.musicSheet.sourceMeasures)||void 0===e?void 0:e[0];if(s&&s.FirstInstructionsStaffEntries.length>0){const e=s.FirstInstructionsStaffEntries[0];let n,r;for(let t=0,i=e.Instructions.length;t<i;++t){const i=e.Instructions[t];i instanceof J||(i instanceof Z?n=i:i instanceof x&&(r=i))}if(n){t.CurrentKeyInstruction=n;const e=Jt.keySignature(n),s=new pt("1="+e),o=new pt(`${r.Rhythm.Numerator}\n\n${r.Rhythm.Denominator}`),a=new mt(s,this.rules.SheetAuthorHeight,ce.LeftCenter,this.rules),l=new mt(o,this.rules.SheetAuthorHeight,ce.LeftCenter,this.rules),h=new pt("ᅳ"),u=new mt(h,this.rules.SheetAuthorHeight,ce.LeftCenter,this.rules);s.fontFamily="Arial",s.IsCreditLabel=!0,s.colorDefault=i,o.fontFamily="Arial",o.IsCreditLabel=!0,o.colorDefault=i,h.fontFamily="Arial",h.IsCreditLabel=!0,h.colorDefault=i,this.graphicalMusicSheet.JianpuKeySignature=a,this.graphicalMusicSheet.jianpuTimeSignature=l,this.graphicalMusicSheet.jianpuLine=u,a.setLabelPositionAndShapeBorders(),l.setLabelPositionAndShapeBorders(),u.setLabelPositionAndShapeBorders()}}}checkMeasuresForWholeRestNotes(){for(let e=0,t=this.musicSystems.length;e<t;++e){const t=this.musicSystems[e];for(let e=0,i=t.StaffLines.length;e<i;++e){const i=t.StaffLines[e];for(let e=0,t=i.Measures.length;e<t;++e){const t=i.Measures[e];if(1===t.staffEntries.length){const e=t.staffEntries[0];if(e.graphicalVoiceEntries.length>0&&1===e.graphicalVoiceEntries[0].notes.length){const i=e.graphicalVoiceEntries[0].notes[0];!i.sourceNote.Pitch&&new u(1,2).lt(i.sourceNote.Length)&&this.layoutMeasureWithWholeRest(i,e,t)}}}}}}optimizeRestNotePlacement(e,t){if(0===e.graphicalVoiceEntries.length)return;const i=e.graphicalVoiceEntries[0].notes;if(0===i.length)return;const s=i[0],n=s.sourceNote.isRest();if(2===e.graphicalVoiceEntries.length){let t=!1;const i=e.graphicalVoiceEntries[1].notes;i.length>0&&(t=i[0].sourceNote.isRest()),n&&t?this.calculateTwoRestNotesPlacementWithCollisionDetection(e):(n||t)&&this.calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(e)}else if(n&&e!==t.staffEntries[0]&&e!==t.staffEntries[t.staffEntries.length-1]){const i=t.staffEntries.indexOf(e),n=t.staffEntries[i-1],r=t.staffEntries[i+1];if(1===n.graphicalVoiceEntries.length){const t=n.graphicalVoiceEntries[0].notes[0];if(void 0!==t.sourceNote.NoteBeam&&1===r.graphicalVoiceEntries.length){const i=r.graphicalVoiceEntries[0].notes[0];void 0!==i.sourceNote.NoteBeam&&t.sourceNote.NoteBeam===i.sourceNote.NoteBeam&&(this.calculateRestNotePlacementWithinGraphicalBeam(e,s,t,r,i),e.PositionAndShape.calculateBoundingBox())}}}}getRelativePositionInStaffLineFromTimestamp(e,t,i,s,n=0,r=!1){let o,a,l=new z;const h=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length,c=this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(e),d=Math.min(Math.floor(c),h-1),f=Math.min(Math.ceil(c),h-1);if(d<0||t<0)return l;if(o=this.getFirstLeftNotNullStaffEntryFromContainer(d,t,s),a=this.getFirstRightNotNullStaffEntryFromContainer(f,t,s),o&&a){let t=o.parentMeasure.PositionAndShape.RelativePosition.x;n>0&&(t=n);let s=o.PositionAndShape.RelativePosition.x+t,h=a.PositionAndShape.RelativePosition.x+a.parentMeasure.PositionAndShape.RelativePosition.x;const c=e.RealValue>a.getAbsoluteTimestamp().RealValue;n>0?h=a.PositionAndShape.RelativePosition.x+t:r&&(o.getAbsoluteTimestamp().RealValue===e.RealValue||c)&&(s=o.PositionAndShape.RelativePosition.x+o.PositionAndShape.BorderLeft+t,h=s);let d=0;if(o!==a){const t=o.getAbsoluteTimestamp(),i=a.getAbsoluteTimestamp();d=u.minus(e,t).RealValue/u.minus(i,t).RealValue}o.parentMeasure.ParentStaffLine!==a.parentMeasure.ParentStaffLine&&(o.parentMeasure.ParentStaffLine===i?h=i.PositionAndShape.Size.width:s=i.PositionAndShape.RelativePosition.x),l=new z(s+(h-s)*d,0)}return l}getRelativeXPositionFromTimestamp(e){const t=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length,i=this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(e),s=Math.max(0,Math.min(Math.round(i),t-1)),n=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[s].getFirstNonNullStaffEntry();return n.PositionAndShape.RelativePosition.x+n.parentMeasure.PositionAndShape.RelativePosition.x}calculatePageLabels(e){this.rules.RenderSingleHorizontalStaffline&&(e.PositionAndShape.BorderRight=e.PositionAndShape.Size.width,e.PositionAndShape.calculateBoundingBox(),this.graphicalMusicSheet.ParentMusicSheet.pageWidth=e.PositionAndShape.Size.width);let t=10,i=-1;if(e.MusicSystems.length>0){const s=e.MusicSystems[0];t=s.PositionAndShape.RelativePosition.y+s.PositionAndShape.BorderTop;const n=e.MusicSystems[e.MusicSystems.length-1];i=n.PositionAndShape.RelativePosition.y+n.PositionAndShape.BorderBottom}const s=this.graphicalMusicSheet.Title;if(s&&this.rules.RenderTitle){s.PositionAndShape.Parent=e.PositionAndShape;const t=new z;t.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth/2,this.rules.RenderSingleHorizontalStaffline&&(t.x=e.PositionAndShape.BorderMarginLeft+s.PositionAndShape.Size.width),t.y=this.rules.TitleTopDistance+this.rules.SheetTitleHeight,s.PositionAndShape.RelativePosition=t,e.Labels.push(s)}if(this.graphicalMusicSheet.Subtitle&&this.rules.RenderTitle&&this.rules.RenderSubtitle){var n;const t=this.graphicalMusicSheet.Subtitle;t.PositionAndShape.Parent=e.PositionAndShape;const i=new z;i.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth/2,this.rules.RenderSingleHorizontalStaffline&&(i.x=e.PositionAndShape.BorderMarginLeft+s.PositionAndShape.Size.width+t.PositionAndShape.Size.width/2),i.y=this.rules.TitleTopDistance+this.rules.SheetTitleHeight+this.rules.SheetMinimumDistanceBetweenTitleAndSubtitle;const r=null===(n=t.TextLines)||void 0===n?void 0:n.length;r>1&&(i.y+=t.PositionAndShape.BorderBottom*(r-1)/r),t.PositionAndShape.RelativePosition=i,e.Labels.push(t)}const r=this.graphicalMusicSheet.Composer;let o;const a=this.graphicalMusicSheet.Composer&&this.rules.RenderComposer&&this.graphicalMusicSheet.Lyricist&&this.rules.RenderLyricist?2:0;if(r&&this.rules.RenderComposer){var l;r.PositionAndShape.Parent=e.PositionAndShape,r.setLabelPositionAndShapeBorders();const i=new z;i.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth-this.rules.PageRightMargin,this.rules.RenderSingleHorizontalStaffline&&(i.x=e.PositionAndShape.BorderMarginLeft+2*s.PositionAndShape.Size.width),i.y=t,i.y-=this.rules.SystemComposerDistance;const n=null===(l=r.TextLines)||void 0===l?void 0:l.length;n>1&&(i.y-=r.PositionAndShape.BorderBottom*(n-1)/n),o=i.y,i.y-=a,r.PositionAndShape.RelativePosition=i,e.Labels.push(r)}const h=this.graphicalMusicSheet.Lyricist;if(h&&this.rules.RenderLyricist){var u;h.PositionAndShape.Parent=e.PositionAndShape,h.setLabelPositionAndShapeBorders();const i=new z;i.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth-this.rules.PageRightMargin,i.y=t,i.y-=this.rules.SystemLyricistDistance,i.y+=h.PositionAndShape.BorderBottom,i.y=Math.min(i.y,null!==(u=o)&&void 0!==u?u:Number.MAX_SAFE_INTEGER),i.y+=a,h.PositionAndShape.RelativePosition=i,e.Labels.push(h)}const c=this.graphicalMusicSheet.Copyright;if(c&&this.rules.RenderCopyright){c.PositionAndShape.Parent=e.PositionAndShape,c.setLabelPositionAndShapeBorders();const t=new z;t.x=e.PositionAndShape.Size.width/2,t.y=i+this.rules.SheetCopyrightMargin,t.y-=c.PositionAndShape.BorderTop,c.PositionAndShape.RelativePosition=t,e.Labels.push(c)}}createGraphicalTies(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0;i<t.CompleteNumberOfStaves;i++)for(let s=0;s<t.VerticalSourceStaffEntryContainers.length;s++){const n=t.VerticalSourceStaffEntryContainers[s].StaffEntries[i];if(n){const t=this.graphicalMusicSheet.findGraphicalStaffEntryFromMeasureList(i,e,n);t&&(t.GraphicalTies.clear(),t.ties.clear());for(let s=0,r=n.VoiceEntries.length;s<r;++s){const r=n.VoiceEntries[s];for(let s=0,n=r.Notes.length;s<n;++s){const n=r.Notes[s];if(n.NoteTie){const s=n.NoteTie;if(n===n.NoteTie.Notes.last())continue;if(t)for(const e of t.GraphicalTies)e.Tie;this.handleTie(s,t,i,e)}}}this.setTieDirections(t)}}}}handleTie(e,t,i,s){if(!t)return;t.ties.push(e);let n,r,o,a=t;for(let l=1;l<e.Notes.length;l++)if(n=a.findTieGraphicalNoteFromNote(e.Notes[l-1]),r=this.graphicalMusicSheet.GetGraphicalFromSourceStaffEntry(e.Notes[l].ParentStaffEntry),r){if(o=r.findTieGraphicalNoteFromNote(e.Notes[l]),void 0!==n&&void 0!==o&&r){if(!n.sourceNote.PrintObject||!o.sourceNote.PrintObject)continue;const t=this.createGraphicalTie(e,a,r,n,o);a.GraphicalTies.push(t),this.staffEntriesWithGraphicalTies.indexOf(a)>=0&&this.staffEntriesWithGraphicalTies.push(a)}a=r}}setTieDirections(e){if(!e)return;const t=e.ties;if(1===t.length){const e=t[0];if(e.TieDirection===d.NotYetDefined){const t=e.Notes[0].ParentVoiceEntry.ParentVoice.VoiceId;2!==t&&6!==t||(e.TieDirection=d.Below)}}if(t.length>1){let e;for(const i of t){const t=i.Notes[0];(!e||t.Pitch.getHalfTone()>e.Pitch.getHalfTone())&&(e=t)}for(const i of t)i.TieDirection===d.NotYetDefined&&(i.Notes[0]===e?i.TieDirection=d.Above:i.TieDirection=d.Below)}}createAccidentalCalculators(){const e=[],t=this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();if(t)for(let i=0;i<t.CompleteNumberOfStaves;i++){const s=new pi;if(e.push(s),t.FirstInstructionsStaffEntries[i])for(let e=0,n=t.FirstInstructionsStaffEntries[i].Instructions.length;e<n;++e){const n=t.FirstInstructionsStaffEntries[i].Instructions[e];if(n instanceof Z){const e=n;s.ActiveKeyInstruction=e}}}return e}calculateVerticalContainersList(){const e=this.graphicalMusicSheet.MeasureList[0].length;for(let t=0;t<this.graphicalMusicSheet.MeasureList.length;t++)for(let i=0;i<e;i++){const e=this.graphicalMusicSheet.MeasureList[t][i];if(e)for(let t=0,s=e.staffEntries.length;t<s;++t){const s=e.staffEntries[t],n=this.graphicalMusicSheet.getOrCreateVerticalContainer(s.getAbsoluteTimestamp());n&&(n.StaffEntries[i]=s,s.parentVerticalContainer=n)}}}setIndicesToVerticalGraphicalContainers(){for(let e=0;e<this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;e++)this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e].Index=e}createGraphicalMeasuresForSourceMeasure(e,t,i,s,n){this.initGraphicalMeasuresCreation();const r=[],o=[],a=[],l=[];let h=!0;for(let u=0;u<e.CompleteNumberOfStaves;u++){const c=this.createGraphicalMeasure(e,a,o,t[u],n,s,i,u,l);h=h&&c.hasOnlyRests,r.push(c)}return e.allRests=h,e.VerticalMeasureList=r,r}createGraphicalMeasure(e,t,i,s,n,r,o,a,l){const h=this.graphicalMusicSheet.ParentMusicSheet.getStaffFromIndex(a);let c;if(n[a].ClefType===q.TAB)h.isTab=!0,c=yi.symbolFactory.createTabStaffMeasure(e,h);else if(e.multipleRestMeasures&&this.rules.RenderMultipleRestMeasures)c=yi.symbolFactory.createMultiRestMeasure(e,h);else{if(e.multipleRestMeasureNumber>1)return;c=yi.symbolFactory.createGraphicalMeasure(e,h)}if(c.hasError=e.getErrorInMeasure(a),e.FirstInstructionsStaffEntries[a])for(let u=0,y=e.FirstInstructionsStaffEntries[a].Instructions.length;u<y;++u){const t=e.FirstInstructionsStaffEntries[a].Instructions[u];if(t instanceof Z){const e=Z.copy(t),i=c.getTransposedHalftones();0!==i&&c.ParentStaff.ParentInstrument.MidiInstrumentId!==$.Percussion&&yi.transposeCalculator&&yi.transposeCalculator.transposeKey(e,i),s.ActiveKeyInstruction=e}}const d=[];for(let y=0,b=e.StaffLinkedExpressions[a].length;y<b;++y){const t=e.StaffLinkedExpressions[a][y];let i;if(t.OctaveShiftStart?i=t.OctaveShiftStart:t.OctaveShiftEnd&&(i=t.OctaveShiftEnd),i){var f;d.push(t);const s=i;let n=null==s||null===(f=s.ParentEndMultiExpression)||void 0===f?void 0:f.AbsoluteTimestamp;null!=s&&s.ParentEndMultiExpression||(n=u.plus(e.AbsoluteTimestamp,e.Duration)),r[a]=new mi(s,s.ParentStartMultiExpression.AbsoluteTimestamp,n)}}for(let u=0;u<e.VerticalSourceStaffEntryContainers.length;u++){const h=e.VerticalSourceStaffEntryContainers[u].StaffEntries[a];if(h){var m;for(let t=0,i=h.Instructions.length;t<i;++t){const e=h.Instructions[t];e instanceof J&&(n[a]=e)}const e=yi.symbolFactory.createStaffEntry(h,c);u<c.staffEntries.length?c.addGraphicalStaffEntryAtTimestamp(e):c.addGraphicalStaffEntry(e);const f=[];h.Link&&(h.findLinkedNotes(f),this.handleStaffEntryLink(e,l));let y=$t.NONE;if(r[a]&&r[a].getAbsoluteStartTimestamp.lte(h.AbsoluteTimestamp)&&h.AbsoluteTimestamp.lte(r[a].getAbsoluteEndTimestamp)&&(y=r[a].getOpenOctaveShift.Type),y===$t.NONE)for(const t of d){var p,g,S;let e;if(t.OctaveShiftStart?e=t.OctaveShiftStart:t.OctaveShiftEnd&&(e=t.OctaveShiftEnd),null!==(p=e)&&void 0!==p&&null!==(g=p.ParentStartMultiExpression)&&void 0!==g&&g.AbsoluteTimestamp.lte(h.AbsoluteTimestamp)&&(null===(S=e.ParentEndMultiExpression)||void 0===S||!S.AbsoluteTimestamp.lt(h.AbsoluteTimestamp))){y=e.Type;break}}for(let r=0,l=h.VoiceEntries.length;r<l;++r){const l=h.VoiceEntries[r];y=this.handleVoiceEntry(l,e,s,o,n[a],t,i,y,a,f,h)}if(h.Instructions.length>0){const t=h.Instructions[0];yi.symbolFactory.createInStaffClef(e,t)}this.rules.RenderChordSymbols&&(null===(m=h.ChordContainers)||void 0===m?void 0:m.length)>0&&(h.ParentStaff.ParentInstrument.HasChordSymbols=!0,yi.symbolFactory.createChordSymbols(h,e,s.ActiveKeyInstruction,this.graphicalMusicSheet.ParentMusicSheet.Transpose))}}if(s.doCalculationsAtEndOfMeasure(),e.LastInstructionsStaffEntries[a]){const t=e.LastInstructionsStaffEntries[a];for(let e=0,i=t.Instructions.length;e<i;++e){const i=t.Instructions[e];i instanceof J&&(n[a]=i)}}for(let u=0,y=e.StaffLinkedExpressions[a].length;u<y;++u){const t=e.StaffLinkedExpressions[a][u];void 0!==t.OctaveShiftEnd&&void 0!==r[a]&&t.OctaveShiftEnd===r[a].getOpenOctaveShift&&(r[a]=void 0)}for(const u of c.staffEntries)for(const e of u.graphicalVoiceEntries)this.setBeamNotesWantedStemDirections(e.parentVoiceEntry);if(this.rules.FillEmptyMeasuresWithWholeRest>=1&&0===c.staffEntries.length){const t=new Je(new Ke(c.parentSourceMeasure,c.parentSourceMeasure.AbsoluteTimestamp,c.parentSourceMeasure.CompleteNumberOfStaves),h);if(0===h.Voices.length){const e=new _e(c.ParentStaff.ParentInstrument,-1);h.Voices.push(e)}const i=new ut(new u(0,1),h.Voices[0],t);let s=e.Duration;0===s.RealValue&&(s=e.ActiveTimeSignature.clone());const n=new Ae(i,t,s,void 0,e,!0);n.IsWholeMeasureRest=!0,n.PrintObject=this.rules.FillEmptyMeasuresWithWholeRest===C.YesVisible,i.addNote(n);const r=yi.symbolFactory.createStaffEntry(t,c);c.addGraphicalStaffEntry(r),r.relInMeasureTimestamp=i.Timestamp;const o=yi.symbolFactory.createVoiceEntry(i,r);r.graphicalVoiceEntries.push(o);const a=yi.symbolFactory.createNote(n,o,new J,$t.NONE,this.rules);yi.stafflineNoteCalculator.trackNote(a),o.notes.push(a)}c.hasOnlyRests=!0;for(const u of c.staffEntries)if(c.hasOnlyRests=u.hasOnlyRests(),!c.hasOnlyRests)break;return c}checkNoteForAccidental(e,t,i,s){let n=e.sourceNote.Pitch;const r=e.parentVoiceEntry.parentStaffEntry.parentMeasure.getTransposedHalftones();0!==r&&e.sourceNote.ParentStaffEntry.ParentStaff.ParentInstrument.MidiInstrumentId!==$.Percussion&&(n=e.Transpose(t.ActiveKeyInstruction,i,r,s),e.sourceNote.TransposedPitch=n),e.sourceNote.halfTone=n.getHalfTone(),t.checkAccidental(e,n)}handleStaffEntries(e){for(let t=0,i=this.graphicalMusicSheet.MeasureList.length;t<i;++t){const i=this.graphicalMusicSheet.MeasureList[t];for(let t=0,s=i.length;t<s;++t){const s=i[t];if(s){if(this.rules.PercussionOneLineCutoff>0&&!this.rules.PercussionUseCajon2NoteSystem&&e[t]&&(-1===this.rules.PercussionOneLineCutoff||yi.stafflineNoteCalculator.getStafflineUniquePositionCount(t)<this.rules.PercussionOneLineCutoff)){const e=s.ParentStaff.ParentInstrument.Name.trim().toLocaleLowerCase()||s.ParentStaff.ParentInstrument.NameLabel.text.trim().toLocaleLowerCase();this.specialTrackNames.includes(e)?s.ParentStaff.StafflineCount=5:s.ParentStaff.StafflineCount=1}for(const e of s.staffEntries)void 0!==e.parentMeasure&&e.graphicalVoiceEntries.length>0&&e.graphicalVoiceEntries[0].notes.length>0&&(this.layoutVoiceEntries(e,t),this.layoutStaffEntry(e));this.graphicalMeasureCreatedCalculations(s)}}}}calculateSkyBottomLines(){for(const e of this.musicSystems)for(const t of e.StaffLines)t.SkyBottomLineCalculator.calculateLines()}calculateExpressionAlignements(){}calculateStaffEntryArticulationMarks(){for(let e=0,t=this.musicSystems.length;e<t;++e){const t=this.musicSystems[e];for(let e=0,i=t.StaffLines.length;e<i;++e){const i=t.StaffLines[e];for(let e=0,t=i.Measures.length;e<t;++e){const t=i.Measures[e];for(let e=0,i=t.staffEntries.length;e<i;++e){const i=t.staffEntries[e];for(let e=0,t=i.sourceStaffEntry.VoiceEntries.length;e<t;++e){const t=i.sourceStaffEntry.VoiceEntries[e];t.Articulations.length>0&&this.layoutArticulationMarks(t.Articulations,t,i)}}}}}}calculateOrnaments(){for(let e=0,t=this.musicSystems.length;e<t;++e){const t=this.musicSystems[e];for(let e=0,i=t.StaffLines.length;e<i;++e){const i=t.StaffLines[e];for(let e=0,t=i.Measures.length;e<t;++e){const t=i.Measures[e];for(let e=0,i=t.staffEntries.length;e<i;++e){const i=t.staffEntries[e];for(let e=0,t=i.sourceStaffEntry.VoiceEntries.length;e<t;++e){const t=i.sourceStaffEntry.VoiceEntries[e];if(t.OrnamentContainer){if(t.hasTie()&&!i.relInMeasureTimestamp.Equals(t.Timestamp))continue;this.layoutOrnament(t.OrnamentContainer,t,i),-1===this.staffEntriesWithOrnaments.indexOf(i)&&this.staffEntriesWithOrnaments.push(i)}}}}}}}getFingeringPlacement(e){let t=this.rules.FingeringPosition;return t!==d.NotYetDefined&&t!==d.AboveOrBelow||(t=e.isUpperStaffOfInstrument()?d.Above:d.Below),t}calculateFingerings(){if(this.rules.FingeringPosition!==d.Left&&this.rules.FingeringPosition!==d.Right)for(const e of this.musicSystems)for(const t of e.StaffLines)for(const e of t.Measures){if(e.isTabMeasure&&!this.rules.TabFingeringsRendered)continue;const i=this.getFingeringPlacement(e);for(const s of e.staffEntries){s.FingeringEntries=[];const n=t.SkyBottomLineCalculator,r=s.PositionAndShape.RelativePosition.x+e.PositionAndShape.RelativePosition.x,o=[];for(const e of s.graphicalVoiceEntries)if(!e.parentVoiceEntry.IsGrace)for(const t of e.parentVoiceEntry.TechnicalInstructions)t.type===ot.Fingering&&o.push(t);i===d.Below&&o.reverse();for(let e=0;e<o.length;e++){const a=o[e],l=i===d.Above?ce.CenterBottom:ce.CenterTop,h=new pt(a.value,l),u=new mt(h,this.rules.FingeringTextSize,h.textAlignment,this.rules,t.PositionAndShape),c=r+u.PositionAndShape.BorderMarginLeft,f=r+u.PositionAndShape.BorderMarginRight;let m;m=i===d.Above?n.getSkyLineMinInRange(c,f):n.getBottomLineMaxInRange(c,f);let p=0;0===e?(p+=this.rules.FingeringOffsetY,i===d.Above&&(p+=.1)):p+=this.rules.FingeringPaddingY,i===d.Above&&(p*=-1),u.PositionAndShape.RelativePosition.y+=m+p,u.PositionAndShape.RelativePosition.x=r,u.setLabelPositionAndShapeBorders(),u.PositionAndShape.calculateBoundingBox(),s.FingeringEntries.push(u);const g=u.PositionAndShape.RelativePosition.x+u.PositionAndShape.BorderLeft,S=g-u.PositionAndShape.BorderLeft+u.PositionAndShape.BorderRight;i===d.Above?n.updateSkyLineInRange(g,S,u.PositionAndShape.RelativePosition.y+u.PositionAndShape.BorderTop):i===d.Below&&n.updateBottomLineInRange(g,S,u.PositionAndShape.RelativePosition.y+u.PositionAndShape.BorderBottom)}}}}optimizeRestPlacement(){for(let e=0,t=this.musicSystems.length;e<t;++e){const t=this.musicSystems[e];for(let e=0,i=t.StaffLines.length;e<i;++e){const i=t.StaffLines[e];for(let e=0,t=i.Measures.length;e<t;++e){const t=i.Measures[e];for(let e=0,i=t.staffEntries.length;e<i;++e){const i=t.staffEntries[e];this.optimizeRestNotePlacement(i,t)}}}}}calculateTwoRestNotesPlacementWithCollisionDetection(e){const t=e.graphicalVoiceEntries[0].notes[0],i=e.graphicalVoiceEntries[1].notes[0];i.PositionAndShape.RelativePosition=new z(0,2.5),e.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement(),t.PositionAndShape.computeNonOverlappingPositionWithMargin(e.PositionAndShape,ae.Up,new z(0,i.PositionAndShape.RelativePosition.y));const s=t.PositionAndShape.RelativePosition;s.y-=1,t.PositionAndShape.RelativePosition=s,e.PositionAndShape.calculateBoundingBox()}calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(e){let t,i;e.graphicalVoiceEntries[0].notes[0].sourceNote.isRest()?(t=e.graphicalVoiceEntries[0].notes[0],i=e.graphicalVoiceEntries[1].notes):(i=e.graphicalVoiceEntries[0].notes,t=e.graphicalVoiceEntries[1].notes[0]);let s=!1;e.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement();for(let n=0,r=i.length;n<r;++n){const e=i[n];if(t.PositionAndShape.marginCollisionDetection(e.PositionAndShape)){s=!0;break}}if(s)if(t.sourceNote.ParentVoiceEntry.ParentVoice instanceof Ge){const e=i[0].PositionAndShape.BorderMarginBottom+i[0].PositionAndShape.RelativePosition.y;t.PositionAndShape.RelativePosition=new z(0,e-t.PositionAndShape.BorderMarginTop+.5)}else{const e=i[i.length-1],s=e.PositionAndShape.BorderMarginTop+e.PositionAndShape.RelativePosition.y;if(i[0].sourceNote.ParentVoiceEntry.ParentVoice instanceof Ge)t.PositionAndShape.RelativePosition=new z(0,s-t.PositionAndShape.BorderMarginBottom-.5);else{const e=i[0].PositionAndShape.BorderMarginBottom+i[0].PositionAndShape.RelativePosition.y;t.PositionAndShape.RelativePosition=new z(0,e<2?e-t.PositionAndShape.BorderMarginTop+.5:s-t.PositionAndShape.BorderMarginBottom-0)}}e.PositionAndShape.calculateBoundingBox()}calculateTieCurves(){for(const e of this.musicSystems)for(const t of e.StaffLines)for(const e of t.Measures)for(const t of e.staffEntries)for(const i of t.GraphicalTies)if(void 0!==i.StartNote&&i.StartNote.parentVoiceEntry.parentStaffEntry===t){const t=i.StartNote.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentStaffLine!==i.EndNote.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentStaffLine;this.layoutGraphicalTie(i,t,e.ParentStaff.isTab)}}calculateLyricsPosition(){const e=new i;for(let t=0,i=this.graphicalMusicSheet.ParentMusicSheet.Instruments.length;t<i;++t){const e=this.graphicalMusicSheet.ParentMusicSheet.Instruments[t];e.HasLyrics&&e.LyricVersesNumbers.length>0&&e.LyricVersesNumbers.sort()}for(let t=0,i=this.musicSystems.length;t<i;++t){const i=this.musicSystems[t];for(let t=0,s=i.StaffLines.length;t<s;++t){const s=i.StaffLines[t],n=this.calculateSingleStaffLineLyricsPosition(s,s.ParentStaff.ParentInstrument.LyricVersesNumbers);e.setValue(s,n),this.calculateLyricsExtendsAndDashes(e.getValue(s))}}for(let t=0,i=this.musicSystems.length;t<i;++t){const i=this.musicSystems[t];for(let t=0,s=i.StaffLines.length;t<s;++t){const s=i.StaffLines[t];this.calculateLyricsExtendsAndDashes(e.getValue(s))}}}calculateSingleLyricWord(e){const t=e.ParentLyricWord,i=t.GraphicalLyricsEntries.indexOf(e);let s;if(i>=0&&(s=t.GraphicalLyricsEntries[i+1]),!s)return;const n=e.StaffEntryParent.parentMeasure.ParentStaffLine,r=s.StaffEntryParent.parentMeasure.ParentStaffLine,o=e.StaffEntryParent,a=s.StaffEntryParent;if(e.StaffEntryParent.parentMeasure.ParentStaffLine===s.StaffEntryParent.parentMeasure.ParentStaffLine){const t=o.parentMeasure.PositionAndShape.RelativePosition.x+o.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.BorderMarginRight-e.GraphicalLabel.CenteringXShift,i=a.parentMeasure.PositionAndShape.RelativePosition.x+a.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.RelativePosition.x+s.GraphicalLabel.PositionAndShape.BorderMarginLeft,r=e.GraphicalLabel.PositionAndShape.RelativePosition.y;let l=1;i-t>3*this.rules.MinimumDistanceBetweenDashes&&(l=Math.floor((i-t)/this.rules.MinimumDistanceBetweenDashes)-1),1===l?this.calculateSingleDashForLyricWord(n,t,i,r):this.calculateDashes(n,t,i,r)}else{const t=o.parentMeasure.PositionAndShape.RelativePosition.x+o.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.BorderMarginRight,i=n.Measures[n.Measures.length-1],l=i.PositionAndShape.RelativePosition.x+i.PositionAndShape.Size.width;let h=e.GraphicalLabel.PositionAndShape.RelativePosition.y;if(this.calculateDashes(n,t,l,h),r&&r.Measures[0]&&a.parentMeasure.ParentStaffLine&&(a!==a.parentMeasure.staffEntries[0]||a.parentMeasure!==a.parentMeasure.ParentStaffLine.Measures[0])){const e=r.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x,t=a.parentMeasure.PositionAndShape.RelativePosition.x+a.PositionAndShape.RelativePosition.x+s.GraphicalLabel.PositionAndShape.BorderMarginLeft;h=s.GraphicalLabel.PositionAndShape.RelativePosition.y,this.calculateDashes(r,e,t,h)}}}calculateDashes(e,t,i,s){let n=i-t;if(n<3*this.rules.MinimumDistanceBetweenDashes)this.calculateSingleDashForLyricWord(e,t,i,s);else{const r=Math.floor(n/this.rules.MinimumDistanceBetweenDashes)-1,o=n/(r+1);let a=0;for(t+=o,i-=o;a<=Math.floor(r/2)&&i>t;)n=this.calculateRightAndLeftDashesForLyricWord(e,t,i,s),t+=o,i-=o,a++;n>2*o&&this.calculateSingleDashForLyricWord(e,t,i,s)}}calculateSingleDashForLyricWord(e,t,i,s){const n=new pt("-");n.colorDefault=this.rules.DefaultColorLyrics;let r=this.rules.LyricsHeight;i-t<.8&&(r*=.8,s-=.1*r);const o=new mt(n,r,ce.CenterBottom,this.rules);o.setLabelPositionAndShapeBorders(),e.LyricsDashes.push(o),-1===this.staffLinesWithLyricWords.indexOf(e)&&this.staffLinesWithLyricWords.push(e),o.PositionAndShape.Parent=e.PositionAndShape;const a=new z(t+(i-t)/2,s);o.PositionAndShape.RelativePosition=a}calculateLyricExtend(e){let t=e.GraphicalLabel.PositionAndShape.RelativePosition.y;const i=e.StaffEntryParent,s=i.parentMeasure.ParentStaffLine;let n,r;const o=i.parentMeasure.ParentStaff.idInMusicSheet;for(let a=i.parentVerticalContainer.Index+1;a<this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;++a){const e=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[a].StaffEntries[o];if(e){if(e.hasOnlyRests())break;if(e.LyricsEntries.length>0)break;n=e,r=n.parentMeasure.ParentStaffLine,r||(r=i.parentMeasure.ParentStaffLine)}}if(n&&r)if(s===r&&n.parentMeasure.ParentStaffLine){const r=i.parentMeasure.PositionAndShape.RelativePosition.x+i.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.BorderMarginRight,o=n.parentMeasure.PositionAndShape.RelativePosition.x+n.PositionAndShape.RelativePosition.x+n.PositionAndShape.BorderMarginRight;t-=e.GraphicalLabel.PositionAndShape.Size.height/4,this.calculateSingleLyricWordWithUnderscore(s,r,o,t)}else{const o=s.Measures[s.Measures.length-1].PositionAndShape,a=i.parentMeasure.PositionAndShape.RelativePosition.x+i.PositionAndShape.RelativePosition.x+e.GraphicalLabel.PositionAndShape.BorderMarginRight,l=o.RelativePosition.x+o.Size.width;if(t-=e.GraphicalLabel.PositionAndShape.Size.height/4,this.calculateSingleLyricWordWithUnderscore(s,a,l,t),!n)return;if(n.parentMeasure.ParentStaffLine&&n.parentMeasure.staffEntries&&(n!==n.parentMeasure.staffEntries[0]||n.parentMeasure!==n.parentMeasure.ParentStaffLine.Measures[0])){const e=r.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x,i=n.parentMeasure.PositionAndShape.RelativePosition.x+n.PositionAndShape.RelativePosition.x+n.PositionAndShape.BorderMarginRight;this.calculateSingleLyricWordWithUnderscore(r,e,i,t)}}}calculateSingleLyricWordWithUnderscore(e,t,i,s){const n=new z(t,s),r=new z(i,s),o=new X(n,r,this.rules.LyricUnderscoreLineWidth);o.colorHex=this.rules.DefaultColorLyrics,e.LyricLines.push(o),-1===this.staffLinesWithLyricWords.indexOf(e)&&this.staffLinesWithLyricWords.push(e)}calculateRightAndLeftDashesForLyricWord(e,t,i,s){const n=new pt("-");n.colorDefault=this.rules.DefaultColorLyrics;const r=new mt(n,this.rules.LyricsHeight,ce.CenterBottom,this.rules);r.setLabelPositionAndShapeBorders(),e.LyricsDashes.push(r),-1===this.staffLinesWithLyricWords.indexOf(e)&&this.staffLinesWithLyricWords.push(e),r.PositionAndShape.Parent=e.PositionAndShape;const o=new z(t,s);r.PositionAndShape.RelativePosition=o;const a=new pt("-"),l=new mt(a,this.rules.LyricsHeight,ce.CenterBottom,this.rules);l.setLabelPositionAndShapeBorders(),e.LyricsDashes.push(l),l.PositionAndShape.Parent=e.PositionAndShape;const h=new z(i,s);return l.PositionAndShape.RelativePosition=h,l.PositionAndShape.RelativePosition.x-r.PositionAndShape.RelativePosition.x}calculateDynamicExpressions(){const e=Math.min(this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length-1,this.rules.MaxMeasureToDrawIndex);for(let t=Math.min(this.rules.MinMeasureToDrawIndex,this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length);t<=e;t++){const e=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[t];this.dynamicExpressionMap.clear();for(let i=0;i<e.StaffLinkedExpressions.length;i++)if(this.graphicalMusicSheet.MeasureList[t]&&this.graphicalMusicSheet.MeasureList[t][i]&&this.graphicalMusicSheet.MeasureList[t][i].ParentStaff.ParentInstrument.Visible)for(let s=0;s<e.StaffLinkedExpressions[i].length;s++)(void 0!==e.StaffLinkedExpressions[i][s].InstantaneousDynamic||void 0!==e.StaffLinkedExpressions[i][s].StartingContinuousDynamic&&e.StaffLinkedExpressions[i][s].StartingContinuousDynamic.StartMultiExpression===e.StaffLinkedExpressions[i][s]&&0===e.StaffLinkedExpressions[i][s].UnknownList.length)&&this.calculateDynamicExpressionsForMultiExpression(e.StaffLinkedExpressions[i][s],t,i)}this.dynamicExpressionMap.clear()}calculateOctaveShifts(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0;i<t.StaffLinkedExpressions.length;i++)if(this.graphicalMusicSheet.MeasureList[e]&&this.graphicalMusicSheet.MeasureList[e][i]&&this.graphicalMusicSheet.MeasureList[e][i].ParentStaff.ParentInstrument.Visible)for(let s=0;s<t.StaffLinkedExpressions[i].length;s++)t.StaffLinkedExpressions[i][s].OctaveShiftStart&&this.calculateSingleOctaveShift(t,t.StaffLinkedExpressions[i][s],e,i)}}calculatePedals(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0;i<t.StaffLinkedExpressions.length;i++)if(this.graphicalMusicSheet.MeasureList[e]&&this.graphicalMusicSheet.MeasureList[e][i]&&this.graphicalMusicSheet.MeasureList[e][i].ParentStaff.ParentInstrument.Visible)for(let s=0;s<t.StaffLinkedExpressions[i].length;s++)t.StaffLinkedExpressions[i][s].PedalStart&&this.calculateSinglePedal(t,t.StaffLinkedExpressions[i][s],e,i)}}calculateWavyLines(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0;i<t.StaffLinkedExpressions.length;i++)if(this.graphicalMusicSheet.MeasureList[e]&&this.graphicalMusicSheet.MeasureList[e][i]&&this.graphicalMusicSheet.MeasureList[e][i].ParentStaff.ParentInstrument.Visible)for(let s=0;s<t.StaffLinkedExpressions[i].length;s++)t.StaffLinkedExpressions[i][s].WavyLineStart&&this.calculateSingleWavyLine(t,t.StaffLinkedExpressions[i][s],e,i)}}getFirstLeftNotNullStaffEntryFromContainer(e,t,i){var s;if(null!==(s=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e])&&void 0!==s&&s.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e].StaffEntries[t];for(let r=e-1;r>=0;r--){var n;if(null!==(n=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r])&&void 0!==n&&n.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r].StaffEntries[t]}}getFirstRightNotNullStaffEntryFromContainer(e,t,i){var s;if(null!==(s=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e])&&void 0!==s&&s.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e].StaffEntries[t];for(let r=e+1;r<this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;r++){var n;if(null!==(n=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r])&&void 0!==n&&n.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r].StaffEntries[t]}}calculateWordRepetitionInstructions(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0,s=t.FirstRepetitionInstructions.length;i<s;++i){const s=t.FirstRepetitionInstructions[i];this.calculateWordRepetitionInstruction(s,e)}for(let i=0,s=t.LastRepetitionInstructions.length;i<s;++i){const s=t.LastRepetitionInstructions[i];this.calculateWordRepetitionInstruction(s,e)}}}calculateRepetitionEndings(){const e=this.graphicalMusicSheet.ParentMusicSheet;for(let t=0,i=e.Repetitions.length;t<i;++t){const i=e.Repetitions[t];this.calcGraphicalRepetitionEndingsRecursively(i)}}calculateTempoExpressions(){const e=Math.min(this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length-1,this.rules.MaxMeasureToDrawIndex);for(let t=this.rules.MinMeasureToDrawIndex;t<=e;t++){const e=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[t];for(let i=0;i<e.TempoExpressions.length;i++)this.calculateTempoExpressionsForMultiTempoExpression(e,e.TempoExpressions[i],t,i)}}calculateRehearsalMarks(){if(this.rules.RenderRehearsalMarks)for(const e of this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures)this.calculateRehearsalMark(e)}calculateRehearsalMark(e){throw new Error(this.abstractNotImplementedErrorMessage)}calculateMoodAndUnknownExpressions(){for(let e=0;e<this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length;e++){const t=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e];for(let i=0;i<t.StaffLinkedExpressions.length;i++)if(this.graphicalMusicSheet.MeasureList[e]&&this.graphicalMusicSheet.MeasureList[e][i]&&this.graphicalMusicSheet.MeasureList[e][i].ParentStaff.ParentInstrument.Visible)for(let s=0;s<t.StaffLinkedExpressions[i].length;s++)(t.StaffLinkedExpressions[i][s].MoodList.length>0||t.StaffLinkedExpressions[i][s].UnknownList.length>0)&&this.calculateMoodAndUnknownExpression(t.StaffLinkedExpressions[i][s],e,i)}}calculateStemDirectionFromVoices(e){if(void 0!==e.ParentSourceStaffEntry.Link)return e===e.ParentSourceStaffEntry.VoiceEntries[0]?void(e.WantedStemDirection=dt.Up):void(e.WantedStemDirection=dt.Down);e.ParentVoice instanceof Ge?e.WantedStemDirection=dt.Down:e.ParentSourceStaffEntry.VoiceEntries.length>1&&(e.WantedStemDirection=dt.Up)}setBeamNotesWantedStemDirections(e){if(!(e.Notes.length>0))return;const t=e.Notes[0].NoteBeam;if(t)for(const i of t.Notes)if(i.ParentVoiceEntry.WantedStemDirection!==dt.Undefined&&i.ParentVoiceEntry.ParentSourceStaffEntry.ParentStaff.Id===e.ParentSourceStaffEntry.ParentStaff.Id){e.WantedStemDirection=i.ParentVoiceEntry.WantedStemDirection;break}}}class bi{constructor(e,t,i){this.instrumentalGroups=[],this.name=e,this.musicSheet=t,this.parent=i}get InstrumentalGroups(){return this.instrumentalGroups}get Parent(){return this.parent}get Name(){return this.name}set Name(e){this.name=e}get GetMusicSheet(){return this.musicSheet}}class Mi extends bi{constructor(e,t,i,s){super(void 0,i,s),this.Transpose=0,this.voices=[],this.staves=[],this.hasLyrics=!1,this.hasChordSymbols=!1,this.playbackTranspose=0,this.lyricVersesNumbers=[],this.subInstruments=[],this.id=e,this.idString=t,this.nameLabel=new pt(t)}get Voices(){return this.voices}get Staves(){return this.staves}get NameLabel(){return this.nameLabel}get HasLyrics(){return this.hasLyrics}set HasLyrics(e){this.hasLyrics=e}get HasChordSymbols(){return this.hasChordSymbols}set HasChordSymbols(e){this.hasChordSymbols=e}get LyricVersesNumbers(){return this.lyricVersesNumbers}set LyricVersesNumbers(e){this.lyricVersesNumbers=e}get Name(){return this.nameLabel.text}set Name(e){this.nameLabel.text=e}get IdString(){return this.idString}get Id(){return this.id}get MidiInstrumentId(){return this.subInstruments[0].midiInstrumentID}set MidiInstrumentId(e){this.subInstruments[0].midiInstrumentID=e}get Volume(){return this.subInstruments[0].volume}set Volume(e){for(let t=0,i=this.subInstruments.length;t<i;++t)this.subInstruments[t].volume=e}get PlaybackTranspose(){return this.playbackTranspose}set PlaybackTranspose(e){this.playbackTranspose=e}get SubInstruments(){return this.subInstruments}getSubInstrument(e){for(let t=0,i=this.subInstruments.length;t<i;++t){const i=this.subInstruments[t];if(i.idString===e)return i}}get PartAbbreviation(){return this.partAbbreviation}set PartAbbreviation(e){this.partAbbreviation=e}get Visible(){return this.voices.length>0&&this.Voices[0].Visible}set Visible(e){for(let t=0,i=this.Voices.length;t<i;++t)this.Voices[t].Visible=e}get Audible(){let e=!1;for(let t=0,i=this.Voices.length;t<i;++t){const i=this.Voices[t];e=e||i.Audible}return e}set Audible(e){for(let t=0,i=this.Voices.length;t<i;++t)this.Voices[t].Audible=e;for(let t=0,i=this.staves.length;t<i;++t)this.staves[t].audible=e}get Solo(){let e=!1;for(let t=0,i=this.Voices.length;t<i;++t){const i=this.Voices[t];e=e||i.Solo}return e}set Solo(e){for(let t=0,i=this.Voices.length;t<i;++t)this.Voices[t].Solo=e;for(let t=0,i=this.Staves.length;t<i;++t)this.Staves[t].Solo=e}get Following(){let e=!1;for(let t=0,i=this.Voices.length;t<i;++t){const i=this.Voices[t];e=e||i.Following}return e}set Following(e){for(let t=0,i=this.Voices.length;t<i;++t)this.Voices[t].Following=e;for(let t=0,i=this.staves.length;t<i;++t)this.staves[t].following=e}SetVoiceAudible(e,t){for(let i=0,s=this.Voices.length;i<s;++i){const s=this.Voices[i];if(s.VoiceId===e){s.Audible=t;break}}}SetVoiceFollowing(e,t){for(let i=0,s=this.Voices.length;i<s;++i){const s=this.Voices[i];if(s.VoiceId===e){s.Following=t;break}}}SetStaffAudible(e,t){const i=this.staves[e-1];if(i.audible=t,t)for(let s=0,n=i.Voices.length;s<n;++s)i.Voices[s].Audible=!0;else for(let s=0,n=i.Voices.length;s<n;++s){const t=i.Voices[s];let n=!1;for(let i=0,s=this.Staves.length;i<s;++i){const s=this.Staves[i];if(s.Id!==e&&s.audible)for(let e=0,i=s.Voices.length;e<i;++e)s.Voices[e]===t&&(n=!0)}n||(t.Audible=!1)}}SetStaffFollow(e,t){const i=this.staves[e-1];if(i.following=t,t)for(let s=0,n=i.Voices.length;s<n;++s)i.Voices[s].Following=!0;else for(let s=0,n=i.Voices.length;s<n;++s){const t=i.Voices[s];let n=!1;for(let i=0,s=this.Staves.length;i<s;++i){const s=this.Staves[i];if(s.Id!==e&&s.following)for(let e=0,i=s.Voices.length;e<i;++e)s.Voices[e]===t&&(n=!0)}n||(t.Following=!1)}}areAllVoiceVisible(){for(const e of this.Voices)if(!e.Visible)return!1;return!0}createStaves(e){for(let t=0;t<e;t++)this.staves.push(new it(this,t+1))}toString(){return`${this.Name} , id: ${this.id}, idstring: ${this.idString}`}}class vi extends ne{constructor(e){super(),this.needsToBeRedrawn=!0,this.staffLines=[],this.graphicalMeasures=[],this.labels=new o,this.measureNumberLabels=[],this.objectsToRedraw=[],this.instrumentBrackets=[],this.groupBrackets=[],this.graphicalMarkedAreas=[],this.systemLines=[],this.breaksPage=!1,this.id=e,this.boundingBox=new oe(this),this.maxLabelLength=0}get Parent(){return this.parent}set Parent(e){if(this.parent){const e=this.parent.MusicSystems.indexOf(this,0);e>-1&&this.parent.MusicSystems.splice(e,1)}this.parent=e,this.boundingBox.Parent=e.PositionAndShape}get NextSystem(){const e=this.Parent.MusicSystems.indexOf(this);return e!==this.Parent.MusicSystems.length?this.Parent.MusicSystems[e+1]:void 0}get StaffLines(){return this.staffLines}get GraphicalMeasures(){return this.graphicalMeasures}get MeasureNumberLabels(){return this.measureNumberLabels}get Labels(){return this.labels.values()}get ObjectsToRedraw(){return this.objectsToRedraw}get InstrumentBrackets(){return this.instrumentBrackets}get GroupBrackets(){return this.groupBrackets}get GraphicalMarkedAreas(){return this.graphicalMarkedAreas}get SystemLines(){return this.systemLines}get Id(){return this.id}createSystemLeftLine(e,t,i){let s=-e/2;i&&(s=this.maxLabelLength+t-e/2);const n=this.staffLines[0].Measures[0];let r;this.staffLines.length>1&&(r=this.staffLines[this.staffLines.length-1].Measures[0]);const o=this.createSystemLine(s,e,Ne.SingleThin,ft.MeasureBegin,this,n,r);this.SystemLines.push(o),o.PositionAndShape.RelativePosition=new z(s,0),o.PositionAndShape.BorderLeft=0,o.PositionAndShape.BorderRight=e,o.PositionAndShape.BorderTop=o.PositionAndShape.Parent.BorderTop,o.PositionAndShape.BorderBottom=o.PositionAndShape.Parent.BorderBottom,this.createLinesForSystemLine(o)}createVerticalLineForMeasure(e,t,i,s,n,r){const o=r.ParentStaffLine,a=new z(o.PositionAndShape.RelativePosition.x,o.PositionAndShape.RelativePosition.y),l=o.ParentStaff.ParentInstrument.Staves;if(o.ParentStaff===l[0]){let h;l.length>1&&(h=this.getBottomStaffLine(o).Measures[n]);const u=this.createSystemLine(e,t,i,s,this,r,h),c=a.x+e;u.PositionAndShape.RelativePosition=new z(c,0),u.PositionAndShape.BorderLeft=0,u.PositionAndShape.BorderRight=t,this.SystemLines.push(u)}}setYPositionsToVerticalLineObjectsAndCreateLines(e){}calculateBorders(e){}alignBeginInstructions(){}GetLeftBorderAbsoluteXPosition(){return this.StaffLines[0].PositionAndShape.AbsolutePosition.x+this.StaffLines[0].Measures[0].beginInstructionsWidth}GetRightBorderAbsoluteXPosition(){return this.StaffLines[0].PositionAndShape.AbsolutePosition.x+this.StaffLines[0].StaffLines[0].End.x}AddGraphicalMeasures(e){for(let t=0,i=e.length;t<i;++t)e[t].ParentMusicSystem=this;this.graphicalMeasures.push(e)}GetSystemsFirstTimeStamp(){return this.graphicalMeasures[0][0].parentSourceMeasure.AbsoluteTimestamp}GetSystemsLastTimeStamp(){const e=this.graphicalMeasures[this.graphicalMeasures.length-1][0].parentSourceMeasure;return u.plus(e.AbsoluteTimestamp,e.Duration)}createInstrumentBrackets(e,t){for(let i=0,s=e.length;i<s;++i){const t=e[i];if(t.Staves.length>1){let e,i;for(let s=0,n=this.staffLines.length;s<n;++s){const n=this.staffLines[s];n.ParentStaff===t.Staves[0]&&(e=n),n.ParentStaff===t.Staves[t.Staves.length-1]&&(i=n)}e&&i&&this.createInstrumentBracket(e,i)}}}createGroupBrackets(e,t,i){for(let s=0,n=e.length;s<n;++s){const n=e[s];if(n.InstrumentalGroups.length<1)continue;const r=this.findFirstVisibleInstrumentInInstrumentalGroup(n),o=this.findLastVisibleInstrumentInInstrumentalGroup(n);if(!r||!o)continue;let a,l;for(let e=0,t=this.staffLines.length;e<t;++e){const t=this.staffLines[e];t.ParentStaff===r.Staves[0]&&(a=t),t.ParentStaff===o.Staves[0]&&(l=t)}a&&l&&this.createGroupBracket(a,l,i),n.InstrumentalGroups.length<1||this.createGroupBrackets(n.InstrumentalGroups,t,i+1)}}createMusicSystemLabel(e,t,i,s=!1){const n=t;for(let l=0,h=this.staffLines.length;l<h;++l){var r;const i=this.staffLines[l].ParentStaff.ParentInstrument;let n;if(s){var o;n=i.NameLabel,this.rules.RenderPartNames&&null!==(o=n)&&void 0!==o&&o.print||(n=new pt("",i.NameLabel.textAlignment,i.NameLabel.font),t=0)}else{if(!this.rules.RenderPartAbbreviations||!this.rules.RenderPartNames||1===this.staffLines.length||!i.PartAbbreviation||""===i.PartAbbreviation)return;const e=i.PartAbbreviation;n=new pt(e,i.NameLabel.textAlignment,i.NameLabel.font),void 0!==i.NameLabel.trackIndex&&(n.trackIndex=i.NameLabel.trackIndex)}if(null!=i&&null!==(r=i.NameLabel)&&void 0!==r&&r.print){const t=new mt(n,e,ce.LeftCenter,this.rules,this.boundingBox);t.setLabelPositionAndShapeBorders(),this.labels.setValue(i,t)}else t=0}this.maxLabelLength=0;const a=this.labels.values();for(let l=0,h=a.length;l<h;++l){const e=a[l];e.Label.print&&e.PositionAndShape.Size.width>this.maxLabelLength&&(this.maxLabelLength=e.PositionAndShape.Size.width,t=n)}this.updateMusicSystemStaffLineXPosition(t)}setMusicSystemLabelsYPosition(){this.labels.forEach(((e,t)=>{let i=0,s=0;for(let n=0;n<this.staffLines.length;n++)if(this.staffLines[n].ParentStaff.ParentInstrument===e){for(let t=n;t<this.staffLines.length;t++){const n=this.staffLines[t];if(n.ParentStaff.ParentInstrument!==e)break;i+=n.PositionAndShape.RelativePosition.y,s++}break}s>0&&(t.PositionAndShape.RelativePosition=new z(0,i/s+2))}))}checkStaffEntriesForStaffEntryLink(){let e=!1,t=!1;for(let i=0;i<this.staffLines.length-1;i++){for(let t=0,s=this.staffLines[i].Measures.length;t<s;++t){const s=this.staffLines[i].Measures[t];for(let t=0,i=s.staffEntries.length;t<i;++t)s.staffEntries[t].sourceStaffEntry.Link&&(e=!0)}for(let e=0,s=this.staffLines[i+1].Measures.length;e<s;++e){const s=this.staffLines[i+1].Measures[e];for(let e=0,i=s.staffEntries.length;e<i;++e)s.staffEntries[e].sourceStaffEntry.Link&&(t=!0)}}return!(!e||!t)}getBottomStaffLine(e){const t=e.ParentStaff.ParentInstrument.Staves,i=t[t.length-1];for(const s of e.ParentMusicSystem.staffLines)if(s.ParentStaff===i)return s}createSystemLine(e,t,i,s,n,r,o=void 0){throw new Error("not implemented")}createLinesForSystemLine(e){}calcBracketsWidth(){let e=0;for(let t=0,i=this.GroupBrackets.length;t<i;++t){const i=this.GroupBrackets[t];e=Math.max(e,i.PositionAndShape.Size.width)}for(let t=0,i=this.InstrumentBrackets.length;t<i;++t){const i=this.InstrumentBrackets[t];e=Math.max(e,i.PositionAndShape.Size.width)}return e}createInstrumentBracket(e,t){}createGroupBracket(e,t,i){}findFirstVisibleInstrumentInInstrumentalGroup(e){for(let t=0,i=e.InstrumentalGroups.length;t<i;++t){const i=e.InstrumentalGroups[t];if(!(i instanceof Mi))return this.findFirstVisibleInstrumentInInstrumentalGroup(i);if(!0===i.Visible)return i}}findLastVisibleInstrumentInInstrumentalGroup(e){let t;for(let i=e.InstrumentalGroups.length-1;i>=0;i--){if(t=e.InstrumentalGroups[i],!(t instanceof Mi))return this.findLastVisibleInstrumentInInstrumentalGroup(t);if(!0===t.Visible)return t}}updateMusicSystemStaffLineXPosition(e){for(let t=0,i=this.StaffLines.length;t<i;++t){const i=this.StaffLines[t],s=i.PositionAndShape.RelativePosition;s.x=this.maxLabelLength+e,i.PositionAndShape.RelativePosition=s,i.PositionAndShape.BorderRight=this.boundingBox.Size.width-this.maxLabelLength-e;for(let e=0;e<i.StaffLines.length;e++){const t=new z(i.PositionAndShape.Size.width,i.StaffLines[e].End.y);i.StaffLines[e].End=t}}}}class Pi extends ne{constructor(e,t,i,s,n=void 0){super(),this.lineType=e,this.linePosition=t,this.parentMusicSystem=i,this.topMeasure=s,this.bottomMeasure=n,this.parentTopStaffLine=null==s?void 0:s.ParentStaffLine,this.boundingBox=new oe(this,i.PositionAndShape)}static getObjectWidthForLineType(e,t){switch(t){case Ne.SingleThin:return e.SystemThinLineWidth;case Ne.DoubleThin:return 2*e.SystemThinLineWidth+e.DistanceBetweenVerticalSystemLines;case Ne.ThinBold:return e.SystemThinLineWidth+e.SystemBoldLineWidth+e.DistanceBetweenVerticalSystemLines;case Ne.BoldThinDots:case Ne.DotsThinBold:return e.SystemThinLineWidth+e.SystemBoldLineWidth+e.DistanceBetweenVerticalSystemLines+e.SystemDotWidth+e.DistanceBetweenDotAndLine;case Ne.DotsBoldBoldDots:return 2*e.SystemBoldLineWidth+2*e.SystemDotWidth+2*e.DistanceBetweenDotAndLine+e.DistanceBetweenVerticalSystemLines;default:return 0}}}const Ei=n.Flow;class Li extends ne{constructor(e,t,i=0){super(),this.Visible=!0,this.PositionAndShape=new oe(this,e.ParentMusicSystem.PositionAndShape);const s=e.Measures[0],n=t.Measures[0];this.addConnector(s.getVFStave(),n.getVFStave(),Ei.StaveConnector.type.BRACKET,i)}draw(e){this.Visible&&this.vexflowConnector.setContext(e).draw();const t=this.vexflowConnector,i=t.top_stave.getYForLine(0),s=t.bottom_stave.getYForLine(t.bottom_stave.getNumLines()-1)+t.thickness;this.PositionAndShape.AbsolutePosition.x=(t.top_stave.getX()-2+t.x_shift)/zt,this.PositionAndShape.AbsolutePosition.y=i/zt,this.PositionAndShape.Size.height=(s-i)/zt,this.PositionAndShape.Size.width=1.2}addConnector(e,t,i,s){this.vexflowConnector=new Ei.StaveConnector(e,t).setType(i).setXShift(-5*s)}}const xi=n.Flow;class Ti extends Li{constructor(e,t,i=0){super(e,t,i),this.vexflowConnector.setType(xi.StaveConnector.type.BRACE)}}class wi extends vi{constructor(e,t){super(e),this.rules=t}calculateBorders(e){if(0===this.staffLines.length)return;const t=this.calcBracketsWidth();this.boundingBox.BorderLeft=-t,this.boundingBox.BorderMarginLeft=-t,this.boundingBox.XBordersHaveBeenSet=!0;const i=this.staffLines[0].SkyBottomLineCalculator.getSkyLineMin();this.boundingBox.BorderTop=i,this.boundingBox.BorderMarginTop=i;const s=this.staffLines[this.staffLines.length-1],n=s.SkyBottomLineCalculator.getBottomLineMax()+s.PositionAndShape.RelativePosition.y;this.boundingBox.BorderBottom=n,this.boundingBox.BorderMarginBottom=n,this.boundingBox.XBordersHaveBeenSet=!0,this.boundingBox.YBordersHaveBeenSet=!0}createSystemLine(e,t,i,s,n,r,o=void 0){const a=r;let l=!1;if(o&&(l=!0,o.lineTo(r,Jt.line(i,s)),o.addMeasureLine(i,s),i===Ne.DotsBoldBoldDots)){const e=o.ParentStaffLine.Measures.indexOf(o)+1,t=o.ParentStaffLine.Measures[e],i=r.ParentStaffLine.Measures[e];t&&i&&(t.lineTo(i,Jt.line(Ne.BoldThinDots,s)),t.addMeasureLine(Ne.BoldThinDots,s))}return a&&a.addMeasureLine(i,s,l),new Pi(i,s,this,r,o)}createInstrumentBracket(e,t){const i=new Ti(e,t);this.InstrumentBrackets.push(i)}createGroupBracket(e,t,i){const s=e,n=t;if(0===i){const e=new Li(s,n,i);this.GroupBrackets.push(e)}else{const e=new Ti(s,n,i);this.GroupBrackets.push(e)}}}class Ii extends we{constructor(e,t,i){super(e,t,i)}applyBordersFromVexflow(){var e;const t=this.vfStaveNote;if(!t.getNoteHeadBeginX)return;const i=t.getBoundingBox(),s=t.getNoteHeadBeginX()-i.x;this.PositionAndShape.RelativePosition.y=i.y/zt,this.PositionAndShape.BorderTop=0,this.PositionAndShape.BorderBottom=i.h/zt;const n=(t.width-(null!==(e=t.paddingRight)&&void 0!==e?e:0))/2;this.PositionAndShape.BorderLeft=-(s+n)/zt,this.PositionAndShape.BorderRight=(i.w-s)/zt}set vfStaveNote(e){this.mVexFlowStaveNote=e}get vfStaveNote(){return this.mVexFlowStaveNote}color(){const e=this.rules.DefaultColorNotehead,t=this.rules.DefaultColorRest,i=this.rules.DefaultColorStem,s="#00000000";let n,r;const o=this.vfStaveNote;for(let d=0;d<this.notes.length;d++){const i=this.notes[d];if(r=i.sourceNote.NoteheadColor,n=r,this.rules.ColoringMode===fe.AutoColoring||this.rules.ColoringMode===fe.CustomColorSet)if(i.sourceNote.isRest())n=this.rules.ColoringSetCurrent.getValue(-1);else{const e=i.sourceNote.Pitch.FundamentalNote;n=this.rules.ColoringSetCurrent.getValue(e)}if(i.sourceNote.PrintObject?n&&"#000000"!==n||(n=this.rules.DefaultColorNotehead):n=s,!r&&this.rules.ColoringMode===fe.XML&&i.sourceNote.PrintObject&&(!i.sourceNote.isRest()&&e?n=e:i.sourceNote.isRest()&&t&&(n=t)),n&&i.sourceNote.PrintObject)i.sourceNote.NoteheadColorCurrentlyRendered=n;else if(!n)continue;if(this.rules.ColoringEnabled&&i.sourceNote.NoteBeam&&this.rules.ColorBeams){const e=i.sourceNote.NoteBeam.Notes;let t=!0;for(let i=0;i<e.length;i++)e[i].NoteheadColorCurrentlyRendered!==n&&(t=!1);var a;t&&null!=o&&null!==(a=o.beam)&&void 0!==a&&a.setStyle&&o.beam.setStyle({fillStyle:n,strokeStyle:n})}if(o){if(o.note_heads){const e=o.note_heads[d];e&&e.setStyle({fillStyle:n,strokeStyle:n})}o.setLedgerLineStyle&&(n===s?o.setLedgerLineStyle({fillStyle:n,strokeStyle:n,lineWidth:this.rules.LedgerLineWidth}):o.setLedgerLineStyle({fillStyle:this.rules.LedgerLineColorDefault,lineWidth:this.rules.LedgerLineWidth,strokeStyle:this.rules.LedgerLineColorDefault}))}}let l=i,h=!1;this.rules.ColoringEnabled&&(l=this.parentVoiceEntry.StemColor,l&&"#000000"!==l||(l=i),this.rules.ColorStemsLikeNoteheads&&n&&(l=n,h=!0));let u=!0;for(const d of this.parentVoiceEntry.Notes)if(d.PrintObject){u=!1;break}u&&(l=s);const c={fillStyle:l,strokeStyle:l};o&&o.setStemStyle&&(!u&&h&&(this.parentVoiceEntry.StemColor=l),o.setStemStyle(c),o.flag&&o.setFlagStyle&&this.rules.ColorFlags&&o.setFlagStyle(c))}}const Ai=n.Flow,Ri=Ai.NoteSubGroup;let Ni=!1;class Ci extends Re{constructor(e,t,i){super(e,t,i),this.octaveOffset=3,this.vfVoices={},this.vfTies=[],this.vfRepetitionWords=[],this.hasMetronomeMark=!1,this.connectors=[],this.beams={},this.autoVfBeams=[],this.autoTupletVfBeams=[],this.vfbeams={},this.tuplets={},this.vftuplets={},this.minimumStaffEntriesWidth=-1,this.rules=i?i.ParentMusicSystem.rules:t?t.Rules:new xe,this.resetLayout()}setAbsoluteCoordinates(e,t){this.stave.setX(e).setY(t)}resetLayout(){this.stave=new Ai.Stave(0,0,0,{fill_style:this.rules.StaffLineColor,space_above_staff_ln:0,space_below_staff_ln:0,DYMusicScoreType:this.rules.DYMusicScoreType}),this.InitiallyActiveClef&&(this.stave.clef=Jt.Clef(this.InitiallyActiveClef).type),this.stave.MeasureNumber=this.MeasureNumber,this.hasMetronomeMark=!1,this.ParentStaff&&this.setLineNumber(this.ParentStaff.StafflineCount),this.stave.setBegBarType(Ai.Barline.type.NONE),this.parentSourceMeasure&&this.parentSourceMeasure.endingBarStyleEnum===Ne.None&&this.stave.setEndBarType(Ai.Barline.type.NONE),this.updateInstructionWidth()}clean(){this.vfTies.length=0,this.connectors=[],this.resetLayout()}getLineWidth(e){switch(e){case Ne.BoldThinDots:case Ne.DotsThinBold:return 1;case Ne.DotsBoldBoldDots:return 1+this.rules.RepeatEndStartPadding;default:return 0}}addClefAtBegin(e){if(this.rules.RenderClefsAtBeginningOfStaffline){if(this.octaveOffset=e.OctaveOffset,"jianpu"!==this.rules.DYMusicScoreType)if(e.ClefType===q.TAB)this.stave.addClef("tab",void 0,void 0,void 0);else{const t=Jt.Clef(e,"default");this.stave.addClef(t.type,t.size,t.annotation,Ai.StaveModifier.Position.BEGIN)}this.updateInstructionWidth()}}setLineNumber(e){5!==e&&(0===e?(this.stave.setNumLines(0),this.stave.getBottomLineY=function(){return this.getYForLine(this.options.num_lines)}):1===e?(this.stave.options.line_config=[{visible:!1},{visible:!1},{visible:!0},{visible:!1},{visible:!1}],this.stave.getBottomLineY=function(){return this.getYForLine(2)}):2===e?(this.stave.options.line_config=[{visible:!1},{visible:!1},{visible:!0},{visible:!0},{visible:!1}],this.stave.getBottomLineY=function(){return this.getYForLine(3)}):3===e?(this.stave.options.line_config=[{visible:!1},{visible:!0},{visible:!0},{visible:!0},{visible:!1}],this.stave.getBottomLineY=function(){return this.getYForLine(2)}):(this.stave.setNumLines(e),this.stave.getBottomLineY=function(){return this.getYForLine(this.options.num_lines)}))}addKeyAtBegin(e,t,i){var s;if(this.rules.RenderKeySignatures&&this.ShowKeySignature&&(!this.isTabMeasure||this.rules.TabKeySignatureRendered||this.rules.TabKeySignatureSpacingAdded)&&(null===(s=this.parentSourceMeasure)||void 0===s||!s.isReducedToMultiRest||this.rules.MultipleRestMeasureAddKeySignature)){if(this.stave.setKeySignature(Jt.keySignature(e),Jt.keySignature(t),void 0),this.isTabMeasure&&!this.rules.TabKeySignatureRendered){const e=this.stave.getModifiers();for(const t of e)if(t instanceof Ai.KeySignature){t.setStyle({fillStyle:"#00000000"}),t.hidden=!0;break}}this.updateInstructionWidth()}}addRhythmAtBegin(e,t){if(this.isTabMeasure&&!this.rules.TabTimeSignatureRendered&&!this.rules.TabTimeSignatureSpacingAdded)return;if("jianpu"===this.rules.DYMusicScoreType&&t&&t>0){var i;const e=null===(i=window.GYM)||void 0===i?void 0:i.multitrack;e&&e>1&&(Ni=!0)}else Ni=!1;const s=Jt.TimeSignature(e);Ni||this.stave.addModifier(s,Ai.StaveModifier.Position.BEGIN,{numerator:e.Rhythm.Numerator,denominator:e.Rhythm.Denominator}),(!this.ShowTimeSignature||this.isTabMeasure&&!this.rules.TabTimeSignatureRendered)&&(s.setStyle({fillStyle:"#00000000"}),s.hidden=!0),this.updateInstructionWidth()}addClefAtEnd(e,t=!0){const i=Jt.Clef(e,"small");if(t||!this.stave.endClef){this.stave.setEndClef(i.type,i.size,i.annotation);for(const e of this.stave.getModifiers())if(t){const t=e.originalStrokeStyle,i=e.originalFillStyle;e.getStyle()&&(t&&i?(e.getStyle().strokeStyle=t,e.getStyle().fillStyle=i):(e.getStyle().strokeStyle=null,e.getStyle().fillStyle=null))}else if("clefs"===e.getCategory()&&e.getPosition()===Ai.StaveModifier.Position.END&&e.type===i.type){const t="#12345600",i=e.getStyle();i&&(e.originalStrokeStyle=i.strokeStyle,e.originalFillStyle=i.fillStyle),e.setStyle({strokeStyle:t,fillStyle:t})}return this.parentSourceMeasure.hasEndClef=!0,this.updateInstructionWidth()}}addMeasureLine(e,t,i=!0){switch(t){case ft.MeasureBegin:e===Ne.BoldThinDots&&(i||(this.stave.modifiers[0].draw=function(e){switch(e.checkContext(),this.setRendered(),this.type){case Ai.Barline.type.SINGLE:this.drawVerticalBar(e,this.x,!1);break;case Ai.Barline.type.DOUBLE:this.drawVerticalBar(e,this.x,!0);break;case Ai.Barline.type.END:this.drawVerticalEndBar(e,this.x);break;case Ai.Barline.type.REPEAT_BEGIN:this.drawRepeatBar(e,this.x,!0);break;case Ai.Barline.type.REPEAT_END:this.drawRepeatBar(e,this.x,!1);break;case Ai.Barline.type.REPEAT_BOTH:this.drawRepeatBar(e,this.x,!1),this.drawRepeatBar(e,this.x,!0)}}),this.stave.setBegBarType(Ai.Barline.type.REPEAT_BEGIN));break;case ft.MeasureEnd:switch(e){case Ne.DotsBoldBoldDots:this.stave.setEndBarType(Ai.Barline.type.REPEAT_BOTH);break;case Ne.DotsThinBold:this.stave.setEndBarType(Ai.Barline.type.REPEAT_END);break;case Ne.DoubleThin:this.stave.setEndBarType(Ai.Barline.type.DOUBLE);break;case Ne.ThinBold:this.stave.setEndBarType(Ai.Barline.type.END);break;case Ne.None:this.stave.setEndBarType(Ai.Barline.type.NONE)}}}addMeasureNumber(){const e=this.MeasureNumber.toString();this.stave.setText(e,3,{justification:1,shift_x:0,shift_y:0})}addWordRepetition(e){let t,i=Ai.StaveModifier.Position.END;const s=this.beginInstructionsWidth;switch(e.type){case Qe.Segno:t=Ai.Repetition.type.SEGNO_LEFT,i=Ai.StaveModifier.Position.LEFT;break;case Qe.Coda:t=Ai.Repetition.type.CODA_LEFT,i=Ai.StaveModifier.Position.LEFT;break;case Qe.DaCapo:t=Ai.Repetition.type.DC;break;case Qe.DalSegno:t=Ai.Repetition.type.DS;break;case Qe.Fine:t=Ai.Repetition.type.FINE;break;case Qe.ToCoda:t=Ai.Repetition.type.TO_CODA;break;case Qe.DaCapoAlFine:t=Ai.Repetition.type.DC_AL_FINE;break;case Qe.DaCapoAlCoda:t=Ai.Repetition.type.DC_AL_CODA;break;case Qe.DalSegnoAlFine:t=Ai.Repetition.type.DS_AL_FINE;break;case Qe.DalSegnoAlCoda:t=Ai.Repetition.type.DS_AL_CODA}if(t){if(this.stave.getModifiers().find((e=>e.symbol_type===t)))return;const e=new Ai.Repetition(t,s,-this.rules.RepetitionSymbolsYOffset);return e.xShiftAsPercentOfStaveWidth=this.rules.RepetitionEndInstructionXShiftAsPercentOfStaveWidth,void this.stave.addModifier(e,i)}this.addVolta(e)}addVolta(e){let t=Ai.Volta.type.BEGIN;if(e.type===Qe.Ending){switch(e.alignment){case Ze.Begin:t=this.parentSourceMeasure.endsRepetitionEnding()?Ai.Volta.type.BEGIN_END:Ai.Volta.type.BEGIN;break;case Ze.End:if(this.parentSourceMeasure.beginsRepetitionEnding())return;t=Ai.Volta.type.END}const s=this.ParentStaffLine.SkyBottomLineCalculator,n=this.PositionAndShape.AbsolutePosition.x+this.PositionAndShape.BorderMarginLeft+.4,r=Math.max(this.PositionAndShape.AbsolutePosition.x+this.PositionAndShape.BorderMarginRight,n+.4),o=s.getSkyLineMinInRange(n,r)-2;let a,l=-6.1+this.rules.VoltaOffset,h=this.rules.VoltaOffset;o<l&&(h+=o-l,l=o);const u=this.parentSourceMeasure.MeasureNumber;for(let e=0;e<this.ParentStaffLine.Measures.length;e++){var i;const t=this.ParentStaffLine.Measures[e];t instanceof Ci&&(t.MeasureNumber!==u-1&&t.MeasureNumber+(null===(i=t.parentSourceMeasure)||void 0===i?void 0:i.multipleRestMeasures)!==u||(a=t))}if(a){const e=a.stave.getModifiers();for(let t=0;t<e.length;t++){const i=e[t];if(i.hasOwnProperty("volta")){const e=a.ParentStaffLine.SkyBottomLineCalculator,t=a.PositionAndShape.AbsolutePosition.x+a.PositionAndShape.BorderMarginLeft+.4,s=Math.max(a.PositionAndShape.AbsolutePosition.x+a.PositionAndShape.BorderMarginRight,t+.4),n=e.getSkyLineMinInRange(t,s);n<=l?(h+=n-l,l=n):(i.y_shift=h*zt,a.ParentStaffLine.SkyBottomLineCalculator.updateSkyLineInRange(t,s,l))}}}h*=10,this.stave.setVoltaType(t,e.endingIndices[0],h,e.originalVal),s.updateSkyLineInRange(n,r,l)}}setWidth(e){super.setWidth(e),this.stave.setWidth(e*zt)}layoutSymbols(){}draw(e){var t,i,s,n,r,o,a,l;const h=e.openGroup();null==h||null===(t=h.classList)||void 0===t||t.add("vf-measure"),null==h||h.setAttribute("data-num",String(null==this||null===(i=this.parentSourceMeasure)||void 0===i?void 0:i.MeasureNumberXML));const u=e.openGroup();null==u||null===(s=u.classList)||void 0===s||s.add("vf-stave"),null==u||u.setAttribute("id",null===(n=this.stave)||void 0===n||null===(r=n.attrs)||void 0===r?void 0:r.id),this.stave.setContext(e).draw(),e.closeGroup();const c=e.openGroup();null==c||null===(o=c.classList)||void 0===o||o.add("vf-voices");for(const m in this.vfVoices)this.vfVoices.hasOwnProperty(m)&&(e.save(),this.vfVoices[m].draw(e,this.stave),e.restore());e.closeGroup();const d=e.openGroup();if(null==d||null===(a=d.classList)||void 0===a||a.add("vf-beams"),"jianpu"!==this.rules.DYMusicScoreType)for(const m in this.vfbeams)if(this.vfbeams.hasOwnProperty(m))for(const t of this.vfbeams[m])t.setContext(e).draw();if(this.autoVfBeams)for(const m of this.autoVfBeams)m.setContext(e).draw();if(!this.isTabMeasure||this.rules.TupletNumbersInTabs){if(this.autoTupletVfBeams)for(const t of this.autoTupletVfBeams)t.setContext(e).draw();for(const t in this.vftuplets)if(this.vftuplets.hasOwnProperty(t))for(const i of this.vftuplets[t])if("jianpu"===this.rules.DYMusicScoreType){let e=i.getNotes();const t=new Ai.StaveTie({first_note:e[0],last_note:e[e.length-1]},e.length+"");this.vfTies.push(t),i.setTupletLocation(1)}else i.setContext(e).draw()}e.closeGroup(),e.closeGroup();const f=e.openGroup();null==f||null===(l=f.classList)||void 0===l||l.add("vf-ties");for(const m of this.vfTies){if("jianpu"===this.rules.DYMusicScoreType&&m.setDirection(-1),m instanceof Ai.TabSlide)return;m.setContext(e),m.draw()}e.closeGroup();for(const m of this.connectors)m.setContext(e).draw();return this.correctNotePositions(),h}format(){this.formatVoices&&this.formatVoices((this.PositionAndShape.Size.width-this.beginInstructionsWidth-this.endInstructionsWidth)*zt,this)}correctNotePositions(){if(!this.isTabMeasure)for(const e of this.getVoicesWithinMeasure())for(const t of e.VoiceEntries)for(const e of t.Notes){const t=this.rules.GNote(e);if(null==t||!t.vfnote)return;const i=t.vfnote[0];let s=0;t.parentVoiceEntry.parentVoiceEntry.StemDirection===dt.Up&&"w"!==t.vfnote[0].getDuration()?s+=3.5:s+=.5,s+=-t.notehead(i).line+t.parentVoiceEntry.notes.last().notehead().line,t.PositionAndShape.RelativePosition.y=s}}getVoicesWithinMeasure(){const e=[];for(const t of this.staffEntries)for(const i of t.graphicalVoiceEntries)-1===e.indexOf(i.parentVoiceEntry.ParentVoice)&&e.push(i.parentVoiceEntry.ParentVoice);return e}getGraphicalVoiceEntriesPerVoice(e){const t=[];for(const i of this.staffEntries)for(const s of i.graphicalVoiceEntries)s.parentVoiceEntry.ParentVoice===e&&t.push(s);return t}getRestFilledVexFlowStaveNotesPerVoice(e){let t,i=this.getGraphicalVoiceEntriesPerVoice(e);for(let o=0;o<i.length;o++){const e=i[o],n=e.notes[0].sourceNote.getAbsoluteTimestamp();let r=new u;for(const t of e.notes){const e=u.plus(t.sourceNote.getAbsoluteTimestamp(),t.sourceNote.Length);r.lt(e)&&(r=e)}if(t){const e=u.minus(n,t);if(e.RealValue>0){s.trace(`Ghost Found in between (measure ${this.MeasureNumber})`);const t=this.createGhostGves(e);i.splice(o,0,...t),o+=t.length}}else{const e=u.minus(n,this.parentSourceMeasure.AbsoluteTimestamp);if(e.RealValue>0){s.trace(`Ghost Found at start (measure ${this.MeasureNumber})`);const t=this.createGhostGves(e);i.splice(0,0,...t),o+=t.length}}t=r}const n=u.plus(this.parentSourceMeasure.AbsoluteTimestamp,this.parentSourceMeasure.Duration),r=u.minus(n,t);if(r.RealValue>0){s.trace(`Ghost Found at end (measure ${this.MeasureNumber})`);const e=this.createGhostGves(r);i=i.concat(e)}return i}createGhostGves(e){const t=Jt.GhostNotes(e),i=[];for(const s of t){const e=new Ii(void 0,void 0,this.rules);e.vfStaveNote=s,i.push(e)}return i}handleBeam(e,t){const i=e.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;let s,n=this.beams[i];n||(n=this.beams[i]=[]);for(const o of n)o[0]===t&&(s=o);s||(s=[t,[]],n.push(s));const r=e.parentVoiceEntry;s[1].indexOf(r)<0&&s[1].push(r)}handleTuplet(e,t){const i=e.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;t=e.sourceNote.NoteTuplet;let s,n=this.tuplets[i];n||(n=this.tuplets[i]=[]);for(const o of n)o[0]===t&&(s=o);s||(s=[t,[]],n.push(s));const r=e.parentVoiceEntry;s[1].indexOf(r)<0&&s[1].push(r)}finalizeBeams(){if(this.vfbeams={},this.isTabMeasure&&!this.rules.TabBeamsRendered)return;const e=[];for(const t in this.beams)if(this.beams.hasOwnProperty(t)){let i=this.vfbeams[t];i||(i=this.vfbeams[t]=[]);for(const n of this.beams[t]){let t=!1;for(const e of n[0].Notes)if(e.Length.RealValue>=new u(1,4).RealValue&&(!e.TypeLength||e.TypeLength.RealValue>.125)){t=!0;break}if(t){s.debug("Beam between note >= quarter, likely tremolo, currently unsupported. continuing.");continue}const r=[],o=n[0],a=n[1];let l=!0;for(const e of a)e.parentVoiceEntry.ParentVoice===o.Notes[0].ParentVoiceEntry.ParentVoice&&(l=e.parentVoiceEntry.WantedStemDirection===dt.Undefined);let h,c=!1;const d=[];for(const i of a){const t=i.vfStaveNote;t&&(r.push(t),e.push(t)),i.parentVoiceEntry.IsGrace&&(c=!0),i.parentVoiceEntry.StemColor&&this.rules.ColoringEnabled&&d.push(i.parentVoiceEntry.StemColor)}if(r.length>1){const e=new Ai.Beam(r,l);if(c&&(e.render_options.beam_width=3,e.render_options.partial_beam_length=4),d.length>=2&&this.rules.ColorBeams){h=d[0];for(const e of d)if(e!==h){h=void 0;break}e.setStyle({fillStyle:h,strokeStyle:h})}this.rules.FlatBeams&&(e.render_options.flat_beams=!0,e.render_options.flat_beam_offset=this.rules.FlatBeamOffset,e.render_options.flat_beam_offset_per_beam=this.rules.FlatBeamOffsetPerBeam),i.push(e)}else s.debug("Warning! Beam with no notes!")}}this.rules.AutoBeamNotes&&this.autoBeamNotes(e)}autoBeamNotes(e){if(!this.rules.AutoBeamTabs&&this.isTabMeasure)return;let t,i=60,s=[],n=[],r=[];this.autoTupletVfBeams=[];const o=[];this.autoVfBeams=[];let a=this.parentSourceMeasure.ActiveTimeSignature;a||(a=this.parentSourceMeasure.Duration);for(const c of this.staffEntries)for(const l of c.graphicalVoiceEntries){const h=l.vfStaveNote,d=l.notes[0],f={vfStaveNote:h,sourceNote:d.sourceNote},m=c.relInMeasureTimestamp.isOnBeat(a),p=n.length>=2,g=d.sourceNote.Length.RealValue-new u(1,4).RealValue>-u.FloatInaccuracyTolerance,S=l.parentVoiceEntry.IsGrace||g||e.contains(h);if(S||m){if(p){for(const e of n)s.push(e);o.push(s.slice()),s=[]}if(n=[],S)continue}const y=l.notes[0].sourceNote.NoteTuplet;if(y){let e=!1;for(const t of y.Notes){for(const i of t)if(i.NoteTypeXml>=ze.QUARTER||i.ParentVoiceEntry.IsGrace||i.isRest()&&!this.rules.AutoBeamOptions.beam_rests){e=!0;break}if(e)break}if(t){if(t!==y){if(r.length>1){const e=[];for(const i of r)e.push(i.vfStaveNote);const t=new Ai.Beam(e,!0);this.rules.FlatBeams&&(t.render_options.flat_beams=!0,t.render_options.flat_beam_offset=this.rules.FlatBeamOffset,t.render_options.flat_beam_offset_per_beam=this.rules.FlatBeamOffsetPerBeam),this.autoTupletVfBeams.push(t);const s=new Fe(i++);s.AutoGenerated=!0;for(const i of r)s.addNoteToBeam(i.sourceNote)}r=[],t=y}}else t=y;e||r.push(f)}else t=void 0,n.push(f)}if(r.length>=2){const e=[];for(const i of r)e.push(i.vfStaveNote);const t=new Ai.Beam(e,!0);this.rules.FlatBeams&&(t.render_options.flat_beams=!0,t.render_options.flat_beam_offset=this.rules.FlatBeamOffset,t.render_options.flat_beam_offset_per_beam=this.rules.FlatBeamOffsetPerBeam),this.autoTupletVfBeams.push(t);const s=new Fe(i++);s.AutoGenerated=!0;for(const i of r)s.addNoteToBeam(i.sourceNote)}if(n.length>=2){for(const e of n)s.push(e);o.push(s)}const l=this.rules.AutoBeamOptions,h={beam_middle_only:l.beam_middle_rests_only,beam_rests:l.beam_rests,maintain_stem_directions:l.maintain_stem_directions};if(l.groups&&l.groups.length){const e=[];for(const t of l.groups)e.push(new Ai.Fraction(t[0],t[1]));h.groups=e}for(const u of o){const e=[];for(const i of u)e.push(i.vfStaveNote);const t=Ai.Beam.generateBeams(e,h);for(const i of t)this.rules.FlatBeams&&(i.render_options.flat_beams=!0,i.render_options.flat_beam_offset=this.rules.FlatBeamOffset,i.render_options.flat_beam_offset_per_beam=this.rules.FlatBeamOffsetPerBeam),this.autoVfBeams.push(i)}}finalizeTuplets(){this.vftuplets={};for(const e in this.tuplets)if(this.tuplets.hasOwnProperty(e)){let t=this.vftuplets[e];t||(t=this.vftuplets[e]=[]);for(const i of this.tuplets[e]){const e=[],n=i[1];for(const t of n)e.push(t.vfStaveNote);if(e.length>1){const s=i[0],n=s.Notes[0][0].NormalNotes,r=s.shouldBeBracketed(this.rules.TupletsBracketedUseXMLValue,this.rules.TupletsBracketed,this.rules.TripletsBracketed,this.isTabMeasure,this.rules.TabTupletsBracketed);let o=Ai.Tuplet.LOCATION_TOP;s.tupletLabelNumberPlacement===d.Below&&(o=Ai.Tuplet.LOCATION_BOTTOM);let a=0;if(this.isTabMeasure&&(a=10*this.rules.TabTupletYOffsetBottom,o===Ai.Tuplet.LOCATION_TOP)){a=-10*this.rules.TabTupletYOffsetTop;const e=s.Notes[0][0];null!=e&&e.hasTabEffects()&&(a-=10*this.rules.TabTupletYOffsetEffects)}const l=new Ai.Tuplet(e,{bracketed:r,location:o,notes_occupied:n,num_notes:s.TupletLabelNumber,ratioed:this.rules.TupletsRatioed,y_offset:a});t.push(l)}else s.debug("Warning! Tuplet with no notes! Trying to ignore, but this is a serious problem.")}}}layoutStaffEntry(e){}graphicalMeasureCreatedCalculations(){let e,t=[];const i=[];for(const n of this.staffEntries){e=!1,t=[];for(const s of n.graphicalVoiceEntries)if(s.parentVoiceEntry.IsGrace)t.push(s),i.push(s),e||(e=s.parentVoiceEntry.GraceSlur);else if(s.vfStaveNote=Jt.StaveNote(s),t.length>0){const i=[];for(let e=0;e<t.length;e++){const s=t[e];s.GraceSlash=s.parentVoiceEntry.GraceNoteSlash,e>0&&(s.GraceSlash=!1);const n=Jt.StaveNote(s);s.vfStaveNote=n,i.push(n)}const n=new Ai.GraceNoteGroup(i,e);n.spacing=10*this.rules.GraceNoteGroupXMargin,s.vfStaveNote.addModifier(0,n),t=[]}}if(t.length>0)for(const n of t)n.vfStaveNote=Jt.StaveNote(n),n.parentVoiceEntry.GraceAfterMainNote=!0;this.finalizeBeams(),this.finalizeTuplets();const s=this.getVoicesWithinMeasure();if(this.rules.RenderFingerings)for(const n of this.staffEntries)n.setModifierXOffsets();for(const n of s){if(!n)continue;this.vfVoices[n.VoiceId]=new Ai.Voice({beat_value:this.parentSourceMeasure.ActiveTimeSignature.Denominator,num_beats:this.parentSourceMeasure.ActiveTimeSignature.Numerator,resolution:Ai.RESOLUTION}).setMode(Ai.Voice.Mode.SOFT);const e=this.getRestFilledVexFlowStaveNotesPerVoice(n);for(const t of e){if(t.parentVoiceEntry&&t.parentVoiceEntry.IsGrace&&!t.parentVoiceEntry.GraceAfterMainNote)continue;const e=t;if(0===e.vfStaveNote.getTicks().denominator&&(e.vfStaveNote.getTicks().denominator=1),0===t.notes.length||!t.notes[0]||!t.notes[0].sourceNote.PrintObject){this.vfVoices[n.VoiceId].addTickable(e.vfStaveNote);continue}const i=e.parentStaffEntry;if(i&&i.vfClefBefore){const t=new Ri([i.vfClefBefore]);e.vfStaveNote.getCategory&&"stavenotes"===e.vfStaveNote.getCategory()&&e.vfStaveNote.addModifier(0,t)}t.parentVoiceEntry&&this.rules.RenderFingerings&&(this.rules.FingeringPosition!==d.Left&&this.rules.FingeringPosition!==d.Right||this.createFingerings(t),this.createStringNumber(t)),this.createArpeggio(t),this.vfVoices[n.VoiceId].addTickable(e.vfStaveNote)}}this.setStemDirectionFromVexFlow();for(const n of i)this.createFingerings(n),this.createStringNumber(n),this.createArpeggio(n);this.createArticulations(),this.createOrnaments()}createArpeggio(e){if(e.parentVoiceEntry&&e.parentVoiceEntry.Arpeggio){const t=e.parentVoiceEntry.Arpeggio;if(e.notes&&e.notes.length>1){const i=Jt.StrokeTypeFromArpeggioType(t.type),s=new Ai.Stroke(i,{all_voices:this.rules.ArpeggiosGoAcrossVoices});this.rules.RenderArpeggios&&e.vfStaveNote.addStroke(0,s)}else s.debug(`[OSMD] arpeggio in measure ${this.MeasureNumber} could not be drawn.\n voice entry had less than two notes, arpeggio is likely between voice entries, not currently supported in Vexflow.`)}}setStemDirectionFromVexFlow(){for(const e of this.staffEntries)for(const t of e.graphicalVoiceEntries)for(const e of t.notes){const i=e.vfnote;if(i&&i[0])switch(i[0].getStemDirection()){case Ai.Stem.UP:t.parentVoiceEntry.StemDirection=dt.Up;break;case Ai.Stem.DOWN:t.parentVoiceEntry.StemDirection=dt.Down}}}createArticulations(){for(let e=0,t=this.staffEntries.length;e<t;++e){const t=this.staffEntries[e].graphicalVoiceEntries;for(const e of t){const t=e.vfStaveNote;Jt.generateArticulations(t,e.notes[0],this.rules)}}}createOrnaments(){for(let e=0,t=this.staffEntries.length;e<t;++e){const t=this.staffEntries[e].graphicalVoiceEntries;for(const e in t)if(t.hasOwnProperty(e)){const i=t[e].vfStaveNote,s=t[e].notes[0].sourceNote.ParentVoiceEntry.OrnamentContainer;s&&Jt.generateOrnaments(i,s)}}}createFingerings(e){const t=e;let i=0;for(const r of e.notes)r.sourceNote.Fingering&&i++;const s=[];for(const r of e.parentVoiceEntry.TechnicalInstructions)r.type===ot.Fingering&&s.push(r);if(s.length>i){let t=0;for(const n of e.notes)if(n.sourceNote.Fingering)t++;else{if(n.sourceNote.Fingering=s.pop(),i++,t>s.length-1)break;n.sourceNote.Fingering=s[t],t++}}let n=-1;for(const r of e.notes){const s=r.sourceNote.Fingering;if(!s){n++;continue}n++;let o=this.rules.FingeringPosition;this.rules.FingeringPositionGrace===d.AboveOrBelow&&(this.isUpperStaffOfInstrument()?o=d.Above:this.isLowerStaffOfInstrument()&&(o=d.Below)),s.placement!==d.NotYetDefined&&(o=s.placement);let a,l=this.rules.FingeringOffsetX;switch(o){default:case d.Left:a=Ai.StaveModifier.Position.LEFT,l-=r.baseFingeringXOffset*zt;break;case d.Right:a=Ai.StaveModifier.Position.RIGHT,l+=r.baseFingeringXOffset*zt;break;case d.Above:a=Ai.StaveModifier.Position.ABOVE;break;case d.Below:a=Ai.StaveModifier.Position.BELOW;break;case d.NotYetDefined:const t=e.parentStaffEntry.sourceStaffEntry.ParentStaff;e.notes.length>1||e.parentStaffEntry.graphicalVoiceEntries.length>1?a=Ai.StaveModifier.Position.LEFT:0===t.idInMusicSheet?(a=Ai.StaveModifier.Position.ABOVE,o=d.Above):(a=Ai.StaveModifier.Position.BELOW,o=d.Below)}const h=new Ai.FretHandFinger(s.value);if(h.setPosition(a),h.setOffsetX(l),o===d.Above||o===d.Below){const e=o===d.Above?-1:1,r=o===d.Above?n:i-1-n;if(this.rules.FingeringInsideStafflines&&i>1){const t=h.getWidth()/2,s=2.5*i;h.setOffsetY(e*(r+s)*t)}else if(!this.rules.FingeringInsideStafflines){const i=new Ai.StringNumber(s.value);i.radius=0,i.setPosition(a),i.setOffsetY(e*r*i.getWidth()*2/3),t.vfStaveNote.addModifier(n,i);continue}}t.vfStaveNote.addModifier(n,h)}}createStringNumber(e){if(!this.rules.RenderStringNumbersClassical)return;const t=e;e.notes.forEach(((i,s)=>{const n=i.sourceNote.StringInstruction;if(n){let r=n.value;switch(r){case"1":r="I";break;case"2":r="II";break;case"3":r="III";break;case"4":r="IV";break;case"5":r="V";break;case"6":r="VI"}const o=new Ai.StringNumber(r);o.radius=0;const a=-this.rules.StringNumberOffsetY;e.notes.length>1||e.parentStaffEntry.graphicalVoiceEntries.length>1?(o.setOffsetX(13*i.baseStringNumberXOffset),o.setPosition(Ai.Modifier.Position.RIGHT)):o.setPosition(Ai.Modifier.Position.ABOVE),o.setOffsetY(a),t.vfStaveNote.addModifier(s,o)}}))}lineTo(e,t){const i=new Ai.StaveConnector(e.getVFStave(),this.stave);i.setType(t),this.connectors.push(i)}getVFStave(){return this.stave}updateInstructionWidth(){var e,t;let i=0,s=0;const n=this.stave.getModifiers();for(const r of n)5===r.getPosition()?i+=r.getWidth()+r.getPadding(void 0):6===r.getPosition()&&(s+=r.getWidth()+r.getPadding(void 0));this.beginInstructionsWidth=(null!==(e=i)&&void 0!==e?e:0)/zt,this.endInstructionsWidth=(null!==(t=s)&&void 0!==t?t:0)/zt}addStaveTie(e,t){this.vfTies.push(e),t.vfTie=e,t.Tie.TieDirection===d.Below&&e.setDirection(1)}}class Bi extends ne{constructor(e,t=void 0,i=void 0){super(),this.graphicalChordContainers=[],this.tabStaffEntry=void 0,this.MaxAccidentals=0,this.graphicalInstructions=[],this.ties=[],this.graphicalTies=[],this.lyricsEntries=[],this.parentMeasure=e,this.graphicalVoiceEntries=[],this.sourceStaffEntry=t,i?(this.staffEntryParent=i,this.parentVerticalContainer=i.parentVerticalContainer,this.PositionAndShape=new oe(this,i.PositionAndShape)):this.PositionAndShape=new oe(this,e.PositionAndShape),t&&(this.relInMeasureTimestamp=t.Timestamp),this.FingeringEntries=[]}get GraphicalInstructions(){return this.graphicalInstructions}get GraphicalTies(){return this.graphicalTies}get LyricsEntries(){return this.lyricsEntries}set LyricsEntries(e){this.lyricsEntries=e}getAbsoluteTimestamp(){const e=this.parentMeasure.parentSourceMeasure.AbsoluteTimestamp.clone();return this.relInMeasureTimestamp&&e.Add(this.relInMeasureTimestamp),e}findTieGraphicalNoteFromNote(e){var t;const i=(null===(t=window.GYM)||void 0===t?void 0:t.graceCustom)||!1;for(const s of this.graphicalVoiceEntries)for(const t of s.notes){const s=t.sourceNote;if(i){if(e.NoteToGraphicalNoteObjectId==s.NoteToGraphicalNoteObjectId)return t}else if(!s.isRest()&&s.Pitch.FundamentalNote===e.Pitch.FundamentalNote&&s.Pitch.Octave===e.Pitch.Octave&&s.getAbsoluteTimestamp().Equals(e.getAbsoluteTimestamp()))return t}}findEndTieGraphicalNoteFromNoteWithStartingSlur(e,t){if(e)for(const i of this.graphicalVoiceEntries)if(i.parentVoiceEntry===e.ParentVoiceEntry)for(const e of i.notes){const i=e.sourceNote;if(i.NoteTie&&-1!==i.NoteSlurs.indexOf(t))return e}}findGraphicalNoteFromGraceNote(e){if(e)for(const t of this.graphicalVoiceEntries)if(t.parentVoiceEntry===e.ParentVoiceEntry)for(const i of t.notes)if(i.sourceNote===e)return i}findGraphicalNoteFromNote(e){if(e)for(const t of this.graphicalVoiceEntries)if(t.parentVoiceEntry===e.ParentVoiceEntry)for(const i of t.notes)if(i.sourceNote===e&&this.getAbsoluteTimestamp().Equals(e.getAbsoluteTimestamp()))return i}getGraphicalNoteDurationFromVoice(e){for(const t of this.graphicalVoiceEntries)if(t.parentVoiceEntry.ParentVoice===e)return t.notes[0].graphicalNoteLength;return new u(0,1)}findVoiceEntryGraphicalNotes(e){for(const t of this.graphicalVoiceEntries)if(t.parentVoiceEntry===e)return t.notes}isVoiceEntryPartOfLinkedVoiceEntry(e){if(this.sourceStaffEntry.Link)for(let t=0,i=this.sourceStaffEntry.Link.LinkStaffEntries.length;t<i;++t){const i=this.sourceStaffEntry.Link.LinkStaffEntries[t];if(-1!==i.VoiceEntries.indexOf(e)&&i!==this.sourceStaffEntry)return!0}return!1}findStaffEntryMinNoteLength(){let e=new u(Number.MAX_VALUE,1);for(const t of this.graphicalVoiceEntries)for(const i of t.notes){const t=i.graphicalNoteLength;t.lt(e)&&t.GetExpandedNumerator()>0&&(e=t)}return e}findStaffEntryMaxNoteLength(){let e=new u(0,1);for(const t of this.graphicalVoiceEntries)for(const i of t.notes){const t=i.graphicalNoteLength;e.lt(t)&&t.GetExpandedNumerator()>0&&(e=t)}return e}findOrCreateGraphicalVoiceEntry(e){for(const i of this.graphicalVoiceEntries)if(i.parentVoiceEntry===e)return i;const t=yi.symbolFactory.createVoiceEntry(e,this);return this.graphicalVoiceEntries.push(t),t}findOrCreateGraphicalVoiceEntryFromGraphicalNote(e){for(const i of this.graphicalVoiceEntries)if(i===e.parentVoiceEntry)return i;const t=yi.symbolFactory.createVoiceEntry(e.sourceNote.ParentVoiceEntry,this);return this.graphicalVoiceEntries.push(t),t}addGraphicalNoteToListAtCorrectYPosition(e,t){const i=e.notes;if(0===i.length||t.PositionAndShape.RelativePosition.y<le.last(i).PositionAndShape.RelativePosition.y)i.push(t);else for(let s=i.length-1;s>=0;s--){if(i[s].PositionAndShape.RelativePosition.y>t.PositionAndShape.RelativePosition.y){i.splice(s+1,0,t);break}if(0===s){i.splice(0,0,t);break}}}hasOnlyRests(){return this.sourceStaffEntry.hasOnlyRests}getSkylineMin(){var e;const t=null===(e=this.parentMeasure)||void 0===e?void 0:e.ParentStaffLine.SkyBottomLineCalculator;if(!t)return;const[i,s]=this.getAbsoluteStartAndEnd();return t.getSkyLineMinInRange(i,s)}getHighestYAtEntry(){return this.parentMeasure.ParentStaffLine.PositionAndShape.AbsolutePosition.y+this.getSkylineMin()}getLowestYAtEntry(){return this.parentMeasure.ParentStaffLine.PositionAndShape.AbsolutePosition.y+this.getBottomlineMax()}getBottomlineMax(){var e;const t=null===(e=this.parentMeasure)||void 0===e?void 0:e.ParentStaffLine.SkyBottomLineCalculator;if(!t)return;const[i,s]=this.getAbsoluteStartAndEnd();return t.getBottomLineMaxInRange(i,s)}getAbsoluteStartAndEnd(){let e=this.PositionAndShape.AbsolutePosition.x;return e-=this.parentMeasure.ParentStaffLine.PositionAndShape.AbsolutePosition.x,[e,e+this.PositionAndShape.Size.width]}}class Di extends Bi{constructor(e,t,i){super(e,t,i)}calculateXPosition(){const e=this.parentMeasure.getVFStave();let t=0;for(const i of this.graphicalVoiceEntries)if(i.vfStaveNote){if(i.vfStaveNote.setStave(e),!i.vfStaveNote.preFormatted)continue;i.applyBordersFromVexflow();let s=!1,n=this.PositionAndShape;i.notes[0].sourceNote.isWholeRest()&&!this.hasOnlyRests()&&(s=!0,n=i.PositionAndShape),this.parentMeasure.ParentStaff.isTab?n.RelativePosition.x=(i.vfStaveNote.getAbsoluteX()+i.vfStaveNote.glyph.getWidth())/zt:(n.RelativePosition.x=i.vfStaveNote.getBoundingBox().getX()/zt,s&&(n.RelativePosition.x-=e.getNoteStartX()/zt,n.RelativePosition.x-=1.3));const r=i.notes[0].sourceNote;r.isRest()&&r.Length.RealValue===this.parentMeasure.parentSourceMeasure.ActiveTimeSignature.RealValue&&(n.RelativePosition.x+=this.parentMeasure.parentSourceMeasure.Rules.WholeRestXShiftVexflow-.1,i.PositionAndShape.BorderLeft=-.7,i.PositionAndShape.BorderRight=.7),i.PositionAndShape.BorderLeft<t&&(t=i.PositionAndShape.BorderLeft)}this.PositionAndShape.RelativePosition.x-=t,this.PositionAndShape.calculateBoundingBox()}setMaxAccidentals(){for(const e of this.graphicalVoiceEntries)for(const t of e.notes)if(t.DrawnAccidental!==Y.NONE)return this.MaxAccidentals=1;return this.MaxAccidentals=0}setModifierXOffsets(){let e=[];for(const n of this.graphicalVoiceEntries)e=e.concat(n.notes);const t=e.map((e=>e.staffLine)),i=this.calculateModifierXOffsets(t,1),s=this.calculateModifierXOffsets(t,.5);e.forEach(((e,t)=>{e.baseFingeringXOffset=s[t],e.baseStringNumberXOffset=i[t]}))}calculateModifierXOffsets(e,t){const i=[];for(let s=0;s<e.length;s++){let n=0,r=!0;for(;r;)for(let o=s;o>=0;o--){if(Math.abs(e[s]-e[o])<=t&&n===i[o]){n++,r=!0;break}r=!1}i.push(n)}return i}}class Vi extends Ee{constructor(e,t,i,s=$t.NONE,n,r=void 0){if(super(e,t,n,r),this.clef=i,this.octaveShift=s,e.Pitch){const t=e.isRest()?e.Pitch:qt.getPitchFromOctaveShift(e.Pitch,s);this.vfpitch=Jt.pitch(t,e.isRest(),this.clef,this.sourceNote.Notehead),this.vfpitch[1]=void 0}}setAccidental(e){const t=this.drawPitch(e);this.vfpitch=Jt.pitch(t,this.sourceNote.isRest(),this.clef,this.sourceNote.Notehead),this.DrawnAccidental=t.Accidental}drawPitch(e){return qt.getPitchFromOctaveShift(e,this.octaveShift)}Transpose(e,t,i,s){const n=super.Transpose(e,t,i,s),r=qt.getPitchFromOctaveShift(n,this.octaveShift);return this.vfpitch=Jt.pitch(r,this.sourceNote.isRest(),this.clef,this.sourceNote.Notehead),this.vfpitch[1]=void 0,r}setIndex(e,t){this.vfnote=[e,t],this.vfnoteIndex=t}notehead(e=void 0){let t=e;t||(t=this.vfnote[0]);const i=t.note_heads;return i&&i.length>this.vfnoteIndex&&i[this.vfnoteIndex]?t.note_heads[this.vfnoteIndex]:{line:0}}Clef(){return this.clef}getSVGId(){if(this.vfnote)return this.vfnote[0].getAttribute("id")}getSVGGElement(){if(this.vfnote)return this.vfnote[0].getAttribute("el")}getStemSVG(){return document.getElementById("vf-"+this.getSVGId()+"-stem")}getBeamSVGs(){const e=[];for(let t=0;;t++){const i=document.getElementById(`vf-${this.getSVGId()}-beam${t}`);if(!i)break;e.push(i)}return e}}class ki extends ne{constructor(e,t,i,s,n,r){super(),this.chordSymbolContainer=e,this.boundingBox=new oe(this,t),this.rules=r,this.calculateLabel(i,n,s)}get GetChordSymbolContainer(){return this.chordSymbolContainer}get GraphicalLabel(){return this.graphicalLabel}calculateLabel(e,t,i){const s=ye.calculateChordText(this.chordSymbolContainer,t,i);this.graphicalLabel=new mt(new pt(s),e,this.rules.ChordSymbolTextAlignment,this.rules,this.boundingBox),this.graphicalLabel.PositionAndShape.RelativePosition=new z(this.rules.ChordSymbolRelativeXOffset,0),this.graphicalLabel.Label.colorDefault=this.rules.DefaultColorChordSymbol}}const Fi=n.Flow;class Oi extends Ci{constructor(e,t=void 0,i=void 0){super(e,t,i),this.isTabMeasure=!0}resetLayout(){var e;const t=null!==(e=this.ParentStaff.StafflineCount)&&void 0!==e?e:6;this.stave=new Fi.TabStave(0,0,0,{space_above_staff_ln:0,space_below_staff_ln:0,num_lines:t}),this.updateInstructionWidth()}graphicalMeasureCreatedCalculations(){for(let t=0,i=this.staffEntries.length;t<i;++t){const e=this.staffEntries[t];for(const t of e.graphicalVoiceEntries)if(t.notes[0].sourceNote.isRest()){const e=Jt.GhostNotes(t.notes[0].sourceNote.Length);t.vfStaveNote=e[0],t.vfGhostNotes=e}else t.vfStaveNote=Jt.CreateTabNote(t)}this.finalizeTuplets();const e=this.getVoicesWithinMeasure();for(const t of e){if(!t)continue;this.vfVoices[t.VoiceId]=new Fi.Voice({beat_value:this.parentSourceMeasure.Duration.Denominator,num_beats:this.parentSourceMeasure.Duration.Numerator,resolution:Fi.RESOLUTION}).setMode(Fi.Voice.Mode.SOFT);const e=this.getRestFilledVexFlowStaveNotesPerVoice(t);for(const i of e){if(i.parentVoiceEntry&&i.parentVoiceEntry.IsGrace&&!i.parentVoiceEntry.GraceAfterMainNote)continue;const e=i;if(0!==i.notes.length&&i.notes[0]&&i.notes[0].sourceNote.PrintObject){if(i.parentVoiceEntry&&i.parentVoiceEntry.Arpeggio){const t=i.parentVoiceEntry.Arpeggio;if(i.notes&&i.notes.length>1){const i=Jt.StrokeTypeFromArpeggioType(t.type),s=new Fi.Stroke(i,{all_voices:this.rules.ArpeggiosGoAcrossVoices});this.rules.RenderArpeggios&&e.vfStaveNote.addStroke(0,s)}else s.debug(`[OSMD] arpeggio in measure ${this.MeasureNumber} could not be drawn.\n voice entry had less than two notes, arpeggio is likely between voice entries, not currently supported in Vexflow.`)}if(e.vfGhostNotes)for(const i of e.vfGhostNotes)this.vfVoices[t.VoiceId].addTickable(i);else this.vfVoices[t.VoiceId].addTickable(e.vfStaveNote)}else if(e.vfGhostNotes)for(const i of e.vfGhostNotes)this.vfVoices[t.VoiceId].addTickable(i);else this.vfVoices[t.VoiceId].addTickable(e.vfStaveNote)}}}}class _i extends ne{constructor(e){super(),this.parentStaffLine=e;const t=e.PositionAndShape;this.boundingBox=new oe(this,t),this.boundingBox.BorderRight=6,this.boundingBox.BorderBottom=4.5,this.boundingBox.BorderLeft=-1.5,this.boundingBox.BorderTop=-1.5}}class Gi extends ne{constructor(e,t){super(),this.measures=[],this.staffLines=new Array(5),this.octaveShifts=[],this.lyricLines=[],this.lyricsDashes=[],this.abstractExpressions=[],this.graphicalSlurs=[],this.graphicalGlissandi=[],this.Pedals=[],this.WavyLines=[],this.parentMusicSystem=e,this.parentStaff=t,this.boundingBox=new oe(this,e.PositionAndShape),this.skyBottomLine=yi.symbolFactory.createSkyBottomLineCalculator(this),this.staffHeight=this.parentMusicSystem.rules.StaffHeight,this.topLineOffset=0,this.bottomLineOffset=4,this.calculateStaffLineOffsets()}calculateStaffLineOffsets(){if(this.ParentStaff.isTab)5===this.ParentStaff.StafflineCount?this.staffHeight=this.bottomLineOffset=6*this.ParentStaff.ParentInstrument.GetMusicSheet.Rules.TabStaffInterlineHeight:this.staffHeight=this.bottomLineOffset=this.ParentStaff.ParentInstrument.GetMusicSheet.Rules.TabStaffInterlineHeight*this.ParentStaff.StafflineCount;else switch(this.ParentStaff.StafflineCount){case 4:this.bottomLineOffset=1;break;case 3:this.topLineOffset=1,this.bottomLineOffset=1;break;case 2:this.topLineOffset=2,this.bottomLineOffset=1;break;case 1:this.topLineOffset=2,this.bottomLineOffset=2}}get Measures(){return this.measures}set Measures(e){this.measures=e}get StaffLines(){return this.staffLines}set StaffLines(e){this.staffLines=e}get Index(){return this.parentMusicSystem.StaffLines.indexOf(this)}get NextStaffLine(){const e=this.Index;return e!==this.parentMusicSystem.StaffLines.length?this.parentMusicSystem.StaffLines[e+1]:void 0}get LyricLines(){return this.lyricLines}get AbstractExpressions(){return this.abstractExpressions}set AbstractExpressions(e){this.abstractExpressions=e}set LyricLines(e){this.lyricLines=e}get LyricsDashes(){return this.lyricsDashes}set LyricsDashes(e){this.lyricsDashes=e}get ParentMusicSystem(){return this.parentMusicSystem}set ParentMusicSystem(e){this.parentMusicSystem=e}get ParentStaff(){return this.parentStaff}set ParentStaff(e){this.parentStaff=e}get SkyBottomLineCalculator(){return this.skyBottomLine}get SkyLine(){return this.skyBottomLine.SkyLine}get BottomLine(){return this.skyBottomLine.BottomLine}get OctaveShifts(){return this.octaveShifts}set OctaveShifts(e){this.octaveShifts=e}get StaffHeight(){return this.staffHeight}get TopLineOffset(){return this.topLineOffset}get BottomLineOffset(){return this.bottomLineOffset}get GraphicalSlurs(){return this.graphicalSlurs}get GraphicalGlissandi(){return this.graphicalGlissandi}addSlurToStaffline(e){this.graphicalSlurs.push(e)}addGlissandoToStaffline(e){this.graphicalGlissandi.push(e),e.StaffLine=this}addActivitySymbolClickArea(){const e=new _i(this),t=this.PositionAndShape;e.PositionAndShape.RelativePosition=new z(t.RelativePosition.x+t.BorderRight+.5,t.RelativePosition.y+.5),e.PositionAndShape.Parent=this.parentMusicSystem.PositionAndShape}isPartOfMultiStaffInstrument(){return this.parentStaff.ParentInstrument.Staves.length>1}findClosestStaffEntry(e){let t;for(let i=0,s=this.Measures.length;i<s;++i){const s=this.Measures[i];for(let i=0,n=s.staffEntries.length;i<n;++i){const n=s.staffEntries[i];Math.abs(n.PositionAndShape.RelativePosition.x-e+s.PositionAndShape.RelativePosition.x)<10&&(t=n)}}return t}}class Wi extends Ft{constructor(e,t,i,s){if(super(e,t,i),this.IsVerbal){const t=new pt(e.Label);this.label=new mt(t,s||this.rules.ContinuousDynamicTextHeight,ce.LeftCenter,this.rules,this.PositionAndShape),this.label.Label.fontStyle=me.Italic,this.label.setLabelPositionAndShapeBorders(),this.PositionAndShape.calculateBoundingBox()}}}class Ui{constructor(e){this.parentStaffline=e,this.rules=this.parentStaffline.ParentMusicSystem.rules}alignDynamicExpressions(){const e=[];let t=new Array;for(let o=0;o<this.parentStaffline.AbstractExpressions.length-1;o++){var i,s;const n=this.parentStaffline.AbstractExpressions[o],r=this.parentStaffline.AbstractExpressions[o+1];if((null==n||null===(i=n.SourceExpression)||void 0===i?void 0:i.Placement)===(null==r||null===(s=r.SourceExpression)||void 0===s?void 0:s.Placement)){const i=this.getDistance(n.PositionAndShape,r.PositionAndShape);Math.abs(i.x)<this.rules.DynamicExpressionMaxDistance?(-1===t.indexOf(n)&&t.push(n),t.push(r)):(e.push(t),t=new Array)}}e.push(t);for(const o of e)if(o.length>0){var n,r;const e=o.map((e=>e.PositionAndShape.Center.y)),t=Math.max(...e),i=(null===(n=window.GYM)||void 0===n?void 0:n.noNeedContinuousDynamic)||!1,s=(null===(r=window.GYM)||void 0===r?void 0:r.noNeedGraphicalContinuousDynamic)||!1;for(let n=0;n<o.length;n++){const r=o[n],a=e[n]-t;if(r instanceof Wi?i||(r.shiftYPosition(-a),r.calcPsi()):(s||(r.PositionAndShape.RelativePosition.y-=.8*a),r.PositionAndShape.calculateBoundingBox()),!i&&r.squeeze){const e=n<o.length-1?o[n+1]:void 0,t=n>0?o[n-1]:void 0;if(e){const t=this.getOverlap(r.PositionAndShape,e.PositionAndShape);r.squeeze(-(t.x+this.rules.DynamicExpressionSpacer))}if(t){const e=this.getOverlap(t.PositionAndShape,r.PositionAndShape);r.squeeze(e.x+this.rules.DynamicExpressionSpacer)}}}}}getDistance(e,t){const i=e.RelativePosition.x+e.BorderMarginRight,s=t.RelativePosition.x+t.BorderMarginLeft,n=e.RelativePosition.y+e.BorderMarginBottom,r=t.RelativePosition.y+t.BorderMarginTop;return new z(s-i,r-n)}getOverlap(e,t){return new z(e.RelativePosition.x+e.BorderMarginRight-(t.RelativePosition.x+t.BorderMarginLeft),e.RelativePosition.y+e.BorderMarginBottom-(t.RelativePosition.y+t.BorderMarginTop))}}class Xi extends Gi{constructor(e,t){super(e,t),this.slursInVFStaffLine=[],this.alignmentManager=new Ui(this)}get SlursInVFStaffLine(){return this.slursInVFStaffLine}addVFSlurToVFStaffline(e){this.slursInVFStaffLine.push(e)}get AlignmentManager(){return this.alignmentManager}}const zi=n.Flow;class Hi extends Ci{constructor(e,t=void 0,i=void 0){super(e,t,i),this.minimumStaffEntriesWidth=-1,i?this.rules=i.ParentMusicSystem.rules:t&&(this.rules=t.Rules),this.resetLayout(),this.multiRestElement=new zi.MultiMeasureRest(t.multipleRestMeasures,{})}draw(e){var t,i,s,n,r,o;const a=e.openGroup();null==a||null===(t=a.classList)||void 0===t||t.add("vf-measure"),null==a||a.setAttribute("data-num",String(null==this||null===(i=this.parentSourceMeasure)||void 0===i?void 0:i.MeasureNumberXML));const l=e.openGroup();null==l||null===(s=l.classList)||void 0===s||s.add("vf-stave"),null==l||l.setAttribute("id",null===(n=this.stave)||void 0===n||null===(r=n.attrs)||void 0===r?void 0:r.id),this.stave.setContext(e).draw(),e.closeGroup();const h=e.openGroup();null==h||null===(o=h.classList)||void 0===o||o.add("vf-voices"),this.multiRestElement.setStave(this.stave),this.multiRestElement.setContext(e),this.multiRestElement.draw(),e.closeGroup();for(const u of this.connectors)u.setContext(e).draw();return e.closeGroup(),a}format(){for(const i of this.staffEntries){var e,t;const s=this.PositionAndShape.Size.width-this.beginInstructionsWidth;i.PositionAndShape.RelativePosition.x=this.PositionAndShape.Size.width/2+this.beginInstructionsWidth/3,i.PositionAndShape.RelativePosition.y=0;const n=null===(e=i.graphicalVoiceEntries[0])||void 0===e||null===(t=e.notes[0])||void 0===t?void 0:t.PositionAndShape;n.BorderLeft=-s/3,n.BorderRight=s/3,n.BorderTop=2,n.BorderBottom=4,i.PositionAndShape.calculateBoundingBox()}}getVoicesWithinMeasure(){return[]}getGraphicalVoiceEntriesPerVoice(e){return[]}getRestFilledVexFlowStaveNotesPerVoice(e){return[]}handleBeam(e,t){}handleTuplet(e,t){}finalizeBeams(){}finalizeTuplets(){}layoutStaffEntry(e){}graphicalMeasureCreatedCalculations(){}createArticulations(){}createOrnaments(){}createFingerings(e){}getVFStave(){return this.stave}}class Yi{constructor(e,t){this.skyLine=e,this.bottomLine=t}}const ji=n.Flow;class Ki extends Wt{constructor(e){super(),this.rules=e}getVexflowBackendType(){return ji.Renderer.Backends.CANVAS}getOSMDBackendType(){return B.Canvas}getCanvasSize(){var e;return null===(e=document.getElementById("osmdCanvasPage"+this.graphicalMusicPage.PageNumber))||void 0===e?void 0:e.offsetHeight}initialize(e,t){this.zoom=t,this.canvas=document.createElement("canvas"),this.graphicalMusicPage||(this.graphicalMusicPage=new he(void 0),this.graphicalMusicPage.PageNumber=1),this.canvas.id="osmdCanvasVexFlowBackendCanvas"+this.graphicalMusicPage.PageNumber,this.inner=document.createElement("div"),this.inner.id="osmdCanvasPage"+this.graphicalMusicPage.PageNumber,this.inner.style.position="relative",this.canvas.style.zIndex="0",this.inner.appendChild(this.canvas),e.appendChild(this.inner),this.renderer=new ji.Renderer(this.canvas,this.getVexflowBackendType()),this.ctx=this.renderer.getContext()}initializeHeadless(e=300,t=300){this.graphicalMusicPage||(this.graphicalMusicPage=new he(void 0),this.graphicalMusicPage.PageNumber=1),this.canvas=document.createElement("canvas"),this.canvas.width=e,this.canvas.height=t,this.renderer=new ji.Renderer(this.canvas,this.getVexflowBackendType()),this.ctx=this.renderer.getContext()}getContext(){return this.ctx}free(){this.canvas&&(this.canvas.width=0,this.canvas.height=0,this.canvas.remove(),delete this.canvas,this.canvas=null)}clear(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.rules.PageBackgroundColor&&(this.ctx.save(),this.ctx.setFillStyle(this.rules.PageBackgroundColor),this.zoom=1,this.ctx.fillRect(0,0,this.canvas.width/this.zoom,this.canvas.height/this.zoom),this.ctx.restore())}scale(e){this.ctx.scale(e,e)}translate(e,t){this.CanvasRenderingCtx.translate(e,t)}renderText(e,t,i,s,n,r,o=void 0,a=void 0){const l=this.CanvasRenderingCtx.font;this.CanvasRenderingCtx.save(),this.CanvasRenderingCtx.font=Jt.font(e,t,i,this.rules,a),this.CanvasRenderingCtx.fillStyle=o,this.CanvasRenderingCtx.strokeStyle=o,this.CanvasRenderingCtx.fillText(s,r.x,r.y+n),this.CanvasRenderingCtx.restore(),this.CanvasRenderingCtx.font=l}renderRectangle(e,t,i,s=1){const n=this.CanvasRenderingCtx.fillStyle;this.CanvasRenderingCtx.fillStyle=i||Jt.style(t),this.CanvasRenderingCtx.globalAlpha=s,this.ctx.fillRect(e.x,e.y,e.width,e.height),this.CanvasRenderingCtx.fillStyle=n,this.CanvasRenderingCtx.globalAlpha=1}renderLine(e,t,i="#FF0000FF",s=2,n){const r=this.CanvasRenderingCtx.strokeStyle;this.CanvasRenderingCtx.strokeStyle=i,this.CanvasRenderingCtx.beginPath(),this.CanvasRenderingCtx.moveTo(e.x,e.y),this.CanvasRenderingCtx.lineTo(t.x,t.y),this.CanvasRenderingCtx.stroke(),this.CanvasRenderingCtx.strokeStyle=r}renderCurve(e){this.ctx.beginPath(),this.ctx.moveTo(e[0].x,e[0].y),this.ctx.bezierCurveTo(e[1].x,e[1].y,e[2].x,e[2].y,e[3].x,e[3].y),this.ctx.lineTo(e[7].x,e[7].y),this.ctx.bezierCurveTo(e[6].x,e[6].y,e[5].x,e[5].y,e[4].x,e[4].y),this.ctx.lineTo(e[0].x,e[0].y),this.ctx.closePath(),this.ctx.fill()}renderPath(e,t=!0,i){let s;this.ctx.beginPath();for(const n of e)s?this.ctx.lineTo(n.x,n.y):(this.ctx.moveTo(n.x,n.y),s=n);this.ctx.closePath(),t?this.ctx.fill():this.ctx.stroke()}get CanvasRenderingCtx(){return this.ctx.vexFlowCanvasContext}}class Ji{constructor(e){this.mStaffLineParent=e,this.mRules=e.ParentMusicSystem.rules}updateLines(e){const t=this.StaffLineParent.Measures;if(e.length!==t.length)if(s.warn("SkyBottomLineCalculator: lengths of calculation result array and measure array do not match"),e.length<t.length)for(;e.length<t.length;)e.push(new Yi([],[]));else e=e.slice(0,t.length);const i=Math.max(Math.ceil(this.StaffLineParent.PositionAndShape.Size.width*this.SamplingUnit),1);this.mSkyLine=[],this.mBottomLine=[];for(const{skyLine:s,bottomLine:h}of e)this.mSkyLine.push(...s),this.mBottomLine.push(...h);const n=this.mSkyLine.length/i,r=[],o=[];for(let s=0;s<this.mSkyLine.length&&r.length!==i;s+=n){const e=Math.min(this.mSkyLine.length,s+n);let t=this.mSkyLine.slice(s,e+1);r.push(Math.min(...t)),t=this.mBottomLine.slice(s,e+1),o.push(Math.max(...t))}this.mSkyLine=r,this.mBottomLine=o,this.mSkyLine.length!==i&&s.debug(`SkyLine calculation was not correct (${this.mSkyLine.length} instead of ${i})`);const a=Math.max(...this.mSkyLine);this.mSkyLine=this.mSkyLine.map((e=>(e-a)/zt+this.StaffLineParent.TopLineOffset));const l=Math.min(...this.mBottomLine);this.mBottomLine=this.mBottomLine.map((e=>(e-l)/zt+this.StaffLineParent.BottomLineOffset))}calculateLines(){const e=Math.max(Math.ceil(this.StaffLineParent.PositionAndShape.Size.width*this.SamplingUnit),1);this.mSkyLine=[],this.mBottomLine=[];const t=new Ki(this.StaffLineParent.ParentMusicSystem.rules);for(const a of this.StaffLineParent.Measures){a.PositionAndShape.calculateAbsolutePositionsRecursive(0,0);const e=a.getVFStave();let i=e.getWidth();if(i>0||a.IsExtraGraphicalMeasure||(s.warn("SkyBottomLineCalculator: width not > 0 in measure "+a.MeasureNumber),i=50),!(i>=50)&&a.IsExtraGraphicalMeasure)continue;t.initializeHeadless(i);const n=t.getContext(),r=t.getCanvas();i=r.width;const l=r.height;"jianpu"===this.mRules.DYMusicScoreType||e.setY(e.y+100);const h=e.getWidth();e.setWidth(i),a.format(),e.setWidth(h);try{a.draw(n)}catch(o){s.warn("SkyBottomLineCalculator.calculateLines.draw",o)}const u=n.getImageData(0,0,i,l),c=4,d=Math.max(Math.ceil(a.PositionAndShape.Size.width*this.mRules.SamplingUnit),1),f=new Array(d),m=new Array(d);for(let t=0;t<i;t++){for(let e=0;e<l;e++){const s=e*i*c+t*c;if(u.data[s+3]>0){f[t]=e;break}}for(let e=l;e>0;e--){const s=e*i*c+t*c;if(u.data[s+3]>0){m[t]=e;break}}}for(let t=0;t<f.length;t++)void 0===f[t]&&(f[t]=Math.max(this.findPreviousValidNumber(t,f),this.findNextValidNumber(t,f)));for(let t=0;t<m.length;t++)void 0===m[t]&&(m[t]=Math.max(this.findPreviousValidNumber(t,m),this.findNextValidNumber(t,m)));this.mSkyLine.push(...f),this.mBottomLine.push(...m),t.clear()}const i=this.mSkyLine.length/e,n=[],r=[];for(let s=0;s<this.mSkyLine.length&&n.length!==e;s+=i){const e=Math.min(this.mSkyLine.length,s+i);let t=this.mSkyLine.slice(s,e+1);n.push(Math.min(...t)),t=this.mBottomLine.slice(s,e+1),t.length&&r.push(Math.max(...t))}this.mSkyLine=n,this.mBottomLine=r,this.mSkyLine.length!==e&&s.debug(`SkyLine calculation was not correct (${this.mSkyLine.length} instead of ${e})`),this.mSkyLine=this.mSkyLine.map((e=>(e-Math.max(...this.mSkyLine))/zt+this.StaffLineParent.TopLineOffset)),this.mBottomLine=this.mBottomLine.map((e=>(e-Math.min(...this.mBottomLine))/zt+this.StaffLineParent.BottomLineOffset))}updateSkyLineWithLine(e,t,i){const s=Math.floor(e.x*this.SamplingUnit),n=Math.ceil(t.x*this.SamplingUnit);for(let r=s+1;r<Math.min(n,this.SkyLine.length);r++)this.SkyLine[r]=i}updateSkyLineWithWedge(e,t){let i=Math.floor(e.x*this.SamplingUnit),s=Math.ceil(t.x*this.SamplingUnit),n=(t.y-e.y)/(t.x-e.x);s-i<=1&&(s++,n=0),i<0&&(i=0),i>=this.BottomLine.length&&(i=this.BottomLine.length-1),s<0&&(s=0),s>=this.BottomLine.length&&(s=this.BottomLine.length),this.SkyLine[i]=e.y;for(let r=i+1;r<Math.min(s,this.SkyLine.length);r++)this.SkyLine[r]=this.SkyLine[r-1]+n/this.SamplingUnit}updateBottomLineWithWedge(e,t){let i=Math.floor(e.x*this.SamplingUnit),s=Math.ceil(t.x*this.SamplingUnit),n=(t.y-e.y)/(t.x-e.x);s-i<=1&&(s++,n=0),i<0&&(i=0),i>=this.BottomLine.length&&(i=this.BottomLine.length-1),s<0&&(s=0),s>=this.BottomLine.length&&(s=this.BottomLine.length),this.BottomLine[i]=e.y;for(let r=i+1;r<s;r++)this.BottomLine[r]=this.BottomLine[r-1]+n/this.SamplingUnit}updateSkyLineInRange(e,t,i){this.updateInRange(this.mSkyLine,e,t,i)}updateBottomLineInRange(e,t,i){this.updateInRange(this.BottomLine,e,t,i)}resetSkyLineInRange(e,t){this.updateInRange(this.SkyLine,e,t)}resetBottomLineInRange(e,t){this.setInRange(this.BottomLine,e,t)}setSkyLineWithValue(e){this.SkyLine.forEach((t=>e))}setBottomLineWithValue(e){this.BottomLine.forEach((t=>e))}getLeftIndexForPointX(e,t){const i=Math.floor(e*this.SamplingUnit);return i<0?0:i>=t?t-1:i}getRightIndexForPointX(e,t){const i=Math.ceil(e*this.SamplingUnit);return i<0?0:i>=t?t-1:i}updateStaffLineBorders(){this.mStaffLineParent.PositionAndShape.BorderTop=this.getSkyLineMin(),this.mStaffLineParent.PositionAndShape.BorderMarginTop=this.getSkyLineMin(),this.mStaffLineParent.PositionAndShape.BorderBottom=this.getBottomLineMax(),this.mStaffLineParent.PositionAndShape.BorderMarginBottom=this.getBottomLineMax()}getSkyLineMin(){return Math.min(...this.SkyLine.filter((e=>!isNaN(e))))}getSkyLineMinAtPoint(e){const t=Math.round(e*this.SamplingUnit);return this.mSkyLine[t]}getSkyLineMinInRange(e,t){return this.getMinInRange(this.SkyLine,e,t)}getBottomLineMax(){return Math.max(...this.BottomLine.filter((e=>!isNaN(e))))}getBottomLineMaxAtPoint(e){const t=Math.round(e*this.SamplingUnit);return this.mBottomLine[t]}getBottomLineMaxInRange(e,t){return this.getMaxInRange(this.BottomLine,e,t)}getBottomLineMaxInBoundingBox(e){const t=Math.floor(e.AbsolutePosition.x+e.BorderLeft),i=Math.ceil(e.AbsolutePosition.x+e.BorderRight);return this.getMaxInRange(this.mBottomLine,t,i)}updateWithBoundingBoxRecursively(e){if(e.ChildElements&&e.ChildElements.length>0)for(const t of e.ChildElements)this.updateWithBoundingBoxRecursively(t);else{const t=e.BorderTop+e.AbsolutePosition.y,i=e.BorderBottom+e.AbsolutePosition.y;if(t<0){const i=Math.floor(e.AbsolutePosition.x+e.BorderLeft),s=Math.ceil(e.AbsolutePosition.x+e.BorderRight);this.updateInRange(this.mSkyLine,i,s,t)}else if(i>this.StaffLineParent.StaffHeight){const t=Math.floor(e.AbsolutePosition.x+e.BorderLeft),s=Math.ceil(e.AbsolutePosition.x+e.BorderRight);this.updateInRange(this.mBottomLine,t,s,i)}}}findPreviousValidNumber(e,t){for(let i=e;i>=0;i--)if(!isNaN(t[i]))return t[i];return 0}findNextValidNumber(e,t){if(e>=t.length)return t[e-1];for(let i=e;i<t.length;i++)if(!isNaN(t[i]))return t[i];return 0}drawPixel(e,t,i="#FF0000FF"){const s=t.getContext(),n=s.fillStyle;s.fillStyle=i,s.fillRect(e.x,e.y,2,2),s.fillStyle=n}updateInRange(e,t=0,i=e.length,s=0){if(t=Math.floor(t*this.SamplingUnit),(i=Math.ceil(i*this.SamplingUnit))<t)throw new Error("start index of line is greater than the end index");t<0&&(t=0),i>e.length&&(i=e.length);for(let n=t;n<i;n++)e[n]=Math.abs(s)>Math.abs(e[n])?s:e[n]}setInRange(e,t=0,i=e.length,s=0){if(t=Math.floor(t*this.SamplingUnit),(i=Math.ceil(i*this.SamplingUnit))<t)throw new Error("start index of line is greater then the end index");t<0&&(t=0),i>e.length&&(i=e.length);for(let n=t;n<i;n++)e[n]=s}getMinInRange(e,t,i){return t=Math.floor(t*this.SamplingUnit),i=Math.ceil(i*this.SamplingUnit),e?(t<0&&(t=0),t>=e.length&&(t=e.length-1),i<0&&(i=0),i>=e.length&&(i=e.length),t>=0&&i<=e.length?Math.min(...e.slice(t,i+1)):void 0):Number.MAX_VALUE}getMaxInRange(e,t,i){return t=Math.floor(t*this.SamplingUnit),i=Math.ceil(i*this.SamplingUnit),e?(t<0&&(t=0),t>=e.length&&(t=e.length-1),i<0&&(i=0),i>=e.length&&(i=e.length),t>=0&&i<=e.length?Math.max(...e.slice(t,i+1)):void 0):Number.MIN_VALUE}get SamplingUnit(){return this.mRules.SamplingUnit}get StaffLineParent(){return this.mStaffLineParent}get SkyLine(){return this.mSkyLine}get BottomLine(){return this.mBottomLine}}class qi extends Ji{recursiveUpdate(e,t,i,s){const n=e.getBBox(),r=n.y/zt,o=n.height/zt+r,[l,h]=s;if(r<t.top||o>t.bottom)switch(e.tagName.toLowerCase()){case"g":for(const n of e.children)this.recursiveUpdate(n,t,i,s);break;case"circle":case"rect":case"line":case"path":let u=Math.floor((n.x-i.x)/zt*this.mRules.SamplingUnit);const c=u+Math.ceil(n.width/zt*this.mRules.SamplingUnit);if(e.parentElement.classList.contains("vf-beams")&&e.hasAttribute("d")){const t=a(e.getAttribute("d"));if(5===t.length){const e=t[0],i=t[3],s=(i.end.y-e.end.y)/(i.end.x-e.end.x);let n=e.end.y/zt;for(;u<=c;u++)n<l[u]&&(l[u]=n),n>h[u]&&(h[u]=n),n+=s/this.mRules.SamplingUnit}}else for(;u<=c;u++)r<l[u]&&(l[u]=r),o>h[u]&&(h[u]=o)}}calculateLinesForMeasure(e,t){var i,s;const n=t.getBBox(),r=Math.max(Math.round(e.PositionAndShape.Size.width*this.mRules.SamplingUnit),1),o=n.height/zt,a=t.getElementsByClassName("vf-stave")[0].getBBox();let l=(null==a?void 0:a.height)/zt,h=(null==a?void 0:a.y)/zt;const u=e.getVFStave();let c=(null!==(i=u.options)&&void 0!==i&&i.num_lines?u.options.num_lines:5)-1,d=-1,f=0;const m=[c];for(const P of null===(p=u.options)||void 0===p?void 0:p.line_config){var p;P.visible?(-1===d&&(d=f),m.push(f)):c--,f++}-1===d&&(d=0),c=m.pop()-d;const g=null===(s=u.options)||void 0===s?void 0:s.spacing_between_lines_px,S=c*g/zt;l-S>.2&&(l=S,h=d*g/zt);const y=h+l,b=new Array(r).fill(h),M=new Array(r).fill(y),v=[b,M];if(o>l)for(const P of t.children)this.recursiveUpdate(P,{top:h,bottom:y},n,[b,M]);return v}calculateLines(){this.mSkyLine=[],this.mBottomLine=[];const e=document.createElement("div");document.body.append(e);const t=new Xt(this.mRules);t.initialize(e,1,"0");const i=t.getContext(),s=i.openGroup();s.classList.add("staffline");for(const n of this.StaffLineParent.Measures){n.PositionAndShape.calculateAbsolutePositionsRecursive(0,0),n.setAbsoluteCoordinates(n.PositionAndShape.AbsolutePosition.x*zt,n.PositionAndShape.AbsolutePosition.y*zt);const e=n.draw(i),[t,s]=this.calculateLinesForMeasure(n,e);this.mSkyLine.push(...t),this.mBottomLine.push(...s)}i.closeGroup();for(const n of s.getElementsByClassName("vf-ties"))for(const e of n.childNodes)if("path"===e.nodeName.toLowerCase()){const t=e.getBBox();let i=Math.floor(t.x/zt*this.mRules.SamplingUnit);const s=i+Math.ceil(t.width/zt*this.mRules.SamplingUnit),n=t.y/zt,r=t.height/zt+n;for(;i<=s;i++)n<this.mSkyLine[i]&&(this.mSkyLine[i]=n),r>this.mBottomLine[i]&&(this.mBottomLine[i]=r)}t.clear(),e.remove()}}const $i=n.Flow;class Qi{constructor(){this.hasBBox=!1,void 0!==document.createElementNS("http://www.w3.org/2000/svg","g").getBBox&&(this.hasBBox=!0)}createMusicSystem(e,t){return new wi(e,t)}createStaffLine(e,t){return new Xi(e,t)}createSkyBottomLineCalculator(e){return e.ParentMusicSystem.rules.PerformanceMode&&this.hasBBox?new qi(e):new Ji(e)}createGraphicalMeasure(e,t,i=!1){return new Ci(t,e,void 0)}createMultiRestMeasure(e,t,i){return new Hi(t,e,i)}createTabStaffMeasure(e,t){return new Oi(t,e)}createExtraGraphicalMeasure(e){const t=new Ci(e.ParentStaff,void 0,e);return t.IsExtraGraphicalMeasure=!0,t.ExtraGraphicalMeasurePreviousMeasure=e.Measures.last(),t}createStaffEntry(e,t){return new Di(t,e,void 0)}createVoiceEntry(e,t){return new Ii(e,t)}createNote(e,t,i,s=$t.NONE,n,r=void 0){return new Vi(e,t,i,s,n,r)}createGraceNote(e,t,i,s,n=$t.NONE){return new Vi(e,t,i,n,s)}addGraphicalAccidental(e,t){e.setAccidental(t)}addFermataAtTiedEndNote(e,t){}createInStaffClef(e,t){const i=e,s=Jt.Clef(t,"small");i.vfClefBefore=new $i.ClefNote(s.type,s.size,s.annotation)}createChordSymbols(e,t,i,s){const n=t.parentMeasure.parentSourceMeasure.Rules;let r=0;const o=n.ChordSymbolXSpacing;for(const a of e.ChordContainers){let e=t.PositionAndShape;1===t.graphicalVoiceEntries.length&&1===t.graphicalVoiceEntries[0].notes.length&&t.graphicalVoiceEntries[0].notes[0].sourceNote.isWholeRest()&&(e=t.parentMeasure.PositionAndShape,r+=t.parentMeasure.beginInstructionsWidth,r+=n.ChordSymbolWholeMeasureRestXOffset);const l=new ki(a,e,n.ChordSymbolTextHeight,i,s,t.parentMeasure.parentSourceMeasure.Rules),h=l.GraphicalLabel;h.PositionAndShape.RelativePosition.y-=n.ChordSymbolYOffset,h.setLabelPositionAndShapeBorders();let u=0;h.PositionAndShape.Size.width<n.ChordSymbolExtraXShiftWidthThreshold&&(u=n.ChordSymbolExtraXShiftForShortChordSymbols),h.PositionAndShape.RelativePosition.x+=r+u,h.setLabelPositionAndShapeBorders(),l.PositionAndShape.calculateBoundingBox(),t.graphicalChordContainers.push(l),r+=h.PositionAndShape.Size.width+o}}createGraphicalTechnicalInstruction(e,t){}}class Zi{constructor(e,t=void 0,i=void 0){this.tie=e,this.startNote=t,this.endNote=i}get SVGElement(){return this.vfTie.getAttribute("el")}get GetTie(){return this.tie}get StartNote(){return this.startNote}get Tie(){return this.tie}set StartNote(e){this.startNote=e}get EndNote(){return this.endNote}set EndNote(e){this.endNote=e}}class es{constructor(e,t,i,s){var n,r;this.lyricsEntry=e,this.graphicalStaffEntry=t;const o=t.parentMeasure.parentSourceMeasure.Rules.LyricsAlignmentStandard;e.Text.length>=4&&e.Parent.Notes[0].Length.Denominator>4&&ce.LeftBottom;const a=new pt(e.Text);a.isLyricText=!0,a.lyricExtendNoteId=null==e||null===(n=e.Parent)||void 0===n||null===(r=n.Notes[0])||void 0===r?void 0:r.NoteToGraphicalNoteObjectId,a.lyricVerseNumber=null==e?void 0:e.verseNumber;const l=this.graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules;this.graphicalLabel=new mt(a,i,o,l,t.PositionAndShape),this.graphicalLabel.Label.colorDefault=l.DefaultColorLyrics,this.graphicalLabel.PositionAndShape.RelativePosition=new z(0,s),this.graphicalLabel.setLabelPositionAndShapeBorders(),this.graphicalLabel.PositionAndShape.Size.width<l.LyricsExtraXShiftForShortLyricsWidthThreshold&&(this.graphicalLabel.PositionAndShape.RelativePosition.x+=l.LyricsExtraXShiftForShortLyrics,this.graphicalLabel.CenteringXShift=l.LyricsExtraXShiftForShortLyrics),o===ce.LeftBottom&&(this.graphicalLabel.PositionAndShape.RelativePosition.x-=1)}hasDashFromLyricWord(){if(!this.ParentLyricWord)return!1;const e=this.ParentLyricWord.GraphicalLyricsEntries.indexOf(this);return this.ParentLyricWord.GraphicalLyricsEntries.length>1&&e<this.ParentLyricWord.GraphicalLyricsEntries.length-1}get LyricsEntry(){return this.lyricsEntry}get ParentLyricWord(){return this.graphicalLyricWord}set ParentLyricWord(e){this.graphicalLyricWord=e}get GraphicalLabel(){return this.graphicalLabel}set GraphicalLabel(e){this.graphicalLabel=e}get StaffEntryParent(){return this.graphicalStaffEntry}set StaffEntryParent(e){this.graphicalStaffEntry=e}}class ts{constructor(e){this.graphicalLyricsEntries=[],this.lyricWord=e,this.initialize()}get GetLyricWord(){return this.lyricWord}get GraphicalLyricsEntries(){return this.graphicalLyricsEntries}set GraphicalLyricsEntries(e){this.graphicalLyricsEntries=e}isFilled(){for(let e=0;e<this.graphicalLyricsEntries.length;e++)if(!this.graphicalLyricsEntries[e])return!1;return!0}initialize(){for(let e=0;e<this.lyricWord.Syllables.length;e++)this.graphicalLyricsEntries.push(void 0)}}class is extends ne{constructor(e,t){super(),this.getOctaveShift=e,this.setSymbol(),this.PositionAndShape=new oe(this,t)}setSymbol(){switch(this.getOctaveShift.Type){case $t.VA8:this.octaveSymbol=It.VA8;break;case $t.VB8:this.octaveSymbol=It.VB8;break;case $t.MA15:this.octaveSymbol=It.MA15;break;case $t.MB15:this.octaveSymbol=It.MB15;break;default:throw new y("")}}}const ss=n.Flow;class ns extends is{constructor(e,t){switch(super(e,t),e.Type){case $t.VA8:this.position=ss.TextBracket.Positions.TOP,this.supscript="va",this.text="8";break;case $t.MA15:this.position=ss.TextBracket.Positions.TOP,this.supscript="ma",this.text="15";break;case $t.VB8:this.position=ss.TextBracket.Positions.BOTTOM,this.supscript="vb",this.text="8";break;case $t.MB15:this.position=ss.TextBracket.Positions.BOTTOM,this.supscript="mb",this.text="15";break;default:s.error("Unknown or NONE octaveshift. This should not be called!")}}setStartNote(e){for(const t of e.graphicalVoiceEntries){const e=t;if(null!=e&&e.vfStaveNote)return this.startNote=e.vfStaveNote,!0}return!1}setEndNote(e){for(const i of e.graphicalVoiceEntries){const s=i;var t;if(null!=s&&s.vfStaveNote)return this.endNote=s.vfStaveNote,this.endMeasure=e.parentMeasure,null!==(t=this.endMeasure)&&void 0!==t&&t.parentSourceMeasure.Rules.OctaveShiftOnWholeMeasureNoteUntilEndOfMeasure&&s.notes[0].sourceNote.isWholeMeasureNote()&&(this.graphicalEndAtMeasureEnd=!0),!0}return!1}getTextBracket(){let e,t=this.endNote;const i=this;this.graphicalEndAtMeasureEnd&&(e={getAbsoluteX:()=>10*(i.endMeasure.PositionAndShape.AbsolutePosition.x+i.endMeasure.PositionAndShape.Size.width),getGlyph:()=>({getWidth:()=>0})}),e&&(t=e);const s=new ss.TextBracket({position:this.position,start:this.startNote,stop:t,superscript:this.supscript,text:this.text});return this.endsOnDifferentStaffLine&&(s.render_options.show_bracket=!1),s}}class rs extends kt{constructor(e,t,i){super(e,t,i);const s=new pt(this.Expression);this.label=new mt(s,this.rules.ContinuousDynamicTextHeight,ce.CenterCenter,this.rules,this.PositionAndShape),this.label.Label.fontStyle=me.BoldItalic,this.label.setLabelPositionAndShapeBorders(),this.PositionAndShape.calculateBoundingBox()}get InstantaneousDynamic(){return this.mInstantaneousDynamicExpression}get Expression(){return P[this.mInstantaneousDynamicExpression.DynEnum]}}const os=class{constructor(){os.tPow3=new Array(os.bezierCurveStepSize),os.oneMinusTPow3=new Array(os.bezierCurveStepSize),os.bezierFactorOne=new Array(os.bezierCurveStepSize),os.bezierFactorTwo=new Array(os.bezierCurveStepSize);for(let e=0;e<os.bezierCurveStepSize;e++){const t=e/os.bezierCurveStepSize;os.tPow3[e]=Math.pow(t,3),os.oneMinusTPow3[e]=Math.pow(1-t,3),os.bezierFactorOne[e]=3*Math.pow(1-t,2)*t,os.bezierFactorTwo[e]=3*(1-t)*Math.pow(t,2)}}calculateCurvePointAtIndex(e){const t=Math.round(e*os.bezierCurveStepSize);return t<0||t>=os.bezierCurveStepSize?new z:new z(os.oneMinusTPow3[t]*this.bezierStartPt.x+os.bezierFactorOne[t]*this.bezierStartControlPt.x+os.bezierFactorTwo[t]*this.bezierEndControlPt.x+os.tPow3[t]*this.bezierEndPt.x,os.oneMinusTPow3[t]*this.bezierStartPt.y+os.bezierFactorOne[t]*this.bezierStartControlPt.y+os.bezierFactorTwo[t]*this.bezierEndControlPt.y+os.tPow3[t]*this.bezierEndPt.y)}};let as=os;as.bezierCurveStepSize=1e3;const ls=n.Flow,hs=class extends as{constructor(e,t){super(),this.staffEntries=[],this.slur=e,this.rules=t}static Compare(e,t){if(e.staffEntries.length<1)return-1;if(t.staffEntries.length<1)return 1;const i=u.minus(e.staffEntries[e.staffEntries.length-1].getAbsoluteTimestamp(),e.staffEntries[0].getAbsoluteTimestamp()),s=u.minus(t.staffEntries[t.staffEntries.length-1].getAbsoluteTimestamp(),t.staffEntries[0].getAbsoluteTimestamp());return i.RealValue>s.RealValue?1:s.RealValue>i.RealValue?-1:0}calculateCurve(e){const t=this.staffEntries[0],i=this.staffEntries[this.staffEntries.length-1];let s=t.findGraphicalNoteFromNote(this.slur.StartNote);!s&&this.graceStart&&(s=t.findGraphicalNoteFromGraceNote(this.slur.StartNote)),s||(s=t.findEndTieGraphicalNoteFromNoteWithStartingSlur(this.slur.StartNote,this.slur));let n=i.findGraphicalNoteFromNote(this.slur.EndNote);!n&&this.graceEnd&&(n=i.findGraphicalNoteFromGraceNote(this.slur.EndNote));const r=t.parentMeasure.ParentStaffLine,o=r.SkyBottomLineCalculator;this.calculatePlacement(o,r);const a=this.calculateStartAndEnd(s,n,r,e,o),l=a.startX,h=a.endX;let u=a.startY,c=a.endY;const f=e.SlurTangentMinAngle,m=e.SlurTangentMaxAngle;let p;if(this.placement===d.Above){u-=e.SlurNoteHeadYOffset,c-=e.SlurNoteHeadYOffset;const t=new z(this.staffEntries[0].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[0].PositionAndShape.RelativePosition.x,u);s?t.x+=this.staffEntries[0].PositionAndShape.BorderRight:t.x=this.staffEntries[0].parentMeasure.beginInstructionsWidth,this.graceStart&&(t.x+=i.PositionAndShape.RelativePosition.x);const a=new z(this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[this.staffEntries.length-1].PositionAndShape.RelativePosition.x,c);if(n?a.x+=this.staffEntries[this.staffEntries.length-1].PositionAndShape.BorderLeft:a.x=this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.Size.width,this.graceEnd&&(a.x+=i.staffEntryParent.PositionAndShape.RelativePosition.x),p=this.calculateTopPoints(t,a,r,o),0===p.length){const e=new z((a.x-t.x)/2+t.x,(a.y-t.y)/2+t.y);p.push(e)}const d=Math.atan((c-u)/(h-l)),g=new z(0,0);let S=new z(h-l,-(c-u));const y=Be.getRotationMatrix(d),b=y.getTransposeMatrix();S=y.vectorMultiplication(S);const M=this.calculateTranslatedAndRotatedPointListAbove(p,l,u,y),v=this.calculateMaxLeftSlope(M,g,S),P=this.calculateMaxRightSlope(M,g,S),E=g.y-g.x*v,L=S.y-S.x*P,x=new z;let T=!1;Math.abs(Math.abs(v)-Math.abs(P))<1e-4?(x.x=S.x/2,x.y=0,T=!0):(x.x=(L-E)/(v-P),x.y=v*x.x+E);const w=this.calculateHeightWidthRatio(S.x,M),I=0,A=0;let R=f,N=-f;if(!T){const e=this.calculateAngles(f,v,P,m);R=e.startAngle,N=e.endAngle}const C=this.calculateControlPoints(S.x,R,N,M,w,u,c);let B=C.startControlPoint,D=C.endControlPoint;B=b.vectorMultiplication(B),B.x+=l,B.y=-B.y+u,D=b.vectorMultiplication(D),D.x+=l,D.y=-D.y+u,this.bezierStartPt=new z(l,u-I),this.bezierStartControlPt=new z(B.x,B.y-I),this.bezierEndControlPt=new z(D.x,D.y-A),this.bezierEndPt=new z(h,c-A);const V=r.SkyLine.length,k=o.getLeftIndexForPointX(this.bezierStartPt.x,V),F=o.getLeftIndexForPointX(this.bezierEndPt.x,V),O=this.bezierEndPt.x-this.bezierStartPt.x,_=o.SamplingUnit;for(let e=k;e<F;e++){const t=e/_-this.bezierStartPt.x,i=this.calculateCurvePointAtIndex(Math.abs(t)/O);let s=o.getLeftIndexForPointX(i.x,V);s>=k&&(r.SkyLine[s]=Math.min(r.SkyLine[s],i.y)),s++,s<V&&(r.SkyLine[s]=Math.min(r.SkyLine[s],i.y))}}else{u+=e.SlurNoteHeadYOffset,c+=e.SlurNoteHeadYOffset;const t=new z(this.staffEntries[0].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[0].PositionAndShape.RelativePosition.x,u);s?t.x+=this.staffEntries[0].PositionAndShape.BorderRight:t.x=this.staffEntries[0].parentMeasure.beginInstructionsWidth,this.graceStart&&(t.x+=i.PositionAndShape.RelativePosition.x);const a=new z(this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[this.staffEntries.length-1].PositionAndShape.RelativePosition.x,c);if(n?a.x+=this.staffEntries[this.staffEntries.length-1].PositionAndShape.BorderLeft:a.x=this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.Size.width,this.graceEnd&&(a.x+=i.staffEntryParent.PositionAndShape.RelativePosition.x),p=this.calculateBottomPoints(t,a,r,o),0===p.length){const e=new z((a.x-t.x)/2+t.x,(a.y-t.y)/2+t.y);p.push(e)}const d=Math.atan((c-u)/(h-l)),g=new z(0,0);let S=new z(h-l,c-u);const y=Be.getRotationMatrix(-d),b=y.getTransposeMatrix();S=y.vectorMultiplication(S);const M=this.calculateTranslatedAndRotatedPointListBelow(p,l,u,y),v=this.calculateMaxLeftSlope(M,g,S),P=this.calculateMaxRightSlope(M,g,S),E=g.y-g.x*v,L=S.y-S.x*P,x=new z;let T=!1;Math.abs(Math.abs(v)-Math.abs(P))<1e-4?(x.x=S.x/2,x.y=0,T=!0):(x.x=(L-E)/(v-P),x.y=v*x.x+E);const w=this.calculateHeightWidthRatio(S.x,M),I=0,A=0;let R=f,N=-f;if(!T){const e=this.calculateAngles(f,v,P,m);R=e.startAngle,N=e.endAngle}const C=this.calculateControlPoints(S.x,R,N,M,w,u,c);let B=C.startControlPoint,D=C.endControlPoint;B=b.vectorMultiplication(B),B.x+=l,B.y+=u,D=b.vectorMultiplication(D),D.x+=l,D.y+=u,this.bezierStartPt=new z(l,u+I),this.bezierStartControlPt=new z(B.x,B.y+I),this.bezierEndControlPt=new z(D.x,D.y+A),this.bezierEndPt=new z(h,c+A);const V=r.BottomLine.length,k=o.getLeftIndexForPointX(this.bezierStartPt.x,V),F=o.getLeftIndexForPointX(this.bezierEndPt.x,V),O=this.bezierEndPt.x-this.bezierStartPt.x,_=o.SamplingUnit;for(let e=k;e<F;e++){const t=e/_-this.bezierStartPt.x,i=this.calculateCurvePointAtIndex(Math.abs(t)/O);let s=o.getLeftIndexForPointX(i.x,V);s>=k&&(r.BottomLine[s]=Math.max(r.BottomLine[s],i.y)),s++,s<V&&(r.BottomLine[s]=Math.max(r.BottomLine[s],i.y))}}}calculateStartAndEnd(e,t,i,s,n){let r=0,o=0,a=0,l=0;if(e){r=e.PositionAndShape.RelativePosition.x+e.parentVoiceEntry.parentStaffEntry.PositionAndShape.RelativePosition.x+e.parentVoiceEntry.parentStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x,this.graceStart&&(r+=e.parentVoiceEntry.parentStaffEntry.staffEntryParent.PositionAndShape.RelativePosition.x);const t=e.parentVoiceEntry;this.placement===d.Above?(o=t.PositionAndShape.RelativePosition.y+t.PositionAndShape.BorderTop,this.rules.SlurPlacementUseSkyBottomLine&&(o=Math.min(l,t.parentStaffEntry.getSkylineMin()))):(o=t.PositionAndShape.RelativePosition.y+t.PositionAndShape.BorderBottom,this.rules.SlurPlacementUseSkyBottomLine&&(o=Math.max(l,t.parentStaffEntry.getBottomlineMax()))),t.parentVoiceEntry.StemDirection===dt.Down&&this.placement===d.Below&&(r-=.5),t.parentVoiceEntry.StemDirection===dt.Up&&this.placement===d.Above&&(r+=.5)}else r=0;if(t){a=t.PositionAndShape.RelativePosition.x+t.parentVoiceEntry.parentStaffEntry.PositionAndShape.RelativePosition.x+t.parentVoiceEntry.parentStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x,this.graceEnd&&(a+=t.parentVoiceEntry.parentStaffEntry.staffEntryParent.PositionAndShape.RelativePosition.x);const e=t.parentVoiceEntry;let i;for(const s of e.parentVoiceEntry.Articulations)if(i=s.placement,s.placement===d.NotYetDefined)for(const e of t.vfnote[0].modifiers)if(e.getCategory()===ls.Articulation.CATEGORY){e.position===ls.Modifier.Position.ABOVE?(s.placement=d.Above,i=d.Above):e.position===ls.Modifier.Position.BELOW&&(s.placement=d.Below,i=d.Below);break}this.placement===d.Above?(l=e.PositionAndShape.RelativePosition.y+e.PositionAndShape.BorderTop,this.rules.SlurPlacementUseSkyBottomLine&&(l=Math.min(l,e.parentStaffEntry.getSkylineMin())),i===d.Above&&(l-=this.rules.SlurEndArticulationYOffset)):(l=e.PositionAndShape.RelativePosition.y+e.PositionAndShape.BorderBottom,this.rules.SlurPlacementUseSkyBottomLine&&(l=Math.max(l,e.parentStaffEntry.getBottomlineMax())),i===d.Below&&(l+=this.rules.SlurEndArticulationYOffset)),e.parentVoiceEntry.StemDirection===dt.Down&&this.placement===d.Below&&(a-=.5),e.parentVoiceEntry.StemDirection===dt.Up&&this.placement===d.Above&&(a+=.5)}else a=i.PositionAndShape.Size.width;return e||t||(o=-1.5,l=-1.5),e||(o=this.placement===d.Above?l-1:l+1),t||(l=this.placement===d.Above?o-1:o+1),this.slur.startNoteHasMoreStartingSlurs()&&this.slur.isSlurLonger()&&(this.placement===d.Above?o-=s.SlursStartingAtSameStaffEntryYOffset:o+=s.SlursStartingAtSameStaffEntryYOffset),this.slur.endNoteHasMoreEndingSlurs()&&this.slur.isSlurLonger()&&(this.placement===d.Above?l-=s.SlursStartingAtSameStaffEntryYOffset:l+=s.SlursStartingAtSameStaffEntryYOffset),this.placement===d.Above?(o=Math.min(o,1.5),l=Math.min(l,1.5)):(o=Math.max(o,i.StaffHeight-1.5),l=Math.max(l,i.StaffHeight-1.5)),{startX:r,startY:o,endX:a,endY:l}}calculatePlacement(e,t){if(this.rules.SlurPlacementFromXML&&this.slur.PlacementXml!==d.NotYetDefined)return void(this.placement=this.slur.PlacementXml);for(let r=0,o=this.staffEntries.length;r<o;++r)if(this.staffEntries[r].parentMeasure.hasMultipleVoices())return void(this.slur.StartNote.ParentVoiceEntry.ParentVoice instanceof Ge||this.slur.EndNote.ParentVoiceEntry.ParentVoice instanceof Ge?this.placement=d.Below:this.placement=d.Above);for(let r=0,o=this.staffEntries.length;r<o;++r)if(this.staffEntries[r].LyricsEntries.length>0)return void(this.placement=d.Above);const i=this.staffEntries[0],s=this.staffEntries[this.staffEntries.length-1],n=i.graphicalVoiceEntries[0].parentVoiceEntry.StemDirection;if(n===s.graphicalVoiceEntries[0].parentVoiceEntry.StemDirection)this.placement=n===dt.Up?d.Below:d.Above,this.rules.SlurPlacementAtStems&&(this.placement=n===dt.Up?d.Above:d.Below);else{let n=i.PositionAndShape.BorderLeft+i.PositionAndShape.RelativePosition.x+i.parentMeasure.PositionAndShape.RelativePosition.x,r=s.PositionAndShape.BorderRight+s.PositionAndShape.RelativePosition.x+s.parentMeasure.PositionAndShape.RelativePosition.x;this.graceStart&&(n+=s.PositionAndShape.RelativePosition.x),this.graceEnd&&(r+=s.staffEntryParent.PositionAndShape.RelativePosition.x);const o=-1*e.getSkyLineMinInRange(n,r),a=e.getBottomLineMaxInRange(n,r)-t.StaffHeight;this.placement=a>o?d.Above:d.Below}}calculateTopPoints(e,t,i,s){const n=[];let r=s.getRightIndexForPointX(e.x,i.SkyLine.length),o=s.getLeftIndexForPointX(t.x,i.SkyLine.length);r<0&&(r=0),o>=i.SkyLine.length&&(o=i.SkyLine.length-1);for(let a=r;a<o;a++){const e=i.SkyLine[a];if(0!==e){const t=new z((.5+a)/s.SamplingUnit,e);n.push(t)}}return n}calculateBottomPoints(e,t,i,s){const n=[];let r=s.getRightIndexForPointX(e.x,i.BottomLine.length),o=s.getLeftIndexForPointX(t.x,i.BottomLine.length);r<0&&(r=0),o>=i.BottomLine.length&&(o=i.BottomLine.length-1);for(let a=r;a<o;a++){const e=i.BottomLine[a];if(0!==e){const t=new z((.5+a)/s.SamplingUnit,e);n.push(t)}}return n}calculateMaxLeftSlope(e,t,i){let s=-Number.MAX_VALUE;const n=t.x,r=t.y;for(let o=0;o<e.length;o++)Math.abs(e[o].y-Number.MAX_VALUE)<1e-4||Math.abs(e[o].y- -Number.MAX_VALUE)<1e-4||(s=Math.max(s,(e[o].y-r)/(e[o].x-n)));return s=Math.max(s,Math.abs(i.y-r)/(i.x-n)),s=Math.min(s,5.6713),s}calculateMaxRightSlope(e,t,i){let s=Number.MAX_VALUE;const n=i.x,r=i.y;for(let o=0;o<e.length;o++)Math.abs(e[o].y-Number.MAX_VALUE)<1e-4||Math.abs(e[o].y- -Number.MAX_VALUE)<1e-4||(s=Math.min(s,(r-e[o].y)/(n-e[o].x)));return s=Math.min(s,(r-t.y)/(n-t.x)),s=Math.max(s,-5.6713),s}getPointListMaxY(e){let t=-Number.MAX_VALUE;for(let i=0,s=e.length;i<s;++i){const s=e[i];Math.abs(s.y- -Number.MAX_VALUE)<1e-4||Math.abs(s.y-Number.MAX_VALUE)<1e-4||(t=Math.max(t,s.y))}return t}calculateTranslatedAndRotatedPointListAbove(e,t,i,s){const n=[];for(let r=0;r<e.length;r++){if(Math.abs(e[r].y-Number.MAX_VALUE)<1e-4||Math.abs(e[r].y- -Number.MAX_VALUE)<1e-4)continue;let o=new z(e[r].x-t,-(e[r].y-i));o=s.vectorMultiplication(o),n.push(o)}return n}calculateTranslatedAndRotatedPointListBelow(e,t,i,s){const n=[];for(let r=0;r<e.length;r++){if(Math.abs(e[r].y-Number.MAX_VALUE)<1e-4||Math.abs(e[r].y- -Number.MAX_VALUE)<1e-4)continue;let o=new z(e[r].x-t,e[r].y-i);o=s.vectorMultiplication(o),n.push(o)}return n}calculateHeightWidthRatio(e,t){return 0===t.length?0:Math.max(0,this.getPointListMaxY(t))/e}calculateControlPoints(e,t,i,s,n,r,o){let a=this.rules.SlurHeightFactor,l=1;const h=this.rules.SlurHeightFlattenLongSlursCutoffAngle,u=this.rules.SlurHeightFlattenLongSlursCutoffWidth;t>h&&e>u&&(l+=e/70*this.rules.SlurHeightFlattenLongSlursFactorByWidth,l*=1+t/30*this.rules.SlurHeightFlattenLongSlursFactorByAngle,a/=l);const c=Math.min(.5,Math.max(.1,1.7*t/80*a*Math.pow(Math.max(n,.05),.4))),d=Math.min(.5,Math.max(.1,1.7*-i/80*a*Math.pow(Math.max(n,.05),.4))),f=new z;f.x=e*c*Math.cos(t*hs.degreesToRadiansFactor),f.y=e*c*Math.sin(t*hs.degreesToRadiansFactor);const m=new z;m.x=e-e*d*Math.cos(i*hs.degreesToRadiansFactor),m.y=-e*d*Math.sin(i*hs.degreesToRadiansFactor);let p=f.y-m.y;for(;this.rules.SlurMaximumYControlPointDistance&&Math.abs(p)>this.rules.SlurMaximumYControlPointDistance;)p<0?(f.y+=1,m.y-=1):(f.y-=1,m.y+=1),p=f.y-m.y;return{startControlPoint:f,endControlPoint:m}}calculateAngles(e,t,i,s){let n=Math.atan(t)/hs.degreesToRadiansFactor;t>0?n+=20:n-=20;let r=Math.atan(i)/hs.degreesToRadiansFactor;return i<0?r-=20:r+=20,{startAngle:Math.min(Math.max(e,n),s),endAngle:Math.max(Math.min(-e,r),-s)}}};let us=hs;us.degreesToRadiansFactor=Math.PI/180;class cs{constructor(e){this.staffPitchListMapping=new i,this.baseLineNote=H.B,this.baseLineOctave=1,this.rules=e}trackNote(e){if(!(e instanceof Vi)||e.Clef().ClefType!==q.percussion||e.sourceNote.isRest()||0===this.rules.PercussionOneLineCutoff||-1===this.rules.PercussionForceVoicesOneLineCutoff)return;const t=e.parentVoiceEntry.parentStaffEntry.sourceStaffEntry.ParentStaff.idInMusicSheet;let i;this.staffPitchListMapping.containsKey(t)||this.staffPitchListMapping.setValue(t,new Array),i=this.staffPitchListMapping.getValue(t);const s=e.sourceNote.Pitch;cs.findOrInsert(i,s)}static PitchIndexOf(e,t,i=0){if(i>e.length-1)return-1;for(let s=i;s<e.length;s++){const i=e[s];if(t.OperatorEquals(i))return s}return-1}static findOrInsert(e,t){for(let i=0;i<e.length;i++){const s=e[i];if(t.OperatorEquals(s))return i;if(t.OperatorFundamentalLessThan(s))return e.splice(i,0,t),i}return e.push(t),e.length-1}positionNote(e){const t=e.parentVoiceEntry.parentStaffEntry.sourceStaffEntry.ParentStaff.idInMusicSheet;if(!(e instanceof Vi)||e.sourceNote.isRest()||!this.staffPitchListMapping.containsKey(t))return e;const i=this.staffPitchListMapping.getValue(t),s=this.rules.PercussionUseXMLDisplayStep&&void 0!==e.sourceNote.displayStepUnpitched;if(i.length>this.rules.PercussionOneLineCutoff&&!s&&!this.rules.PercussionUseCajon2NoteSystem)return e;const n=e,r=e.sourceNote.Pitch;let o=this.baseLineNote,a=this.baseLineOctave;if(this.rules.PercussionUseCajon2NoteSystem?r.FundamentalNote===H.C&&(o=H.G,a=1):this.rules.PercussionUseXMLDisplayStep&&void 0!==e.sourceNote.displayStepUnpitched&&(o=e.sourceNote.displayStepUnpitched,a=e.sourceNote.displayOctaveUnpitched+this.rules.PercussionOneLineXMLDisplayStepOctaveOffset),i.length<=this.rules.PercussionForceVoicesOneLineCutoff)n.setAccidental(new K(o,a,r.Accidental));else{const e=cs.PitchIndexOf(i,r);if(e>-1){const t=Math.ceil(i.length/2);if(!this.rules.PercussionUseXMLDisplayStep)if(e>=t)switch(a=2,(e-t)%5){case 1:o=H.E;break;case 2:o=H.G;break;case 3:o=H.B;break;case 4:o=H.D,a=3;break;default:o=H.C}else switch(e%5){case 1:o=H.F;break;case 2:o=H.D;break;case 3:o=H.B,a=0;break;case 4:o=H.G,a=0;break;default:o=H.A}const s=new K(o,a,r.Accidental);n.setAccidental(s);const l=n.parentVoiceEntry.parentVoiceEntry;!this.rules.SetWantedStemDirectionByXml&&l.Notes.length<2&&(s.Octave>this.baseLineOctave||s.FundamentalNote===this.baseLineNote&&s.Octave===this.baseLineOctave?n.parentVoiceEntry.parentVoiceEntry.WantedStemDirection=dt.Up:n.parentVoiceEntry.parentVoiceEntry.WantedStemDirection=dt.Down)}}return n}getStafflineUniquePositionCount(e){return this.staffPitchListMapping.containsKey(e)?this.staffPitchListMapping.getValue(e).length:0}}class ds extends ne{constructor(e,t){super(),this.getPedal=e,this.setSymbol(),this.PositionAndShape=new oe(this,t)}setSymbol(){!this.getPedal.IsLine&&this.getPedal.IsSign?this.pedalSymbol=It.PEDAL_SYMBOL:this.getPedal.IsLine&&this.getPedal.IsSign?this.pedalSymbol=It.PEDAL_MIXED:this.pedalSymbol=It.PEDAL_BRACKET}}class fs extends ds{constructor(e,t,i=!1,s=!1){switch(super(e,t),this.vfStyle=n.Flow.PedalMarking.Styles.BRACKET,this.ChangeBegin=!1,this.ChangeEnd=!1,this.line=-3,this.EndSymbolPositionAndShape=void 0,this.ChangeBegin=e.ChangeBegin,this.ChangeEnd=e.ChangeEnd,this.pedalSymbol){case It.PEDAL_SYMBOL:this.vfStyle=n.Flow.PedalMarking.Styles.TEXT,this.EndSymbolPositionAndShape=new oe(this,t);break;case It.PEDAL_MIXED:this.vfStyle=i&&s?n.Flow.PedalMarking.Styles.BRACKET_OPEN_BOTH:i?n.Flow.PedalMarking.Styles.BRACKET_OPEN_BEGIN:s?n.Flow.PedalMarking.Styles.MIXED_OPEN_END:n.Flow.PedalMarking.Styles.MIXED;break;case It.PEDAL_BRACKET:default:this.vfStyle=i&&s?n.Flow.PedalMarking.Styles.BRACKET_OPEN_BOTH:i?n.Flow.PedalMarking.Styles.BRACKET_OPEN_BEGIN:s?n.Flow.PedalMarking.Styles.BRACKET_OPEN_END:n.Flow.PedalMarking.Styles.BRACKET}}setStartNote(e){if(!e)return!1;for(const t of e.graphicalVoiceEntries){const e=t;if(null!=e&&e.vfStaveNote)return this.startNote=e.vfStaveNote,this.startVfVoiceEntry=e,!0}return!1}setEndNote(e){if(!e)return!1;for(const t of e.graphicalVoiceEntries){const e=t;if(null!=e&&e.vfStaveNote)return this.endNote=e.vfStaveNote,this.endVfVoiceEntry=e,!0}return!1}setEndMeasure(e){this.endMeasure=e}CalculateBoundingBox(){}setLine(e){this.line=e}getPedalMarking(){const e=new n.Flow.PedalMarking([this.startNote,this.endNote]);return this.endMeasure&&e.setEndStave(this.endMeasure.getVFStave()),e.setStyle(this.vfStyle),e.setLine(this.line),e.setCustomText(this.DepressText,this.ReleaseText),this.endVfVoiceEntry&&!this.getPedal.EndsStave||(e.EndsStave=!0),this.getPedal.BeginsStave&&(e.BeginsStave=!0),e.ChangeBegin=this.ChangeBegin,e.ChangeEnd=this.ChangeEnd,e}setEndsStave(e,t){null!=t&&t.gte(e.parentSourceMeasure.Duration)&&(this.getPedal.EndsStave=!0)}setBeginsStave(e,t){e&&0===t.RealValue&&(this.getPedal.BeginsStave=!0)}}class ms{constructor(e){this.Glissando=e,this.staffEntries=[]}calculateLine(e){const t=this.staffEntries[0],i=this.staffEntries[this.staffEntries.length-1],s=t.findGraphicalNoteFromNote(this.Glissando.StartNote),n=i.findGraphicalNoteFromNote(this.Glissando.EndNote);if(!s&&!n)return;const r=t.parentMeasure.ParentStaffLine;let o,a,l,h;if(s&&t.parentMeasure.ParentStaffLine===this.StaffLine)o=s.PositionAndShape.RelativePosition.x+s.parentVoiceEntry.parentStaffEntry.PositionAndShape.RelativePosition.x+s.parentVoiceEntry.parentStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x+e.GlissandoNoteOffset,l=s.PositionAndShape.AbsolutePosition.y;else{o=i.parentMeasure.beginInstructionsWidth-.4;const t=this.Glissando.Direction===ae.Down?-1:1;l=n.PositionAndShape.AbsolutePosition.y+t*e.GlissandoStafflineStartYDistanceToNote}if(n&&i.parentMeasure.ParentStaffLine===this.StaffLine)a=n.PositionAndShape.RelativePosition.x+n.parentVoiceEntry.parentStaffEntry.PositionAndShape.RelativePosition.x+n.parentVoiceEntry.parentStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x-.5-e.GlissandoNoteOffset,o>a&&(o=a-e.GlissandoStafflineStartMinimumWidth),h=n.PositionAndShape.AbsolutePosition.y;else{if(r.Measures.last().parentSourceMeasure.HasEndLine)return;a=r.PositionAndShape.Size.width,a-o>e.GlissandoStafflineEndOffset&&(o=a-e.GlissandoStafflineEndOffset);const t=this.Glissando.Direction===ae.Down?1:-1;h=s.PositionAndShape.AbsolutePosition.y+t*e.GlissandoStafflineStartYDistanceToNote}const u=new z(o,l),c=new z(a,h);void 0===this.Width&&(this.Width=e.GlissandoDefaultWidth),this.Line=new X(u,c,this.Width)}}class ps extends ms{}class gs extends ne{constructor(e,t){super(),this.getWavyLine=e,this.PositionAndShape=new oe(this,t)}}class Ss extends gs{constructor(e,t,i=!1){super(e,t),this.line=1,this.isVibrato=!1,this.toEndOfStopStave=!1,this.isVibrato=i}get ToEndOfStopStave(){return this.toEndOfStopStave}setStartNote(e){for(const t of e.graphicalVoiceEntries){const e=t;if(null!=e&&e.vfStaveNote)return this.startNote=e.vfStaveNote,this.startVfVoiceEntry=e,!0}return!1}setEndNote(e){for(const t of e.graphicalVoiceEntries){const e=t;if(null!=e&&e.vfStaveNote){this.endNote=e.vfStaveNote,this.endVfVoiceEntry=e;const t=this.endVfVoiceEntry.parentStaffEntry.parentMeasure.staffEntries,i=t[t.length-1];return this.toEndOfStopStave=i===this.endVfVoiceEntry.parentStaffEntry,!0}}return!1}CalculateBoundingBox(){const e=this.getVibratoBracket();this.boundingBox.Size.height=.2*e.render_options.wave_height}getVibratoBracket(){const e=new n.Flow.VibratoBracket({start:this.startNote,stop:this.endNote,toEndOfStopStave:this.toEndOfStopStave});return e.setLine(this.line),this.isVibrato?e.render_options.vibrato_width=20:e.render_options.wave_girth=4,e}}const ys=n.Flow;class bs extends yi{constructor(e){var t,i,s,r,o;if(super(),this.beamsNeedUpdate=!1,this.rules=e,yi.symbolFactory=new Qi,yi.TextMeasurer=new Bt(this.rules),yi.stafflineNoteCalculator=new cs(this.rules),"gonville"===(null===(t=this.rules.DefaultVexFlowNoteFont)||void 0===t?void 0:t.toLowerCase()))n.Flow.DEFAULT_FONT_STACK=[null===(s=n.Flow.Fonts)||void 0===s?void 0:s.Gonville,null===(r=n.Flow.Fonts)||void 0===r?void 0:r.Bravura,null===(o=n.Flow.Fonts)||void 0===o?void 0:o.Custom];else if("petaluma"===(null===(i=this.rules.DefaultVexFlowNoteFont)||void 0===i?void 0:i.toLowerCase())){var a,l,h;n.Flow.DEFAULT_FONT_STACK=[null===(a=n.Flow.Fonts)||void 0===a?void 0:a.Petaluma,null===(l=n.Flow.Fonts)||void 0===l?void 0:l.Gonville,null===(h=n.Flow.Fonts)||void 0===h?void 0:h.Bravura]}}clearRecreatedObjects(){super.clearRecreatedObjects(),yi.stafflineNoteCalculator=new cs(this.rules);for(const e of this.graphicalMusicSheet.MeasureList)for(const t of e)null==t||t.clean()}formatMeasures(){for(const e of this.graphicalMusicSheet.MeasureList)if(e&&e[0]){e.find((e=>null==e?void 0:e.isVisible())).format();for(const t of e){for(const e of t.staffEntries)e.calculateXPosition();t.finalizeBeams()}}this.beamsNeedUpdate=!1}calculateMeasureXLayout(e){const t=[];for(const s of e)null!=s&&s.isVisible()&&t.push(s);if(0===t.length)return 0;e=t;const i=[],n=new ys.Formatter({softmaxFactor:this.rules.SoftmaxFactorVexFlow});let r=e[0].staffEntries.length,o=1;for(const h of e){if(!h)continue;let e=0;for(const i of h.staffEntries)e+=i.setMaxAccidentals();h.parentSourceMeasure.ImplicitMeasure&&(r=Math.max(h.staffEntries.length,r),o=Math.max(h.staffEntries.length+e,o));const t=h.vfVoices,a=[];for(const s in t)if(t.hasOwnProperty(s)){const e=t[s];h.hasOnlyRests&&!e.ticksUsed.equals(e.totalTicks)&&(e.ticksUsed=e.totalTicks),a.push(e),i.push(e)}0!==a.length?n.joinVoices(a):s.debug("Found a measure with no voices. Continuing anyway.",t)}let a=12;const l=e[0].parentSourceMeasure;if(i.length>0){if(a=n.preCalculateMinTotalWidth(i)/zt*this.rules.VoiceSpacingMultiplierVexflow+this.rules.VoiceSpacingAddendVexflow+.3*r,null!=l&&l.ImplicitMeasure){a=l.Duration.RealValue/l.ActiveTimeSignature.RealValue*a;let e=0;const t=l.measureListIndex;if(t>1)for(const i of this.graphicalMusicSheet.MeasureList[t-1]){const t=null==i?void 0:i.parentSourceMeasure.endingBarStyleEnum;if(t===Ne.ThinBold||t===Ne.DotsThinBold){e=this.rules.PickupMeasureRepetitionSpacing;break}}a+=e,r>1?a+=.3*o*1.5:t>1&&1===r&&(a+=this.rules.PickupMeasureSpacingSingleNoteAddend),a*=this.rules.PickupMeasureWidthMultiplier}yi.setMeasuresMinStaffEntriesWidth(e,a);const t=(e,t)=>{n.formatToStave(i,t.getVFStave())},s=(e,t)=>{n.formatToStave(i,t.getVFStave(),{align_rests:!0,context:void 0})};for(const i of e){if(this.rules.AlignRests===N.Never)i.formatVoices=t;else if(this.rules.AlignRests===N.Always)i.formatVoices=s;else if(this.rules.AlignRests===N.Auto){let e=!1;for(const t of i.staffEntries){let i=0,s=0;for(const n of t.graphicalVoiceEntries)if(n.parentVoiceEntry.IsGrace||n&&n.notes&&n.notes[0]&&n.notes[0].sourceNote&&n.notes[0].sourceNote.PrintObject&&i++,n&&n.notes&&n.notes[0]&&n.notes[0].sourceNote&&n.notes[0].sourceNote.isRest()&&n.notes[0].sourceNote.PrintObject&&s++,i>1&&s>=1){e=!0;break}if(e)break}i.formatVoices=e?s:t}if(i===e[0]){const e=i;e.formatVoices(a*zt,e)}}}for(const s of e)if(s)for(const e of s.staffEntries)e.calculateXPosition();for(const h of e){if(!h)continue;const e=h.vfVoices,t=[];for(const i in e)e.hasOwnProperty(i)&&t.push(e[i]);0!==t.length?n.joinVoices(t):s.debug("Found a measure with no voices. Continuing anyway.",e)}return a}calculateElongationFactor(e,t,i,s,n,r,o,a){let l=n,h=0;for(const u of e){const e=u.GraphicalLabel.Label.textAlignment;let c=o,d=a;if(u instanceof es&&u.ParentLyricWord){u.LyricsEntry.SyllableIndex>0&&(c=this.rules.BetweenSyllableMinimumDistance,de.IsCenterAligned(e)&&(c+=1));const t=u.ParentLyricWord.GetLyricWord.Syllables;t.length>1&&u.LyricsEntry.SyllableIndex<t.length-1&&(void 0===this.dashSpace&&(this.dashSpace=1.5),d-=this.dashSpace)}const f=u instanceof es?u.GraphicalLabel.PositionAndShape:u.PositionAndShape,m=f.Size.width;let p,g,S,y,b=t.PositionAndShape.RelativePosition.x+f.BorderLeft;u instanceof ki&&u.PositionAndShape.Parent.DataObject instanceof Re&&(b=this.rules.ChordSymbolWholeMeasureRestXOffset+f.BorderMarginLeft+u.PositionAndShape.Parent.DataObject.beginInstructionsWidth),void 0!==i[h]&&i[h].extend,i[h]&&(g=b-i[h].xPosition);const M=s*n;de.IsCenterAligned(e)?(d/=4,S=M-b,y=m/2-d,i[h]&&(p=i[h].labelWidth/2+m/2+c)):de.IsLeft(e)&&(S=M-b,y=m-d,i[h]&&(p=i[h].labelWidth+c));let v=1;const P=y/S;let E=1;u instanceof es&&u.LyricsEntry?i[h]&&(E=p/g,i[h].sourceNoteDuration.Denominator>4&&(E*=1.1)):i[h]&&(E=p/g),v=Math.max(P,E),l=Math.max(l,v);let L=Math.max(p-g||0,0);i[h]&&(L+=i[h].cumulativeOverlap),i[h]={cumulativeOverlap:L,extend:u instanceof es&&u.LyricsEntry.extend,labelWidth:m,measureNumber:r,sourceNoteDuration:u instanceof es&&u.LyricsEntry&&u.LyricsEntry.Parent.Notes[0].Length,text:u instanceof es?u.LyricsEntry.Text:u.GraphicalLabel.Label.text,xPosition:b},h++}return l}calculateElongationFactorFromStaffEntries(e,t,i,s){let n=i;const r={},o={};for(const a of e)a.LyricsEntries.length>0&&this.rules.RenderLyrics&&(n=this.calculateElongationFactor(a.LyricsEntries,a,r,t,n,s,this.rules.HorizontalBetweenLyricsDistance,this.rules.LyricOverlapAllowedIntoNextMeasure)),a.graphicalChordContainers.length>0&&this.rules.RenderChordSymbols&&(n=this.calculateElongationFactor(a.graphicalChordContainers,a,o,t,n,s,this.rules.ChordSymbolXSpacing,this.rules.ChordOverlapAllowedIntoNextMeasure));return n}calculateMeasureWidthFromStaffEntries(e,t){var i;let s=1;if(!(null===(i=window.GYM)||void 0===i?void 0:i.multitrack))for(const n of e)n&&0!==n.staffEntries.length&&(s=this.calculateElongationFactorFromStaffEntries(n.staffEntries,t,s,n.MeasureNumber),s=1);return s=Math.min(s,this.rules.MaximumLyricsElongationFactor),t*s}createGraphicalTie(e,t,i,s,n){return new Zi(e,s,n)}updateStaffLineBorders(e){e.SkyBottomLineCalculator.updateStaffLineBorders()}graphicalMeasureCreatedCalculations(e){e.rules=this.rules,e.graphicalMeasureCreatedCalculations()}layoutVoiceEntry(e,t,i,s){for(let n=0;n<t.length;n++)t[n]=yi.stafflineNoteCalculator.positionNote(t[n])}layoutStaffEntry(e){e.parentMeasure.layoutStaffEntry(e)}initGraphicalMeasuresCreation(){}layoutArticulationMarks(e,t,i){}layoutGraphicalTie(e,t,i){const s=e.StartNote,n=e.EndNote;let r,o,a=0;s&&s.vfnote&&s.vfnote.length>=2&&(r=s.vfnote[0],a=s.vfnote[1]);let l=0;if(n&&n.vfnote&&n.vfnote.length>=2&&(o=n.vfnote[0],l=n.vfnote[1]),t){if(r){const t=new ys.StaveTie({first_indices:[a],first_note:r}),i=s.parentVoiceEntry.parentStaffEntry.parentMeasure;if(o){var h,u,c;"w"===o.getDuration()&&(null===(h=o.keyProps)||void 0===h||null===(u=h[0])||void 0===u?void 0:u.line)>=3&&o.setStemDirection(-1);let e=(null===(c=window.GYM)||void 0===c?void 0:c.tieDirection)||0;var f,m;1===Math.abs(e)&&((null===(f=o.keyProps)||void 0===f||null===(m=f[0])||void 0===m?void 0:m.line)>=3?o.setStemDirection(-e):o.setStemDirection(e)),null==t||t.setDirection(o.getStemDirection())}if(i.vfTies.length>0){const e=i.vfTies[0].direction;null==t||t.setDirection(e?-e:1)}i.addStaveTie(t,e)}if(o){const t=new ys.StaveTie({last_indices:[l],last_note:o}),i=n.parentVoiceEntry.parentStaffEntry.parentMeasure;if(i.vfTies.length>0){const e=i.vfTies[0].direction;null==t||t.setDirection(e?-e:1)}i.addStaveTie(t,e)}}else if(r||o){var p;let t;if(i)if("S"===e.Tie.Type){const i=e.StartNote.sourceNote,s=e.EndNote.sourceNote;let n=1;i.FretNumber>s.FretNumber&&(n=-1),t=new ys.TabSlide({first_indices:[a],first_note:r,last_indices:[l],last_note:o},n)}else t=new ys.TabTie({first_indices:[a],first_note:r,last_indices:[l],last_note:o},e.Tie.Type);else{t=new ys.StaveTie({first_indices:[a],first_note:r,last_indices:[l],last_note:o});const i=e.Tie.getTieDirection(s.sourceNote);i===d.Below?t.setDirection(1):i===d.Above&&t.setDirection(-1)}const h=n.parentVoiceEntry.parentStaffEntry.parentMeasure,u=(null===(p=window.GYM)||void 0===p?void 0:p.graceCustom)||!1;u&&t.setDirection(u.direction),h.addStaveTie(t,e)}}calculateDynamicExpressionsForMultiExpression(e,t,i){if(t<this.rules.MinMeasureToDrawIndex||t>this.rules.MaxMeasureToDrawIndex)return;const n=e.AbsoluteTimestamp,r=this.graphicalMusicSheet.MeasureList[t],o=r[i].ParentStaffLine,a=r[i];if(!o)return;const l=e.StartingContinuousDynamic,h=void 0!==l&&!l.IsStartOfSoftAccent,u=this.getRelativePositionInStaffLineFromTimestamp(n,i,o,null==o?void 0:o.isPartOfMultiStaffInstrument(),void 0,h);if(u.x<=0&&(u.x=a.beginInstructionsWidth+this.rules.RhythmRightMargin),e.InstantaneousDynamic){const t=new rs(e.InstantaneousDynamic,o,a);this.calculateGraphicalInstantaneousDynamicExpression(t,u,n),this.dynamicExpressionMap.set(n.RealValue,t.PositionAndShape)}if(l){const t=new Wi(l,o,a.parentSourceMeasure);if(t.StartMeasure=a,t.IsSoftAccent=e.StartingContinuousDynamic.IsStartOfSoftAccent,!t.IsVerbal&&l.EndMultiExpression)try{this.calculateGraphicalContinuousDynamic(t,u),t.updateSkyBottomLine()}catch(c){}else t.IsVerbal?this.calculateGraphicalVerbalContinuousDynamic(t,u):s.warn("This continuous dynamic is not covered. measure"+e.SourceMeasureParent.MeasureNumber)}}createMetronomeMark(e,t){var i,s,n,r,o;const a=Math.max(e.ParentMultiTempoExpression.SourceMeasureParent.MeasureNumber-1,0),l=t||a,h=Math.max(e.StaffNumber-1,0),u=this.graphicalMusicSheet.MeasureList[l][h].getVFStave();let c="q";if(e.beatUnit){const t=He.getNoteDurationFromType(e.beatUnit);c=Jt.durations(t,!1)[0]}let f=this.rules.MetronomeMarkYShift,m=!1;const p=[];if(e.parentMeasure){for(const t of e.parentMeasure.StaffLinkedExpressions)for(const e of t)e&&e instanceof ni&&p.push(e);for(const t of e.parentMeasure.TempoExpressions){var g;const i=(null===(g=t.InstantaneousTempo)||void 0===g?void 0:g.Enum)===ti.metronomeMark;if(!e.beatUnit&&t.InstantaneousTempo.beatUnit){const t=He.getNoteDurationFromType(e.beatUnit);c=Jt.durations(t,!1)[0]}if(t.getPlacementOfFirstEntry()===d.Above&&!i){m=!0;break}}}m&&(f-=1.4);const S=null===(i=this.graphicalMusicSheet.MeasureList[0][0].ParentStaffLine)||void 0===i?void 0:i.SkyLine;let y=e.TempoInBpm,b="",M="",v="";for(const d of this.graphicalMusicSheet.MeasureList[l][h].parentSourceMeasure.TempoExpressions){if(M=d.CombinedExpressionsText,Tt(d.CombinedExpressionsText)){b=d.CombinedExpressionsText;break}if(Lt(d.CombinedExpressionsText)||xt(d.CombinedExpressionsText)){b=d.CombinedExpressionsText.replace(Et,"").replace(Pt,""),y=d.sourceMeasure.TempoInBPM,Lt(d.CombinedExpressionsText)&&(v=c);break}}const P={bpm:e.TempoInBpm,dots:e.dotted,duration:c,name:b};b&&(P.bpm=y/1,Lt(M)?P.duration=v:y!==gt[b]&&gt[b]||(P.duration=""));const E=(null===(s=this.graphicalMusicSheet.MeasureList[l][h])||void 0===s||null===(n=s.vfVoices)||void 0===n||null===(r=n[1])||void 0===r||null===(o=r.boundingBox)||void 0===o?void 0:o.y)||0;if(this.rules.MetronomeMarksDrawn){if(S){var L,x;const e=(null===(L=this.graphicalMusicSheet.MeasureList[0])||void 0===L||null===(x=L[h])||void 0===x?void 0:x.ParentStaffLine).Measures.map((e=>e.MeasureNumber-1));if(E&&e.includes(l)&&(Lt(M)||xt(M))){const e=S.slice(0,9);let t=Math.min(...e);t=t<0?t-1:t,f+=t}e.includes(l)&&p.length?S[0]=Math.min(S[0],-4.5+f-4):S[0]=Math.min(S[0],-4.5+f)}u.options.line_config.reduce(((e,t)=>(t.visible&&e++,e)),0)<5&&(f-=2),u.setTempo(P,f*zt);let e=-3;u.getModifiers()[u.getModifiers().length-1].setShiftX(e)}}calculateRehearsalMark(e){var t,i,s,n,r,o;const a=e.rehearsalExpression;if(!a)return;const l=null===(t=e.VerticalMeasureList)||void 0===t||null===(i=t[0])||void 0===i||null===(s=i.getVFStave)||void 0===s?void 0:s.call(i);if(!l)return;const h=-this.rules.RehearsalMarkYOffsetDefault-this.rules.RehearsalMarkYOffset;let u=this.rules.RehearsalMarkXOffsetDefault+this.rules.RehearsalMarkXOffset;e.IsSystemStartMeasure&&(u+=this.rules.RehearsalMarkXOffsetSystemStartMeasure);const c=this.rules.RehearsalMarkFontSize,d=l.getModifiers(),f=d.find((e=>"repetitions"===e.getCategory().toLocaleLowerCase()));if(f&&f.setShiftY(f.y_shift-10),l.setSection(a.label,h,u,c),null!==(n=e.VerticalMeasureList)&&void 0!==n&&null!==(r=n[0])&&void 0!==r&&null!==(o=r.ParentStaffLine)&&void 0!==o&&o.AbstractExpressions){const t=d.find((e=>"stavesection"===e.getCategory().toLocaleLowerCase()));for(let i of(null==e||null===(m=e.VerticalMeasureList)||void 0===m||null===(p=m[0])||void 0===p||null===(g=p.ParentStaffLine)||void 0===g?void 0:g.AbstractExpressions)||[]){var m,p,g;i instanceof _t&&(t&&(i.Label.PositionAndShape.RelativePosition.y-=.5),f&&(i.Label.PositionAndShape.RelativePosition.y-=1.7))}}}calculateSingleOctaveShift(e,t,i,n){var r;const o=t.OctaveShiftStart,a=o.ParentStartMultiExpression.Timestamp,l=null===(r=o.ParentEndMultiExpression)||void 0===r?void 0:r.Timestamp,h=this.rules.MinMeasureToDrawIndex,u=this.rules.MaxMeasureToDrawIndex;let c,d,f=this.graphicalMusicSheet.MeasureList[i][n].ParentStaffLine;if(f||(f=this.graphicalMusicSheet.MeasureList[h][n].ParentStaffLine),c=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentEndMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0),c.MeasureNumber>u+1&&(c=this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0)),d=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentStartMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.MeasureList[h][n],d.MeasureNumber<h+1&&(d=this.graphicalMusicSheet.MeasureList[h][n]),d.parentSourceMeasure.measureListIndex<h||d.parentSourceMeasure.measureListIndex>u||c.parentSourceMeasure.measureListIndex<h||c.parentSourceMeasure.measureListIndex>u)return;let m=c.ParentStaffLine;if(m||(m=f),c&&f&&m){const e=new ns(o,f.PositionAndShape);if(!e.startNote){let t;for(const e of d.staffEntries)if(e){t=e;break}if(!t)return;if(e.setStartNote(t),!e.startNote)return}if(!e.endNote){let t;for(let e=c.staffEntries.length-1;e>=0;e++)if(c.staffEntries[e]){t=c.staffEntries[e];break}if(!t)return void(e.graphicalEndAtMeasureEnd=!0);if(e.setEndNote(t),!e.endNote)return}let t=d.findGraphicalStaffEntryFromTimestamp(a);t||(t=d.staffEntries[0]);let i=c.findGraphicalStaffEntryFromTimestamp(l);if(i||(i=c.staffEntries[c.staffEntries.length-1]),e.setStartNote(t),m!==f){e.endsOnDifferentStaffLine=!0;let r=this.findLastStafflineMeasure(f);void 0===r&&(r=c);const a=r.staffEntries[r.staffEntries.length-1];e.setEndNote(a),e.graphicalEndAtMeasureEnd=!0,e.endMeasure=r;const l=m.ParentMusicSystem.Id-f.ParentMusicSystem.Id;if(l>0)for(let e=f.ParentMusicSystem.Id;e<m.ParentMusicSystem.Id;e++){const t=e+1,r=this.musicSystems[t];let a;for(const e of r.StaffLines)if(e.ParentStaff.idInMusicSheet===n){a=e;break}if(!a)continue;const h=a.Measures[0],u=new ns(o,h.PositionAndShape);let d=this.findLastStafflineMeasure(a);e<l-1&&(u.endsOnDifferentStaffLine=!0,u.graphicalEndAtMeasureEnd=!0,u.endMeasure=d);const f=h.staffEntries[0];let m=d.staffEntries[d.staffEntries.length-1];c.ParentStaffLine===a&&(d=c,m=i),1===m.graphicalVoiceEntries.length&&1===m.graphicalVoiceEntries[0].notes.length&&m.graphicalVoiceEntries[0].notes[0].sourceNote.isWholeMeasureNote()&&(u.graphicalEndAtMeasureEnd=!0,u.endMeasure=d);const p="VexFlowMusicSheetCalculator.calculateSingleOctaveShift: ";f||s.warn(p+"no firstNote found"),m||s.warn(p+"no lastNote found"),u.setStartNote(f),u.setEndNote(m),a.OctaveShifts.push(u),this.calculateOctaveShiftSkyBottomLine(f,m,u,a)}this.calculateOctaveShiftSkyBottomLine(t,a,e,f)}else e.setEndNote(i),this.calculateOctaveShiftSkyBottomLine(t,i,e,f);f.OctaveShifts.push(e)}else s.warn("End measure or staffLines for octave shift are undefined! This should not happen!")}findLastStafflineMeasure(e){for(let t=e.Measures.length-1;t>=0;t--){const i=e.Measures[t];if(i.staffEntries.length>0)return i}}calculateSinglePedal(e,t,i,n){var r;const o=t.PedalStart,a=o.ParentStartMultiExpression.Timestamp,l=null===(r=o.ParentEndMultiExpression)||void 0===r?void 0:r.Timestamp,h=this.rules.MinMeasureToDrawIndex,u=this.rules.MaxMeasureToDrawIndex;let c,d,f=this.graphicalMusicSheet.MeasureList[i][n].ParentStaffLine;if(f||(f=this.graphicalMusicSheet.MeasureList[h][n].ParentStaffLine),c=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentEndMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0),c||(c=o.ParentStartMultiExpression.SourceMeasureParent.VerticalMeasureList[n]),c.MeasureNumber>u+1&&(c=this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0)),o.ParentEndMultiExpression?d=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentStartMultiExpression.SourceMeasureParent,n):(d=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentStartMultiExpression.SourceMeasureParent,n),d||(d=this.graphicalMusicSheet.MeasureList[h][n])),d.MeasureNumber<h+1&&(d=this.graphicalMusicSheet.MeasureList[h][n]),d.parentSourceMeasure.measureListIndex<h||d.parentSourceMeasure.measureListIndex>u||c.parentSourceMeasure.measureListIndex<h||c.parentSourceMeasure.measureListIndex>u)return;let m=c.ParentStaffLine;if(m||(m=f),c&&f&&m){let e=!1;f!==m&&(e=!0);const t=new fs(o,f.PositionAndShape,!1,e);t.setEndsStave(c,l);let i=d.findGraphicalStaffEntryFromTimestamp(a);i||(i=d.staffEntries[0]);let s=c.findGraphicalStaffEntryFromTimestamp(l);if(s||(s=c.staffEntries[c.staffEntries.length-1]),!t.setStartNote(i))return;if(t.setBeginsStave(t.startNote.isRest(),a),m!==f)if(t.pedalSymbol===It.PEDAL_SYMBOL){t.setEndNote(s),t.setEndMeasure(c),t.ReleaseText=" ",t.CalculateBoundingBox(),this.calculatePedalSkyBottomLine(t.startVfVoiceEntry,t.endVfVoiceEntry,t,f);const e=m.Measures[0],i=new fs(o,e.PositionAndShape);t.setEndsStave(c,l);const n=e.staffEntries[0];if(!i.setStartNote(n))return;i.setEndNote(s),i.setEndMeasure(c),t.setEndMeasure(c),m.Pedals.push(i),i.CalculateBoundingBox(),i.DepressText=" ",this.calculatePedalSkyBottomLine(i.startVfVoiceEntry,i.endVfVoiceEntry,i,m)}else{let e=this.findLastStafflineMeasure(f);void 0===e&&(e=c);const i=e.staffEntries[e.staffEntries.length-1];t.setEndNote(i),t.setEndMeasure(c),t.ChangeEnd=!1;const r=m.ParentMusicSystem.Id-f.ParentMusicSystem.Id;if(r>0){let e=1;for(let i=f.ParentMusicSystem.Id;i<m.ParentMusicSystem.Id;i++){const a=this.musicSystems[i+1].StaffLines[n],h=a.Measures[0];let u=!1,d=!1;e<r?u=!0:d=!0,e++;const f=new fs(o,h.PositionAndShape,!0,u);t.setEndsStave(c,l),f.ChangeBegin=!1,f.ChangeEnd=!!d&&o.ChangeEnd;let m=this.findLastStafflineMeasure(a);const p=h.staffEntries[0];let g=m.staffEntries[m.staffEntries.length-1];if(c.ParentStaffLine===a?(m=c,f.setEndMeasure(c),g=s):f.setEndMeasure(a.Measures.last()),!f.setStartNote(p))break;f.setEndNote(g),t.setEndMeasure(c),a.Pedals.push(f),f.CalculateBoundingBox(),this.calculatePedalSkyBottomLine(f.startVfVoiceEntry,f.endVfVoiceEntry,f,a)}}t.CalculateBoundingBox(),this.calculatePedalSkyBottomLine(t.startVfVoiceEntry,t.endVfVoiceEntry,t,f)}else t.setEndNote(s),t.setEndMeasure(c),t.CalculateBoundingBox(),this.calculatePedalSkyBottomLine(t.startVfVoiceEntry,t.endVfVoiceEntry,t,f);f.Pedals.push(t)}else s.warn("End measure or staffLines for pedal are undefined! This should not happen!")}calculateSingleWavyLine(e,t,i,n){var r;const o=t.WavyLineStart,a=o.ParentStartMultiExpression.Timestamp,l=null===(r=o.ParentEndMultiExpression)||void 0===r?void 0:r.Timestamp,h=this.rules.MinMeasureToDrawIndex,u=this.rules.MaxMeasureToDrawIndex;let c,d,f=this.graphicalMusicSheet.MeasureList[i][n].ParentStaffLine;if(f||(f=this.graphicalMusicSheet.MeasureList[h][n].ParentStaffLine),c=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentEndMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0),c.MeasureNumber>u+1&&(c=this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0)),d=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentStartMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.MeasureList[h][n],d.MeasureNumber<h+1&&(d=this.graphicalMusicSheet.MeasureList[h][n]),d.parentSourceMeasure.measureListIndex<h||d.parentSourceMeasure.measureListIndex>u||c.parentSourceMeasure.measureListIndex<h||c.parentSourceMeasure.measureListIndex>u)return;let m=c.ParentStaffLine;if(m||(m=f),c&&f&&m){const e=new Ss(o,f.PositionAndShape,d.ParentStaff.isTab);let t=d.findGraphicalStaffEntryFromTimestamp(a);t||(t=d.staffEntries[0]);let i=c.findGraphicalStaffEntryFromTimestamp(l);if(i||(i=c.staffEntries[c.staffEntries.length-1]),e.setStartNote(t),m!==f){let t=f.Measures[f.Measures.length-1];void 0===t&&(t=c);const s=t.staffEntries[t.staffEntries.length-1];if(e.setEndNote(s),m.ParentMusicSystem.Id-f.ParentMusicSystem.Id>0)for(let e=f.ParentMusicSystem.Id;e<m.ParentMusicSystem.Id;e++){const t=this.musicSystems[e+1].StaffLines[n],s=t.Measures[0],r=new Ss(o,s.PositionAndShape,t.ParentStaff.isTab);let a=t.Measures[t.Measures.length-1];const l=s.staffEntries[0];let h=a.staffEntries[a.staffEntries.length-1];c.ParentStaffLine===t&&(a=c,h=i),r.setStartNote(l),r.setEndNote(h),t.WavyLines.push(r),r.CalculateBoundingBox(),this.calculateWavyLineSkyBottomLine(r.startVfVoiceEntry,r.endVfVoiceEntry,r,t)}e.CalculateBoundingBox(),this.calculateWavyLineSkyBottomLine(e.startVfVoiceEntry,e.endVfVoiceEntry,e,f)}else e.setEndNote(i),e.CalculateBoundingBox(),this.calculateWavyLineSkyBottomLine(e.startVfVoiceEntry,e.endVfVoiceEntry,e,f);f.WavyLines.push(e)}else s.warn("End measure or staffLines for wavy line are undefined! This should not happen!")}calculateWavyLineSkyBottomLine(e,t,i,s){var n,r;const o=i.startNote.getStave(),a=i.endNote.getStave(),l=Math.max(o.options.top_text_position,a.options.top_text_position);o.options.top_text_position=l,a.options.top_text_position=l;let h,u=-l,c=0,d=0,f=1/0,m=1/0,p=e.PositionAndShape.AbsolutePosition.x+e.PositionAndShape.BorderLeft;if((null===(n=e.parentVoiceEntry)||void 0===n||null===(r=n.OrnamentContainer)||void 0===r?void 0:r.GetOrnament)===je.Trill&&(c=p,p+=2,d=p,f=s.SkyBottomLineCalculator.getSkyLineMinInRange(c,d),m=f+1.85),i.ToEndOfStopStave)h=t.parentStaffEntry.parentMeasure.PositionAndShape.AbsolutePosition.x+t.parentStaffEntry.parentMeasure.PositionAndShape.BorderRight-1;else{h=t.PositionAndShape.AbsolutePosition.x+t.PositionAndShape.BorderRight;const e=t.parentStaffEntry.vfClefBefore;e&&(h+=e.getWidth()/10)}u=s.SkyBottomLineCalculator.getSkyLineMinInRange(p,h),u!==1/0&&(u<f?(o.options.top_text_position=-u,a.options.top_text_position=-u,s.SkyBottomLineCalculator.updateSkyLineInRange(c,d,u-1.85)):(i.line=-m,u=m),u-=i.PositionAndShape.Size.height,s.SkyBottomLineCalculator.updateSkyLineInRange(p,h,u))}calculatePedalSkyBottomLine(e,t,i,s){let r=null==t?void 0:t.PositionAndShape;r||(r=i.endMeasure.PositionAndShape);const o=n.Flow.PedalMarking.Styles,a=i.getPedalMarking(),l=a.line+3+(s.StaffLines.length-1),h=a.render_options.text_margin_right/10;let u,c=e.PositionAndShape.AbsolutePosition.x-h;a.style!==o.MIXED&&a.style!==o.MIXED_OPEN_END&&a.style!==o.TEXT||(c-=1);let d=s.StaffLines.length-1;for(const n of s.Pedals){const e=n.getPedalMarking().line+3+(s.StaffLines.length-1);d=Math.max(e,d)}if(i.EndSymbolPositionAndShape){const e=a.render_options.glyph_point_size/20;u=c+3.4;const t=r.AbsolutePosition.x-h,n=t+1.5;d=Math.max(s.SkyBottomLineCalculator.getBottomLineMaxInRange(c,u),d),d=Math.max(l+2*e,d);const o=s.SkyBottomLineCalculator.getBottomLineMaxInRange(t,n);i.DepressText||(d=Math.max(d,o)),i.setLine(d-3-(s.StaffLines.length-1)),s.SkyBottomLineCalculator.updateBottomLineInRange(c,u,d+e),s.SkyBottomLineCalculator.updateBottomLineInRange(t,n,d+e)}else{var f;const e=a.render_options.bracket_height/10;if(a.EndsStave)u=t?t.parentStaffEntry.parentMeasure.PositionAndShape.AbsolutePosition.x+t.parentStaffEntry.parentMeasure.PositionAndShape.Size.width-h:r.AbsolutePosition.x+r.Size.width;else switch(a.style){case o.BRACKET_OPEN_END:case o.BRACKET_OPEN_BOTH:case o.MIXED_OPEN_END:u=r.AbsolutePosition.x+r.BorderRight-h;break;default:u=r.AbsolutePosition.x+r.BorderLeft-h}const n=null==t||null===(f=t.parentStaffEntry)||void 0===f?void 0:f.vfClefBefore;if(n&&(u+=n.getWidth()/10),d=Math.max(s.SkyBottomLineCalculator.getBottomLineMaxInRange(c,u),d),d===1/0)return;if(d=Math.max(d,l+e),i.setLine(d-3-(s.StaffLines.length-1)),c>u){const e=u;u=c,c=e}s.SkyBottomLineCalculator.updateBottomLineInRange(c,u,d+e)}for(const n of s.Pedals){const e=n,t=e.getPedalMarking();if(d>t.line+3+(s.StaffLines.length-1)){var m;const i=t.render_options.text_margin_right/10;let n,r=e.startVfVoiceEntry.PositionAndShape.AbsolutePosition.x-i;e.setLine(d-3-(s.StaffLines.length-1));let l=null===(m=e.endVfVoiceEntry)||void 0===m?void 0:m.PositionAndShape;if(l||(l=e.endMeasure.PositionAndShape),e.EndSymbolPositionAndShape){const e=a.render_options.glyph_point_size/20;n=r+3.4;const t=l.AbsolutePosition.x-i,o=t+1.5;s.SkyBottomLineCalculator.updateBottomLineInRange(r,n,d+e),s.SkyBottomLineCalculator.updateBottomLineInRange(t,o,d+e)}else{var p,g;const h=t.render_options.bracket_height/10;if(t.EndsStave)n=l.AbsolutePosition.x+l.Size.width-i;else switch(a.style){case o.BRACKET_OPEN_END:case o.BRACKET_OPEN_BOTH:case o.MIXED_OPEN_END:n=l.AbsolutePosition.x+l.BorderRight-i;break;default:n=l.AbsolutePosition.x+l.BorderLeft-i}const u=null===(p=e.endVfVoiceEntry)||void 0===p||null===(g=p.parentStaffEntry)||void 0===g?void 0:g.vfClefBefore;if(u&&(n+=u.getWidth()/10),r>n){const e=r;r=n,n=e}s.SkyBottomLineCalculator.updateBottomLineInRange(r,n,d+h)}}}}calculateOctaveShiftSkyBottomLine(e,t,i,n){if(!t)return void s.warn("octaveshift: no endStaffEntry");let r=t.PositionAndShape;i.graphicalEndAtMeasureEnd&&(r=t.parentMeasure.PositionAndShape);let o=e.PositionAndShape.Size.width,a=r.Size.width;e.hasOnlyRests()?o=-o:o/=2,i.graphicalEndAtMeasureEnd||(t.hasOnlyRests()?a*=2:a/=2,e===t&&(a*=2));let l=e.PositionAndShape.AbsolutePosition.x-o,h=r.AbsolutePosition.x+a;if(l>h){const e=l;l=h,h=e}i.PositionAndShape.Size.width=h-l;const u=i.getTextBracket(),c=u.font.size/10;if(u.position===ys.TextBracket.Positions.TOP){const e=Math.ceil(n.SkyBottomLineCalculator.getSkyLineMinInRange(l,h));if(e===1/0)return;u.start.getStave().options.top_text_position=Math.abs(e),n.SkyBottomLineCalculator.updateSkyLineInRange(l,h,e-2*c)}else{const i=n.SkyBottomLineCalculator.getBottomLineMaxInRange(l,h);if(i===1/0)return;u.start.getStave().options.bottom_text_position=i,e.parentMeasure!==t.parentMeasure&&(u.stop.getStave().options.bottom_text_position=i),n.SkyBottomLineCalculator.updateBottomLineInRange(l,h,i+1.5*c)}}calculateWordRepetitionInstruction(e,t){let i;const s=this.graphicalMusicSheet.MeasureList[t];for(let n=0,r=s.length;n<r;++n){const e=s[n];if(e&&e.ParentStaffLine&&e.ParentStaff.ParentInstrument.Visible){i=e;break}}i&&i.addWordRepetition(e)}calculateSkyBottomLines(){const e=le.flat(this.musicSystems.map((e=>e.StaffLines)));let t=0;for(const i of e)for(const e of i.Measures)e&&t++;this.rules.AlwaysSetPreferredSkyBottomLineBackendAutomatically&&this.rules.setPreferredSkyBottomLineBackendAutomatically(t);for(const i of e)i.SkyBottomLineCalculator.calculateLines()}calculateExpressionAlignements(){for(const t of this.musicSystems)for(const i of t.StaffLines)try{i.AlignmentManager.alignDynamicExpressions(),i.AbstractExpressions.forEach((e=>{e.updateSkyBottomLine()}))}catch(e){}}handleTiedGraphicalNote(e,t,i,s,n,r,o,a){}handleBeam(e,t,i){e.parentVoiceEntry.parentStaffEntry.parentMeasure.handleBeam(e,t)}handleVoiceEntryLyrics(e,t,i){e.LyricsEntries.forEach(((e,s)=>{const n=new es(s,t,this.rules.LyricsHeight,this.rules.StaffHeight);if(t.LyricsEntries.push(n),n.GraphicalLabel.setLabelPositionAndShapeBorders(),s.Word){const e=s.Word.Syllables.indexOf(s);let t=i.indexOf(s.Word);if(-1===t&&(i.push(s.Word),t=i.indexOf(s.Word)),0===this.graphicalLyricWords.length||t>this.graphicalLyricWords.length-1){const t=new ts(s.Word);n.ParentLyricWord=t,t.GraphicalLyricsEntries[e]=n,this.graphicalLyricWords.push(t)}else{const s=this.graphicalLyricWords[t];n.ParentLyricWord=s,s.GraphicalLyricsEntries[e]=n,s.isFilled()&&(i.splice(t,1),this.graphicalLyricWords.splice(this.graphicalLyricWords.indexOf(s),1))}}}))}handleVoiceEntryOrnaments(e,t,i){}handleVoiceEntryArticulations(e,t,i){}handleVoiceEntryTechnicalInstructions(e,t,i){}handleTuplet(e,t,i){e.parentVoiceEntry.parentStaffEntry.parentMeasure.handleTuplet(e,t)}findIndexGraphicalSlurFromSlur(e,t){for(let i=0;i<e.length;i++)if(e[i].slur===t)return i;return-1}indexOfGraphicalGlissFromGliss(e,t){for(let i=0;i<e.length;i++)if(e[i].Glissando===t)return i;return-1}calculateSlurs(){const e={};for(const t of this.graphicalMusicSheet.MeasureList[0])e[t.ParentStaff.idInMusicSheet]=[];for(const t of this.musicSystems)for(const i of t.StaffLines){const t=e[i.ParentStaff.idInMusicSheet];for(let e=0;e<t.length;e++){const s=t[e],n=new us(s.slur,this.rules);i.addSlurToStaffline(n),t[e]=n}for(const e of i.Measures)for(const s of e.staffEntries){for(const e of s.graphicalVoiceEntries)for(const n of e.notes)for(const e of n.sourceNote.NoteSlurs)if(e.EndNote&&e.StartNote){if(e.StartNote===n.sourceNote){const s=new us(e,this.rules);t.push(s),i.addSlurToStaffline(s)}if(e.EndNote===n.sourceNote){const i=this.findIndexGraphicalSlurFromSlur(t,e);if(i>=0){const e=t[i];-1===e.staffEntries.indexOf(s)&&e.staffEntries.push(s),t.splice(i,1)}}}for(const e of t)-1===e.staffEntries.indexOf(s)&&e.staffEntries.push(s)}}for(const t of this.musicSystems)for(const e of t.StaffLines){const t=e.GraphicalSlurs.sort(us.Compare);for(const e of t)e.slur.isCrossed()||e.calculateCurve(this.rules)}}calculateGlissandi(){const e={};for(const t of this.graphicalMusicSheet.MeasureList[0])e[t.ParentStaff.idInMusicSheet]=[];for(const t of this.musicSystems)for(const i of t.StaffLines){const t=e[i.ParentStaff.idInMusicSheet];for(let e=0;e<t.length;e++){const s=t[e],n=new ps(s.Glissando);i.addGlissandoToStaffline(n),t[e]=n}for(const e of i.Measures)for(const s of e.staffEntries){for(const e of s.graphicalVoiceEntries)for(const n of e.notes){const e=n.sourceNote.NoteGlissando;if(null!=e&&e.EndNote&&null!=e&&e.StartNote){if(e.StartNote===n.sourceNote){const s=new ps(e);t.push(s),i.addGlissandoToStaffline(s)}if(e.EndNote===n.sourceNote){const i=this.indexOfGraphicalGlissFromGliss(t,e);if(i>=0){const e=t[i];-1===e.staffEntries.indexOf(s)&&e.staffEntries.push(s),t.splice(i,1)}}}}for(const e of t)-1===e.staffEntries.indexOf(s)&&e.staffEntries.push(s)}}for(const t of this.musicSystems)for(const e of t.StaffLines)for(const t of e.GraphicalGlissandi)if(e.ParentStaff.isTab){const e=t.Glissando.StartNote,i=t.Glissando.EndNote,s=t.staffEntries[0].findGraphicalNoteFromNote(e),n=t.staffEntries.last().findGraphicalNoteFromNote(i);if(!s&&!n)return;let r,o,a,l,h=1;e.FretNumber>i.FretNumber&&(h=-1),s&&s.vfnote&&s.vfnote.length>=2&&(a=s.vfnote[0],r=[0]),n&&n.vfnote&&n.vfnote.length>=2&&(l=n.vfnote[0],o=[0]);const u=new ys.TabSlide({first_indices:r,first_note:a,last_indices:o,last_note:l},h),c=null==s?void 0:s.parentVoiceEntry.parentStaffEntry.parentMeasure;c&&(c.vfTies.push(u),t.vfTie=u);const d=null==n?void 0:n.parentVoiceEntry.parentStaffEntry.parentMeasure;d&&(d.vfTies.push(u),t.vfTie=u)}}}class Ms{constructor(e){this.musicSheet=e}reInit(){this.init()}init(){this.parts=this.musicSheet.Repetitions.slice(),this.sheetStart=this.musicSheet.SelectionStart=new u(0,1),this.sheetEnd=this.musicSheet.SelectionEnd=this.musicSheet.SheetEndTimestamp,this.calcMapping()}getCurrentRepetitionTimestampTransform(e){let t;for(let i=this.timestamps.length-1;i>=0;i--)if(t=this.timestamps[i],e.gte(t.from))return t;return this.timestamps[0]}absoluteEnrolledToSheetTimestamp(e){if(0===this.timestamps.length)return e;const t=this.getCurrentRepetitionTimestampTransform(e);return u.plus(e,u.minus(t.to,t.from))}get Parts(){return this.parts}get MusicSheet(){return this.musicSheet}getIterator(e){return e?new w(this.musicSheet,e,void 0):new w(this.musicSheet,this.musicSheet.SelectionStart,this.musicSheet.SelectionEnd)}setSelectionStart(e){this.musicSheet.SelectionStart=e,this.musicSheet.SelectionEnd=void 0}setSelectionRange(e,t){this.musicSheet.SelectionStart=null!=e?e:this.sheetStart,this.musicSheet.SelectionEnd=null!=t?t:this.sheetEnd}calcMapping(){this.timestamps=[];const e=this.getIterator();let t=e.CurrentRepetition,i=new vs(e.CurrentEnrolledTimestamp.clone(),e.CurrentSourceTimestamp.clone(),void 0,0);for(this.timestamps.push(i);!e.EndReached;){if(e.JumpOccurred||t!==e.CurrentRepetition){if(t=e.CurrentRepetition,e.backJumpOccurred){const t=e.JumpResponsibleRepetition;i.nextBackJump=e.CurrentEnrolledTimestamp,i.curRepetition=t,i.curRepetitionIteration=e.CurrentJumpResponsibleRepetitionIterationBeforeJump;for(let e=this.timestamps.length-2;e>=0&&!t.AbsoluteTimestamp.gt(this.timestamps[e].to)&&!this.timestamps[e].curRepetition;e--)this.timestamps[e].nextBackJump=i.nextBackJump,this.timestamps[e].curRepetition=t,this.timestamps[e].curRepetitionIteration=i.curRepetitionIteration}i=new vs(e.CurrentEnrolledTimestamp.clone(),e.CurrentSourceTimestamp.clone(),void 0,0),this.timestamps.push(i)}e.moveToNext()}}}class vs{constructor(e,t,i,s){this.from=e,this.to=t,this.curRepetition=i,this.curRepetitionIteration=s,this.nextBackJump=void 0,this.nextForwardJump=void 0}}class Ps{constructor(e){this.enrolledTimestamps=[],this.visible=!0,this.musicSheet=e}get Visible(){return this.visible}set Visible(e){this.visible=e}getFirstSourceMeasure(){return this.musicSheet.SourceMeasures[this.startIndex]}getLastSourceMeasure(){return this.musicSheet.SourceMeasures[this.endIndex]}}class Es extends Ps{constructor(e,t,i){super(e),this.musicSheet=e,this.startIndex=t,this.endIndex=i}get MeasuresCount(){return this.endIndex-this.startIndex+1}get StartIndex(){return this.startIndex}get EndIndex(){return this.endIndex}get ParentRepetition(){return this.parentRepetition}set ParentRepetition(e){this.parentRepetition=e}get AbsoluteTimestamp(){return u.createFromFraction(this.musicSheet.SourceMeasures[this.startIndex].AbsoluteTimestamp)}setStartIndex(e){this.startIndex=e}setEndIndex(e){this.endIndex=e}}class Ls extends Ps{constructor(e,t=!1){super(e),this.backwardJumpInstructions=[],this.endingParts=[],this.endingIndexDict={},this.userNumberOfRepetitions=0,this.visibles=[],this.fromWords=!1,this.repetitonIterationOrder=[],this.numberOfEndings=1,this.musicSheet2=e,this.virtualOverallRepetition=t}get BackwardJumpInstructions(){return this.backwardJumpInstructions}get EndingIndexDict(){return this.endingIndexDict}get EndingParts(){return this.endingParts}get Visibles(){return this.visibles}set Visibles(e){this.visibles=e}get DefaultNumberOfRepetitions(){let e=2;return this.virtualOverallRepetition&&(e=1),Math.max(e,Object.keys(this.endingIndexDict).length,this.checkRepetitionForMultipleLyricVerses())}get UserNumberOfRepetitions(){return this.userNumberOfRepetitions}set UserNumberOfRepetitions(e){this.userNumberOfRepetitions=e,this.repetitonIterationOrder=[];const t=this.userNumberOfRepetitions-this.NumberOfEndings;for(let i=1;i<=this.userNumberOfRepetitions;i++)i<=t?this.repetitonIterationOrder.push(1):this.repetitonIterationOrder.push(i-t)}getForwardJumpTargetForIteration(e){const t=this.repetitonIterationOrder[e-1];return this.endingIndexDict[t]?this.endingIndexDict[t].part.StartIndex:-1}getBackwardJumpTarget(){return this.startMarker.measureIndex}setEndingsStartIndex(e,t){const i=new xs(new Es(this.musicSheet2,t,t));this.endingParts.push(i);for(const r of e)try{this.endingIndexDict[r]=i,i.endingIndices.push(r),this.numberOfEndings<r&&(this.numberOfEndings=r)}catch(n){s.error("Repetition: Exception.",n)}}setEndingStartIndex(e,t){const i=new xs(new Es(this.musicSheet2,t,t));this.EndingIndexDict[e]=i,this.endingParts.push(i),i.endingIndices.push(e),this.numberOfEndings<e&&(this.numberOfEndings=e)}setEndingEndIndex(e,t){this.endingIndexDict[e]&&this.endingIndexDict[e].part.setEndIndex(t)}get NumberOfEndings(){return this.numberOfEndings}get FromWords(){return this.fromWords}set FromWords(e){this.fromWords=e}get AbsoluteTimestamp(){return u.createFromFraction(this.musicSheet2.SourceMeasures[this.startMarker.measureIndex].AbsoluteTimestamp)}get StartIndex(){return this.startMarker.measureIndex}get EndIndex(){if(0===this.BackwardJumpInstructions.length)return this.StartIndex;let e=this.backwardJumpInstructions[this.backwardJumpInstructions.length-1].measureIndex;return this.endingIndexDict[this.NumberOfEndings]&&(e=Math.max(this.endingIndexDict[this.NumberOfEndings].part.EndIndex,e)),e}checkRepetitionForMultipleLyricVerses(){let e=0;const t=this.StartIndex,i=this.EndIndex;for(let s=t;s<=i;s++){const t=this.musicSheet2.SourceMeasures[s];for(let i=0;i<(null==t?void 0:t.CompleteNumberOfStaves);i++)if(t.VerticalSourceStaffEntryContainers[i])for(const s of t.VerticalSourceStaffEntryContainers[i].StaffEntries)if(s){let t=0;for(const e of s.VoiceEntries)t+=e.LyricsEntries.keys.length;e=Math.max(e,t)}}return e}get FirstSourceMeasureNumber(){return this.getFirstSourceMeasure().MeasureNumber}get LastSourceMeasureNumber(){return this.getLastSourceMeasure().MeasureNumber}coversIdenticalMeasures(e){return this.StartIndex===e.StartIndex&&this.EndIndex===e.EndIndex}removeFromRepetitionInstructions(){void 0!==this.startMarker&&(this.startMarker.parentRepetition=void 0),void 0!==this.endMarker&&(this.endMarker.parentRepetition=void 0);for(const e of this.BackwardJumpInstructions)e.parentRepetition=void 0}}class xs{constructor(e){this.endingIndices=[],this.part=e}ToString(){return this.endingIndices.join(", ")}}class Ts{constructor(e=new u,t=100){this.rhythm=e,this.beatsPerMinute=t,this.beatLengthInMilliseconds=6e4/t,this.beatRealValue=1/4}static createFrom(e){return new Ts(e.Rhythm,e.BeatsPerMinute)}get BeatsPerMinute(){return this.beatsPerMinute}set BeatsPerMinute(e){this.beatsPerMinute=e,this.beatLengthInMilliseconds=6e4/this.beatsPerMinute}get Rhythm(){return this.rhythm}set Rhythm(e){this.rhythm=e}get BeatRealValue(){return this.beatRealValue}get BeatLengthInMilliseconds(){return this.beatLengthInMilliseconds}getDurationInMilliseconds(e){return("number"==typeof e?e:e.RealValue)*this.BeatLengthInMilliseconds/this.beatRealValue}getDurationAsNoteDuration(e,t=1024){const i=e/this.BeatLengthInMilliseconds;let s=Math.floor(i);const n=new u(s,4),r=i-s;return s=Math.round(r/(1/t)/4),0!==r&&0===s&&e>0&&(s=1),n.Add(new u(s,t)),n}}class ws{constructor(){this.idString="uninitialized",this.sourceMeasures=[],this.repetitions=[],this.dynListStaves=[],this.timestampSortedDynamicExpressionsList=[],this.timestampSortedTempoExpressionsList=[],this.instrumentalGroups=[],this.instruments=[],this.musicPartManager=void 0,this.musicSheetErrors=new De,this.staves=[],this.playbackDataDict=new i,this.transpose=0,this.defaultStartTempoInBpm=0,this.drawErroneousMeasures=!1,this.hasBeenOpenedForTheFirstTime=!1,this.currentEnrolledPosition=new u(0,1),this.MeasureWidthFactor=1,this.soundTempos=new Map,this.userStartTempoInBPM=100,this.playbackSettings=new Ts(new u(4,4,0,!1),this.userStartTempoInBPM),this.pageWidth=120,this.MusicPartManager=new Ms(this),this.hasBPMInfo=!1}get SoundTempos(){return this.soundTempos}set SoundTempos(e){this.soundTempos=e}static getIndexFromStaff(e){return e.idInMusicSheet}get CurrentKeyInstruction(){return this.currentKeyInstruction}set CurrentKeyInstruction(e){this.currentKeyInstruction=e}get SourceMeasures(){return this.sourceMeasures}set SourceMeasures(e){this.sourceMeasures=e}get Repetitions(){return this.repetitions}set Repetitions(e){this.repetitions=e}get DynListStaves(){return this.dynListStaves}get TimestampSortedTempoExpressionsList(){return this.timestampSortedTempoExpressionsList}get TimestampSortedDynamicExpressionsList(){return this.timestampSortedDynamicExpressionsList}get InstrumentalGroups(){return this.instrumentalGroups}get Parts(){return this.instruments}get Instruments(){return this.instruments}get SheetPlaybackSetting(){return this.playbackSettings}set SheetPlaybackSetting(e){this.playbackSettings=e}get DrawErroneousMeasures(){return this.drawErroneousMeasures}set DrawErroneousMeasures(e){this.drawErroneousMeasures=e}get HasBeenOpenedForTheFirstTime(){return this.hasBeenOpenedForTheFirstTime}set HasBeenOpenedForTheFirstTime(e){this.hasBeenOpenedForTheFirstTime=e}InitializeStartTempoInBPM(e){this.playbackSettings.BeatsPerMinute=e,this.userStartTempoInBPM=e}get DefaultStartTempoInBpm(){return this.defaultStartTempoInBpm}set DefaultStartTempoInBpm(e){this.defaultStartTempoInBpm=e,this.InitializeStartTempoInBPM(e)}get Path(){return this.path}set Path(e){this.path=e}get Staves(){return this.staves}get TitleString(){return this.title?this.title.text:""}set TitleString(e){this.Title=new pt(e)}get SubtitleString(){return this.subtitle?this.subtitle.text:""}set SubtitleString(e){this.Subtitle=new pt(e)}get ComposerString(){return this.composer?this.composer.text:""}set ComposerString(e){this.Composer=new pt(e)}get LyricistString(){return this.lyricist?this.lyricist.text:""}set LyricistString(e){this.Lyricist=new pt(e)}get CopyrightString(){return this.copyright?this.copyright.text:""}set CopyrightString(e){this.Copyright=new pt(e,ce.CenterBottom,void 0,!0)}get Title(){return this.title}set Title(e){this.title=e}get Subtitle(){return this.subtitle}set Subtitle(e){this.subtitle=e}get Composer(){return this.composer}set Composer(e){this.composer=e}get Lyricist(){return this.lyricist}set Lyricist(e){this.lyricist=e}get Copyright(){return this.copyright}set Copyright(e){this.copyright=e}get Rules(){return this.rules||(s.debug("warning: sheet.Rules was undefined. Creating new EngravingRules."),this.rules=new xe),this.rules}set Rules(e){this.rules=e}get SheetErrors(){return this.musicSheetErrors}get PlaybackDataDict(){return this.playbackDataDict}get SelectionStart(){return this.selectionStart}set SelectionStart(e){this.selectionStart=e.clone(),this.currentEnrolledPosition=e.clone()}get SelectionEnd(){return this.selectionEnd}set SelectionEnd(e){this.selectionEnd=e}set HasBPMInfo(e){this.hasBPMInfo=e}get HasBPMInfo(){return this.hasBPMInfo}addMeasure(e){this.sourceMeasures.push(e),e.measureListIndex=this.sourceMeasures.length-1}checkForInstrumentWithNoVoice(){for(let e=0,t=this.instruments.length;e<t;++e){const t=this.instruments[e];if(0===t.Voices.length){const e=new _e(t,1);t.Voices.push(e)}}}getStaffFromIndex(e){return this.staves[e]}fillStaffList(){let e=0;for(let t=0,i=this.instruments.length;t<i;++t){const i=this.instruments[t];for(let t=0,s=i.Staves.length;t<s;++t){const s=i.Staves[t];s.idInMusicSheet=e,this.staves.push(s),e++}}}get MusicPartManager(){return this.musicPartManager}set MusicPartManager(e){this.musicPartManager=e}getCompleteNumberOfStaves(){let e=0;for(let t=0,i=this.instruments.length;t<i;++t)e+=this.instruments[t].Staves.length;return e}getListOfMeasuresFromIndeces(e,t){const i=[];for(let s=e;s<=t;s++)i.push(this.sourceMeasures[s]);return i}getNextSourceMeasure(e){const t=this.sourceMeasures.indexOf(e);return t===this.sourceMeasures.length-1?e:this.sourceMeasures[t+1]}getFirstSourceMeasure(){return this.sourceMeasures[0]}getLastSourceMeasure(){return this.sourceMeasures[this.sourceMeasures.length-1]}resetAllNoteStates(){const e=this.MusicPartManager.getIterator();for(;!e.EndReached&&e.CurrentVoiceEntries;){for(let t=0,i=e.CurrentVoiceEntries.length;t<i;++t){const i=e.CurrentVoiceEntries[t];for(let e=0,t=i.Notes.length;e<t;++e)i.Notes[e].state=W.Normal}e.moveToNext()}}getMusicSheetInstrumentIndex(e){return this.Instruments.indexOf(e)}getGlobalStaffIndexOfFirstStaff(e){const t=this.getMusicSheetInstrumentIndex(e);let i=0;for(let s=0;s<t;s++)i+=this.Instruments[s].Staves.length;return i}setRepetitionNewUserNumberOfRepetitions(e,t){let i=0;for(let s=0;s<this.repetitions.length;s++)if(this.repetitions[s]instanceof Ls){if(e===i){this.repetitions[s].UserNumberOfRepetitions=t;break}i++}}getRepetitionByIndex(e){let t=0;for(let i=0;i<this.repetitions.length;i++)if(this.repetitions[i]instanceof Ls){if(e===t)return this.repetitions[i];t++}}CompareTo(e){return this.Title.text.localeCompare(e.Title.text)}getExpressionsStartTempoInBPM(){if(this.TimestampSortedTempoExpressionsList.length>0){const e=this.TimestampSortedTempoExpressionsList[0];if(e.InstantaneousTempo)return e.InstantaneousTempo.TempoInBpm;if(e.ContinuousTempo)return e.ContinuousTempo.StartTempo}return this.userStartTempoInBPM}get Errors(){return this.musicSheetErrors.measureErrors}get FirstMeasureNumber(){try{return this.getFirstSourceMeasure().MeasureNumber}catch(e){return s.info("MusicSheet.FirstMeasureNumber: ",e),0}}get LastMeasureNumber(){try{return this.getLastSourceMeasure().MeasureNumber}catch(e){return s.info("MusicSheet.LastMeasureNumber: ",e),0}}get CurrentEnrolledPosition(){return this.currentEnrolledPosition.clone()}set CurrentEnrolledPosition(e){this.currentEnrolledPosition=e.clone()}get Transpose(){return this.transpose}set Transpose(e){this.transpose=e}get FullNameString(){return this.ComposerString+" "+this.TitleString}get IdString(){return this.idString}set IdString(e){this.idString=e}getEnrolledSelectionStartTimeStampWorkaround(){const e=this.MusicPartManager.getIterator(this.SelectionStart);return u.createFromFraction(e.CurrentEnrolledTimestamp)}get SheetEndTimestamp(){const e=this.getLastSourceMeasure();return u.plus(e.AbsoluteTimestamp,e.Duration)}getSourceMeasureFromTimeStamp(e){for(let t=0,i=this.sourceMeasures.length;t<i;++t){const i=this.sourceMeasures[t];for(let t=0,s=i.VerticalSourceStaffEntryContainers.length;t<s;++t){const s=i.VerticalSourceStaffEntryContainers[t];if(e.Equals(s.getAbsoluteTimestamp()))return i}}return this.findSourceMeasureFromTimeStamp(e)}findSourceMeasureFromTimeStamp(e){for(const t of this.sourceMeasures)if(t.AbsoluteTimestamp.lte(e)&&e.lt(u.plus(t.AbsoluteTimestamp,t.Duration)))return t}getVisibleInstruments(){const e=[];for(let t=0,i=this.Instruments.length;t<i;++t){const i=this.Instruments[t];i.Voices.length>0&&i.Voices[0].Visible&&e.push(i)}return e}}ws.defaultTitle="defaultTitle";class Is{constructor(){this.syllables=[]}get Syllables(){return this.syllables}containsVoiceEntry(e){for(let t=0,i=this.Syllables.length;t<i;++t)if(this.Syllables[t].Parent===e)return!0;return!1}findLyricEntryInVoiceEntry(e){for(let t=0,i=this.Syllables.length;t<i;++t){const i=this.Syllables[t];if(i.Parent===e)return i}}}class As{constructor(e,t,i,s,n=-1){this.text=e,this.word=i,this.parent=s,this.verseNumber=t,n>=0&&(this.syllableIndex=n)}get Text(){return this.text}set Text(e){this.text=e}get Word(){return this.word}get Parent(){return this.parent}set Parent(e){this.parent=e}get VerseNumber(){return this.verseNumber}get SyllableIndex(){return this.syllableIndex}get IsTranslation(){return this.VerseNumber.endsWith("translation")}get IsChorus(){return this.VerseNumber.startsWith("chorus")}get FontStyle(){return this.IsChorus||this.IsTranslation?me.Italic:me.Regular}}class Rs{constructor(e){this.openLyricWords={},this.musicSheet=e}addLyricEntry(e,t){if(e){const r=e;for(let e=0,o=r.length;e<o;++e){const o=r[e];try{let e="single";if(o.element("text")){let n=o.element("text");if(o.element("syllabic")&&(e=o.element("syllabic").value),n){let r="";const a=o.elements();for(const e of a)"text"!==e.name&&"elision"!==e.name||(r+=e.value);if(r=r.replace(" "," "),void 0!==o.element("elision")&&"-"===r){const t=o.elements();let i,s,r=0;for(let e=0;e<t.length;e++)if("elision"===t[e].name){r=e;break}if(r>0)for(let e=r;e<t.length;e++){const n=t[e];"text"===n.name&&(i=n),"syllabic"===n.name&&(s=n)}void 0!==i&&s&&(n=i,e="middle")}let l,h="1";if(void 0!==o.attributes()&&o.attribute("number")&&(h=o.attribute("number").value),"single"===e||"end"===e){if(this.openLyricWords[h]){this.currentLyricWord=this.openLyricWords[h];const e=this.currentLyricWord.Syllables.length;l=new As(r,h,this.currentLyricWord,t,e),this.currentLyricWord.Syllables.push(l),delete this.openLyricWords[h],this.currentLyricWord=void 0}else l=new As(r,h,void 0,t);l.extend=void 0!==o.element("extend")}else if("begin"===e)this.openLyricWords[h]&&(delete this.openLyricWords[h],this.currentLyricWord=void 0),this.currentLyricWord=new Is,this.openLyricWords[h]=this.currentLyricWord,l=new As(r,h,this.currentLyricWord,t,0),this.currentLyricWord.Syllables.push(l);else if("middle"===e)if(this.openLyricWords[h]){this.currentLyricWord=this.openLyricWords[h];const e=this.currentLyricWord.Syllables.length;l=new As(r,h,this.currentLyricWord,t,e),this.currentLyricWord.Syllables.push(l)}else l=new As(r,h,void 0,t);var i,s;if(l)t.LyricsEntries[h]||(t.LyricsEntries.setValue(h,l),null!==(i=t.ParentSourceStaffEntry)&&void 0!==i&&null!==(s=i.VerticalContainerParent)&&void 0!==s&&s.ParentMeasure&&(t.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.hasLyrics=!0)),t.ParentVoice.Parent.LyricVersesNumbers.includes(h)||t.ParentVoice.Parent.LyricVersesNumbers.push(h)}}}catch(n){const e=Xe.translateText("ReaderErrorMessages/LyricError","Error while reading lyric entry.");this.musicSheet.SheetErrors.pushMeasureError(e);continue}}}}}class Ns{constructor(e,t){this.articulationEnum=e,this.placement=t}Equals(e){return e.articulationEnum===this.articulationEnum&&e.placement===this.placement}}class Cs{constructor(){}get StartNote(){return this.startNote}set StartNote(e){this.startNote=e}get EndNote(){return this.endNote}set EndNote(e){this.endNote=e}startNoteHasMoreStartingSlurs(){if(!this.startNote)return!1;for(let e=0,t=this.startNote.NoteSlurs.length;e<t;++e){const t=this.startNote.NoteSlurs[e];if(t!==this&&t.StartNote===this.startNote)return!0}return!1}endNoteHasMoreEndingSlurs(){if(!this.endNote)return!1;for(let e=0,t=this.endNote.NoteSlurs.length;e<t;++e){const t=this.endNote.NoteSlurs[e];if(t!==this&&t.EndNote===this.endNote)return!0}return!1}isCrossed(){return this.startNote.ParentStaffEntry.ParentStaff!==this.endNote.ParentStaffEntry.ParentStaff}isSlurLonger(){if(!this.endNote||!this.startNote)return!1;const e=u.minus(this.endNote.getAbsoluteTimestamp(),this.startNote.getAbsoluteTimestamp());for(let t=0,i=this.startNote.NoteSlurs.length;t<i;++t){const i=this.startNote.NoteSlurs[t];if(i!==this&&void 0!==i.EndNote&&void 0!==i.StartNote&&-1===u.minus(i.EndNote.getAbsoluteTimestamp(),i.StartNote.getAbsoluteTimestamp()).CompareTo(e))return!0}for(let t=0,i=this.endNote.NoteSlurs.length;t<i;++t){const i=this.endNote.NoteSlurs[t];if(i!==this&&void 0!==i.EndNote&&void 0!==i.StartNote&&u.minus(i.EndNote.getAbsoluteTimestamp(),i.StartNote.getAbsoluteTimestamp()).CompareTo(e))return!0}return!1}}class Bs{constructor(e){this.rules=e}getAccEnumFromString(e){switch(e){case"sharp":return Y.SHARP;case"flat":return Y.FLAT;case"natural":return Y.NATURAL;case"double-sharp":case"sharp-sharp":return Y.DOUBLESHARP;case"double-flat":case"flat-flat":return Y.DOUBLEFLAT;case"triple-sharp":return Y.TRIPLESHARP;case"triple-flat":return Y.TRIPLEFLAT;case"quarter-sharp":return Y.QUARTERTONESHARP;case"quarter-flat":return Y.QUARTERTONEFLAT;case"three-quarters-sharp":return Y.THREEQUARTERSSHARP;case"three-quarters-flat":return Y.THREEQUARTERSFLAT;case"slash-quarter-sharp":return Y.SLASHQUARTERSHARP;case"slash-sharp":return Y.SLASHSHARP;case"double-slash-flat":return Y.DOUBLESLASHFLAT;case"sori":return Y.SORI;case"koron":return Y.KORON;default:return Y.NONE}}addArticulationExpression(e,t){if(void 0!==e&&e.elements().length>0){const o=e.elements();for(let e=0,a=o.length;e<a;++e){const a=o[e];let l=a.name;try{l=l.replace("-","");const e=ct[l];if(ut.isSupportedArticulation(e)){var i;let s=d.NotYetDefined;const r=null===(i=a.attribute("placement"))||void 0===i?void 0:i.value;"above"===r?s=d.Above:"below"===r&&(s=d.Below);const o=new Ns(e,s);if("staccato"===l)t.Articulations.length>0&&t.Articulations[0].articulationEnum!==ct.staccato&&t.Articulations.splice(0,0,o);else if("breathmark"===l)s===d.NotYetDefined&&(o.placement=d.Above);else if("strongaccent"===l){var n;const e=null==a||null===(n=a.attribute("type"))||void 0===n?void 0:n.value;"up"===e?o.articulationEnum=ct.marcatoup:"down"===e&&(o.articulationEnum=ct.marcatodown)}else if(e===ct.softaccent){const e=t.ParentSourceStaffEntry.ParentStaff.Id-1;s===d.NotYetDefined&&(s=d.Above,e>0&&(s=d.Below));const i=t.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure,n=new ri(i,t.Timestamp);n.StartingContinuousDynamic=new m(p.crescendo,s,e,i,null,-1),n.StartingContinuousDynamic.IsStartOfSoftAccent=!0,n.StartingContinuousDynamic.StartMultiExpression=n,n.StartingContinuousDynamic.EndMultiExpression=n,n.EndingContinuousDynamic=new m(p.diminuendo,s,e,i,null,-1),n.EndingContinuousDynamic.StartMultiExpression=n,n.EndingContinuousDynamic.EndMultiExpression=n,i.StaffLinkedExpressions[e].push(n)}if(!t.hasArticulation(o))switch(t.Articulations.push(o),o.articulationEnum){case ct.staccato:case ct.staccatissimo:t.DurationModifier=o;break;case ct.accent:case ct.strongaccent:t.VolumeModifier=o}}}catch(r){const e="Invalid note articulation.";return void s.debug("addArticulationExpression",e,r)}}}}addFermata(e,t){var i;let s=ct.fermata;e.attributes().length>0&&e.attribute("type")&&"inverted"===e.attribute("type").value&&(s=ct.invertedfermata);let n=d.Above;"below"===(null===(i=e.attribute("placement"))||void 0===i?void 0:i.value)&&(n=d.Below),t.Articulations.push(new Ns(s,n))}addTechnicalArticulations(e,t,i){const s={bend:ct.bend,"down-bow":ct.downbow,"open-string":ct.naturalharmonic,"snap-pizzicato":ct.snappizzicato,stopped:ct.lefthandpizzicato,"up-bow":ct.upbow,harmonic:ct.naturalharmonic};for(const l in s){if(!s.hasOwnProperty(l))continue;const i=s[l],o=e.element(l);if(o){var n,r;let e;"above"===(null===(n=o.attribute("placement"))||void 0===n?void 0:n.value)&&(e=d.Above),"below"===(null===(r=o.attribute("placement"))||void 0===r?void 0:r.value)&&(e=d.Below);const s=new Ns(i,e);t.hasArticulation(s)||t.Articulations.push(s)}}const o=e.elements("fingering");for(const l of o){const e=this.createTechnicalInstruction(l,i);e.type=ot.Fingering,i.Fingering||(i.Fingering=e),t.TechnicalInstructions.push(e)}const a=e.element("string");if(a){const e=this.createTechnicalInstruction(a,i);e.type=ot.String,i.StringInstruction=e,t.TechnicalInstructions.push(e)}}createTechnicalInstruction(e,t){const i=new at;i.sourceNote=t,i.value=e.value;const s=e.attribute("placement");return this.rules.FingeringPositionFromXML&&(i.placement=this.getPlacement(s)),i}getPlacement(e,t=d.NotYetDefined){if(t!==d.NotYetDefined)return t;if(!e)return d.NotYetDefined;switch(e.value){case"above":return d.Above;case"below":return d.Below;case"left":return d.Left;case"right":return d.Right;default:return d.NotYetDefined}}addOrnament(e,t){if(e){let i;const s={"delayed-inverted-turn":je.DelayedInvertedTurn,"delayed-turn":je.DelayedTurn,"inverted-mordent":je.InvertedMordent,"inverted-turn":je.InvertedTurn,mordent:je.Mordent,"trill-mark":je.Trill,turn:je.Turn};for(const t in s){if(!s.hasOwnProperty(t))continue;const n=e.element(t);if(n){i=new Ye(s[t]);const e=n.attribute("placement");e&&"below"===e.value&&(i.placement=d.Below)}}if(i){const s=e.elements("accidental-mark");if(s){let e=d.Below,t=Y.NONE;const n=s;for(let s=0,r=n.length;s<r;++s){const r=n[s];let o=r.value;t=this.getAccEnumFromString(o);const a=r.attribute("placement");r.hasAttributes&&a&&(o=a.value,"above"===o?e=d.Above:"below"===o&&(e=d.Below)),e===d.Above?i.AccidentalAbove=t:e===d.Below&&(i.AccidentalBelow=t)}}t.OrnamentContainer=i}}}}class Ds{constructor(e,t,i,s,n=void 0){this.openBeams=[],this.beamNumberOffset=0,this.currentOctaveShift=0,this.tupletDict={},this.openTupletNumber=0,this.currMeasureVoiceEntries=[],this.graceVoiceEntriesTempList=[],this.staff=t,this.instrument=t.ParentInstrument,this.musicSheet=this.instrument.GetMusicSheet,this.slurReader=s,this.pluginManager=e,this.voice=n?new Ge(this.instrument,i,n):new _e(this.instrument,i),this.instrument.Voices.push(this.voice),this.staff.Voices.push(this.voice),this.lyricsReader=new Rs(this.musicSheet),this.articulationReader=new Bs(this.musicSheet.Rules)}get openTieDict(){return this.staff.openTieDict}get GetVoice(){return this.voice}get OctaveShift(){return this.currentOctaveShift}set OctaveShift(e){this.currentOctaveShift=e}createVoiceEntry(e,t,i,s,n=!1,r=!1,o=!1){this.activeKey=i,this.activeRhythm=s,this.currentVoiceEntry=new ut(u.createFromFraction(e),this.voice,t,!0,n,r,o),n?this.graceVoiceEntriesTempList.push(this.currentVoiceEntry):(this.currentNormalVoiceEntry=this.currentVoiceEntry,this.currMeasureVoiceEntries.push(this.currentNormalVoiceEntry),this.graceVoiceEntriesTempList.length>0&&(this.currentVoiceEntry.GraceVoiceEntriesBefore=this.graceVoiceEntriesTempList,this.graceVoiceEntriesTempList=[]))}finalizeReadingMeasure(){this.graceVoiceEntriesTempList.length>0&&void 0!==this.currentNormalVoiceEntry&&this.currentNormalVoiceEntry.GraceVoiceEntriesAfter.concat(this.graceVoiceEntriesTempList),this.graceVoiceEntriesTempList=[],this.pluginManager.processVoiceMeasureReadPlugins(this.currMeasureVoiceEntries,this.activeKey,this.activeRhythm),this.currMeasureVoiceEntries.length=0,this.openBeams.length>1&&this.handleOpenBeam()}read(e,t,i,n,r,o,a,l,h,u,c,d,f,m,p,g,S,y,b,M,v,P,E){this.currentStaffEntry=a,this.currentMeasure=l;try{this.currentNote=o?this.addRestNote(e.element("rest"),t,n,i,r,f,m,b,e):this.addSingleNote(e,t,n,i,r,c,d,f,m,p,g,S,y,b,v,P,E),this.currentNote.DotsXml=M;const s=e.elements("lyric");void 0!==this.lyricsReader&&s&&(this.lyricsReader.addLyricEntry(s,this.currentVoiceEntry),this.voice.Parent.HasLyrics=!0);let a=!1;const l=e.element("notations");if(l){this.articulationReader&&this.readArticulations(l,this.currentVoiceEntry,this.currentNote);const t=l.elements("slur"),i=l.elements("slide"),s=l.elements("glissando");void 0!==this.slurReader&&(t.length>0||i.length>0)&&!this.currentNote.ParentVoiceEntry.IsGrace&&(this.slurReader.addSlur(t,this.currentNote),i.length>0&&this.slurReader.addSlur(i,this.currentNote),s.length>0&&this.slurReader.addSlur(s,this.currentNote));const n=l.elements("tuplet");n.length>0&&(this.openTupletNumber=this.addTuplet(e,n),a=!0);const r=l.element("arpeggiate");if(void 0!==r){let e;if(this.currentVoiceEntry.Arpeggio)e=this.currentVoiceEntry.Arpeggio;else{let t=!1;for(const i of this.currentStaffEntry.VoiceEntries)if(i.Arpeggio){t=!0,e=i.Arpeggio;break}if(!t){let t=ke.ARPEGGIO_DIRECTIONLESS;const i=r.attribute("direction");if(i)switch(i.value){case"up":t=ke.ROLL_UP;break;case"down":t=ke.ROLL_DOWN;break;default:t=ke.ARPEGGIO_DIRECTIONLESS}e=new Ve(this.currentVoiceEntry,t),this.currentVoiceEntry.Arpeggio=e}}e.addNote(this.currentNote)}const o=l.elements("tied");o.length>0&&this.addTie(o,h,u,Se.SIMPLE);const c=l.element("technical");if(c){const e=c.elements("hammer-on");e.length>0&&this.addTie(e,h,u,Se.HAMMERON);const t=c.elements("pull-off");t.length>0&&this.addTie(t,h,u,Se.PULLOFF)}}void 0===e.element("time-modification")||a||this.handleTimeModificationNode(e)}catch(L){s.warn(L);const e=Xe.translateText("ReaderErrorMessages/NoteError","Ignored erroneous Note.");this.musicSheet.SheetErrors.pushMeasureError(e),this.musicSheet.SheetErrors.pushMeasureError(L)}return this.currentNote}checkForStaffEntryLink(e,t,i,s){const n=new st(this.currentVoiceEntry);n.LinkStaffEntries.push(i),i.Link=n;const r=this.currentVoiceEntry.Timestamp.clone(),o=s.getVerticalContainerByTimestamp(r);return(i=o.StaffEntries[e])||(i=new Je(o,t),o.StaffEntries[e]=i),i.VoiceEntries.push(this.currentVoiceEntry),n.LinkStaffEntries.push(i),i.Link=n,i}checkForOpenBeam(){this.openBeams.length>0&&this.currentNote&&this.handleOpenBeam()}checkOpenTies(){const e=this.openTieDict;for(const t in e)if(e.hasOwnProperty(t)){const i=e[t];u.plus(i.StartNote.ParentStaffEntry.Timestamp,i.Duration).lt(i.StartNote.SourceMeasure.Duration)&&delete e[t]}}hasVoiceEntry(){return void 0!==this.currentVoiceEntry}readArticulations(e,t,i){const s=e.element("articulations");s&&this.articulationReader.addArticulationExpression(s,t);const n=e.element("fermata");n&&this.articulationReader.addFermata(n,t);const r=e.element("technical");r&&this.articulationReader.addTechnicalArticulations(r,t,i);const o=e.element("ornaments");o&&this.articulationReader.addOrnament(o,t)}addSingleNote(e,t,i,n,r,o,a,l,h,c,d,f,m,p,g,y,b){var M;let v,P,E,L,x=0,T=Y.NONE,w=H.C,I=H.C,A=0,R=0;const N=e.elements();for(let u=0,X=N.length;u<X;++u){const e=N[u];try{if("pitch"===e.name){const t=e.elements();for(let e=0,i=t.length;e<i;++e){const i=t[e];E=void 0,L=void 0;try{if("step"===i.name){if(w=H[i.value],void 0===w){const e=Xe.translateText("ReaderErrorMessages/NotePitchError","Invalid pitch while reading note.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S(e,void 0)}}else if("alter"===i.name){if(x=parseFloat(i.value),isNaN(x)){const e=Xe.translateText("ReaderErrorMessages/NoteAlterationError","Invalid alteration while reading note.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S(e,void 0)}T=K.AccidentalFromHalfTones(x)}else if("octave"===i.name&&(A=parseInt(i.value,10),isNaN(A))){const e=Xe.translateText("ReaderErrorMessages/NoteOctaveError","Invalid octave value while reading note.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S(e,void 0)}}catch(U){s.info("VoiceGenerator.addSingleNote read Step: ",U.message)}}}else if("accidental"===e.name)v=e.value,"natural"===v?T=Y.NATURAL:"slash-flat"===v?T=Y.SLASHFLAT:"slash-quarter-sharp"===v?T=Y.SLASHQUARTERSHARP:"slash-sharp"===v?T=Y.SLASHSHARP:"double-slash-flat"===v?T=Y.DOUBLESLASHFLAT:"sori"===v?T=Y.SORI:"koron"===v&&(T=Y.KORON);else if("unpitched"===e.name){const t=e.element("display-step"),i=e.element("display-octave");if(i&&(A=parseInt(i.value,10),R=A-3,a&&(A+=1),1===this.instrument.Staves[0].StafflineCount&&(R+=1)),t){w=H[t.value.toUpperCase()];let e=0,i=this.musicSheet.Rules.PercussionXMLDisplayStepNoteValueShift;1===this.instrument.Staves[0].StafflineCount&&(i-=3),[I,e]=K.lineShiftFromNoteEnum(w,i),R+=e}}else"instrument"===e.name?e.firstAttribute&&(P=e.firstAttribute.value):"notehead"===e.name&&(E=e.value,e.attribute("filled")&&(L="yes"===e.attribute("filled").value))}catch(U){s.info("VoiceGenerator.addSingleNote: ",U)}}A-=K.OctaveXmlDifference;const C=new K(w,A,T,v),B=u.createFromFraction(t);let D,V=-1,k=-1;const F=[],O=e.element("notations");if(O){const e=O.element("technical");if(e){const t=e.element("string");t&&(V=parseInt(t.value,10));const i=e.element("fret");i&&(k=parseInt(i.value,10)),e.elements("bend").forEach((function(e){const t=e.element("bend-alter");void 0!==e.element("release")?F.push({bendalter:parseInt(t.value,10),direction:"down"}):F.push({bendalter:parseInt(t.value,10),direction:"up"})}))}}D=V<0||k<0?new Ae(this.currentVoiceEntry,this.currentStaffEntry,B,C,this.currentMeasure):new Yt(this.currentVoiceEntry,this.currentStaffEntry,B,C,this.currentMeasure,V,k,F);let _=[];const G=e.element("times"),W=null==G||null===(M=G.elem)||void 0===M?void 0:M.getElementsByTagName("time");return W&&W.length&&Array.from(W).forEach((e=>{const t=e.getAttribute("begin"),i=e.getAttribute("end");_.push({begin:t?t/1e3:0,end:i?i/1e3:0})})),this.addNoteInfo(D,i,l,h,r,I,R,p,p,_),D.TypeLength=n,D.IsGraceNote=c,D.StemDirectionXml=d,D.TremoloInfo=f,D.PlaybackInstrumentId=P,(void 0!==E&&"normal"!==E||void 0!==L)&&(D.Notehead=new We(D,E,L)),D.NoteheadColorXml=p,D.NoteheadColor=p,D.PlaybackInstrumentId=P,D.TremoloType=g,D.glissandoType=y,D.slideType=b,this.currentVoiceEntry.addNote(D),d===dt.None&&(m="#00000000"),this.currentVoiceEntry.StemDirectionXml=d,m&&(this.currentVoiceEntry.StemColorXml=m,this.currentVoiceEntry.StemColor=m,D.StemColorXml=m),e.elements("beam")&&!o&&this.createBeam(e,D),D.IsChordNote=o,D}addRestNote(e,t,i,s,n,r,o,a,l){var h;const c=u.createFromFraction(t),d=e.element("display-step"),f=e.element("display-octave");let m,p,g;d&&f&&(m=H[d.value.toUpperCase()],p=parseInt(f.value,10),g=new K(m,p,Y.NONE,void 0,!0));const S=new Ae(this.currentVoiceEntry,this.currentStaffEntry,c,g,this.currentMeasure,!0);let y=[];const b=e.element("times")||l.element("times"),M=null==b||null===(h=b.elem)||void 0===h?void 0:h.getElementsByTagName("time");return M&&M.length&&Array.from(M).forEach((e=>{const t=e.getAttribute("begin"),i=e.getAttribute("end");y.push({begin:t?t/1e3:0,end:i?i/1e3:0})})),this.addNoteInfo(S,i,r,o,n,m,p,a,a,y),S.TypeLength=s,this.currentVoiceEntry.Notes.push(S),this.openBeams.length>0&&this.openBeams.last().ExtendedNoteList.push(S),S}addNoteInfo(e,t,i,s,n,r,o,a,l,h){e.NoteTypeXml=t,e.PrintObject=i,e.IsCueNote=s,e.NormalNotes=n,e.displayStepUnpitched=r,e.displayOctaveUnpitched=o,e.NoteheadColorXml=a,e.NoteheadColor=a,e.noteTimeInfo=h}createBeam(e,t){try{const n=e.element("beam");let r;if(void 0!==n&&n.hasAttributes&&(r=n.attribute("number")),r){let n=parseInt(r.value,10);const o=e.elements("beam"),a=o[0].value;var i;o&&("begin"===a?(n===(null===(i=this.openBeams.last())||void 0===i?void 0:i.BeamNumber)?(this.beamNumberOffset++,n+=this.beamNumberOffset):this.openBeams.last()&&this.handleOpenBeam(),this.openBeams.push(new Fe(n,this.beamNumberOffset))):n+=this.beamNumberOffset);let l=!1;if(!(n>0&&n<=this.openBeams.length&&this.openBeams[n-1]))return void s.debug("[OSMD] invalid beamnumber");for(let e=0,t=this.openBeams[n-1].Notes.length;e<t;++e){const t=this.openBeams[n-1].Notes[e];this.currentVoiceEntry===t.ParentVoiceEntry&&(l=!0)}l||(this.openBeams[n-1].addNoteToBeam(t),"end"===a&&this.endBeam())}}catch(n){const e=Xe.translateText("ReaderErrorMessages/BeamError","Error while reading beam.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S("",n)}}endBeam(){this.openBeams.pop(),this.beamNumberOffset=Math.max(0,this.beamNumberOffset-1)}handleOpenBeam(){const e=this.openBeams.last();if(0!==e.Notes.length){if(1===e.Notes.length)return e.Notes[0].NoteBeam=void 0,void this.endBeam();if(this.currentNote===le.last(e.Notes))this.endBeam();else{const t=le.last(e.Notes).ParentStaffEntry,i=this.currentMeasure.getVerticalContainerIndexByTimestamp(t.Timestamp),s=t.VerticalContainerParent.StaffEntries.indexOf(t);if(i<this.currentMeasure.VerticalSourceStaffEntryContainers.length-1){const e=this.currentMeasure.VerticalSourceStaffEntryContainers[i+1].StaffEntries[s];if(e)for(let t=0,i=e.VoiceEntries.length;t<i;++t){const i=e.VoiceEntries[t];if(i.ParentVoice===this.voice){const e=i.Notes[0];e.Length.lte(new u(1,8))?(this.openBeams.last().addNoteToBeam(e),this.endBeam()):this.endBeam()}}}else this.endBeam()}}else this.endBeam()}addTuplet(e,t){let i,s=!1;if(void 0!==t&&t.length>1){let n=e.element("time-modification");n&&(n=n.element("actual-notes"));const r=t;for(let t=0,o=r.length;t<o;++t){const o=r[t];if(void 0!==o&&o.attributes()){const t=o.attribute("bracket");t&&"yes"===t.value?(s=!0,i=!0):t&&"no"===t.value&&(i=!1);const r=this.readShowNumberNoneGiven(o),a=o.attribute("type");if(a&&"start"===a.value){let t=1;o.attribute("number")&&(t=parseInt(o.attribute("number").value,10));let a=0;if(n&&(a=parseInt(n.value,10),isNaN(a))){const e=Xe.translateText("ReaderErrorMessages/TupletNoteDurationError","Invalid tuplet note duration.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S(e,void 0)}const l=new rt(a,s);l.BracketedXmlValue=i,l.ShowNumberNoneGivenInXml=r,l.tupletLabelNumberPlacement=d.Above;const h=o.attribute("placement");h&&("below"===h.value&&(l.tupletLabelNumberPlacement=d.Below),l.PlacementFromXml=!0),this.tupletDict[t]&&(delete this.tupletDict[t],0===Object.keys(this.tupletDict).length?this.openTupletNumber=0:Object.keys(this.tupletDict).length>1&&this.openTupletNumber--),this.tupletDict[t]=l;const u=[];u.push(this.currentNote),l.Notes.push(u),l.Fractions.push(this.getTupletNoteDurationFromType(e)),this.currentNote.NoteTuplet=l,this.openTupletNumber=t}else if("stop"===a.value){let t=1;o.attribute("number")&&(t=parseInt(o.attribute("number").value,10));const i=this.tupletDict[t];if(i){const s=o.attribute("placement");s&&("below"===s.value?i.tupletLabelNumberPlacement=d.Below:i.tupletLabelNumberPlacement=d.Above,i.PlacementFromXml=!0);const n=[];if(n.push(this.currentNote),i.Notes.push(n),!i.PlacementFromXml){let e=!1;for(const t of i.Notes){for(const s of t)if(!s.isRest()){s.StemDirectionXml===dt.Down?i.tupletLabelNumberPlacement=d.Below:i.tupletLabelNumberPlacement=d.Above,e=!0;break}if(e)break}}i.Fractions.push(this.getTupletNoteDurationFromType(e)),this.currentNote.NoteTuplet=i,delete this.tupletDict[t],0===Object.keys(this.tupletDict).length?this.openTupletNumber=0:Object.keys(this.tupletDict).length>1&&this.openTupletNumber--}}}}}else if(t[0]){const n=t[0];if(n.hasAttributes){const t=n.attribute("type").value;let r=1;n.attribute("number")&&(r=parseInt(n.attribute("number").value,10));const o=isNaN(r),a=this.readShowNumberNoneGiven(n),l=n.attribute("bracket");if(l&&"yes"===l.value?(s=!0,i=!0):l&&"no"===l.value&&(i=!1),"start"===t){let t=0,l=e.element("time-modification");if(l&&(l=l.element("actual-notes")),l&&(t=parseInt(l.value,10),isNaN(t))){const e=Xe.translateText("ReaderErrorMessages/TupletNoteDurationError","Invalid tuplet note duration.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S(e)}o&&(this.openTupletNumber++,r=this.openTupletNumber);let h=this.tupletDict[r];h||(h=this.tupletDict[r]=new rt(t,s),h.BracketedXmlValue=i,h.ShowNumberNoneGivenInXml=a,h.tupletLabelNumberPlacement=d.Above);const u=n.attribute("placement");u&&("below"===u.value?h.tupletLabelNumberPlacement=d.Below:h.tupletLabelNumberPlacement=d.Above,h.PlacementFromXml=!0);const c=[];c.push(this.currentNote),h.Notes.push(c),h.Fractions.push(this.getTupletNoteDurationFromType(e)),this.currentNote.NoteTuplet=h,this.openTupletNumber=r}else if("stop"===t){o&&(r=this.openTupletNumber);const t=this.tupletDict[this.openTupletNumber];if(t){const i=n.attribute("placement");i&&("below"===i.value?t.tupletLabelNumberPlacement=d.Below:t.tupletLabelNumberPlacement=d.Above,t.PlacementFromXml=!0);const s=[];if(s.push(this.currentNote),t.Notes.push(s),!t.PlacementFromXml){let e=!1;for(const i of t.Notes){for(const s of i)if(!s.isRest()){s.StemDirectionXml===dt.Down?t.tupletLabelNumberPlacement=d.Below:t.tupletLabelNumberPlacement=d.Above,e=!0;break}if(e)break}}t.Fractions.push(this.getTupletNoteDurationFromType(e)),this.currentNote.NoteTuplet=t,0===Object.keys(this.tupletDict).length?this.openTupletNumber=0:Object.keys(this.tupletDict).length>1&&this.openTupletNumber--,delete this.tupletDict[r]}}}}return this.openTupletNumber}readShowNumberNoneGiven(e){const t=e.attribute("show-number");return!(null==t||!t.value||"none"!==t.value)}handleTimeModificationNode(e){if(this.tupletDict[this.openTupletNumber])try{const t=this.tupletDict[this.openTupletNumber],i=le.last(t.Notes);let s;i[0].ParentVoiceEntry.Timestamp.Equals(this.currentVoiceEntry.Timestamp)?s=i:(s=[],t.Notes.push(s),t.Fractions.push(this.getTupletNoteDurationFromType(e))),s.push(this.currentNote),this.currentNote.NoteTuplet=t}catch(t){const e=Xe.translateText("ReaderErrorMessages/TupletNumberError","Invalid tuplet number.");throw this.musicSheet.SheetErrors.pushMeasureError(e),t}else if(this.currentVoiceEntry.Notes.length>0){const e=this.currentVoiceEntry.Notes[0];if(e.NoteTuplet){const t=e.NoteTuplet;le.last(t.Notes).push(this.currentNote),this.currentNote.NoteTuplet=t}}}addTie(e,t,i,s){if(e)if(1===e.length){const t=e[0];if(void 0!==t&&t.attributes()){const e=this.getTieDirection(t),i=t.attribute("type").value;try{if("start"===i){const t=this.findCurrentNoteInTieDict(this.currentNote);t<0&&delete this.openTieDict[t];const i=this.getNextAvailableNumberForTie(),n=new nt(this.currentNote,s);this.openTieDict[i]=n,n.TieNumber=i,n.TieDirection=e}else if("stop"===i){const e=this.findCurrentNoteInTieDict(this.currentNote),t=this.openTieDict[e];t&&(t.AddNote(this.currentNote),delete this.openTieDict[e])}}catch(n){const e=Xe.translateText("ReaderErrorMessages/TieError","Error while reading tie.");this.musicSheet.SheetErrors.pushMeasureError(e)}}}else if(2===e.length){const t=this.findCurrentNoteInTieDict(this.currentNote);if(t>=0){const i=this.openTieDict[t];i.AddNote(this.currentNote);for(const t of e)if("start"===t.attribute("type").value){const e=this.getTieDirection(t);i.NoteIndexToTieDirection[i.Notes.length-1]=e}}}}getTieDirection(e){let t=d.NotYetDefined;const i=e.attribute("placement");i&&("above"===i.value?t=d.Above:"below"===i.value&&(t=d.Below));const s=e.attribute("orientation");return s&&("over"===s.value?t=d.Above:"under"===s.value&&(t=d.Below)),t}getNextAvailableNumberForTie(){const e=Object.keys(this.openTieDict);if(0===e.length)return 1;e.sort(((e,t)=>+e-+t));for(let t=0;t<e.length;t++)if(""+(t+1)!==e[t])return t+1;return+e[e.length-1]+1}findCurrentNoteInTieDict(e){const t=this.openTieDict;for(const i in t)if(t.hasOwnProperty(i)){const s=t[i],n=s.Notes[0],r=e;if(s.Pitch.FundamentalNote===e.Pitch.FundamentalNote&&s.Pitch.Octave===e.Pitch.Octave)return parseInt(i,10);if(void 0!==n.StringNumberTab&&n.StringNumberTab===r.StringNumberTab)return parseInt(i,10)}return-1}getTupletNoteDurationFromType(e){if(e.element("type")){const i=e.element("type");if(i){const e=i.value;try{return He.getNoteDurationFromType(e)}catch(t){const e=Xe.translateText("ReaderErrorMessages/NoteDurationError","Invalid note duration.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new S("",t)}}}}}class Vs{static readChordSymbol(e,t,i){const n=e.element("root"),r=e.element("kind"),o=r.attribute("text");if(!n||!r)return;const a=n.element("root-step"),l=n.element("root-alter");if(!a)return;let h;try{h=H[a.value.trim()]}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}let u=Y.NONE;if(l)try{u=K.AccidentalFromHalfTones(parseInt(l.value,10))}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");t.SheetErrors.pushMeasureError(e),s.debug("InstrumentReader.readChordSymbol",e,y)}const c=new K(h,1,u);let d,f,m=r.value.trim().replace("-","");if(o)switch(o.value){case"aug":m="augmented";break;case"dim":m="diminished"}try{d=Pe[m]}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}const p=e.element("bass");if(p){const e=p.element("bass-step"),i=p.element("bass-alter");let n=H.C;if(e)try{n=H[e.value.trim()]}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}let r=Y.NONE;if(i)try{r=K.AccidentalFromHalfTones(parseInt(i.value,10))}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");t.SheetErrors.pushMeasureError(e),s.debug("InstrumentReader.readChordSymbol",e,y)}f=new K(n,1,r)}const g=[],S=e.elements("degree");for(const b of S)if(b){const e=b.element("degree-value"),i=b.element("degree-alter"),n=b.element("degree-type");if(!e||!i||!n)return;let r,o,a;try{r=parseInt(e.value.trim(),10)}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}try{o=K.AccidentalFromHalfTones(parseInt(i.value,10))}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}try{a=ve[n.value.trim().toLowerCase()]}catch(y){const e=Xe.translateText("ReaderErrorMessages/ChordSymbolError","Invalid chord symbol");return t.SheetErrors.pushMeasureError(e),void s.debug("InstrumentReader.readChordSymbol",e,y)}g.push(new be(r,o,a))}return new ye(c,d,f,g,t.Rules)}}class ks{constructor(e=!1,t=!0){this.ChangeEnd=!1,this.ChangeBegin=!1,this.EndsStave=!1,this.BeginsStave=!1,this.line=e,this.sign=t}get IsLine(){return this.line}get IsSign(){return this.sign}}class Fs extends c{constructor(e){super(e)}}class Os{constructor(e,t,i){this.openContinuousDynamicExpressions=[],this.musicSheet=e,this.staffNumber=i,this.globalStaffIndex=e.getGlobalStaffIndexOfFirstStaff(t)+(i-1),this.initialize()}readExpressionParameters(e,t,i,n,r,o,a){this.initialize(),this.divisions=i;const l=e.element("offset");if(void 0!==l&&!a)try{this.offsetDivisions=parseInt(l.value,10)}catch(g){const e="ReaderErrorMessages/ExpressionOffsetError, Invalid expression offset -> set to default.";s.debug("ExpressionReader.readExpressionParameters",e,g),this.musicSheet.SheetErrors.pushMeasureError(e),this.offsetDivisions=0}this.directionTimestamp=u.createFromFraction(n);let h,c=new u(Math.abs(this.offsetDivisions),4*i);this.offsetDivisions>0?n.RealValue>0?(c=u.multiply(u.minus(n,r),c),this.directionTimestamp=u.plus(c,n)):this.directionTimestamp=u.createFromFraction(c):this.offsetDivisions<0&&(n.RealValue>0?(c=u.multiply(u.minus(n,r),c),this.directionTimestamp=u.minus(n,c)):this.directionTimestamp=u.createFromFraction(c));const f=e.element("direction-type");let m;if(f&&(m=f.element("wedge"),m)){const e=m.attribute("default-y");e&&(h=this.readPosition(e))}this.WedgeYPosXml=h;const p=e.attribute("placement");if(p)try{const e=p.value;"below"===e?this.placement=d.Below:"above"===e&&(this.placement=d.Above)}catch(g){const e=Xe.translateText("ReaderErrorMessages/ExpressionPlacementError","Invalid expression placement -> set to default.");s.debug("ExpressionReader.readExpressionParameters",e,g),this.musicSheet.SheetErrors.pushMeasureError(e),this.placement=d.Below}if(this.placement===d.NotYetDefined)try{if(f){const e=f.element("dynamics");if(e){const t=e.attribute("default-y");t&&this.readExpressionPlacement(t,"read dynamics y pos")}if(m){const e=m.attribute("default-y");e&&this.readExpressionPlacement(e,"read wedge y pos")}const t=f.element("words");if(t){const e=t.attribute("default-y");e&&this.readExpressionPlacement(e,"read words y pos")}const i=f.element("rehearsal");if(i){const e=i.attribute("default-y");e&&this.readExpressionPlacement(e,"read rehearsal pos")}}}catch(g){const e=Xe.translateText("ReaderErrorMessages/ExpressionPlacementError","Invalid expression placement. Set to default.");s.debug("ExpressionReader.readExpressionParameters",e,g),this.musicSheet.SheetErrors.pushMeasureError(e),this.placement=d.Below}this.placement===d.NotYetDefined&&(t.Staves.length>1?this.placement=d.Below:t.HasLyrics?this.placement=d.Above:this.placement=d.Below)}read(e,t,i,n=void 0,r=0,o){let a=!1,l=!1;const h=e.element("sound");if(h){const e=h.attribute("tempo"),i=h.attribute("dynamics");if(e){const i=e.value.match(/^(\d+)(\.\d+)?$/);(null==i?void 0:i.length)>0?this.soundTempo=Math.round(Number.parseFloat(e.value)):(s.info("invalid xml tempo: "+e.value),this.soundTempo=100),t.TempoInBPM=this.soundTempo,0===this.musicSheet.DefaultStartTempoInBpm&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),this.musicSheet.HasBPMInfo=!0,a=!0}if(i){const e=i.value.match(/\d+/);this.soundDynamic=void 0!==e?parseInt(e[0],10):100,l=!0}}const c=e.element("direction-type");if(!c)return;let d=c.element("metronome");if(d){t.metronomeNoteIndex=r;const e=d.element("beat-unit"),s=void 0!==d.element("beat-unit-dot"),n=d.element("per-minute");if(void 0!==e&&n){d.hasAttributes&&void 0!==d.attribute("default-x")&&(this.directionTimestamp=u.createFromFraction(i));const r=parseFloat(n.value);!o&&this.createNewTempoExpressionIfNeeded(t);const a=new ei(void 0,this.placement,this.staffNumber,r,this.currentMultiTempoExpression,!0);a.parentMeasure=t,this.soundTempo=r,t.TempoInBPM=1*this.soundTempo,0===this.musicSheet.DefaultStartTempoInBpm&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),1===t.MeasureNumberXML&&0===this.musicSheet.SourceMeasures.length&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),this.musicSheet.HasBPMInfo=!0,a.dotted=s,a.beatUnit=e.value,this.currentMultiTempoExpression.addExpression(a,""),this.currentMultiTempoExpression.CombinedExpressionsText="test"}}else if(d=c.element("dynamics"),d){const s=void 0!==e.element("notations");this.interpretInstantaneousDynamics(d,t,i,s)}else if(d=c.element("words"),d){const e=c.elements("words");let s="";for(const t of e)s+=t.value;if(d.value=s,d.value&&d.value.toLocaleLowerCase().includes("compound_tempo")&&(d.value=""),a||Lt(d.value)||xt(d.value)){this.createNewTempoExpressionIfNeeded(t),this.currentMultiTempoExpression.CombinedExpressionsText=d.value,(Lt(d.value)||xt(d.value))&&(d.value=void 0);const e=new ei(d.value,this.placement,this.staffNumber,this.soundTempo,this.currentMultiTempoExpression);this.currentMultiTempoExpression.addExpression(e,"")}else l||this.interpretWords(d,t,i)}else d=c.element("wedge"),d?this.interpretWedge(e,d,t,n,t.MeasureNumber):(d=c.element("rehearsal"),d&&this.interpretRehearsalMark(d,t,i,t.MeasureNumber))}closeOpenExpressions(e,t){for(const i of this.openContinuousDynamicExpressions)this.createNewMultiExpressionIfNeeded(e,i.NumberXml,t),this.closeOpenContinuousDynamic(i,e,t);this.openContinuousTempoExpression&&this.closeOpenContinuousTempo(u.plus(e.AbsoluteTimestamp,t))}addOctaveShift(e,t,i){let n=1;const r=e.element("staff");if(r)try{n=parseInt(r.value,10)}catch(l){const e=Xe.translateText("ReaderErrorMessages/OctaveShiftStaffError","Invalid octave shift staff number. Set to default");this.musicSheet.SheetErrors.pushMeasureError(e),n=1,s.debug("ExpressionReader.addOctaveShift",e,l)}const o=e.element("direction-type");if(o){const r=o.element("octave-shift"),h=this.readPlacement(e);if(void 0!==r&&r.hasAttributes)try{const e=this.readNumber(r);if(r.attribute("size")){var a;const o=parseInt(r.attribute("size").value,10);let l=0;8===o?l=1:15===o&&(l=2);let u=null===(a=r.attribute("type"))||void 0===a?void 0:a.value;if(u||(h===d.Above?u="down":h===d.Below&&(u="up")),"up"===u||"down"===u){const i=new qt(u,l);i.StaffNumber=n,this.getMultiExpression=this.createNewMultiExpressionIfNeeded(t,e),this.getMultiExpression.OctaveShiftStart=i,i.ParentStartMultiExpression=this.getMultiExpression,this.openOctaveShift=i}else"stop"===u?this.openOctaveShift&&(this.getMultiExpression=this.createNewMultiExpressionIfNeeded(t,this.openOctaveShift.numberXml,i),this.getMultiExpression.OctaveShiftEnd=this.openOctaveShift,this.openOctaveShift.ParentEndMultiExpression=this.getMultiExpression,this.openOctaveShift=void 0):u||s.debug("octave-shift missing type in xml")}}catch(l){const e=Xe.translateText("ReaderErrorMessages/OctaveShiftError","Error while reading octave shift.");this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("ExpressionReader.addOctaveShift",e,l)}}}addPedalMarking(e,t,i){const n=e.element("direction-type");if(n){const e=n.element("pedal");if(void 0!==e&&e.hasAttributes){let n=!1,h=!1;try{var r,o,a;switch("yes"===(null===(r=e.attribute("line"))||void 0===r?void 0:r.value)?h=!0:"no"===(null===(o=e.attribute("line"))||void 0===o?void 0:o.value)?(h=!1,n=!0):"yes"===(null===(a=e.attribute("sign"))||void 0===a?void 0:a.value)?n=!0:(n=!1,h=!0),e.attribute("type").value){case"start":this.openPedal&&this.openPedal.IsLine&&this.endOpenPedal(t),this.createNewMultiExpressionIfNeeded(t,-1),this.openPedal=new ks(h,n),this.getMultiExpression.PedalStart=this.openPedal,this.openPedal.ParentStartMultiExpression=this.getMultiExpression;break;case"stop":this.openPedal&&this.endOpenPedal(t,i);break;case"change":this.openPedal&&this.openPedal.IsLine&&(this.openPedal.ChangeEnd=!0,this.createNewMultiExpressionIfNeeded(t,-1),this.getMultiExpression.PedalEnd=this.openPedal,this.openPedal.ParentEndMultiExpression=this.getMultiExpression,this.createNewMultiExpressionIfNeeded(t,-1),this.openPedal=new ks(h,n),this.openPedal.ChangeBegin=!0,this.getMultiExpression.PedalStart=this.openPedal,this.openPedal.ParentStartMultiExpression=this.getMultiExpression)}}catch(l){const e=Xe.translateText("ReaderErrorMessages/PedalError","Error while reading pedal.");this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("ExpressionReader.addPedalMarking",e,l)}}}}endOpenPedal(e,t){this.createNewMultiExpressionIfNeeded(e,-1,t),this.getMultiExpression.PedalEnd=this.openPedal,this.openPedal.ParentEndMultiExpression=this.getMultiExpression,this.openPedal=void 0}addWavyLine(e,t,i,n){if(e&&e.hasAttributes)try{switch(e.attribute("type").value){case"start":this.createNewMultiExpressionIfNeeded(t,-1),this.openWavyLine=new Fs(this.placement),this.getMultiExpression.WavyLineStart=this.openWavyLine,this.openWavyLine.ParentStartMultiExpression=this.getMultiExpression;break;case"stop":this.openWavyLine&&(this.createNewMultiExpressionIfNeeded(t,-1,i),this.getMultiExpression.WavyLineEnd=this.openWavyLine,this.openWavyLine.ParentEndMultiExpression=this.getMultiExpression,this.openWavyLine=void 0)}}catch(r){const e=Xe.translateText("ReaderErrorMessages/WavyLineError","Error while reading wavy-line.");this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("ExpressionReader.addWavyLine",e,r)}}initialize(){this.placement=d.NotYetDefined,this.soundTempo=0,this.soundDynamic=0,this.offsetDivisions=0}readPlacement(e){var t;const i=null===(t=e.attribute("placement"))||void 0===t?void 0:t.value;return"above"===i?d.Above:"below"===i?d.Below:d.NotYetDefined}readExpressionPlacement(e,t){try{const t=this.readPosition(e);t<0?this.placement=d.Below:t>0&&(this.placement=d.Above)}catch(i){s.debug("ExpressionReader.readExpressionParameters",t,i)}}readPosition(e){try{const t=parseInt(e.value,10);return t<0?this.placement=d.Below:t>0&&(this.placement=d.Above),t}catch(t){s.debug("ExpressionReader.readExpressionParameters",t)}}interpretInstantaneousDynamics(e,t,i,s){if(e.hasElements){var n;e.hasAttributes&&e.attribute("default-x")&&(this.directionTimestamp=u.createFromFraction(i));const l=this.readNumber(e);let h=null===(n=e.elements()[0])||void 0===n?void 0:n.name;if("other-dynamics"===h&&(h=e.elements()[0].value),h){var r;if(null!==(r=t.Rules)&&void 0!==r&&r.IgnoreRepeatedDynamics){var o;let e;try{e=P[h]}catch(a){const e=Xe.translateText("ReaderErrorMessages/DynamicError","Error while reading dynamic.");return void this.musicSheet.SheetErrors.pushMeasureError(e)}if((null===(o=this.activeInstantaneousDynamic)||void 0===o?void 0:o.DynEnum)===e)return}s?this.createNewMultiExpressionIfNeeded(t,l,u.createFromFraction(i)):this.createNewMultiExpressionIfNeeded(t,l);const e=new v(h,this.soundDynamic,this.placement,this.staffNumber,t);e.InMeasureTimestamp=i.clone(),this.getMultiExpression.addExpression(e,""),this.initialize(),this.activeInstantaneousDynamic?this.activeInstantaneousDynamic.DynEnum=e.DynEnum:this.activeInstantaneousDynamic=new v(h,0,d.NotYetDefined,1,t)}}}interpretWords(e,t,i){const s=e.value;if(t.Rules.IgnoreBracketsWords&&(/^\(\s*\)$/.test(s)||/^\[\s*\]$/.test(s)))return;let n;const r=e.attribute("font-style");let o,a,l;r&&(o=r.value,"italic"===o&&(n=me.Italic));const h=e.attribute("font-weight");h&&(a=h.value,"bold"===a&&(n=me.Bold,"italic"===o&&(n=me.BoldItalic)));const c=e.attribute("color");let d;if(c&&(l=c.value),t.Rules.PlaceWordsInsideStafflineFromXml){var f;const t=null===(f=e.attribute("default-y"))||void 0===f?void 0:f.value;(null==t?void 0:t.length)>0&&(d=Number.parseInt(t,10))}if(s.length>0){if(e.hasAttributes&&e.attribute("default-x")&&(this.directionTimestamp=u.createFromFraction(i)),this.checkIfWordsNodeIsRepetitionInstruction(s))return;this.fillMultiOrTempoExpression(s,t,i,n,l,d),this.initialize()}}readNumber(e){var t;let i=1;const s=null===(t=e.attribute("number"))||void 0===t?void 0:t.value;return s&&(i=Number.parseInt(s,10)),i}interpretWedge(e,t,i,s,n){var r,o;void 0!==t&&t.hasAttributes&&t.attribute("default-x")&&(this.directionTimestamp=u.createFromFraction(s));const a=this.readNumber(t),l=null===(r=t.attribute("type"))||void 0===r||null===(o=r.value)||void 0===o?void 0:o.toLowerCase();this.lastWedge&&this.lastWedge.parentMeasure.MeasureNumberXML===i.MeasureNumberXML&&this.lastWedge.StaffNumber===this.staffNumber&&this.placement===this.lastWedge.Placement&&void 0!==this.WedgeYPosXml&&this.lastWedge.YPosXml===this.WedgeYPosXml&&this.lastWedge.StartMultiExpression.Timestamp.Equals(this.directionTimestamp)&&this.lastWedge.DynamicType===p[l]||("stop"===l?(this.createNewMultiExpressionIfNeeded(i,a,s),this.getMultiExpression.EndOffsetFraction=new u(this.offsetDivisions,4*this.divisions)):this.createNewMultiExpressionIfNeeded(i,a),this.addWedge(t,i,s),this.initialize())}interpretRehearsalMark(e,t,i,s){t.rehearsalExpression=new ci(e.value,this.placement)}createNewMultiExpressionIfNeeded(e,t,i=void 0){i||(i=this.directionTimestamp);let s=this.getMultiExpression;return(!s||s&&(s.SourceMeasureParent!==e||s.numberXml!==t||s.SourceMeasureParent===e&&!s.Timestamp.Equals(i)))&&(this.getMultiExpression=s=new ri(e,u.createFromFraction(i)),this.getMultiExpression.numberXml=t,e.StaffLinkedExpressions[this.globalStaffIndex].push(s)),s}createNewTempoExpressionIfNeeded(e){this.currentMultiTempoExpression&&this.currentMultiTempoExpression.SourceMeasureParent===e&&this.currentMultiTempoExpression.Timestamp===this.directionTimestamp||(this.currentMultiTempoExpression=new hi(e,u.createFromFraction(this.directionTimestamp)),e.TempoExpressions.push(this.currentMultiTempoExpression))}addWedge(e,t,i){if(void 0!==e&&e.hasAttributes){const r=this.readNumber(e),o=e.attribute("type").value.toLowerCase();try{if("crescendo"===o||"diminuendo"===o){const e=new m(p[o],this.placement,this.staffNumber,t,this.activeInstantaneousDynamic,r);this.lastWedge=e,this.lastWedge.YPosXml=this.WedgeYPosXml,this.openContinuousDynamicExpressions.push(e);let i=this.getMultiExpression;i||(i=this.createNewMultiExpressionIfNeeded(t,r)),i.StartingContinuousDynamic=e,e.StartMultiExpression=i,void 0!==this.activeInstantaneousDynamic&&this.activeInstantaneousDynamic.StaffNumber===e.StaffNumber&&(this.activeInstantaneousDynamic=void 0)}else if("stop"===o)for(const e of this.openContinuousDynamicExpressions)e.NumberXml===r&&this.closeOpenContinuousDynamic(e,t,i)}catch(n){const e="ReaderErrorMessages/WedgeError, Error while reading Crescendo / Diminuendo.";this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("ExpressionReader.addWedge",e,n)}}}fillMultiOrTempoExpression(e,t,i,s,n,r=void 0){if(!e)return;const o=e.trim();this.createExpressionFromString("",o,t,i,e,s,n,r)}createExpressionFromString(e,t,i,s,n,r,o,a=void 0){if(ei.isInputStringInstantaneousTempo(t)||li.isInputStringContinuousTempo(t)){if(i.TempoExpressions.length>0)for(let e=0,s=i.TempoExpressions.length;e<s;++e){const s=i.TempoExpressions[e];if(s.Timestamp===this.directionTimestamp&&void 0!==s.InstantaneousTempo&&-1!==s.InstantaneousTempo.Label.indexOf(t))return!1}if(this.createNewTempoExpressionIfNeeded(i),this.currentMultiTempoExpression.CombinedExpressionsText=n,ei.isInputStringInstantaneousTempo(t)){const i=new ei(t,this.placement,this.staffNumber,this.soundTempo,this.currentMultiTempoExpression);return i.ColorXML=o,this.currentMultiTempoExpression.addExpression(i,e),!0}if(li.isInputStringContinuousTempo(t)){const i=new li(t,this.placement,this.staffNumber,this.currentMultiTempoExpression);return i.ColorXML=o,this.currentMultiTempoExpression.addExpression(i,e),!0}}if(m.isInputStringContinuousDynamic(t)){const n=new m(void 0,this.placement,this.staffNumber,i,this.activeInstantaneousDynamic,-1,t);n.ColorXML=o;const r=this.getMultiExpression;return r&&this.closeOpenContinuousDynamic(r.StartingContinuousDynamic,i,s),this.createNewMultiExpressionIfNeeded(i,-1),void 0!==this.activeInstantaneousDynamic&&this.activeInstantaneousDynamic.StaffNumber===n.StaffNumber&&(this.activeInstantaneousDynamic=void 0),this.openContinuousDynamicExpressions.push(n),n.StartMultiExpression=this.getMultiExpression,this.getMultiExpression.addExpression(n,e),!0}if(si.isInputStringMood(t)){const s=this.createNewMultiExpressionIfNeeded(i,-1);i.hasMoodExpressions=!0;const n=new si(t,this.placement,this.staffNumber);return n.fontStyle=r,n.ColorXML=o,s.addExpression(n,e),!0}const l=this.createNewMultiExpressionIfNeeded(i,-1);if(i.TempoExpressions.length>0)for(let c=0,d=i.TempoExpressions.length;c<d;++c){const e=i.TempoExpressions[c];if(e.Timestamp===this.directionTimestamp&&void 0!==e.InstantaneousTempo&&e.EntriesList.length>0&&!this.hasDigit(t)&&this.globalStaffIndex>0){if(e.EntriesList[0].label.indexOf(t)>=0)return!1;break}}let h=ce.CenterBottom;this.musicSheet.Rules.CompactMode&&(h=ce.LeftBottom);const u=new ni(t,this.placement,h,this.staffNumber);return u.fontStyle=r,u.ColorXML=o,u.defaultYXml=a,l.addExpression(u,e),!1}closeOpenContinuousDynamic(e,t,i){if(!e)return;const s=e.NumberXml;e.EndMultiExpression=this.createNewMultiExpressionIfNeeded(t,s,i),e.StartMultiExpression.EndingContinuousDynamic=e,this.openContinuousDynamicExpressions=this.openContinuousDynamicExpressions.filter((t=>t!==e))}closeOpenContinuousTempo(e){this.openContinuousTempoExpression.AbsoluteEndTimestamp=e,this.openContinuousTempoExpression=void 0}checkIfWordsNodeIsRepetitionInstruction(e){return"coda"===(e=e.trim().toLowerCase())||"tocoda"===e||"to coda"===e||"fine"===e||"d.c."===e||"dacapo"===e||"da capo"===e||"d.s."===e||"dalsegno"===e||"dal segno"===e||"d.c. al fine"===e||"d.s. al fine"===e||"d.c. al coda"===e||"d.s. al coda"===e}hasDigit(e){return/\d/.test(e)}}class _s{constructor(e){this.openSlurDict={},this.musicSheet=e}addSlur(e,t,i){try{if(e)for(const r of e)if(r.attributes().length>0){const e=r.attribute("type").value;let o=1;try{r.attribute("number")&&(o=parseInt(r.attribute("number").value,10))}catch(n){s.debug("VoiceGenerator.addSlur number: ",n)}let a=d.NotYetDefined;const l=r.attribute("placement");l&&l.value&&("above"===l.value?a=d.Above:"below"===l.value&&(a=d.Below));const h=r.attribute("orientation");if(h&&h.value&&("over"===h.value?a=d.Above:"under"===h.value&&(a=d.Below)),"start"===e){let e=new Cs;this.openSlurDict[o]=e,e.StartNote=t,e.idx=i,e.PlacementXml=a}else if("stop"===e){const e=this.openSlurDict[o];if(e){const s=r.name;if("slide"===s||"glissando"===s){const i=e.StartNote,s=new Oe(i);s.AddNote(t),s.EndNote=t,t.NoteGlissando=s,delete this.openSlurDict[o]}else e.idx=i,e.EndNote=t,t.isDuplicateSlur(e)||(t.NoteSlurs.push(e),e.StartNote.NoteSlurs.push(e)),delete this.openSlurDict[o]}}}}catch(r){const e=Xe.translateText("ReaderErrorMessages/SlurError","Error while reading slur.");this.musicSheet.SheetErrors.pushMeasureError(e)}}}class Gs{constructor(e,t,i,s){this.voiceGeneratorsDict={},this.staffMainVoiceGeneratorDict={},this.divisions=0,this.currentClefNumber=1,this.currentXmlMeasureIndex=0,this.activeKeyHasBeenInitialized=!1,this.abstractInstructions=[],this.soundTempos=new Map,this.xmlNotes=[],this.preCompoundTempo="",this.repetitionInstructionReader=t,this.xmlMeasureList=i,this.musicSheet=s.GetMusicSheet,this.instrument=s,this.activeClefs=new Array(s.Staves.length),this.activeClefsHaveBeenInitialized=new Array(s.Staves.length);for(let n=0;n<s.Staves.length;n++)this.activeClefsHaveBeenInitialized[n]=!1;this.createExpressionGenerators(s.Staves.length),this.slurReader=new _s(this.musicSheet),this.pluginManager=e}get SoundTempos(){return this.soundTempos}get ActiveKey(){return this.activeKey}get MaxTieNoteFraction(){return this.maxTieNoteFraction}get ActiveRhythm(){return this.activeRhythm}set ActiveRhythm(e){this.activeRhythm=e}readNextXmlMeasure(e,t,i){if(this.currentXmlMeasureIndex>=this.xmlMeasureList.length)return!1;this.currentMeasure=e,this.followingMultirestMeasures=Math.max(this.followingMultirestMeasures-1,0),this.inSourceMeasureInstrumentIndex=this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument),this.repetitionInstructionReader&&this.repetitionInstructionReader.prepareReadingMeasure(e,this.currentXmlMeasureIndex);let n=new u(0,1),r=new u(0,1),o=!1;this.maxTieNoteFraction=new u(0,1);let a=!1;const l=[];let h=!1;try{const T=this.xmlMeasureList[this.currentXmlMeasureIndex],w=T.attribute("osmdWidthFactor");w&&(e.WidthFactor=Number.parseFloat(w.value));const I=T.elements();if(e.Rules.UseXMLMeasureNumbers&&!Number.isInteger(e.MeasureNumberXML)){var c;const t=parseInt(null===(c=T.attribute("number"))||void 0===c?void 0:c.value,10);Number.isInteger(t)&&(e.MeasureNumberXML=t)}let A;for(let c=0;c<I.length;c++){const T=I[c];if(c>0&&(A=I[c-1]),"print"===T.name){const t=T.attribute("new-system");"yes"===(null==t?void 0:t.value)&&(e.printNewSystemXml=!0);const i=T.attribute("new-page");"yes"===(null==i?void 0:i.value)&&(e.printNewPageXml=!0)}else if("attributes"===T.name){const t=T.element("divisions");if(t&&(this.divisions=parseInt(t.value,10),isNaN(this.divisions))){const e=Xe.translateText("ReaderErrorMessages/DivisionError","Invalid divisions value at Instrument: ");if(s.debug("InstrumentReader.readNextXmlMeasure",e),this.divisions=this.readDivisionsFromNotes(),!(this.divisions>0))throw o=!0,new S(e+this.instrument.Name);this.musicSheet.SheetErrors.push(e+this.instrument.Name)}if(!T.element("divisions")&&0===this.divisions&&0===this.currentXmlMeasureIndex){const e=Xe.translateText("ReaderErrorMessages/DivisionError","Invalid divisions value at Instrument: ");if(this.divisions=this.readDivisionsFromNotes(),!(this.divisions>0))throw o=!0,new S(e+this.instrument.Name);this.musicSheet.SheetErrors.push(e+this.instrument.Name)}this.addAbstractInstruction(T,i,A,n.clone()),n.Equals(new u(0,1))&&this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex],T)&&this.saveAbstractInstructionList(this.instrument.Staves.length,!0),this.isAttributesNodeAtEndOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex],T,n)&&this.saveClefInstructionAtEndOfMeasure();const r=T.elements("staff-details");for(const e of r){const t=e.element("staff-lines");if(t){let i=1;const s=e.attribute("number");s&&(i=parseInt(s.value,10)),this.instrument.Staves[i-1].StafflineCount=parseInt(t.value,10)}}const a=T.element("measure-style");if(a){const t=a.element("multiple-rest");if(t){const i=t.value;let s=0;try{s=Number.parseInt(i,10),void 0!==e.multipleRestMeasures&&s!==e.multipleRestMeasures?e.multipleRestMeasures=0:(e.multipleRestMeasures=s,this.currentMultirestStartMeasure=e,this.followingMultirestMeasures=s+1)}catch(x){}}}}else if("note"===T.name){var d;let e=!0;"no"===(null===(d=T.attribute("print-object"))||void 0===d?void 0:d.value)&&(e=!1);const o=this.getNoteStaff(T);this.currentStaff=this.instrument.Staves[o-1];const h=void 0!==T.element("chord");if(T.element("voice")){const e=parseInt(T.element("voice").value,10);this.currentVoiceGenerator=this.getOrCreateVoiceGenerator(e,o-1)}else h&&this.currentVoiceGenerator||(this.currentVoiceGenerator=this.getOrCreateVoiceGenerator(1,o-1));let c,f=0,m=new u(0,1),p=2;if(T.element("duration")){if(f=parseInt(T.element("duration").value,10),isNaN(f)){const e=Xe.translateText("ReaderErrorMessages/NoteDurationError","Invalid Note Duration.");this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("InstrumentReader.readNextXmlMeasure",e);continue}if(m=new u(f,4*this.divisions),0===f?m=this.getNoteDurationFromTypeNode(T):c=this.getNoteDurationFromTypeNode(T),T.element("time-modification")){m=this.getNoteDurationForTuplet(T);const e=T.element("time-modification");null!=e&&e.element("normal-notes")&&(p=parseInt(e.element("normal-notes").value,10))}}const g=void 0!==T.element("rest"),S=T.combinedElement("notations"),y=void 0!==T.element("grace")||0===f||h&&a;let b=!1,M=!1;if(y){const e=T.element("duration"),t=T.element("grace");t&&t.attributes()&&t.attribute("slash")&&"yes"===t.attribute("slash").value&&(b=!0),e||(m=this.getNoteDurationFromTypeNode(T)),S&&S.element("slur")&&(M=!0)}const[v,P]=this.getCueNoteAndNoteTypeXml(T),[E,L,x]=this.getStemDirectionAndColors(T);let w,I=0,A="",R="",N="";if(S){const e=S.element("ornaments");if(e){w=this.getTremoloInfo(e),this.getWavyLines(e,T,n,r);const t=e.element("tremolo");if(t){const e=t.attribute("type");if(A=e.value,e){const i=parseInt(t.value,10);i>0&&(I=i),"start"!==e.value&&"stop"!==e.value||(m=new u(parseInt(T.element("duration").value,10),4*this.divisions))}}const i=e.elements("wavy-line");if(void 0!==i)for(const e of i){const t=this.expressionReaders[this.readExpressionStaffNumber(T)-1];t&&(t.readExpressionParameters(e,this.instrument,this.divisions,n,r,this.currentMeasure.MeasureNumber,!1),t.addWavyLine(e,this.currentMeasure,n,r))}}const t=S.elements("glissando");t.find((e=>"start"===e.attribute("type").value))&&(R="start");const i=S.elements("slide");i.find((e=>"start"===e.attribute("type").value))&&(N="start")}const C=h?r.clone():n.clone();this.currentStaffEntry=this.currentMeasure.findOrCreateStaffEntry(C,this.inSourceMeasureInstrumentIndex+o-1,this.currentStaff).staffEntry,(!this.currentVoiceGenerator.hasVoiceEntry()||!h&&!y&&!a||y&&!a||y&&!h||!y&&a)&&this.currentVoiceGenerator.createVoiceEntry(C,this.currentStaffEntry,this.activeKey,this.ActiveRhythm,y,b,M),y||h||(r=n.clone(),n.Add(m)),h&&void 0!==this.currentStaffEntry&&this.currentStaffEntry.ParentStaff!==this.currentStaff&&(this.currentStaffEntry=this.currentVoiceGenerator.checkForStaffEntryLink(this.inSourceMeasureInstrumentIndex+o-1,this.currentStaff,this.currentStaffEntry,this.currentMeasure));const B=void 0!==this.currentStaffEntry&&void 0!==this.currentStaffEntry.Timestamp&&this.currentStaffEntry.Timestamp.Equals(new u(0,1))&&!this.currentStaffEntry.hasNotes();this.saveAbstractInstructionList(this.instrument.Staves.length,B),this.activeRhythm;const D=T.elements("dot").length;if(this.currentVoiceGenerator.read(T,m,c,P,p,g,this.currentStaffEntry,this.currentMeasure,t,this.maxTieNoteFraction,h,i,e,v,y,E,w,L,x,D,A,R,N),void 0!==S&&S.element("dynamics")){const e=this.expressionReaders[this.readExpressionStaffNumber(T)-1];e&&(e.readExpressionParameters(T,this.instrument,this.divisions,n,r,this.currentMeasure.MeasureNumber,!1),e.read(T,this.currentMeasure,r,void 0,l.length))}a=y}else if("forward"===T.name){const e=parseInt(T.element("duration").value,10);n.Add(new u(e,4*this.divisions))}else if("backup"===T.name){const e=parseInt(T.element("duration").value,10);n.Sub(new u(e,4*this.divisions)),n.IsNegative()&&(n=new u(0,1)),r.Sub(new u(e,4*this.divisions)),r.IsNegative()&&(r=new u(0,1))}else if("direction"===T.name){const t=T.elements("direction-type"),i=T.element("direction-type");let s=Math.min(1,n.RealValue);void 0!==this.activeRhythm&&this.activeRhythm.Rhythm&&(s/=this.activeRhythm.Rhythm.RealValue);let o=!1;if(this.repetitionInstructionReader&&(o=this.repetitionInstructionReader.handleRepetitionInstructionsFromWordsOrSymbols(i,s)),!o){let s=this.expressionReaders[0];const o=this.readExpressionStaffNumber(T)-1;if(o<this.expressionReaders.length&&(s=this.expressionReaders[o]),s){var f;i.element("octave-shift")&&(s.readExpressionParameters(T,this.instrument,this.divisions,n,r,this.currentMeasure.MeasureNumber,!0),s.addOctaveShift(T,this.currentMeasure,r.clone())),i.element("pedal")&&(s.readExpressionParameters(T,this.instrument,this.divisions,n,r,this.currentMeasure.MeasureNumber,!0),s.addPedalMarking(T,this.currentMeasure,n.clone()));const o=i.element("words");if(o){var m,p,g,y,b,M,v,P;if(bt.map((e=>null==e?void 0:e.toLocaleLowerCase())).includes(null===(m=o.value)||void 0===m?void 0:m.toLocaleLowerCase())&&(this.currentGradualChangeMeasure=this.currentMeasure,this.currentMeasure.speedInfo={startWord:null===(b=o.value)||void 0===b?void 0:b.toLocaleLowerCase(),startXmlNoteIndex:l.length,endXmlNoteIndex:0,resetXmlNoteIndex:0,startMeasureListIndex:this.currentXmlMeasureIndex,endMeasureListIndex:0,resetMeasureListIndex:0},this.xmlNotes=[]),o.value.startsWith(Mt)&&null!==(p=this.currentGradualChangeMeasure)&&void 0!==p&&p.speedInfo&&(this.currentGradualChangeMeasure.speedInfo={...this.currentGradualChangeMeasure.speedInfo,endXmlNoteIndex:this.xmlNotes.length,endMeasureListIndex:this.currentXmlMeasureIndex}),(null===(g=o.value)||void 0===g?void 0:g.toLocaleLowerCase())==="a tempo".toLocaleLowerCase()&&null!==(y=this.currentGradualChangeMeasure)&&void 0!==y&&y.speedInfo){const{endXmlNoteIndex:e,resetXmlNoteIndex:t,endMeasureListIndex:i}=this.currentGradualChangeMeasure.speedInfo;0===t&&(this.currentGradualChangeMeasure.speedInfo={...this.currentGradualChangeMeasure.speedInfo,endXmlNoteIndex:e||this.xmlNotes.length,endMeasureListIndex:i||this.currentXmlMeasureIndex,resetXmlNoteIndex:this.xmlNotes.length,resetMeasureListIndex:this.currentXmlMeasureIndex}),this.xmlNotes=[]}h=!(!o.value||"hiddenspeed"!==o.value.toLocaleLowerCase()),o.value&&o.value.toLocaleLowerCase().includes("compound_tempo")&&(e.CompoundTempo=(null===(M=o.value.split("("))||void 0===M||null===(v=M[1])||void 0===v||null===(P=v.split(")"))||void 0===P?void 0:P[0])||"",this.preCompoundTempo=e.CompoundTempo)}if(t.find((e=>e.element("metronome")))&&null!==(f=this.currentGradualChangeMeasure)&&void 0!==f&&f.speedInfo){const{endXmlNoteIndex:e,resetXmlNoteIndex:t,endMeasureListIndex:i}=this.currentGradualChangeMeasure.speedInfo;0===t&&(this.currentGradualChangeMeasure.speedInfo={...this.currentGradualChangeMeasure.speedInfo,endXmlNoteIndex:e||this.xmlNotes.length,endMeasureListIndex:i||this.currentXmlMeasureIndex,resetXmlNoteIndex:this.xmlNotes.length,resetMeasureListIndex:this.currentXmlMeasureIndex}),this.xmlNotes=[]}s.readExpressionParameters(T,this.instrument,this.divisions,n,r,this.currentMeasure.MeasureNumber,!1),s.read(T,this.currentMeasure,n,r.clone(),l.length,h)}}}else if("barline"===T.name){var E;this.repetitionInstructionReader&&this.repetitionInstructionReader.handleLineRepetitionInstructions(T)&&(this.currentMeasure.HasEndLine=!0);const e=T.attribute("location"),t=null!==(E=null==e?void 0:e.value)&&void 0!==E?E:"right";if(c===I.length-1||"right"===t){var L;const e=null===(L=T.element("bar-style"))||void 0===L?void 0:L.value;e&&(this.currentMeasure.endingBarStyleXml=e,this.currentMeasure.endingBarStyleEnum=Ce.xmlBarlineStyleToSystemLinesEnum(e))}}else if("sound"===T.name)try{if(T.attribute("tempo")){const e=parseFloat(T.attribute("tempo").value);T.element("offset")&&(this.soundTempos.has(this.currentXmlMeasureIndex)||this.soundTempos.set(this.currentXmlMeasureIndex,[]),this.soundTempos.get(this.currentXmlMeasureIndex).push(e)),0===this.currentXmlMeasureIndex&&(this.musicSheet.DefaultStartTempoInBpm=e,this.musicSheet.HasBPMInfo=!0)}}catch(x){s.debug("InstrumentReader.readTempoInstruction",x)}else if("harmony"===T.name){const e=this.getNoteStaff(T);this.currentStaff=this.instrument.Staves[e-1];const t=n.clone();this.currentStaffEntry=this.currentMeasure.findOrCreateStaffEntry(t,this.inSourceMeasureInstrumentIndex+e-1,this.currentStaff).staffEntry,this.currentStaffEntry.ChordContainers.push(Vs.readChordSymbol(T,this.musicSheet,this.activeKey))}}e.CompoundTempo||(e.CompoundTempo=this.preCompoundTempo);for(const e in this.voiceGeneratorsDict)this.voiceGeneratorsDict.hasOwnProperty(e)&&this.voiceGeneratorsDict[e].checkForOpenBeam();if(this.currentXmlMeasureIndex===this.xmlMeasureList.length-1){for(let e=0;e<this.instrument.Staves.length;e++)this.activeClefsHaveBeenInitialized[e]||this.createDefaultClefInstruction(this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument)+e);this.activeKeyHasBeenInitialized||this.createDefaultKeyInstruction();for(let e=0;e<this.expressionReaders.length;e++){const t=this.expressionReaders[e];t&&t.closeOpenExpressions(this.currentMeasure,n)}}Object.keys(this.voiceGeneratorsDict).forEach((e=>{this.voiceGeneratorsDict[e].finalizeReadingMeasure()})),this.musicSheet.HasBPMInfo?0===e.TempoInBPM&&this.previousMeasure&&(this.currentMeasure.TempoInBPM=this.previousMeasure.TempoInBPM||this.musicSheet.DefaultStartTempoInBpm):this.currentMeasure.TempoInBPM=window.baseMeasureSpeed||120}catch(x){if(o)throw new S(x.Message);const e=Xe.translateText("ReaderErrorMessages/MeasureError","Error while reading Measure.");this.musicSheet.SheetErrors.pushMeasureError(e),s.debug("InstrumentReader.readNextXmlMeasure",e,x)}return this.previousMeasure=this.currentMeasure,this.currentXmlMeasureIndex+=1,!0}getStemDirectionAndColors(e){let t,i=dt.Undefined;const s=e.element("stem");if(s){i=this.getStemDirectionType(s);const e=s.attribute("color");e&&(t=this.parseXmlColor(e.value))}let n=this.getNoteHeadColorXml(e);const r=this.getNoteColorXml(e);return r&&!n&&(n=r),r&&!t&&(t=r),[i,t,n]}parseXmlColor(e){if(e)return 7===e.length?e:9===e.length?"#"+e.substr(3):void 0}doCalculationsAfterDurationHasBeenSet(){for(const e in this.voiceGeneratorsDict)this.voiceGeneratorsDict.hasOwnProperty(e)&&this.voiceGeneratorsDict[e].checkOpenTies()}getOrCreateVoiceGenerator(e,t){const i=this.instrument.Staves[t];let s=this.voiceGeneratorsDict[e];if(s)-1===i.Voices.indexOf(s.GetVoice)&&i.Voices.push(s.GetVoice);else{const n=this.staffMainVoiceGeneratorDict[t];n?(s=new Ds(this.pluginManager,i,e,this.slurReader,n.GetVoice),i.Voices.push(s.GetVoice),this.voiceGeneratorsDict[e]=s):(s=new Ds(this.pluginManager,i,e,this.slurReader),i.Voices.push(s.GetVoice),this.voiceGeneratorsDict[e]=s,this.staffMainVoiceGeneratorDict[t]=s)}return s}createExpressionGenerators(e){this.expressionReaders=new Array(e);for(let t=0;t<e;t++)this.expressionReaders[t]=new Os(this.musicSheet,this.instrument,t+1)}createDefaultClefInstruction(e){let t;t=this.musicSheet.SourceMeasures.length>0?this.musicSheet.SourceMeasures[0]:this.currentMeasure;const i=new J(q.G,0,2);let s;t.FirstInstructionsStaffEntries[e]?(s=t.FirstInstructionsStaffEntries[e],s.removeFirstInstructionOfTypeClefInstruction()):(s=new Je(void 0,void 0),t.FirstInstructionsStaffEntries[e]=s),i.Parent=s,s.Instructions.splice(0,0,i)}createDefaultKeyInstruction(){let e;e=this.musicSheet.SourceMeasures.length>0?this.musicSheet.SourceMeasures[0]:this.currentMeasure;const t=new Z(void 0,0,ee.major);for(let i=this.inSourceMeasureInstrumentIndex;i<this.inSourceMeasureInstrumentIndex+this.instrument.Staves.length;i++)if(e.FirstInstructionsStaffEntries[i]){const s=e.FirstInstructionsStaffEntries[i];t.Parent=s,s.removeFirstInstructionOfTypeKeyInstruction(),s.Instructions[0]instanceof J?s.Instructions.splice(1,0,t):s.Instructions.splice(0,0,t)}else{const s=new Je(void 0,void 0);e.FirstInstructionsStaffEntries[i]=s,t.Parent=s,s.Instructions.push(t)}}isAttributesNodeAtBeginOfMeasure(e,t){const i=e.elements(),s=i.indexOf(t);if(s>0&&"backup"===i[s-1].name)return!0;let n=-1;for(let r=0;r<i.length;r++)if("note"===i[r].name){n=r;break}return s<n&&n>0||n<0}isAttributesNodeAtEndOfMeasure(e,t,i){var s;if(i.Equals(null===(s=this.ActiveRhythm)||void 0===s?void 0:s.Rhythm))return!0;const n=e.elements().slice();let r=0;for(let a=0;a<n.length;a++)if(n[a]===t){r=a;break}let o=0;for(let a=r;a<n.length;a++)if("note"===n[a].name){o=a;break}return r>o}getNoteDurationFromTypeNode(e){const t=e.element("type");if(t){const e=t.value;return He.getNoteDurationFromType(e)}return new u(0,4*this.divisions)}addAbstractInstruction(e,t,i,n){if(e.element("divisions")&&1===e.elements().length)return;const r=e.element("transpose");if(r){const e=r.element("chromatic");e&&(this.instrument.PlaybackTranspose=parseInt(e.value,10))}const o=e.elements("clef");let a;if(o.length>0)for(let u=0,d=o.length;u<d;++u){const e=o[u];let t=q.G,i=2,r=1,d=0;const f=e.element("line");if(f)try{i=parseInt(f.value,10)}catch(l){a=Xe.translateText("ReaderErrorMessages/ClefLineError","Invalid clef line. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),i=2,s.debug("InstrumentReader.addAbstractInstruction",a,l)}const m=e.element("sign");if(m)try{t=q[m.value],J.isSupportedClef(t)||(a=Xe.translateText("ReaderErrorMessages/ClefError","Unsupported clef. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),t=q.G,i=2),t===q.TAB&&(d=-1)}catch(h){a=Xe.translateText("ReaderErrorMessages/ClefError","Invalid clef. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),t=q.G,i=2,s.debug("InstrumentReader.addAbstractInstruction",a,h)}const p=e.element("clef-octave-change");if(p)try{d=parseInt(p.value,10)}catch(h){a=Xe.translateText("ReaderErrorMessages/ClefOctaveError","Invalid clef octave. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),d=0}if(e.hasAttributes&&e.attribute("number"))try{r=parseInt(e.attribute("number").value,10),r>this.currentClefNumber&&(r=this.currentClefNumber),this.currentClefNumber=r+1}catch(c){a=Xe.translateText("ReaderErrorMessages/ClefError","Invalid clef. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),r=1,this.currentClefNumber=r+1}const g=new J(t,d,i);this.abstractInstructions.push([r,g,n])}if(void 0!==e.element("key")&&this.instrument.MidiInstrumentId!==$.Percussion){let t=0;const i=e.element("key").element("fifths");if(i)try{t=parseInt(i.value,10)}catch(l){a=Xe.translateText("ReaderErrorMessages/KeyError","Invalid key. Set to default."),this.musicSheet.SheetErrors.pushMeasureError(a),t=0,s.debug("InstrumentReader.addAbstractInstruction",a,l)}let r=ee.none,o=e.element("key");if(o&&(o=o.element("mode")),o)try{r=ee[o.value]}catch(l){a=Xe.translateText("ReaderErrorMessages/KeyError","Invalid key/mode. Set to default."),this.musicSheet.SheetErrors.pushMeasureError(a),r=ee.major,s.debug("InstrumentReader.addAbstractInstruction",a,l)}const h=new Z(void 0,t,r);this.abstractInstructions.push([1,h,n])}if(e.element("time")){const t=e.element("time");let i=T.NONE,r=!0;if(void 0!==t&&t.hasAttributes){const e=t.attribute("symbol");e&&("common"===e.value?i=T.COMMON:"cut"===e.value&&(i=T.CUT));const s=t.attribute("print-object");s&&"no"===s.value&&(r=!1)}let o=0,h=0;const c=t&&void 0!==t.element("senza-misura"),d=e.elements("time"),f=[],m=[];for(let e=0,s=d.length;e<s;++e){const t=d[e];f.push.apply(f,t.elements("beats")),m.push.apply(m,t.elements("beat-type"))}if(c)this.abstractInstructions.push([1,new x(new u(4,4,0,!1),T.NONE),n]);else{try{if(void 0!==f&&f.length>0&&void 0!==m&&f.length===m.length){const e=f.length,t=new Array(e);let i=0;for(let s=0;s<e;s++){const e=f[s].value;let n=0,r=0;if(-1!==e.indexOf("+")){const t=e.split("+");for(let e=0,i=t.length;e<i;++e)n+=parseInt(t[e],10)}else n=parseInt(e,10);r=parseInt(m[s].value,10),i=Math.max(i,r),t[s]=new u(n,r,0,!1)}for(let s=0;s<e;s++)t[s].Denominator===i?o+=t[s].Numerator:o+=i/t[s].Denominator*t[s].Numerator;h=i}else o=parseInt(e.element("time").element("beats").value,10),h=parseInt(e.element("time").element("beat-type").value,10)}catch(l){a=Xe.translateText("ReaderErrorMessages/RhythmError","Invalid rhythm. Set to default."),this.musicSheet.SheetErrors.pushMeasureError(a),o=4,h=4,s.debug("InstrumentReader.addAbstractInstruction",a,l)}const t=new x(new u(o,h,0,!1),i);t.PrintObject=r,this.abstractInstructions.push([1,t,n])}}}saveAbstractInstructionList(e,t){for(let i=this.abstractInstructions.length-1;i>=0;i--){const s=this.abstractInstructions[i],n=s[0],r=s[1],o=s[2];if(r instanceof J){const e=r;if(0===this.currentXmlMeasureIndex||n<=this.activeClefs.length&&e!==this.activeClefs[n-1])if(t||void 0===this.currentStaffEntry||this.currentStaffEntry.hasNotes()||n-1!==this.instrument.Staves.indexOf(this.currentStaffEntry.ParentStaff))if(t){if(0!==o.RealValue)continue;let t;if(this.currentMeasure){const s=e,r=this.inSourceMeasureInstrumentIndex+n-1,o=this.currentMeasure.FirstInstructionsStaffEntries[r];if(0===this.currentXmlMeasureIndex)if(o)if(void 0===this.currentMeasure.FirstInstructionsStaffEntries[r]||o.Instructions[0]instanceof J){const e=new Je(void 0,void 0);this.currentMeasure.LastInstructionsStaffEntries[r]=e,s.Parent=e,e.Instructions.push(s)}else t=o,s.Parent=t,t.removeFirstInstructionOfTypeClefInstruction(),t.Instructions.splice(0,0,s),this.activeClefsHaveBeenInitialized[n-1]=!0;else t=new Je(void 0,void 0),this.currentMeasure.FirstInstructionsStaffEntries[r]=t,s.Parent=t,t.Instructions.push(s),this.activeClefsHaveBeenInitialized[n-1]=!0;else if(this.activeClefsHaveBeenInitialized[n-1]){let e=this.previousMeasure;this.followingMultirestMeasures>0&&this.currentMeasure.Rules.RenderMultipleRestMeasures&&(e=this.currentMultirestStartMeasure);const t=new Je(void 0,void 0);e.LastInstructionsStaffEntries[r]=t,s.Parent=t,t.Instructions.push(s)}else{const e=this.musicSheet.SourceMeasures[0];e.FirstInstructionsStaffEntries[r]?(t=e.FirstInstructionsStaffEntries[r],t.removeFirstInstructionOfTypeClefInstruction()):t=new Je(void 0,void 0),s.Parent=t,t.Instructions.splice(0,0,s),this.activeClefsHaveBeenInitialized[n-1]=!0}this.activeClefs[n-1]=e,this.abstractInstructions.splice(i,1)}}else{let t;const s=this.activeRhythm.Rhythm;s.RealValue>0&&o.RealValue/s.RealValue>.9&&s.RealValue!==o.RealValue&&(this.currentMeasure.LastInstructionsStaffEntries[n-1]||(this.currentMeasure.LastInstructionsStaffEntries[n-1]=new Je(void 0,this.instrument.Staves[n-1])),t=this.currentMeasure.LastInstructionsStaffEntries[n-1]),t&&(e.Parent=t,t.Instructions.push(e),this.activeClefs[n-1]=e,this.abstractInstructions.splice(i,1))}else{const t=e,s=this.currentStaffEntry;if(o&&Math.abs(o.RealValue-s.Timestamp.RealValue)>.01)continue;t.Parent=s,s.removeFirstInstructionOfTypeClefInstruction(),s.Instructions.push(t),this.activeClefs[n-1]=e,this.abstractInstructions.splice(i,1)}else n<=this.activeClefs.length&&e===this.activeClefs[n-1]&&this.abstractInstructions.splice(i,1)}if(r instanceof Z){const t=r;if(this.activeKey&&this.activeKey.Key===t.Key)this.abstractInstructions.splice(i,1);else{let s;if(this.activeKey=t,this.abstractInstructions.splice(i,1),this.activeKeyHasBeenInitialized?s=this.currentMeasure:(this.activeKeyHasBeenInitialized=!0,s=this.currentXmlMeasureIndex>0?this.musicSheet.SourceMeasures[0]:this.currentMeasure),s)for(let i=this.inSourceMeasureInstrumentIndex;i<this.inSourceMeasureInstrumentIndex+e;i++){const e=t;if(s.FirstInstructionsStaffEntries[i]){const t=s.FirstInstructionsStaffEntries[i];e.Parent=t,t.removeFirstInstructionOfTypeKeyInstruction(),0===t.Instructions.length?t.Instructions.push(e):t.Instructions[0]instanceof J?t.Instructions.splice(1,0,e):t.Instructions.splice(0,0,e)}else{const t=new Je(void 0,void 0);s.FirstInstructionsStaffEntries[i]=t,e.Parent=t,t.Instructions.push(e)}}}}if(r instanceof x){const t=r;if(this.activeRhythm&&this.activeRhythm===t)this.abstractInstructions.splice(i,1);else if(this.activeRhythm=t,this.abstractInstructions.splice(i,1),this.currentMeasure)for(let i=this.inSourceMeasureInstrumentIndex;i<this.inSourceMeasureInstrumentIndex+e;i++){const e=t;let s;this.currentMeasure.FirstInstructionsStaffEntries[i]?(s=this.currentMeasure.FirstInstructionsStaffEntries[i],s.removeFirstInstructionOfTypeRhythmInstruction()):(s=new Je(void 0,void 0),this.currentMeasure.FirstInstructionsStaffEntries[i]=s),e.Parent=s,s.Instructions.push(e)}}}}saveClefInstructionAtEndOfMeasure(){for(let e=this.abstractInstructions.length-1;e>=0;e--){const t=this.abstractInstructions[e][0],i=this.abstractInstructions[e][1];if(i instanceof J){const s=i;if(!this.activeClefs[t-1]||s.ClefType!==this.activeClefs[t-1].ClefType||s.ClefType===this.activeClefs[t-1].ClefType&&s.Line!==this.activeClefs[t-1].Line){const i=new Je(void 0,void 0);this.currentMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex+t-1]=i;const n=s;n.Parent=i,i.Instructions.push(n),this.activeClefs[t-1]=s,this.abstractInstructions.splice(e,1)}}}}getNoteDurationForTuplet(e){const t=e.element("duration"),i=Number.parseInt(t.value,10);return new u(i,4*this.divisions)}readExpressionStaffNumber(e){let t=1;if(e.element("staff")){const n=e.element("staff");if(n)try{t=parseInt(n.value,10)}catch(i){const e=Xe.translateText("ReaderErrorMessages/ExpressionStaffError","Invalid Expression staff number. Set to default.");this.musicSheet.SheetErrors.pushMeasureError(e),t=1,s.debug("InstrumentReader.readExpressionStaffNumber",e,i)}}return t}readDivisionsFromNotes(){let e=0,t=this.currentXmlMeasureIndex,i=!1;for(;!i;){const r=this.xmlMeasureList[t].elements();for(let t=0,o=r.length;t<o;++t){const o=r[t];if("note"===o.name&&!o.element("time-modification")){const t=o.element("duration"),i=o.element("type");if(void 0!==t&&i){const r=i.value;let o=0;try{o=parseInt(t.value,10)}catch(n){s.debug("InstrumentReader.readDivisionsFromNotes",n);continue}switch(r){case"1024th":e=o/4*1024;break;case"512th":e=o/4*512;break;case"256th":e=o/4*256;break;case"128th":e=o/4*128;break;case"64th":e=o/4*64;break;case"32nd":e=o/4*32;break;case"16th":e=o/4*16;break;case"eighth":e=o/4*8;break;case"quarter":e=o/4*4;break;case"half":e=o/4*2;break;case"whole":e=o/4;break;case"breve":e=o/4/2;break;case"long":e=o/4/4;break;case"maxima":e=o/4/8}}}if(e>0){i=!0;break}}if(0===e&&(t++,t===this.xmlMeasureList.length)){const e=Xe.translateText("ReaderErrorMEssages/DivisionsError","Invalid divisions value at Instrument: ");throw new S(e+this.instrument.Name)}}return e}getCueNoteAndNoteTypeXml(e){let t=!1;e.element("cue")&&(t=!0);const i=e.element("type");let s=ze.UNDEFINED;if(i){const e=i.attribute("size");"cue"===(null==e?void 0:e.value)&&(t=!0),s=He.StringToNoteType(i.value)}return[t,s]}getStemDirectionType(e){switch(e.value){case"down":return dt.Down;case"up":return dt.Up;case"double":return dt.Double;case"none":return dt.None;default:return dt.Undefined}}getNoteHeadColorXml(e){const t=e.element("notehead");if(t){const e=t.attribute("color");if(e)return this.parseXmlColor(e.value)}return null}getNoteColorXml(e){const t=e.attribute("color");return t?this.parseXmlColor(t.value):null}getTremoloInfo(e){let t,i;const s=e.element("tremolo");if(s){const e=s.attribute("type");if(e){if("single"===e.value){const e=parseInt(s.value,10);e>0&&(t=e)}else t=0;"unmeasured"===e.value&&(i=!0)}}return{tremoloStrokes:t,tremoloUnmeasured:i}}getWavyLines(e,t,i,s){const n=e.elements("wavy-line");if(n)for(const r of n){const e=this.expressionReaders[this.readExpressionStaffNumber(t)-1];e&&(e.readExpressionParameters(r,this.instrument,this.divisions,i,s,this.currentMeasure.MeasureNumber,!1),e.addWavyLine(r,this.currentMeasure,i,s))}}getNoteStaff(e){let t=1;return this.instrument.Staves.length>1&&e.element("staff")&&(t=parseInt(e.element("staff").value,10),isNaN(t)&&(s.debug("InstrumentReader.readNextXmlMeasure.get staff number"),t=1)),t}}class Ws{}Ws.MidiInstrument={banjo:$.Banjo,blockfloete:$.Recorder,brass:$.Trombone,bratsche:$.Viola,cello:$.Cello,clarinet:$.Clarinet,contrabass:$.Contrabass,"steel drum":$.Steel_Drums,drums:$.Percussion,flute:$.Flute,floete:$.Flute,frenchhorn:$.French_Horn,gitarre:$.Acoustic_Guitar_nylon,guitar:$.Acoustic_Guitar_nylon,harfe:$.Orchestral_Harp,harp:$.Orchestral_Harp,klarinette:$.Clarinet,klavier:$.Acoustic_Grand_Piano,kontrabass:$.Contrabass,oboe:$.Oboe,organ:$.Church_Organ,orgel:$.Church_Organ,orgue:$.Church_Organ,percussion:$.Percussion,piano:$.Acoustic_Grand_Piano,piccolo:$.Piccolo,posaune:$.Trombone,recorder:$.Recorder,sax:$.Tenor_Sax,schlagwerk:$.Percussion,schlagzeug:$.Percussion,steeldrum:$.Steel_Drums,streicher:$.String_Ensemble_1,strings:$.String_Ensemble_1,tpt:$.Trumpet,trombone:$.Trombone,trompete:$.Trumpet,trumpet:$.Trumpet,tuba:$.Tuba,unnamed:$.Acoustic_Grand_Piano,viola:$.Viola,violin:$.Violin,"violon-c":$.Cello,"violon.":$.Violin,voice:$.Synth_Voice,woodblock:$.Woodblock,alt:$.Synth_Voice,alto:$.Synth_Voice,bariton:$.Synth_Voice,baritone:$.Synth_Voice,bass:$.Synth_Voice,sopran:$.Synth_Voice,tenor:$.Synth_Voice},Ws.MidiInstrumentSounds={"brass.alphorn":$.French_Horn,"brass.alto-horn":$.French_Horn,"brass.baritone-horn":$.French_Horn,"brass.bugle":$.Trumpet,"brass.bugle.alto":$.Trumpet,"brass.bugle.baritone":$.Trombone,"brass.bugle.contrabass":$.Trombone,"brass.bugle.euphonium-bugle":$.French_Horn,"brass.bugle.mellophone-bugle":$.French_Horn,"brass.bugle.soprano":$.Trumpet,"brass.cimbasso":$.Trombone,"brass.conch-shell":$.Flute,"brass.cornet":$.Trumpet,"brass.cornet.soprano":$.Trumpet,"brass.cornett":$.Trumpet,"brass.cornett.tenor":$.Trumpet,"brass.cornettino":$.Trumpet,"brass.didgeridoo":$.Flute,"brass.euphonium":$.French_Horn,"brass.fiscorn":$.French_Horn,"brass.flugelhorn":$.French_Horn,"brass.french-horn":$.French_Horn,"brass.group":$.Brass_Section,"brass.group.synth":$.Synth_Brass_1,"brass.helicon":$.French_Horn,"brass.horagai":$.Trumpet,"brass.kuhlohorn":$.French_Horn,"brass.mellophone":$.French_Horn,"brass.natural-horn":$.French_Horn,"brass.ophicleide":$.French_Horn,"brass.posthorn":$.French_Horn,"brass.saxhorn":$.French_Horn,"brass.sousaphone":$.Tuba,"brass.trombone":$.Trombone,"brass.trombone.alto":$.Trombone,"brass.trombone.bass":$.Trombone,"brass.trombone.contrabass":$.Trombone,"brass.trombone.tenor":$.Trombone,"brass.trumpet":$.Trumpet,"brass.trumpet.baroque":$.Trumpet,"brass.trumpet.bass":$.Trombone,"brass.trumpet.bflat":$.Trumpet,"brass.trumpet.c":$.Trumpet,"brass.trumpet.d":$.Trumpet,"brass.trumpet.piccolo":$.Trumpet,"brass.trumpet.pocket":$.Trumpet,"brass.trumpet.slide":$.Trumpet,"brass.trumpet.tenor":$.Trumpet,"brass.tuba":$.Tuba,"brass.tuba.bass":$.Tuba,"brass.tuba.subcontrabass":$.Tuba,"brass.vienna-horn":$.French_Horn,"brass.wagner-tuba":$.French_Horn,"drum.ashiko":$.Shakuhachi,"drum.bass-drum":$.Percussion,"drum.bongo":$.Percussion,"drum.bougarabou":$.Percussion,"drum.buffalo-drum":$.Percussion,"drum.cajon":$.Percussion,"drum.chenda":$.Percussion,"drum.chu-daiko":$.Percussion,"drum.conga":$.Percussion,"drum.cuica":$.Percussion,"drum.dabakan":$.Percussion,"drum.daff":$.Percussion,"drum.dafli":$.Percussion,"drum.daibyosi":$.Percussion,"drum.damroo":$.Percussion,"drum.darabuka":$.Percussion,"drum.def":$.Percussion,"drum.dhol":$.Percussion,"drum.dholak":$.Percussion,"drum.djembe":$.Percussion,"drum.doira":$.Percussion,"drum.dondo":$.Percussion,"drum.doun-doun-ba":$.Percussion,"drum.duff":$.Percussion,"drum.dumbek":$.Percussion,"drum.fontomfrom":$.Percussion,"drum.frame-drum":$.Percussion,"drum.frame-drum.arabian":$.Percussion,"drum.geduk":$.Percussion,"drum.ghatam":$.Percussion,"drum.gome":$.Percussion,"drum.group":$.Percussion,"drum.group.chinese":$.Percussion,"drum.group.ewe":$.Percussion,"drum.group.indian":$.Percussion,"drum.group.set":$.Percussion,"drum.hand-drum":$.Percussion,"drum.hira-daiko":$.Percussion,"drum.ibo":$.Percussion,"drum.igihumurizo":$.Percussion,"drum.inyahura":$.Percussion,"drum.ishakwe":$.Percussion,"drum.jang-gu":$.Percussion,"drum.kagan":$.Percussion,"drum.kakko":$.Percussion,"drum.kanjira":$.Percussion,"drum.kendhang":$.Percussion,"drum.kendhang.ageng":$.Percussion,"drum.kendhang.ciblon":$.Percussion,"drum.kenkeni":$.Percussion,"drum.khol":$.Percussion,"drum.kick-drum":$.Percussion,"drum.kidi":$.Percussion,"drum.ko-daiko":$.Percussion,"drum.kpanlogo":$.Percussion,"drum.kudum":$.Percussion,"drum.lambeg":$.Percussion,"drum.lion-drum":$.Percussion,"drum.log-drum":$.Percussion,"drum.log-drum.african":$.Percussion,"drum.log-drum.native":$.Percussion,"drum.log-drum.nigerian":$.Percussion,"drum.madal":$.Percussion,"drum.maddale":$.Percussion,"drum.mridangam":$.Percussion,"drum.naal":$.Percussion,"drum.nagado-daiko":$.Percussion,"drum.nagara":$.Percussion,"drum.naqara":$.Percussion,"drum.o-daiko":$.Percussion,"drum.okawa":$.Percussion,"drum.okedo-daiko":$.Percussion,"drum.pahu-hula":$.Percussion,"drum.pakhawaj":$.Percussion,"drum.pandeiro":$.Percussion,"drum.pandero":$.Percussion,"drum.powwow":$.Percussion,"drum.pueblo":$.Percussion,"drum.repinique":$.Percussion,"drum.riq":$.Percussion,"drum.rototom":$.Percussion,"drum.sabar":$.Percussion,"drum.sakara":$.Percussion,"drum.sampho":$.Percussion,"drum.sangban":$.Percussion,"drum.shime-daiko":$.Percussion,"drum.slit-drum":$.Percussion,"drum.slit-drum.krin":$.Percussion,"drum.snare-drum":$.Percussion,"drum.snare-drum.electric":$.Synth_Drum,"drum.sogo":$.Percussion,"drum.surdo":$.Percussion,"drum.tabla":$.Percussion,"drum.tabla.bayan":$.Percussion,"drum.tabla.dayan":$.Percussion,"drum.tabor":$.Percussion,"drum.taiko":$.Taiko_Drum,"drum.talking":$.Percussion,"drum.tama":$.Percussion,"drum.tamborim":$.Percussion,"drum.tamborita":$.Percussion,"drum.tambourine":$.Percussion,"drum.tamte":$.Percussion,"drum.tangku":$.Percussion,"drum.tan-tan":$.Percussion,"drum.taphon":$.Percussion,"drum.tar":$.Percussion,"drum.tasha":$.Percussion,"drum.tenor-drum":$.Percussion,"drum.teponaxtli":$.Percussion,"drum.thavil":$.Percussion,"drum.the-box":$.Percussion,"drum.timbale":$.Percussion,"drum.timpani":$.Timpani,"drum.tinaja":$.Percussion,"drum.toere":$.Percussion,"drum.tombak":$.Percussion,"drum.tom-tom":$.Melodic_Tom,"drum.tom-tom.synth":$.Melodic_Tom,"drum.tsuzumi":$.Percussion,"drum.tumbak":$.Percussion,"drum.uchiwa-daiko":$.Percussion,"drum.udaku":$.Percussion,"drum.udu":$.Percussion,"drum.zarb":$.Percussion,"effect.applause":$.Applause,"effect.gunshot":$.Gunshot,"effect.helicopter":$.Helicopter,"effect.telephone-ring":$.Telephone_Ring,"keyboard.accordion":$.Accordion,"keyboard.bandoneon":$.Accordion,"keyboard.celesta":$.Celesta,"keyboard.clavichord":$.Harpsichord,"keyboard.clavichord.synth":$.Harpsichord,"keyboard.concertina":$.Accordion,"keyboard.fortepiano":$.Acoustic_Grand_Piano,"keyboard.harmonium":$.Drawbar_Organ,"keyboard.harpsichord":$.Harpsichord,"keyboard.ondes-martenot":$.Pad_3_polysynth,"keyboard.organ":$.Church_Organ,"keyboard.organ.drawbar":$.Percussive_Organ,"keyboard.organ.percussive":$.Rock_Organ,"keyboard.organ.pipe":$.Church_Organ,"keyboard.organ.reed":$.Church_Organ,"keyboard.organ.rotary":$.Rock_Organ,"keyboard.piano":$.Acoustic_Grand_Piano,"keyboard.piano.electric":$.Electric_Grand_Piano,"keyboard.piano.grand":$.Acoustic_Grand_Piano,"keyboard.piano.honky-tonk":$.Honky_tonk_Piano,"keyboard.piano.prepared":$.Acoustic_Grand_Piano,"keyboard.piano.toy":$.Honky_tonk_Piano,"keyboard.piano.upright":$.Acoustic_Grand_Piano,"keyboard.virginal":$.Acoustic_Grand_Piano,"metal.adodo":$.Xylophone,"metal.anvil":$.Xylophone,"metal.babendil":$.Xylophone,"metal.bells.agogo":$.Agogo,"metal.bells.almglocken":$.Tubular_Bells,"metal.bells.bell-plate":$.Tubular_Bells,"metal.bells.bell-tree":$.Tubular_Bells,"metal.bells.carillon":$.Tubular_Bells,"metal.bells.chimes":$.Tinkle_Bell,"metal.bells.chimta":$.Tubular_Bells,"metal.bells.chippli":$.Tubular_Bells,"metal.bells.church":$.Tubular_Bells,"metal.bells.cowbell":$.Percussion,"metal.bells.dawuro":$.Percussion,"metal.bells.gankokwe":$.Percussion,"metal.bells.ghungroo":$.Percussion,"metal.bells.hatheli":$.Percussion,"metal.bells.jingle-bell":$.Percussion,"metal.bells.khartal":$.Percussion,"metal.bells.mark-tree":$.Percussion,"metal.bells.sistrum":$.Percussion,"metal.bells.sleigh-bells":$.Percussion,"metal.bells.temple":$.Percussion,"metal.bells.tibetan":$.Percussion,"metal.bells.tinklebell":$.Percussion,"metal.bells.trychel":$.Percussion,"metal.bells.wind-chimes":$.Percussion,"metal.bells.zills":$.Percussion,"metal.berimbau":$.Flute,"metal.brake-drums":$.Percussion,"metal.crotales":$.Percussion,"metal.cymbal.bo":$.Percussion,"metal.cymbal.ceng-ceng":$.Percussion,"metal.cymbal.chabara":$.Percussion,"metal.cymbal.chinese":$.Percussion,"metal.cymbal.ching":$.Percussion,"metal.cymbal.clash":$.Percussion,"metal.cymbal.crash":$.Percussion,"metal.cymbal.finger":$.Percussion,"metal.cymbal.hand":$.Percussion,"metal.cymbal.kesi":$.Percussion,"metal.cymbal.manjeera":$.Percussion,"metal.cymbal.reverse":$.Percussion,"metal.cymbal.ride":$.Percussion,"metal.cymbal.sizzle":$.Percussion,"metal.cymbal.splash":$.Percussion,"metal.cymbal.suspended":$.Percussion,"metal.cymbal.tebyoshi":$.Percussion,"metal.cymbal.tibetan":$.Percussion,"metal.cymbal.tingsha":$.Percussion,"metal.flexatone":$.Percussion,"metal.gong":$.Percussion,"metal.gong.ageng":$.Percussion,"metal.gong.agung":$.Percussion,"metal.gong.chanchiki":$.Percussion,"metal.gong.chinese":$.Percussion,"metal.gong.gandingan":$.Percussion,"metal.gong.kempul":$.Percussion,"metal.gong.kempyang":$.Percussion,"metal.gong.ketuk":$.Percussion,"metal.gong.kkwenggwari":$.Percussion,"metal.gong.luo":$.Percussion,"metal.gong.singing":$.Percussion,"metal.gong.thai":$.Percussion,"metal.guira":$.Percussion,"metal.hang":$.Percussion,"metal.hi-hat":$.Percussion,"metal.jaw-harp":$.Percussion,"metal.kengong":$.Percussion,"metal.murchang":$.Percussion,"metal.musical-saw":$.Percussion,"metal.singing-bowl":$.Percussion,"metal.spoons":$.Percussion,"metal.steel-drums":$.Percussion,"metal.tamtam":$.Percussion,"metal.thundersheet":$.Percussion,"metal.triangle":$.Percussion,"metal.washboard":$.Percussion,"pitched-percussion.angklung":$.Xylophone,"pitched-percussion.balafon":$.Xylophone,"pitched-percussion.bell-lyre":$.Xylophone,"pitched-percussion.bells":$.Tubular_Bells,"pitched-percussion.bianqing":$.Xylophone,"pitched-percussion.bianzhong":$.Xylophone,"pitched-percussion.bonang":$.Xylophone,"pitched-percussion.cimbalom":$.Xylophone,"pitched-percussion.crystal-glasses":$.Xylophone,"pitched-percussion.dan-tam-thap-luc":$.Xylophone,"pitched-percussion.fangxiang":$.Xylophone,"pitched-percussion.gandingan-a-kayo":$.Xylophone,"pitched-percussion.gangsa":$.Xylophone,"pitched-percussion.gender":$.Xylophone,"pitched-percussion.giying":$.Xylophone,"pitched-percussion.glass-harmonica":$.Xylophone,"pitched-percussion.glockenspiel":$.Glockenspiel,"pitched-percussion.glockenspiel.alto":$.Glockenspiel,"pitched-percussion.glockenspiel.soprano":$.Glockenspiel,"pitched-percussion.gyil":$.Xylophone,"pitched-percussion.hammer-dulcimer":$.Dulcimer,"pitched-percussion.handbells":$.Tubular_Bells,"pitched-percussion.handchimes":$.Tubular_Bells,"pitched-percussion.kalimba":$.Kalimba,"pitched-percussion.kantil":$.Xylophone,"pitched-percussion.khim":$.Xylophone,"pitched-percussion.kulintang":$.Xylophone,"pitched-percussion.kulintang-a-kayo":$.Xylophone,"pitched-percussion.kulintang-a-tiniok":$.Xylophone,"pitched-percussion.likembe":$.Xylophone,"pitched-percussion.luntang":$.Xylophone,"pitched-percussion.marimba":$.Marimba,"pitched-percussion.marimba.bass":$.Marimba,"pitched-percussion.mbira":$.Marimba,"pitched-percussion.mbira.array":$.Marimba,"pitched-percussion.metallophone":$.Xylophone,"pitched-percussion.metallophone.alto":$.Xylophone,"pitched-percussion.metallophone.bass":$.Xylophone,"pitched-percussion.metallophone.soprano":$.Xylophone,"pitched-percussion.music-box":$.Glockenspiel,"pitched-percussion.pelog-panerus":$.Xylophone,"pitched-percussion.pemade":$.Xylophone,"pitched-percussion.penyacah":$.Xylophone,"pitched-percussion.ranat.ek":$.Xylophone,"pitched-percussion.ranat.ek-lek":$.Xylophone,"pitched-percussion.ranat.thum":$.Xylophone,"pitched-percussion.ranat.thum-lek":$.Xylophone,"pitched-percussion.reyong":$.Xylophone,"pitched-percussion.sanza":$.Xylophone,"pitched-percussion.saron-barung":$.Xylophone,"pitched-percussion.saron-demong":$.Xylophone,"pitched-percussion.saron-panerus":$.Xylophone,"pitched-percussion.slendro-panerus":$.Xylophone,"pitched-percussion.slentem":$.Xylophone,"pitched-percussion.tsymbaly":$.Xylophone,"pitched-percussion.tubes":$.Tubular_Bells,"pitched-percussion.tubular-bells":$.Tubular_Bells,"pitched-percussion.vibraphone":$.Vibraphone,"pitched-percussion.xylophone":$.Xylophone,"pitched-percussion.xylophone.alto":$.Xylophone,"pitched-percussion.xylophone.bass":$.Xylophone,"pitched-percussion.xylophone.soprano":$.Xylophone,"pitched-percussion.xylorimba":$.Xylophone,"pitched-percussion.yangqin":$.Xylophone,"pluck.archlute":$.Acoustic_Guitar_nylon,"pluck.autoharp":$.Orchestral_Harp,"pluck.baglama":$.Orchestral_Harp,"pluck.bajo":$.Acoustic_Guitar_steel,"pluck.balalaika":$.Acoustic_Guitar_steel,"pluck.balalaika.alto":$.Acoustic_Guitar_steel,"pluck.balalaika.bass":$.Acoustic_Guitar_steel,"pluck.balalaika.contrabass":$.Acoustic_Guitar_steel,"pluck.balalaika.piccolo":$.Acoustic_Guitar_steel,"pluck.balalaika.prima":$.Acoustic_Guitar_steel,"pluck.balalaika.secunda":$.Acoustic_Guitar_steel,"pluck.bandola":$.Acoustic_Guitar_steel,"pluck.bandura":$.Acoustic_Guitar_steel,"pluck.bandurria":$.Acoustic_Guitar_steel,"pluck.banjo":$.Banjo,"pluck.banjo.tenor":$.Banjo,"pluck.banjolele":$.Banjo,"pluck.barbat":$.Acoustic_Guitar_steel,"pluck.bass":$.Electric_Bass_finger,"pluck.bass.acoustic":$.Acoustic_Bass,"pluck.bass.bolon":$.Electric_Bass_finger,"pluck.bass.electric":$.Electric_Bass_finger,"pluck.bass.fretless":$.Fretless_Bass,"pluck.bass.guitarron":$.Acoustic_Bass,"pluck.bass.synth":$.Synth_Bass_1,"pluck.bass.synth.lead":$.Synth_Bass_2,"pluck.celtic-harp":$.Orchestral_Harp,"pluck.charango":$.Acoustic_Guitar_nylon,"pluck.chitarra-battente":$.Acoustic_Guitar_nylon,"pluck.cithara":$.Acoustic_Guitar_nylon,"pluck.cittern":$.Acoustic_Guitar_nylon,"pluck.cuatro":$.Acoustic_Guitar_nylon,"pluck.dulcimer":$.Dulcimer,"pluck.dutar":$.Acoustic_Grand_Piano,"pluck.duxianqin":$.Dulcimer,"pluck.ektara":$.Acoustic_Guitar_nylon,"pluck.guitar":$.Acoustic_Guitar_nylon,"pluck.guitar.acoustic":$.Acoustic_Guitar_nylon,"pluck.guitar.electric":$.Electric_Guitar_clean,"pluck.guitar.nylon-string":$.Electric_Guitar_clean,"pluck.guitar.pedal-steel":$.Electric_Guitar_clean,"pluck.guitar.portuguese":$.Acoustic_Guitar_nylon,"pluck.guitar.requinto":$.Acoustic_Guitar_nylon,"pluck.guitar.resonator":$.Acoustic_Guitar_nylon,"pluck.guitar.steel-string":$.Acoustic_Guitar_steel,"pluck.harp":$.Orchestral_Harp,"pluck.harp-guitar":$.Orchestral_Harp,"pluck.huapanguera":$.Orchestral_Harp,"pluck.lute":$.Acoustic_Grand_Piano,"pluck.lyre":$.Orchestral_Harp,"pluck.mandobass":$.Acoustic_Guitar_nylon,"pluck.mandocello":$.Acoustic_Guitar_nylon,"pluck.mandola":$.Acoustic_Guitar_nylon,"pluck.mandolin":$.Acoustic_Guitar_nylon,"pluck.mandolin.octave":$.Acoustic_Guitar_nylon,"pluck.setar":$.Acoustic_Guitar_nylon,"pluck.shamisen":$.Shamisen,"pluck.sitar":$.Sitar,"pluck.synth":$.Electric_Bass_pick,"pluck.synth.charang":$.Electric_Bass_pick,"pluck.synth.chiff":$.Electric_Bass_pick,"pluck.synth.stick":$.Electric_Bass_pick,"pluck.tambura":$.Acoustic_Grand_Piano,"pluck.ukulele":$.Banjo,"pluck.ukulele.tenor":$.Banjo,"strings.arpeggione":$.Cello,"strings.cello":$.Cello,"strings.cello.piccolo":$.Cello,"strings.contrabass":$.Contrabass,"strings.fiddle":$.Fiddle,"strings.fiddle.hardanger":$.Fiddle,"strings.group":$.String_Ensemble_1,"strings.group.synth":$.Synth_Strings_1,"strings.octobass":$.Contrabass,"strings.tromba-marina":$.Contrabass,"strings.vielle":$.Violin,"strings.viol":$.Violin,"strings.viol.alto":$.Violin,"strings.viol.bass":$.Violin,"strings.viol.tenor":$.Violin,"strings.viol.treble":$.Violin,"strings.viol.violone":$.Violin,"strings.viola":$.Viola,"strings.viola-damore":$.Viola,"strings.violin":$.Violin,"strings.violono.piccolo":$.Violin,"strings.violotta":$.Viola,"synth.group":$.Pad_3_polysynth,"synth.group.fifths":$.Pad_3_polysynth,"synth.group.orchestra":$.Orchestra_Hit,"synth.pad":$.Pad_1_new_age,"synth.pad.bowed":$.Pad_1_new_age,"synth.pad.choir":$.Pad_4_choir,"synth.pad.halo":$.Acoustic_Grand_Piano,"synth.pad.polysynth":$.Pad_3_polysynth,"voice.alto":$.Voice_Oohs,"voice.baritone":$.Voice_Oohs,"voice.bass":$.Voice_Oohs,"voice.female":$.Synth_Voice,"voice.kazoo":$.Flute,"voice.male":$.Voice_Oohs,"voice.mezzo-soprano":$.Voice_Oohs,"voice.soprano":$.Voice_Oohs,"voice.synth":$.Synth_Voice,"voice.tenor":$.Voice_Oohs,"voice.vocals":$.Choir_Aahs,"wind.flutes.flute":$.Flute,"wind.flutes.flute.alto":$.Flute,"wind.flutes.flute.bass":$.Flute,"wind.flutes.flute.contra-alto":$.Flute,"wind.flutes.flute.contrabass":$.Flute,"wind.flutes.flute.double-contrabass":$.Flute,"wind.flutes.flute.irish":$.Flute,"wind.flutes.flute.piccolo":$.Piccolo,"wind.flutes.flute.subcontrabass":$.Flute,"wind.flutes.ocarina":$.Ocarina,"wind.flutes.panpipes":$.Pan_Flute,"wind.flutes.recorder":$.Acoustic_Grand_Piano,"wind.flutes.recorder.alto":$.Recorder,"wind.flutes.recorder.bass":$.Recorder,"wind.flutes.recorder.contrabass":$.Recorder,"wind.flutes.recorder.descant":$.Recorder,"wind.flutes.recorder.garklein":$.Recorder,"wind.flutes.recorder.great-bass":$.Recorder,"wind.flutes.recorder.sopranino":$.Recorder,"wind.flutes.recorder.soprano":$.Recorder,"wind.flutes.recorder.tenor":$.Recorder,"wind.flutes.shakuhachi":$.Shakuhachi,"wind.flutes.whistle":$.Whistle,"wind.flutes.whistle.alto":$.Whistle,"wind.flutes.whistle.low-irish":$.Whistle,"wind.flutes.whistle.shiva":$.Whistle,"wind.flutes.whistle.slide":$.Whistle,"wind.flutes.whistle.tin":$.Whistle,"wind.flutes.whistle.tin.bflat":$.Whistle,"wind.flutes.whistle.tin.c":$.Whistle,"wind.flutes.whistle.tin.d":$.Whistle,"wind.group":$.Flute,"wind.pipes.bagpipes":$.Bag_pipe,"wind.reed.basset-horn":$.Bassoon,"wind.reed.bassoon":$.Bassoon,"wind.reed.bombarde":$.Bassoon,"wind.reed.clarinet":$.Clarinet,"wind.reed.clarinet.a":$.Clarinet,"wind.reed.clarinet.alto":$.Clarinet,"wind.reed.clarinet.bass":$.Clarinet,"wind.reed.clarinet.basset":$.Clarinet,"wind.reed.clarinet.bflat":$.Clarinet,"wind.reed.clarinet.contra-alto":$.Clarinet,"wind.reed.clarinet.contrabass":$.Clarinet,"wind.reed.clarinet.d":$.Clarinet,"wind.reed.clarinet.eflat":$.Clarinet,"wind.reed.clarinet.g":$.Clarinet,"wind.reed.clarinet.piccolo":$.Clarinet,"wind.reed.clarinet.piccolo.aflat":$.Clarinet,"wind.reed.clarinette-damour":$.Clarinet,"wind.reed.contrabass":$.Clarinet,"wind.reed.contrabassoon":$.Clarinet,"wind.reed.cornamuse":$.Bag_pipe,"wind.reed.english-horn":$.English_Horn,"wind.reed.harmonica":$.Harmonica,"wind.reed.harmonica.bass":$.Harmonica,"wind.reed.oboe":$.Oboe,"wind.reed.oboe.bass":$.Oboe,"wind.reed.oboe.piccolo":$.Oboe,"wind.reed.oboe-da-caccia":$.Oboe,"wind.reed.oboe-damore":$.Oboe,"wind.reed.saxonette":$.Soprano_Sax,"wind.reed.saxophone":$.Alto_Sax,"wind.reed.saxophone.alto":$.Alto_Sax,"wind.reed.saxophone.aulochrome":$.Alto_Sax,"wind.reed.saxophone.baritone":$.Baritone_Sax,"wind.reed.saxophone.bass":$.Baritone_Sax,"wind.reed.saxophone.contrabass":$.Baritone_Sax,"wind.reed.saxophone.melody":$.Baritone_Sax,"wind.reed.saxophone.mezzo-soprano":$.Alto_Sax,"wind.reed.saxophone.sopranino":$.Soprano_Sax,"wind.reed.saxophone.sopranissimo":$.Soprano_Sax,"wind.reed.saxophone.soprano":$.Soprano_Sax,"wind.reed.saxophone.subcontrabass":$.Baritone_Sax,"wind.reed.saxophone.tenor":$.Tenor_Sax,"wood.bones":$.Woodblock,"wood.castanets":$.Woodblock,"wood.claves":$.Woodblock,"wood.drum-sticks":$.Woodblock,"wood.gourd":$.Woodblock,"wood.granite-block":$.Woodblock,"wood.guban":$.Woodblock,"wood.guiro":$.Woodblock,"wood.hyoushigi":$.Woodblock,"wood.ipu":$.Woodblock,"wood.jam-block":$.Woodblock,"wood.kaekeeke":$.Woodblock,"wood.kagul":$.Woodblock,"wood.kalaau":$.Woodblock,"wood.kashiklar":$.Woodblock,"wood.kubing":$.Woodblock,"wood.pan-clappers":$.Woodblock,"wood.sand-block":$.Woodblock,"wood.slapstick":$.Woodblock,"wood.stir-drum":$.Woodblock,"wood.temple-block":$.Woodblock,"wood.tic-toc-block":$.Woodblock,"wood.tonetang":$.Woodblock,"wood.wood-block":$.Woodblock};class Us{constructor(e){this.parentInstrument=e,this.fixedKey=-1,this.name=this.parseMidiInstrument(this.parentInstrument.Name),this.midiInstrumentID=Ws.MidiInstrument[this.name],this.volume=1}get ParentInstrument(){return this.parentInstrument}static isPianoInstrument(e){return e===$.Acoustic_Grand_Piano||e===$.Bright_Acoustic_Piano||e===$.Electric_Grand_Piano||e===$.Electric_Piano_1||e===$.Electric_Piano_2}setMidiInstrumentSound(e){this.midiInstrumentID=Ws.MidiInstrumentSounds[e]}setMidiInstrument(e){this.midiInstrumentID=Ws.MidiInstrument[this.parseMidiInstrument(e)]}parseMidiInstrument(e){try{if(e){const t=e.toLowerCase().trim();for(const e in Ws.MidiInstrument)if(-1!==t.indexOf(e))return e}if(this.parentInstrument.Name){const e=this.parentInstrument.Name.toLowerCase().trim();for(const t in Ws.MidiInstrument)if(-1!==e.indexOf(t))return t}}catch(t){s.error("Error parsing MIDI Instrument. Default to Grand Piano.")}return"unnamed"}}class Xs{static StringContainsSeparatedWord(e,t,i=!1){return new RegExp("( |^)"+t+"([ .]|$)",i?"i":void 0).test(e)}}e("S",Xs);class zs{set MusicSheet(e){this.musicSheet=e,this.xmlMeasureList=new Array(this.musicSheet.Instruments.length),this.repetitionInstructions=[]}prepareReadingMeasure(e,t){this.currentMeasureIndex=t}handleLineRepetitionInstructions(e){let t=!1;if(e.elements().length>0){let s="",n=!1,r="",o="",a="";const l=[];let h="";const u=e.element("bar-style");u&&(a=u.value),s=e.attributes().length>0&&e.attribute("location")?e.attribute("location").value:"right";const c=e.elements();for(let e=0,t=c.length;e<t;++e){const t=c[e];if("repeat"===t.name&&t.hasAttributes)n=!0,r=t.attribute("direction").value;else if("ending"===t.name&&t.hasAttributes&&void 0!==t.attribute("type")&&t.attribute("number")){var i;o=t.attribute("type").value;let e=t.attribute("number").value;"结束句"===e&&(h=e,e="1"),(null===(i=e)||void 0===i?void 0:i.split(".").length)>2&&(h=e);const s=e.split("[,+]");for(let t=0,i=s.length;t<i;++t){const e=s[t],i=e.match("[0-9]");if(-1!==e.search("-")&&2===i.length){const e=parseInt(i[0],10),t=parseInt(i[1],10);for(let i=e;i<=t;i++)l.push(i)}else for(let t=0,s=i.length;t<s;++t){const e=i[t];l.push(parseInt(e,10))}}}}if("light-heavy"!==a||0!==l.length||n||(t=!0),n||l.length>0)if("left"===s){if("start"===o){const e=new $e(this.currentMeasureIndex,Qe.Ending,Ze.Begin,void 0,l,h);this.addInstruction(this.repetitionInstructions,e)}if("forward"===r){const e=new $e(this.currentMeasureIndex,Qe.StartLine);this.addInstruction(this.repetitionInstructions,e)}}else{if("stop"===o){const e=new $e(this.currentMeasureIndex,Qe.Ending,Ze.End,void 0,l,h);this.addInstruction(this.repetitionInstructions,e)}if("backward"===r){const e=new $e(this.currentMeasureIndex,Qe.BackJumpLine);this.addInstruction(this.repetitionInstructions,e)}}}return t}handleRepetitionInstructionsFromWordsOrSymbols(e,t){const i=e.element("words"),s=this.currentMeasureIndex;if(i){const e="d\\s?\\.s\\.",t=i.value.trim().toLowerCase();if(Xs.StringContainsSeparatedWord(t,e+" al fine",!0)){const e=new $e(s,Qe.DalSegnoAlFine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,e+" al coda",!0)){const e=new $e(s,Qe.DalSegnoAlCoda);return this.addInstruction(this.repetitionInstructions,e),!0}const n="d\\.\\s?c\\.";if(Xs.StringContainsSeparatedWord(t,n+" al fine",!0)){const e=new $e(s,Qe.DaCapoAlFine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,n+" al coda",!0)){const e=new $e(s,Qe.DaCapoAlCoda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,n)||Xs.StringContainsSeparatedWord(t,"da\\s?capo",!0)){const e=new $e(s,Qe.DaCapo);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,e,!0)||Xs.StringContainsSeparatedWord(t,"dal\\s?segno",!0)){let e;return e=Xs.StringContainsSeparatedWord(t,"al\\s?coda",!0)?new $e(s,Qe.DalSegnoAlCoda):new $e(s,Qe.DalSegno),this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"to\\s?coda",!0)||Xs.StringContainsSeparatedWord(t,"a (la )?coda",!0)){const e=new $e(s,Qe.ToCoda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"fine",!0)){const e=new $e(s,Qe.Fine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"coda",!0)){const e=new $e(s,Qe.Coda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"segno",!0)){const e=new $e(s,Qe.Segno);return this.addInstruction(this.repetitionInstructions,e),!0}}else{if(e.element("segno")){const e=new $e(s,Qe.Segno);return this.addInstruction(this.repetitionInstructions,e),!0}if(e.element("coda")){const e=new $e(s,Qe.Coda);return this.addInstruction(this.repetitionInstructions,e),!0}}return!1}removeRedundantInstructions(){let e=0,t=0,i=0,s=0;for(let n=0;n<this.repetitionInstructions.length;n++){const r=this.repetitionInstructions[n];switch(r.type){case Qe.Coda:i>0&&this.findInstructionInPreviousMeasure(n,r.measureIndex,Qe.ToCoda)&&(r.type=Qe.None),0===t&&0===i&&(r.type=Qe.ToCoda,r.alignment=Ze.End,r.measureIndex--);break;case Qe.Segno:if(e-s>0){let e=!1;for(let s=0,n=this.repetitionInstructions.length;s<n;++s){const n=this.repetitionInstructions[s];if(r.measureIndex-n.measureIndex==1)switch(n.type){case Qe.BackJumpLine:n.type=i-t>0?Qe.DalSegnoAlCoda:Qe.DalSegno,r.type=Qe.None,e=!0;break;case Qe.DalSegno:case Qe.DalSegnoAlFine:case Qe.DalSegnoAlCoda:r.type=Qe.None,e=!0}if(e)break}if(e)break;r.type=i-t>0?Qe.DalSegnoAlCoda:Qe.DalSegno,r.alignment=Ze.End,r.measureIndex--}}if(this.backwardSearchForPreviousIdenticalInstruction(n,r)||r.type===Qe.None)this.repetitionInstructions.splice(n,1),n--;else switch(r.type){case Qe.Fine:break;case Qe.ToCoda:i++;break;case Qe.Coda:t++;break;case Qe.Segno:e++;break;case Qe.DalSegnoAlFine:case Qe.DalSegnoAlCoda:s++}}this.repetitionInstructions.sort(qe.Compare)}findInstructionInPreviousMeasure(e,t,i){for(let s=e-1;s>=0;s--){const e=this.repetitionInstructions[s];if(t-e.measureIndex==1&&e.type===i)return!0}return!1}backwardSearchForPreviousIdenticalInstruction(e,t){for(let i=e-1;i>=0;i--)if(this.repetitionInstructions[i].equals(t))return!0;return!1}addInstruction(e,t){let i=!0;for(let s=0,n=e.length;s<n;++s){const n=e[s];if(t.equals(n)){i=!1;break}}i&&e.push(t)}}class Hs{constructor(){this.repetitionInstructions=[],this.openRepetitions=[],this.lastRepetitionCommonPartStartIndex=0,this.hasNextRepeat=!1}calculateRepetitions(e,t,i){this.musicSheet=e,this.repetitionInstructions=t,this.rules=i,this.rules||(this.rules=new xe),this.openRepetitions.length=0,this.lastRepetitionCommonPartStartIndex=0;const n=this.musicSheet.SourceMeasures;for(const h of this.repetitionInstructions){this.currentMeasureIndex=h.measureIndex;try{this.currentMeasure=n[this.currentMeasureIndex],this.handleRepetitionInstructions(h)}catch(a){s.error("RepetitionCalculator: calculateRepetitions",a)}}for(;this.openRepetitions.length>0;)try{const e=this.openRepetitions.last();if(e.RepetitonUnderConstruction.FromWords){if(e.WaitingForCoda){let t=e.RepetitonUnderConstruction.BackwardJumpInstructions.last().measureIndex+1;t>=this.musicSheet.SourceMeasures.length&&(t=-1),e.RepetitonUnderConstruction.setEndingStartIndex(2,t)}else if(0===e.RepetitonUnderConstruction.BackwardJumpInstructions.length){this.openRepetitions.splice(this.openRepetitions.length-1,1);continue}}else if(0===e.RepetitonUnderConstruction.BackwardJumpInstructions.length){const t=n.length-1,i=new $e(t,Qe.BackJumpLine,Ze.End,e.RepetitonUnderConstruction);e.RepetitonUnderConstruction.BackwardJumpInstructions.push(i),n[t].LastRepetitionInstructions.push(i)}this.finalizeRepetition(this.openRepetitions.last())}catch(l){try{const e=this.openRepetitions.last().RepetitonUnderConstruction;for(const t of this.repetitionInstructions)t.parentRepetition===e&&(t.parentRepetition=void 0);this.openRepetitions.splice(this.openRepetitions.length-1,1)}catch(a){s.error("RepetitionCalculator: calculateRepetitions2",a)}}let r=!1;const o=this.musicSheet.SourceMeasures.length-1;for(const s of this.musicSheet.Repetitions)if(0===s.StartIndex&&s.EndIndex===o){r=!0;break}if(!r){const e=new Ls(this.musicSheet,!0);e.FromWords=!0,e.startMarker=new $e(0,Qe.StartLine),e.startMarker.parentRepetition=e,this.musicSheet.SourceMeasures[0].FirstRepetitionInstructions.push(e.startMarker),e.endMarker=new $e(o,Qe.BackJumpLine),e.endMarker.parentRepetition=e,e.BackwardJumpInstructions.push(e.endMarker),e.UserNumberOfRepetitions=e.DefaultNumberOfRepetitions,this.musicSheet.Repetitions.push(e)}for(let s=0,h=this.musicSheet.SourceMeasures.length;s<h;++s){const e=this.musicSheet.SourceMeasures[s];e.FirstRepetitionInstructions.length>1&&e.FirstRepetitionInstructions.sort(qe.Compare),e.LastRepetitionInstructions.length>1&&e.LastRepetitionInstructions.sort(qe.Compare)}}handleRepetitionInstructions(e){var t,i,s,n,r;let o;switch(e.type){case Qe.StartLine:o=this.createNewRepetition(this.currentMeasureIndex),e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.FromWords=!1,o.RepetitonUnderConstruction.startMarker=e,null===(t=this.currentMeasure)||void 0===t||t.FirstRepetitionInstructions.push(e);break;case Qe.BackJumpLine:o=this.getOrCreateCurrentRepetition2(!1),e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),null===(i=this.currentMeasure)||void 0===i||i.LastRepetitionInstructions.push(e),0===o.RepetitonUnderConstruction.EndingParts.length&&this.finalizeRepetition(o);break;case Qe.Ending:if(o=this.getOrCreateCurrentRepetition(),e.parentRepetition=o.RepetitonUnderConstruction,e.endingIndices.contains(1)&&e.alignment===Ze.Begin){if(o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0||o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)){o=void 0;for(let e=this.openRepetitions.length-1;e>=0;e--){const t=this.openRepetitions[e];if(0===t.RepetitonUnderConstruction.BackwardJumpInstructions.length)for(o=t;this.openRepetitions.length-1>e;){const e=this.openRepetitions.last();this.finalizeRepetition(e)}}void 0===o&&(o=this.createNewRepetition(0),o.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None))}void 0===o.RepetitonUnderConstruction.forwardJumpInstruction&&(o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(this.currentMeasureIndex-1,Qe.ForwardJump,Ze.End,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[this.currentMeasureIndex-1].LastRepetitionInstructions.push(o.RepetitonUnderConstruction.forwardJumpInstruction))}var a;if(e.alignment===Ze.Begin)o.RepetitonUnderConstruction.setEndingsStartIndex(e.endingIndices,this.currentMeasureIndex),null===(a=this.currentMeasure)||void 0===a||a.FirstRepetitionInstructions.push(e);else for(let t=0,i=e.endingIndices.length;t<i;++t){var l;const i=e.endingIndices[t];o.RepetitonUnderConstruction.setEndingEndIndex(i,this.currentMeasureIndex),null===(l=this.currentMeasure)||void 0===l||l.LastRepetitionInstructions.push(e)}break;case Qe.Segno:if(o=this.getCurrentRepetition(!0),void 0!==o&&o.SegnoFound&&o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&Math.abs(o.RepetitonUnderConstruction.BackwardJumpInstructions.last().measureIndex-this.currentMeasureIndex)<=1)break;if(this.openRepetitions.length&&(null===(s=this.openRepetitions)||void 0===s||null===(n=s.find((e=>e.RepetitonUnderConstruction.startMarker.type===Qe.StartLine)))||void 0===n||null===(r=n.RepetitonUnderConstruction)||void 0===r?void 0:r.StartIndex)===this.currentMeasureIndex)break;o=this.createNewRepetition(this.currentMeasureIndex),e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.FromWords=!0,o.SegnoFound=!0,o.RepetitonUnderConstruction.startMarker=e,this.currentMeasure.FirstRepetitionInstructions.push(e);break;case Qe.Fine:if(0===this.openRepetitions.length)break;if(o=this.getCurrentRepetition(!0),void 0===o)break;e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.FromWords=!0,void 0===o.RepetitonUnderConstruction.forwardJumpInstruction?(o.FineFound=!0,o.RepetitonUnderConstruction.forwardJumpInstruction=e,o.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.currentMeasure.LastRepetitionInstructions.push(e)):this.currentMeasure.LastRepetitionInstructions.push(new $e(this.currentMeasureIndex,Qe.Fine,Ze.End,void 0));break;case Qe.ToCoda:if(0===this.openRepetitions.length)break;if(o=this.getCurrentRepetition(!0),void 0===o)break;void 0===o.RepetitonUnderConstruction.forwardJumpInstruction&&(e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.FromWords=!0,o.ToCodaFound=!0,o.RepetitonUnderConstruction.forwardJumpInstruction=e,this.currentMeasure.LastRepetitionInstructions.push(e));break;case Qe.Coda:if(0===this.openRepetitions.length)break;o=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=o.RepetitonUnderConstruction,o.WaitingForCoda?(o.CodaFound=!0,o.RepetitonUnderConstruction.setEndingStartIndex(2,this.currentMeasureIndex),this.currentMeasure.LastRepetitionInstructions.push(e),this.finalizeRepetition(o),this.currentMeasureIndex>0&&(this.musicSheet.SourceMeasures[this.currentMeasureIndex-1].printNewSystemXml=!0)):o.ToCodaFound||(0===o.RepetitonUnderConstruction.BackwardJumpInstructions.length?(o.ToCodaFound=!0,o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(this.currentMeasureIndex,Qe.ToCoda,Ze.End,o.RepetitonUnderConstruction),this.currentMeasure.LastRepetitionInstructions.push(o.RepetitonUnderConstruction.forwardJumpInstruction)):this.currentMeasure.LastRepetitionInstructions.push(new $e(this.currentMeasureIndex,Qe.Coda,Ze.Begin,void 0)));break;case Qe.DaCapo:o=this.getOrCreateCurrentRepetition(),o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&this.finalizeRepetition(o),0!==o.RepetitonUnderConstruction.StartIndex&&(o=this.createNewRepetition(0)),e.parentRepetition=o.RepetitonUnderConstruction,o.RepetitonUnderConstruction.FromWords=!0,o.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None,Ze.Begin,o.RepetitonUnderConstruction),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e),0===o.RepetitonUnderConstruction.EndingParts.length&&this.finalizeRepetition(o);break;case Qe.DalSegno:if(o=this.getOrCreateCurrentRepetition2(!0),o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&(this.finalizeRepetition(o),o=this.createNewRepetition(0),o.RepetitonUnderConstruction.FromWords=!0,o.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None,Ze.Begin,o.RepetitonUnderConstruction)),e.parentRepetition=o.RepetitonUnderConstruction,!o.SegnoFound){const t=this.findInstructionInMainListBackwards(Qe.Segno,e.measureIndex);t>=0&&(o.SegnoFound=!0,o.RepetitonUnderConstruction.startMarker=new $e(t,Qe.Segno,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.startMarker))}o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)&&o.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case Qe.DalSegnoAlFine:if(0===this.openRepetitions.length)break;if(o=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=o.RepetitonUnderConstruction,!o.SegnoFound){const t=this.findInstructionInMainListBackwards(Qe.Segno,e.measureIndex);t>=0&&(o.SegnoFound=!0,o.RepetitonUnderConstruction.startMarker=new $e(t,Qe.Segno,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.startMarker))}if(!o.FineFound){const t=this.findInstructionInMainListBackwards(Qe.Fine,e.measureIndex);t>=0&&(o.FineFound=!0,o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.Fine,Ze.Begin,o.RepetitonUnderConstruction),o.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction))}o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||o.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case Qe.DaCapoAlFine:if(o=this.getOrCreateCurrentRepetition(),o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&(this.finalizeRepetition(o),o=this.createNewRepetition(0)),void 0!==o.RepetitonUnderConstruction.startMarker&&0!==o.RepetitonUnderConstruction.StartIndex&&(o=this.createNewRepetition(0)),o.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None,Ze.Begin,o.RepetitonUnderConstruction),o.RepetitonUnderConstruction.FromWords=!0,e.parentRepetition=o.RepetitonUnderConstruction,!o.FineFound){const t=this.findInstructionInMainListBackwards(Qe.Fine,e.measureIndex);t>=0&&(o.FineFound=!0,o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.Fine,Ze.Begin,o.RepetitonUnderConstruction),o.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction))}o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||o.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case Qe.DalSegnoAlCoda:if(0===this.openRepetitions.length)break;if(o=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=o.RepetitonUnderConstruction,!o.SegnoFound){const t=this.findInstructionInMainListBackwards(Qe.Segno,e.measureIndex);t>=0&&(o.SegnoFound=!0,o.RepetitonUnderConstruction.startMarker=new $e(t,Qe.Segno,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.startMarker))}if(!o.ToCodaFound){const t=this.findInstructionInMainListBackwards(Qe.ToCoda,e.measureIndex);if(t>=0)o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.ToCoda,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction),o.ToCodaFound=!0;else{const t=this.findInstructionInMainListBackwards(Qe.Coda,e.measureIndex);t>=0&&(o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.ToCoda,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction),o.ToCodaFound=!0)}}o.ToCodaFound&&(o.WaitingForCoda=!0),o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||o.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case Qe.DaCapoAlCoda:if(o=this.getOrCreateCurrentRepetition(),(o.RepetitonUnderConstruction.BackwardJumpInstructions.length>0||0===o.RepetitonUnderConstruction.EndingParts.length)&&(this.finalizeRepetition(o),o=this.createNewRepetition(0)),void 0!==o.RepetitonUnderConstruction.startMarker&&0!==o.RepetitonUnderConstruction.StartIndex&&(o=this.createNewRepetition(0)),o.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None,Ze.Begin,o.RepetitonUnderConstruction),o.RepetitonUnderConstruction.FromWords=!0,e.parentRepetition=o.RepetitonUnderConstruction,!o.ToCodaFound){const t=this.findInstructionInMainListBackwards(Qe.ToCoda,e.measureIndex);if(t>=0)o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.ToCoda,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction),o.ToCodaFound=!0;else{const t=this.findInstructionInMainListBackwards(Qe.Coda,e.measureIndex);t>=0&&(o.RepetitonUnderConstruction.forwardJumpInstruction=new $e(t,Qe.ToCoda,Ze.Begin,o.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,o.RepetitonUnderConstruction.forwardJumpInstruction),o.ToCodaFound=!0)}}o.ToCodaFound&&(o.WaitingForCoda=!0),o.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||o.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),o.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case Qe.None:break;default:throw new y("currentRepetitionInstruction")}return!0}findInstructionInMainListBackwards(e,t){for(let i=this.repetitionInstructions.length-1;i>=0;i--){const s=this.repetitionInstructions[i];if(s.measureIndex<=t&&s.type===e)return s.measureIndex}return-1}finalizeRepetition(e){var t,i,s;const n=e.RepetitonUnderConstruction,r=!!(null===(t=n.BackwardJumpInstructions)||void 0===t?void 0:t.some((e=>{var t;return e.measureIndex===(null===(t=this.currentMeasure)||void 0===t?void 0:t.measureListIndex)})))&&"结束句"===(null===(i=this.repetitionInstructions)||void 0===i||null===(s=i.find((e=>{var t;return(null==e?void 0:e.measureIndex)===(null===(t=this.currentMeasure)||void 0===t?void 0:t.measureListIndex)})))||void 0===s?void 0:s.originalVal);if(n.BackwardJumpInstructions.length>0){let e=!0;const t=this.getLastFinalizedRepetition();if(void 0!==t&&n.coversIdenticalMeasures(t)){if(n.NumberOfEndings>t.NumberOfEndings){const e=this.musicSheet.Repetitions.indexOf(t,0);e>-1&&this.musicSheet.Repetitions.splice(e,1),t.removeFromRepetitionInstructions(),this.musicSheet.Repetitions.push(n)}e=!1,n.removeFromRepetitionInstructions()}else r?e=!1:this.musicSheet.Repetitions.push(n);if(e){var o,a;n.startMarker.type===Qe.None&&this.musicSheet.SourceMeasures[n.StartIndex].FirstRepetitionInstructions.push(n.startMarker);let e=(null===(o=window)||void 0===o?void 0:o.DYCustomRepeatCount)>n.DefaultNumberOfRepetitions?null===(a=window)||void 0===a?void 0:a.DYCustomRepeatCount:n.DefaultNumberOfRepetitions;var l,h;!this.hasNextRepeat&&this.currentMeasureIndex<this.musicSheet.SourceMeasures.length-1&&(this.hasNextRepeat=null===(l=this.repetitionInstructions)||void 0===l||null===(h=l.filter((e=>(null==e?void 0:e.measureIndex)>=(null==n?void 0:n.EndIndex))))||void 0===h?void 0:h.some((e=>2==(null==e?void 0:e.type)||4==(null==e?void 0:e.type)))),this.hasNextRepeat&&(e=n.DefaultNumberOfRepetitions),n.UserNumberOfRepetitions=e||n.DefaultNumberOfRepetitions}}this.openRepetitions.splice(this.openRepetitions.length-1,1)}getCurrentRepetition(e){let t;for(let i=this.openRepetitions.length-1;i>=0;i--)if(this.openRepetitions[i].RepetitonUnderConstruction.FromWords===e){for(t=this.openRepetitions[i];i<this.openRepetitions.length-1;)this.finalizeRepetition(this.openRepetitions.last());return t}return t}getOrCreateCurrentRepetition(){if(this.openRepetitions.length>0)return this.openRepetitions.last();const e=this.createNewRepetition(0);return e.RepetitonUnderConstruction.startMarker=new $e(0,Qe.None,Ze.Begin,e.RepetitonUnderConstruction),e}getOrCreateCurrentRepetition2(e){let t;if(this.openRepetitions.length&&this.openRepetitions.last().RepetitonUnderConstruction.EndingParts.length<2)for(let i=this.openRepetitions.length-1;i>=0;i--)if(t=this.openRepetitions[i],t.RepetitonUnderConstruction.FromWords===e){for(;i<this.openRepetitions.length-1;)this.finalizeRepetition(this.openRepetitions.last());return t}return t=this.createNewRepetition(this.lastRepetitionCommonPartStartIndex),t.RepetitonUnderConstruction.startMarker=new $e(this.lastRepetitionCommonPartStartIndex,Qe.None,Ze.Begin,t.RepetitonUnderConstruction),t.RepetitonUnderConstruction.FromWords=e,t}createNewRepetition(e){if(this.openRepetitions.length>0){const e=this.openRepetitions.last(),t=e.RepetitonUnderConstruction;if(t.BackwardJumpInstructions.length>0){const i=Object.keys(t.EndingIndexDict);(0===i.length||t.EndingIndexDict[i[i.length-1]].part.EndIndex>=0)&&this.finalizeRepetition(e)}}const t=new Ys(this.musicSheet);return this.lastRepetitionCommonPartStartIndex=e,this.openRepetitions.push(t),t}getLastFinalizedRepetition(){if(this.musicSheet.Repetitions.length>0)return this.musicSheet.Repetitions.last()}}class Ys{constructor(e){this.RepetitonUnderConstruction=new Ls(e)}}class js{static createRepetitionInstructionReader(){return new zs}static createRepetitionCalculator(){return new Hs}}class Ks{constructor(){this.voiceMeasureReadPlugins=[]}addVoiceMeasureReadPlugin(e){this.voiceMeasureReadPlugins.push(e)}processVoiceMeasureReadPlugins(e,t,i){for(const r of this.voiceMeasureReadPlugins)try{r.measureReadCalculations(e,t,i)}catch(n){s.info("VoiceGenerator.addSingleNote: ",n)}}}class Js{constructor(e=void 0,t=new xe){this.completeNumberOfStaves=0,this.pluginManager=new Ks,this.afterSheetReadingModules=e||[],this.repetitionInstructionReader=js.createRepetitionInstructionReader(),this.repetitionCalculator=js.createRepetitionCalculator(),this.rules=t}get PluginManager(){return this.pluginManager}get CompleteNumberOfStaves(){return this.completeNumberOfStaves}static doCalculationsAfterDurationHasBeenSet(e){for(const t of e)t.doCalculationsAfterDurationHasBeenSet()}createMusicSheet(e,t){try{return this._createMusicSheet(e,t)}catch(i){return void s.error("MusicSheetReader.CreateMusicSheet",i)}}_removeFromArray(e,t){const i=e.indexOf(t);-1!==i&&e.splice(i,1)}trimString(e){return e.replace(/^\s+|\s+$/g,"")}_lastElement(e){return e[e.length-1]}_createMusicSheet(e,t){const i=[];let s=0;this.musicSheet=new ws,this.musicSheet.Path=t,this.musicSheet.Rules=this.rules;const n=e.attribute("osmdMeasureWidthFactor");if(n){const e=Number.parseFloat(n.value);"number"==typeof e&&(this.musicSheet.MeasureWidthFactor=e)}if(!e)throw new S("Undefined root element");this.pushSheetLabels(e,t);const r=e.element("part-list");if(!r)throw new S("Undefined partListNode");const o=e.elements("part"),a=r.elements();this.initializeReading(a,o,i);let l=!0;this.currentFraction=new u(0,1);let h=!1,c=e.element("identification");for(c&&(c=c.element("encoding")),c&&(c=c.element("software")),void 0!==c&&"Guitar Pro 5"===c.value&&(h=!0);l;){void 0!==this.currentMeasure&&this.currentMeasure.HasEndLine&&this.rules.NewPartAndSystemAfterFinalBarline&&(s=0),this.currentMeasure=new tt(this.completeNumberOfStaves,this.musicSheet.Rules);for(const e of i)try{l=l&&e.readNextXmlMeasure(this.currentMeasure,this.currentFraction,h)}catch(d){const e=Xe.translateText("ReaderErrorMessages/InstrumentError","Error while reading instruments.");throw new S(e,d)}l&&(this.musicSheet.addMeasure(this.currentMeasure),this.checkIfRhythmInstructionsAreSetAndEqual(i),this.checkSourceMeasureForNullEntries(),s=this.setSourceMeasureDuration(i,s),Js.doCalculationsAfterDurationHasBeenSet(i),this.currentMeasure.AbsoluteTimestamp=this.currentFraction.clone(),this.musicSheet.SheetErrors.finalizeMeasure(this.currentMeasure.MeasureNumber),this.currentFraction.Add(this.currentMeasure.Duration),this.previousMeasure=this.currentMeasure)}this.repetitionInstructionReader&&(this.repetitionInstructionReader.removeRedundantInstructions(),this.repetitionCalculator&&this.repetitionCalculator.calculateRepetitions(this.musicSheet,this.repetitionInstructionReader.repetitionInstructions)),0===this.musicSheet.DefaultStartTempoInBpm&&(this.musicSheet.DefaultStartTempoInBpm=100),this.musicSheet.checkForInstrumentWithNoVoice(),this.musicSheet.fillStaffList();for(let u=0,f=this.afterSheetReadingModules.length;u<f;++u)this.afterSheetReadingModules[u].calculate(this.musicSheet);return this.musicSheet.userStartTempoInBPM=this.musicSheet.userStartTempoInBPM||this.musicSheet.DefaultStartTempoInBpm,this.musicSheet.InitializeStartTempoInBPM(this.musicSheet.userStartTempoInBPM),this.musicSheet.MusicPartManager.init(),this.musicSheet}initializeReading(e,t,i){const s=this.createInstrumentGroups(e);this.completeNumberOfStaves=this.getCompleteNumberOfStavesFromXml(t),0!==t.length&&(this.repetitionInstructionReader.MusicSheet=this.musicSheet,this.currentFraction=new u(0,1),this.currentMeasure=void 0,this.previousMeasure=void 0);let n=0;for(const o of t){const e=o.attribute("id");if(e){const t=s[e.value],a=o.elements("measure");let l=1;try{l=this.getInstrumentNumberOfStavesFromXml(o)}catch(r){const e=Xe.translateText("ReaderErrorMessages/InstrumentStavesNumberError","Invalid number of staves at instrument: ");this.musicSheet.SheetErrors.push(e+t.Name);continue}t.createStaves(l),i.push(new Gs(this.pluginManager,this.repetitionInstructionReader,a,t)),this.repetitionInstructionReader&&(this.repetitionInstructionReader.xmlMeasureList[n]=a),n++}}}checkIfRhythmInstructionsAreSetAndEqual(e){const t=[];for(let n=0;n<this.completeNumberOfStaves;n++)if(this.currentMeasure.FirstInstructionsStaffEntries[n]){const e=this.currentMeasure.FirstInstructionsStaffEntries[n].Instructions[this.currentMeasure.FirstInstructionsStaffEntries[n].Instructions.length-1];e instanceof x&&t.push(e)}let i=0,s=-1;for(let n=0,r=t.length;n<r;++n){const e=t[n];if(e.Rhythm.RealValue>i){if(this.areRhythmInstructionsMixed(t)&&e.SymbolEnum!==T.NONE)continue;i=e.Rhythm.RealValue,s=t.indexOf(e)}}if(t.length>0&&t.length<this.completeNumberOfStaves){const i=t[s].clone();for(let e=0;e<this.completeNumberOfStaves;e++)void 0===this.currentMeasure.FirstInstructionsStaffEntries[e]||this._lastElement(this.currentMeasure.FirstInstructionsStaffEntries[e].Instructions)instanceof x||(this.currentMeasure.FirstInstructionsStaffEntries[e].removeAllInstructionsOfTypeRhythmInstruction(),this.currentMeasure.FirstInstructionsStaffEntries[e].Instructions.push(i.clone())),this.currentMeasure.FirstInstructionsStaffEntries[e]||(this.currentMeasure.FirstInstructionsStaffEntries[e]=new Je(void 0,void 0),this.currentMeasure.FirstInstructionsStaffEntries[e].Instructions.push(i.clone()));for(let t=0,s=e.length;t<s;++t)e[t].ActiveRhythm=i}if(0===t.length&&this.currentMeasure===this.musicSheet.SourceMeasures[0]){const t=new x(new u(4,4,0,!1),T.NONE);for(let e=0;e<this.completeNumberOfStaves;e++)this.currentMeasure.FirstInstructionsStaffEntries[e]?this.currentMeasure.FirstInstructionsStaffEntries[e].removeAllInstructionsOfTypeRhythmInstruction():this.currentMeasure.FirstInstructionsStaffEntries[e]=new Je(void 0,void 0),this.currentMeasure.FirstInstructionsStaffEntries[e].Instructions.push(t);for(let i=0,s=e.length;i<s;++i)e[i].ActiveRhythm=t}for(let n=0,r=t.length;n<r;++n){const e=t[n];if(e.Rhythm.RealValue<i&&this._lastElement(this.currentMeasure.FirstInstructionsStaffEntries[t.indexOf(e)].Instructions)instanceof x){const i=this.currentMeasure.FirstInstructionsStaffEntries[t.indexOf(e)].Instructions;i[i.length-1]=t[s].clone()}Math.abs(e.Rhythm.RealValue-i)<1e-6&&e.SymbolEnum!==T.NONE&&this.areRhythmInstructionsMixed(t)&&(e.SymbolEnum=T.NONE)}}areRhythmInstructionsMixed(e){for(let t=1;t<e.length;t++)if(Math.abs(e[t].Rhythm.RealValue-e[0].Rhythm.RealValue)<1e-6&&e[t].SymbolEnum!==e[0].SymbolEnum)return!0;return!1}setSourceMeasureDuration(e,t){let i=new u(0,1);const s=[];for(const o of e){s.push(o.MaxTieNoteFraction);const e=o.ActiveRhythm.Rhythm;i.lt(e)&&(i=new u(e.Numerator,e.Denominator,0,!1))}const n=this.currentMeasure.calculateInstrumentsDuration(this.musicSheet,s);let r=new u(0,1);for(const o of n)r.lt(o)&&(r=o);u.Equal(r,i)?this.checkFractionsForEquivalence(r,i):r.lt(i)&&(r=this.currentMeasure.reverseCheck(this.musicSheet,r),this.checkFractionsForEquivalence(r,i)),this.currentMeasure.ImplicitMeasure=this.checkIfMeasureIsImplicit(r,i),(!this.currentMeasure.ImplicitMeasure||t>0)&&t++,this.currentMeasure.Duration=r,this.currentMeasure.ActiveTimeSignature=i,this.currentMeasure.MeasureNumber=t;for(let o=0;o<n.length;o++){const e=n[o];if(this.currentMeasure.ImplicitMeasure&&e!==r||!u.Equal(e,i)&&!this.allInstrumentsHaveSameDuration(n,r)){const e=this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.musicSheet.Instruments[o]);for(let t=0;t<this.musicSheet.Instruments[o].Staves.length;t++)if(!this.graphicalMeasureIsEmpty(e+t)){this.currentMeasure.setErrorInGraphicalMeasure(e+t,!0);const i=Xe.translateText("ReaderErrorMessages/MissingNotesError","Given Notes don't correspond to measure duration.");this.musicSheet.SheetErrors.pushMeasureError(i)}}}return t}checkFractionsForEquivalence(e,t){if(t.Denominator>e.Denominator){const i=t.Denominator/e.Denominator;e.expand(i)}}checkIfMeasureIsImplicit(e,t){return!(this.previousMeasure||!e.lt(t))||!!this.previousMeasure&&u.plus(this.previousMeasure.Duration,e).Equals(t)}allInstrumentsHaveSameDuration(e,t){let i=0;for(let s=0,n=e.length;s<n;++s)e[s].Equals(t)&&i++;return i===e.length&&t!==new u(0,1)}graphicalMeasureIsEmpty(e){let t=0;for(let i=0;i<this.currentMeasure.VerticalSourceStaffEntryContainers.length;i++)this.currentMeasure.VerticalSourceStaffEntryContainers[i].StaffEntries[e]||t++;return t===this.currentMeasure.VerticalSourceStaffEntryContainers.length}checkSourceMeasureForNullEntries(){for(let e=this.currentMeasure.VerticalSourceStaffEntryContainers.length-1;e>=0;e--)for(let t=this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries.length-1;t>=0;t--){const i=this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries[t];if(i)for(let e=i.VoiceEntries.length-1;e>=0;e--){const t=i.VoiceEntries[e];0===t.Notes.length&&(this._removeFromArray(t.ParentVoice.VoiceEntries,t),this._removeFromArray(i.VoiceEntries,t))}void 0!==i&&0===i.VoiceEntries.length&&0===i.ChordContainers.length&&(this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries[t]=void 0)}for(let e=this.currentMeasure.VerticalSourceStaffEntryContainers.length-1;e>=0;e--){let t=0;for(let i=0,s=this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries.length;i<s;++i)this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries[i]||t++;t===this.currentMeasure.VerticalSourceStaffEntryContainers[e].StaffEntries.length&&this._removeFromArray(this.currentMeasure.VerticalSourceStaffEntryContainers,this.currentMeasure.VerticalSourceStaffEntryContainers[e])}}pushSheetLabels(e,t){this.readComposer(e),this.readTitle(e),this.readCopyright(e);try{this.musicSheet.Title&&this.musicSheet.Composer&&this.musicSheet.Subtitle||this.readTitleAndComposerFromCredits(e)}catch(i){s.info("MusicSheetReader.pushSheetLabels","readTitleAndComposerFromCredits",i)}try{if(!this.musicSheet.Title){const e=Math.max(0,t.lastIndexOf("/"),t.lastIndexOf("\\")),i=t.substr(e).split(".",1);this.musicSheet.Title=new pt(i[0])}}catch(i){s.info("MusicSheetReader.pushSheetLabels","read title from file name",i)}}presentAttrsWithValue(e,t){for(const i of e.attributes())if(i.value===t)return!0;return!1}readComposer(e){const t=e.element("identification");if(t){const e=t.elements("creator");for(let t=0,i=e.length;t<i;++t){const i=e[t];if(i.hasAttributes){if(this.presentAttrsWithValue(i,"composer")){this.musicSheet.Composer=new pt(this.trimString(i.value));continue}(this.presentAttrsWithValue(i,"lyricist")||this.presentAttrsWithValue(i,"poet"))&&(this.musicSheet.Lyricist=new pt(this.trimString(i.value)))}}}}readCopyright(e){const t=e.elements("identification");if(t.length>0){const e=t[0].elements("rights");if(e.length>0)for(let t=0,i=e.length;t<i;++t){const i=e[t];if(i.value){this.musicSheet.Copyright=new pt(i.value,ce.CenterBottom,void 0,!0);break}}}}readTitleAndComposerFromCredits(e){if(this.rules.SheetComposerSubtitleUseLegacyParsing)return void this.readTitleAndComposerFromCreditsLegacy(e);const t=this.computeSystemYCoordinates(e);if(0===t)return;let i,s,n;const r=e.elements("credit");for(let c=0,d=r.length;c<d;++c){const e=r[c];if(!e.attribute("page"))return;if("1"===e.attribute("page").value){let r;if(e){let h=!1,u=!1;const c=e.element("credit-type");"subtitle"===(null==c?void 0:c.value)?h=!0:"composer"===(null==c?void 0:c.value)&&(u=!0);let d=h||u;r=e.elements("credit-words");for(const e of r){var o,a,l;const r=null===(o=e.value)||void 0===o?void 0:o.trim();if("Copyright ©"===r)continue;const c=null===(a=e.attribute("justify"))||void 0===a?void 0:a.value;"right"===c?(u=!0,d=!0):"center"===c&&i&&(h=!0,d=!0);const f=null===(l=e.attribute("default-y"))||void 0===l?void 0:l.value,m=null!=f,p=m?parseFloat(f):Number.MIN_VALUE;if(m&&p>t||d)if(i||d){if(u||"right"===c)n?n+="\n"+r:n=r;else if(h||"right"!==c&&"left"!==c)s?s+="\n"+r:s=r;else if("left"===c){this.musicSheet.Lyricist||(this.musicSheet.Lyricist=new pt(r));break}}else i=r}}}}if(!this.musicSheet.Title&&i&&(this.musicSheet.Title=new pt(this.trimString(i))),!this.musicSheet.Subtitle&&s&&(this.musicSheet.Subtitle=new pt(this.trimString(s))),n){let e=!1;var h,u;if(this.musicSheet.Composer)(null!==(h=n.match("\n"))&&void 0!==h?h:[]).length+1>=(null!==(u=this.musicSheet.Composer.text.match("\n"))&&void 0!==u?u:[]).length+1&&(e=!0);else e=!0;e&&(this.musicSheet.Composer=new pt(this.trimString(n)))}}readTitleAndComposerFromCreditsLegacy(e){const t=this.computeSystemYCoordinates(e);if(0===t)return;let i,s,n,r=1,o=0;const a=e.elements("credit");for(let c=0,d=a.length;c<d;++c){const e=a[c];if(!e.attribute("page"))return;if("1"===e.attribute("page").value){let a;if(e){var l,h;if(a=e.element("credit-words"),!a.attribute("justify"))break;const c=null===(l=a.attribute("justify"))||void 0===l?void 0:l.value,d=null===(h=a.attribute("default-y"))||void 0===h?void 0:h.value,f=null!=d,m=f?parseFloat(d):Number.MIN_VALUE;let p=!1;const g=e.element("credit-type");if("subtitle"===(null==g?void 0:g.value)&&(p=!0),f&&m>t||p){if(!this.musicSheet.Title&&!p){var u;const e=null===(u=a.attribute("font-size"))||void 0===u?void 0:u.value;if(e){const t=parseFloat(e);r<t&&(r=t,i=a.value)}}switch(this.musicSheet.Subtitle||("right"!==c&&"left"!==c||p)&&(o<m?(o=m,n?(s=n,n=a.value):n=a.value):s?s+="\n"+a.value:s=a.value),c){case"right":this.musicSheet.Composer||(this.musicSheet.Composer=new pt(this.trimString(a.value)));break;case"left":this.musicSheet.Lyricist||(this.musicSheet.Lyricist=new pt(this.trimString(a.value)))}}}}}!this.musicSheet.Title&&i&&(this.musicSheet.Title=new pt(this.trimString(i))),!this.musicSheet.Subtitle&&s&&(this.musicSheet.Subtitle=new pt(this.trimString(s)))}computeSystemYCoordinates(e){if(!e.element("defaults"))return 0;let t=0,i=0;try{const i=e.element("defaults").element("page-layout").element("page-height").value;t=parseFloat(i)}catch(o){return s.info("MusicSheetReader.computeSystemYCoordinates(): couldn't find page height, not reading title/composer."),0}let n=!1;const r=e.elements("part");for(let s=0,a=r.length;s<a;++s){const e=r[s].elements("measure");for(let t=0,s=e.length;t<s;++t){const s=e[t];if(s.element("print")){const e=s.element("print").elements("system-layout");for(let t=0,s=e.length;t<s;++t){const s=e[t];if(s.element("top-system-distance")){const e=s.element("top-system-distance").value;i=parseFloat(e),n=!0;break}}break}}if(n)break}if(e.element("defaults").element("system-layout")&&e.element("defaults").element("system-layout").element("top-system-distance")){const t=e.element("defaults").element("system-layout").element("top-system-distance").value;i=parseFloat(t)}return 0===i?0:t-i}readTitle(e){const t=e.element("work");let i;t&&(i=t.element("work-title"),i&&i.value&&(this.musicSheet.Title=new pt(this.trimString(i.value))));const s=e.element("movement-title");let n="";if(s&&(this.musicSheet.Title?n=this.trimString(s.value):this.musicSheet.Title=new pt(this.trimString(s.value))),t){const e=t.element("work-number");if(e){const t=e.value;t&&(n=""===n?t:n+", "+t)}}n&&(this.musicSheet.Subtitle=new pt(n))}createInstrumentGroups(e){let t=0;const i={};let n;try{const o=e;for(let e=0,a=o.length;e<a;++e){const a=o[e];if("score-part"===a.name){const e=a.attribute("id").value,o=new Mi(t,e,this.musicSheet,n);let l=e.replace(/\D/g,"")?Number(e.replace(/\D/g,"")):1;l-=1,window.HasCommonTrack&&(l-=1),o.NameLabel.trackIndex=l,t++;const h=a.elements();for(let t=0,i=h.length;t<i;++t){const e=h[t];try{if("part-name"===e.name)o.Name=e.value,e.attribute("print-object")&&"no"===e.attribute("print-object").value&&(o.NameLabel.print=!1);else if("part-abbreviation"===e.name)o.PartAbbreviation=e.value;else if("score-instrument"===e.name){const t=new Us(o);t.idString=e.firstAttribute.value,o.SubInstruments.push(t);const i=e.element("instrument-name");i&&(t.name=i.value,t.setMidiInstrument(i.value));const s=e.element("instrument-sound");s&&(t.instrumentSound=s.value,t.setMidiInstrumentSound(s.value))}else if("midi-instrument"===e.name){let t=o.getSubInstrument(e.firstAttribute.value);for(let s=0,n=o.SubInstruments.length;s<n;++s){const i=o.SubInstruments[s];if(i.idString===e.value){t=i;break}}const i=e.elements();for(let e=0,n=i.length;e<n;++e){const n=i[e];try{if("midi-channel"===n.name)10===parseInt(n.value,10)&&(o.MidiInstrumentId=$.Percussion);else if("midi-program"===n.name)o.SubInstruments.length>0&&o.MidiInstrumentId!==$.Percussion&&(t.midiInstrumentID=Math.max(0,parseInt(n.value,10)-1));else if("midi-unpitched"===n.name)t.fixedKey=Math.max(0,parseInt(n.value,10));else if("volume"===n.name)try{const e=parseFloat(n.value);t.volume=e/127}catch(r){s.debug("ExpressionReader.readExpressionParameters","read volume",r)}else if("pan"===n.name)try{const e=parseFloat(n.value);t.pan=e/64}catch(r){s.debug("ExpressionReader.readExpressionParameters","read pan",r)}}catch(r){s.info("MusicSheetReader.createInstrumentGroups midi settings: ",r)}}}}catch(r){s.info("MusicSheetReader.createInstrumentGroups: ",r)}}if(0===o.SubInstruments.length){const e=new Us(o);o.SubInstruments.push(e)}i[e]=o,n?(n.InstrumentalGroups.push(o),this.musicSheet.Instruments.push(o)):(this.musicSheet.InstrumentalGroups.push(o),this.musicSheet.Instruments.push(o))}else if("part-group"===a.name&&"start"===a.attribute("type").value){const e=new bi("group",this.musicSheet,n);n?n.InstrumentalGroups.push(e):this.musicSheet.InstrumentalGroups.push(e),n=e}else if("part-group"===a.name&&"stop"===a.attribute("type").value&&n){if(1===n.InstrumentalGroups.length){const e=n.InstrumentalGroups[0];n.Parent?(n.Parent.InstrumentalGroups.push(e),this._removeFromArray(n.Parent.InstrumentalGroups,n)):(this.musicSheet.InstrumentalGroups.push(e),this._removeFromArray(this.musicSheet.InstrumentalGroups,n))}n=n.Parent}}}catch(o){const e=Xe.translateText("ReaderErrorMessages/InstrumentError","Error while reading Instruments");throw new S(e,o)}for(let s=0,a=this.musicSheet.Instruments.length;s<a;++s){const e=this.musicSheet.Instruments[s];e.Name||(e.Name="Instr. "+e.IdString)}return i}getCompleteNumberOfStavesFromXml(e){let t=0;for(const i of e){const e=i.elements("measure");if(e.length>0){const i=e[0];if(i){let e=i.element("attributes");e&&(e=e.element("staves")),e?t+=parseInt(e.value,10):t++}}}if(isNaN(t)||t<=0){const e=Xe.translateText("ReaderErrorMessages/StaffError","Invalid number of staves.");throw new S(e)}return t}getInstrumentNumberOfStavesFromXml(e){let t=0;const i=e.element("measure");if(i){const e=i.element("attributes");let s;e&&(s=e.element("staves")),t=e&&s?parseInt(s.value,10):1}if(isNaN(t)||t<=0){const e=Xe.translateText("ReaderErrorMessages/StaffError","Invalid number of Staves.");throw new S(e)}return t}}class qs{static MXLtoIXmlElement(e){const t=new l;return t.loadAsync(e).then((e=>t.file("META-INF/container.xml").async("text")),(e=>{throw e})).then((e=>{const i=(new DOMParser).parseFromString(e,"text/xml").getElementsByTagName("rootfile")[0].getAttribute("full-path");return t.file(i).async("text")}),(e=>{throw e})).then((e=>{const t=(new DOMParser).parseFromString(e,"text/xml"),i=new k(t.documentElement);return Promise.resolve(i)}),(e=>{throw e})).then((e=>e),(e=>{throw new Error("extractSheetFromMxl: "+e.message)}))}static MXLtoXMLstring(e){const t=new l;return t.loadAsync(e).then((e=>t.file("META-INF/container.xml").async("text")),(e=>{throw s.error(e),e})).then((e=>{const i=(new DOMParser).parseFromString(e,"text/xml").getElementsByTagName("rootfile")[0].getAttribute("full-path");return t.file(i).async("text")}),(e=>{throw e}))}}class $s{calculate(e){const t=new w(e);for(;!t.EndReached;){const i=t.CurrentEnrolledTimestamp,s=t.CurrentAudibleVoiceEntries();for(const t of s)this.handleVoiceEntry(e,t,i);t.moveToNext()}}handleVoiceEntry(e,t,i){if(t.IsGrace)return;const s=t.ParentVoice;let n;e.PlaybackDataDict.containsKey(s)?n=e.PlaybackDataDict.getValue(s):(n=[],e.PlaybackDataDict.setValue(s,n));for(const r of t.PlaybackEntries)if(r.HasNotes){for(const t of r.Notes)t.setLength();const e=u.plus(i,r.TimestampShift);$s.addEntrySorted(n,r,e)}}static addEntrySorted(e,t,i){if(0===e.length)e.push({enrolledTimestamp:i,playbackEntry:t});else for(let s=e.length-1;s>=0;s--){const n=e[s];if(i.RealValue>n.enrolledTimestamp.RealValue){if(s===e.length-1){e.push({enrolledTimestamp:i,playbackEntry:t});break}e.splice(s+1,0,{enrolledTimestamp:i,playbackEntry:t});break}}}}class Qs{constructor(e,t,i,s){this.psi=new oe(void 0),this.displaySizeInPixel=e,this.RelativeDisplaySize=t,this.RelativeDisplayPosition=i,this.WidthInUnits=s}static createWithRelativeDefaults(e,t){return new Qs(e,new te(1,1),new z(0,0),t)}static createWithDefaults(){return new Qs(new te(1,1),new te(1,1),new z(0,0),1)}get UpperLeftPositionInUnits(){return this.psi.AbsolutePosition}set UpperLeftPositionInUnits(e){this.psi.AbsolutePosition=e}get DisplaySizeInPixel(){return this.displaySizeInPixel}set DisplaySizeInPixel(e){this.displaySizeInPixel=e,this.regionSizeInPixel=new te(this.displaySizeInPixel.width*this.relativeRegionSize.width,this.displaySizeInPixel.height*this.relativeRegionSize.height),this.recalculateDependentVariables()}get RelativeDisplaySize(){return this.relativeRegionSize}set RelativeDisplaySize(e){this.relativeRegionSize=e,this.regionSizeInPixel=new te(this.displaySizeInPixel.width*this.relativeRegionSize.width,this.displaySizeInPixel.height*this.relativeRegionSize.height),this.recalculateDependentVariables()}get RegionSizeInPixel(){return this.regionSizeInPixel}get WidthInUnits(){return this.psi.BorderRight}set WidthInUnits(e){this.psi.BorderRight=e,this.recalculateDependentVariables()}get ViewRegionInUnits(){return new te(this.psi.BorderRight,this.psi.BorderBottom)}isVisible(e,t){const i=this.psi.collisionDetection(e);return this.psi.liesInsideBorders(e),i}isInsideDisplayArea(e,t){return this.RelativeDisplayPosition.x<=e&&e<=this.RelativeDisplayPosition.x+this.RelativeDisplaySize.width&&this.RelativeDisplayPosition.y<=t&&t<=this.RelativeDisplayPosition.y+this.RelativeDisplaySize.height}transformToUnitCoordinates(e){return new z(this.UpperLeftPositionInUnits.x+this.ViewRegionInUnits.width*((e.x-this.RelativeDisplayPosition.x)/this.RelativeDisplaySize.width),this.UpperLeftPositionInUnits.y+this.ViewRegionInUnits.height*((e.y-this.RelativeDisplayPosition.y)/this.RelativeDisplaySize.height))}transformLengthXToUnitCoordinates(e){return e/this.horizontalUnitToPixelRatio}transformLengthYToUnitCoordinates(e){return e/this.verticalUnitToPixelRatio}recalculateDependentVariables(){const e=this.regionSizeInPixel.width/this.regionSizeInPixel.height;this.psi.BorderBottom=this.psi.BorderRight/e,this.horizontalUnitToPixelRatio=this.regionSizeInPixel.width/this.ViewRegionInUnits.width,this.verticalUnitToPixelRatio=this.regionSizeInPixel.height/this.ViewRegionInUnits.height}}class Zs{constructor(e){this.aspectRatio=1,this.zoomViews=[],this.mouseZoomMode=!1,this.autoScrollY=!0,this.displayInteractionManager=e,this.displayInteractionManager.addListener(this),this.offsetXMin=Number.MIN_VALUE,this.offsetYMin=Number.MIN_VALUE,this.rangeXMin=1,this.rangeYMin=1,this.offsetXMax=Number.MAX_VALUE,this.offsetYMax=Number.MAX_VALUE,this.rangeXMax=1e9,this.rangeYMax=1e9,this.XScrollingEnabled=!1,this.YScrollingEnabled=!0}positionTouched(e,t){if(!this.convertToUnitsReady())return;const i=this.getPositionInUnits(e,t);this.unitPosTouched(i,e,t)}get TouchActive(){return this.displayInteractionManager.TouchActive}get TouchMoving(){return this.displayInteractionManager.TouchMoving}positionDoubleTouched(e,t){if(!this.convertToUnitsReady())return;const i=this.getPositionInUnits(e,t);this.unitPosDoubleTouched(i,e,t)}get UsesManuallyControlledZoomMode(){return this.usesManuallyControlledZoomMode}set UsesManuallyControlledZoomMode(e){this.usesManuallyControlledZoomMode=e}mouseDown(e,t,i=!1){if(!this.convertToUnitsReady())return;this.selectScrollControllerY(!1),this.lastRangeX=Math.max(1,this.RangeX),this.lastRangeY=Math.max(1,this.RangeY),this.lastOffsetX=this.OffsetX,this.lastOffsetY=this.OffsetY;const s=this.getPositionInUnits(e,t);this.unitPosTouchDown(s,e,t),this.usesManuallyControlledZoomMode||(this.mouseZoomMode=!!i)}mouseUp(e,t){const i=this.getPositionInUnits(e,t);this.unitPosTouchUp(i,e,t)}mouseMove(e,t,i,s){this.mouseZoomMode?(Math.abs(i-0)>1e-8&&(this.RangeX=Math.abs(this.lastRangeX/(1+i))),!this.lockRanges&&Math.abs(s-0)>1e-8&&(this.RangeY=Math.abs(this.lastRangeY/(1-s)))):(Math.abs(i-0)>1e-8&&(this.OffsetX=this.lastOffsetX-i*this.RangeX),Math.abs(s-0)>1e-8&&(this.OffsetY=this.lastOffsetY-s*this.RangeY));const n=this.getPositionInUnits(e,t);this.unitPosMove(n,e,t)}zoom(e){this.RangeX=Math.abs(this.lastRangeX/e)}addZoomView(e){this.zoomViews.push(e)}get OffsetX(){return this.offsetX}set OffsetX(e){this.offsetX=Math.min(this.offsetXMax,Math.max(this.offsetXMin,e));for(const t of this.zoomViews)t.viewportXChanged(this.offsetX,this.RangeX)}get OffsetY(){return this.offsetY}set OffsetY(e){this.offsetY=e,this.offsetY>this.offsetYMax?this.offsetY=this.offsetYMax:this.offsetY<this.offsetYMin&&(this.offsetY=this.offsetYMin);for(const t of this.zoomViews)t.viewportYChanged(this.offsetY,this.RangeY)}get RangeX(){return this.rangeX}set RangeX(e){if(this.rangeX=Math.min(this.rangeXMax,Math.max(this.rangeXMin,e)),this.lockRanges){this.RangeY=this.RangeX/this.aspectRatio;for(const e of this.zoomViews)e.viewportXChanged(this.OffsetX,this.RangeX),e.viewportYChanged(this.OffsetY,this.RangeY)}else for(const t of this.zoomViews)t.viewportXChanged(this.OffsetX,this.RangeX)}get RangeY(){return this.rangeY}set RangeY(e){this.rangeY=Math.min(this.rangeYMax,Math.max(this.rangeYMin,e));for(const t of this.zoomViews)t.viewportYChanged(this.OffsetY,this.RangeY)}set AspectRatio(e){this.aspectRatio=e}initialize(e,t,i,s){this.setVerticalViewport(i,s),this.setHorizontalViewport(e,t)}setHorizontalViewport(e,t){this.RangeX=t,this.OffsetX=e,this.lastRangeX=this.RangeX,this.lastOffsetX=this.OffsetX}setVerticalViewport(e,t){this.RangeY=t,this.OffsetY=e,this.lastRangeY=this.RangeY,this.lastOffsetY=this.OffsetY}viewSizeChanged(e,t){this.lockRanges&&(this.aspectRatio=e/t,this.RangeY=this.RangeX/this.aspectRatio,this.lastRangeY=this.RangeY)}outputChanged(e,t,i){this.OffsetY=t}setOffsetXValueOnly(e){this.offsetX=Math.min(this.offsetXMax,Math.max(this.offsetXMin,e))}setXOffset(e,t){!this.displayInteractionManager.TouchActive&&this.XScrollingEnabled}setOffsetYValueOnly(e){this.offsetY=Math.min(this.offsetYMax,Math.max(this.offsetYMin,e))}setYOffset(e,t){!this.displayInteractionManager.TouchActive&&this.YScrollingEnabled&&t&&this.selectScrollControllerY(!0)}selectScrollControllerY(e){this.autoScrollY!==e&&(this.autoScrollY=e)}displaySizeChanged(e,t){throw new Error("Method not implemented.")}}var en=(e=>(e[e.SingleTouch=0]="SingleTouch",e[e.DoubleTouch=1]="DoubleTouch",e[e.TouchUp=2]="TouchUp",e[e.TouchDown=3]="TouchDown",e[e.Move=4]="Move",e))(en||{});class tn{constructor(e){this.renderingManager=e}userDisplayInteraction(e,t,i){switch(i){case en.TouchDown:case en.SingleTouch:case en.DoubleTouch:{const e=this.renderingManager.GraphicalMusicSheet.GetNearestVoiceEntry(t);if(e&&void 0!==e.parentStaffEntry.parentVerticalContainer){var s;const t=e.parentStaffEntry.parentVerticalContainer.AbsoluteTimestamp;var n;this.renderingManager.setStartPosition(t),void 0!==(null===(s=e.notes[0])||void 0===s?void 0:s.sourceNote.Pitch)&&(null===(n=this.renderingManager.PlaybackManager)||void 0===n||n.playVoiceEntry(e.parentVoiceEntry))}break}}}}class sn extends Zs{constructor(e,t){super(e),this.mainViewingRegion=Qs.createWithDefaults(),this.tryAgainToRenderCount=0,this.yOffsetMouseDown=Number.MIN_VALUE,this.unlockCursorDistancePixel=50,this.relativeTopPosition=.06,this.internalPreviewImageScale=3,this.listeners=[],this.LockDisplayToCursor=!0,this.ZoomActive=!1,this.rules=t,this.addZoomView(this),this.lockRanges=!0,this.TopBarHeightInPixel=70,this.BottomBarHeightInPixel=0,this.rules.UseDefaultVoiceInteractionListener&&this.listeners.push(new tn(this))}addListener(e){this.listeners.push(e)}get Listeners(){return this.listeners}convertToUnitsReady(){return void 0!==this.graphicalMusicSheet}unitPosTouched(e,t,i){if(!this.SingleTouchDisabled){const s=new z(t,i);this.handleUserDisplayInteraction(s,e,en.SingleTouch)}}unitPosDoubleTouched(e,t,i){if(!this.DoubleTouchDisabled){const s=new z(t,i);this.handleUserDisplayInteraction(s,e,en.DoubleTouch)}}unitPosTouchDown(e,t,i){const s=new z(t,i);this.handleUserDisplayInteraction(s,e,en.TouchDown),this.yOffsetMouseDown=e.y}unitPosTouchUp(e,t,i){const s=new z(t,i);this.handleUserDisplayInteraction(s,e,en.TouchUp),!1===this.displayInteractionManager.WasZoomGestureActive&&this.unlockFromCursorIfNecessary(e),this.yOffsetMouseDown=Number.MIN_VALUE}unitPosMove(e,t,i){const s=new z(t,i);this.handleUserDisplayInteraction(s,e,en.Move),this.unlockFromCursorIfNecessary(e)}get MainViewingRegion(){return this.mainViewingRegion}setMusicSheet(e){this.graphicalMusicSheet=e,this.adaptDisplayLimitsToSheet(),this.setYOffset(0,!0)}viewportXChanged(e,t){void 0!==this.graphicalMusicSheet&&this.horizontalViewportChanged(e,t)}viewportYChanged(e,t){void 0!==this.graphicalMusicSheet&&(this.yOffsetMouseDown<=Number.MIN_VALUE+.5&&(this.yOffsetMouseDown=e),this.verticalViewportChanged(e,t))}displaySizeChanged(e,t){super.viewSizeChanged(e,t),Math.abs(e-0)<1e-7||Math.abs(t-0)<1e-7||(void 0!==this.graphicalMusicSheet&&this.graphicalMusicSheet.EnforceRedrawOfMusicSystems(),this.mainViewingRegion.DisplaySizeInPixel=new te(e,t),this.adaptDisplayLimitsToSheet())}calcDisplayYPosition(e){return e.PositionAndShape.AbsolutePosition.y+e.PositionAndShape.BorderMarginTop-this.topBarHeightInUnits()-this.relativeTopPosition*this.heightWithoutTopBottomBarsInUnits()}yPositionForLastSystem(e){return e.PositionAndShape.AbsolutePosition.y+e.PositionAndShape.BorderMarginBottom-this.topBarHeightInUnits()-(1-this.relativeTopPosition)*this.heightWithoutTopBottomBarsInUnits()}scorePositionChanged(e,t,i,s,n,r){const o=this.calcDisplayYPosition(s);this.setYPosition(o,r)}setXPosition(e,t){this.LockDisplayToCursor&&this.setXOffset(e,t)}setYPosition(e,t){this.LockDisplayToCursor&&this.setYOffset(e,t)}get DrawingParameters(){return this.musicSheetDrawer.drawingParameters}topBarHeightInUnits(){return this.mainViewingRegion.transformLengthYToUnitCoordinates(this.TopBarHeightInPixel)}bottomBarHeightInUnits(){return this.mainViewingRegion.transformLengthYToUnitCoordinates(this.BottomBarHeightInPixel)}heightWithoutTopBottomBarsInUnits(){return this.mainViewingRegion.ViewRegionInUnits.height-this.topBarHeightInUnits()-this.bottomBarHeightInUnits()}activePositionToBottomBarHeight(){return(this.mainViewingRegion.ViewRegionInUnits.height-this.topBarHeightInUnits()-this.bottomBarHeightInUnits())*(1-2*this.relativeTopPosition)}getClickPosition(e,t){return this.mainViewingRegion.transformToUnitCoordinates(new z(e,t))}graphicalObjectIsVisible(e){return this.mainViewingRegion.isVisible(e,!1)}adaptDisplayLimitsToSheet(){if(void 0===this.graphicalMusicSheet||0===this.graphicalMusicSheet.MusicPages.length||0===this.graphicalMusicSheet.MusicPages[0].MusicSystems.length)return;this.offsetXMin=0,this.rangeXMin=this.graphicalMusicSheet.MinAllowedSystemWidth,this.rangeXMax=300,this.offsetYMin=-.3*this.RangeY;const e=this.graphicalMusicSheet.MusicPages.last().PositionAndShape;this.offsetYMax=Math.max(0,e.BorderMarginBottom-.7*this.RangeY),this.OffsetY>this.offsetYMax&&this.setYOffset(this.offsetYMax,!0)}horizontalViewportChanged(e,t){this.mainViewingRegion.WidthInUnits!==t&&(this.mainViewingRegion.WidthInUnits=t)}verticalViewportChanged(e,t){this.mainViewingRegion.UpperLeftPositionInUnits=new z(this.mainViewingRegion.UpperLeftPositionInUnits.x,e)}unlockFromCursorIfNecessary(e){!1===this.LockDisplayToCursor||this.ZoomActive||this.displayInteractionManager.ZoomGestureActive||this.displayInteractionManager.WasZoomGestureActive||Math.abs((e.y-this.yOffsetMouseDown)*this.mainViewingRegion.RegionSizeInPixel.height/this.mainViewingRegion.ViewRegionInUnits.height)>this.unlockCursorDistancePixel&&(this.LockDisplayToCursor=!1)}getPositionInUnits(e,t){return this.mainViewingRegion.transformToUnitCoordinates(new z(e,t))}handleUserDisplayInteraction(e,t,i){switch(i){case en.TouchDown:case en.SingleTouch:case en.DoubleTouch:case en.TouchUp:case en.TouchDown:case en.Move:for(const s of this.listeners)s.userDisplayInteraction(e,t,i);break;default:throw new Error("type")}}setStartPosition(e){var t;void 0!==this.graphicalMusicSheet&&(this.graphicalMusicSheet.ParentMusicSheet.SelectionStart=e,null===(t=this.PlaybackManager)||void 0===t||t.reset())}get GraphicalMusicSheet(){return this.graphicalMusicSheet}}class nn extends sn{mouseMove(e,t,i,s){const n=this.getPositionInUnits(e,t);this.unitPosMove(n,e,t)}}class rn{constructor(){this.listeners=[],this.zoomGestureActive=!1,this.touchCount=0,this.touchActive=!1,this.touchMoving=!1,this.displayWidth=1,this.displayHeight=1,this.displayDpi=96,this.maxNumerOfFingers=2,this.movementThreshInch=.075,this.interactionWasZoomGesture=!1}addListener(e){this.listeners.push(e)}get ZoomGestureActive(){return this.zoomGestureActive}get WasZoomGestureActive(){return this.interactionWasZoomGesture}displaySizeChanged(e,t){this.displayWidth=e,this.displayHeight=t;for(const i of this.listeners)i.displaySizeChanged(this.displayWidth,this.displayHeight)}Dispose(){this.dispose()}Initialize(){this.initialize()}get DisplayDpi(){return this.displayDpi}get TouchActive(){return this.touchActive}get TouchMoving(){return this.touchMoving}touchDown(e,t,i){this.interactionWasZoomGesture=!1;const s=e/this.displayWidth,n=t/this.displayHeight;this.lastRelPosX=s,this.lastRelPosY=n,this.lastPixelX=e,this.lastPixelY=t,this.touchActive=!0,this.touchMoving=!1,this.touchCount=Math.min(this.touchCount+1,this.maxNumerOfFingers);for(const r of this.listeners)r.mouseDown(s,n,!i)}move(e,t){if(this.touchActive&&!this.zoomGestureActive){const i=e/this.displayWidth,s=t/this.displayHeight,n=i-this.lastRelPosX,r=s-this.lastRelPosY;this.touchMoving=!0;for(const e of this.listeners)e.mouseMove(i,s,n,r)}}zoomGestureStarted(){this.zoomGestureActive=!0}zoomGestureCompleted(){this.zoomGestureActive=!1,this.interactionWasZoomGesture=!0}zoomGestureMove(e){this.zoomGestureActive&&this.listeners.forEach((function(t){t.zoom(e)}))}touchUp(e,t){this.touchActive=!1,this.touchMoving=!1,this.touchCount=Math.max(0,this.touchCount-1);const i=e/this.displayWidth,s=t/this.displayHeight;for(const n of this.listeners)n.mouseUp(i,s)}click(e,t){if(!this.mouseDidMove(this.lastPixelX,e,this.lastPixelY,t)&&!this.ZoomGestureActive){const i=e/this.displayWidth,s=t/this.displayHeight;for(const e of this.listeners)e.positionTouched(i,s)}}doubleClick(e,t){if(!this.mouseDidMove(this.lastPixelX,e,this.lastPixelY,t)&&!this.ZoomGestureActive){const i=e/this.displayWidth,s=t/this.displayHeight;for(const e of this.listeners)e.positionDoubleTouched(i,s)}}mouseDidMove(e,t,i,s){const n=Math.abs(e-t)/this.displayDpi,r=Math.abs(i-s)/this.displayDpi;return n>this.movementThreshInch||r>this.movementThreshInch}}class on extends rn{constructor(e){super(),this.fullOffsetLeft=0,this.fullOffsetTop=0,this.fullScrollTop=0,this.fullScrollLeft=0,this.parentScrollMap=new Map,this.scrollCallbackMap=new Map,this.timeout=void 0,this.resizeObserver=void 0,this.EventCallbackMap=new i,this.DOUBLE_CLICK_WINDOW=200,this.lastClick=0,this.osmdSheetMusicContainer=e,this.listenForInteractions()}get FullOffsetTop(){return this.fullOffsetTop}get FullScrollTop(){return this.fullScrollTop}get FullOffsetLeft(){return this.fullOffsetLeft}get FullScrollLeft(){return this.fullScrollLeft}static resizeCallback(e,t){clearTimeout(t.timeout),t.timeout=setTimeout((()=>{t.fullOffsetLeft=0,t.fullOffsetTop=0;let e=t.osmdSheetMusicContainer;for(;e;)t.fullOffsetLeft+=e.offsetLeft,t.fullOffsetTop+=e.offsetTop,e=e.offsetParent;t.resizeEventListener(),t.deregisterScrollOffsets(),t.registerScrollOffsets()}),500)}registerScrollOffsets(){let e=this.osmdSheetMusicContainer;this.fullScrollTop=0,this.fullScrollLeft=0;const t=this;for(;e&&e!==document.documentElement;){if(this.parentScrollMap.set(e,[e.scrollTop,e.scrollLeft]),this.fullScrollLeft+=e.scrollLeft,this.fullScrollTop+=e.scrollTop,e.scrollHeight>e.clientHeight){const i=function(e){const i=t.parentScrollMap.get(this),s=i[0],n=i[1];t.fullScrollTop=t.fullScrollTop-s+this.scrollTop,t.fullScrollLeft=t.fullScrollLeft-n+this.scrollLeft,t.parentScrollMap.set(this,[this.scrollTop,this.scrollLeft])};this.scrollCallbackMap.set(e,i),e.addEventListener("scroll",i)}e=e.parentElement}}deregisterScrollOffsets(){for(const e of this.scrollCallbackMap.keys())e.removeEventListener("scroll",this.scrollCallbackMap.get(e));this.scrollCallbackMap.clear()}initialize(){this.fullOffsetLeft=0,this.fullOffsetTop=0;let e=this.osmdSheetMusicContainer;const t=[],i=this;for(window.ResizeObserver&&(this.resizeObserver=new ResizeObserver((e=>{on.resizeCallback(e,i)})));e;)this.fullOffsetLeft+=e.offsetLeft,this.fullOffsetTop+=e.offsetTop,this.resizeObserver?this.resizeObserver.observe(e):t.push(e),e=e.offsetParent;if(this.resizeObserver)this.disposeResizeListener=()=>{i.resizeObserver.disconnect(),i.resizeObserver=void 0};else{let e=()=>{on.resizeCallback(t,i)};window.addEventListener("resize",e),this.disposeResizeListener=()=>{window.removeEventListener("resize",e),e=void 0}}i.registerScrollOffsets()}dispose(){this.disposeResizeListener();for(const e of this.EventCallbackMap.keys()){const t=this.EventCallbackMap.getValue(e);t[0].removeEventListener(e,t[1])}this.EventCallbackMap.clear(),this.deregisterScrollOffsets(),this.scrollCallbackMap.clear(),this.parentScrollMap.clear()}isTouch(){if("ontouchstart"in window||window.DocumentTouch)return!0;if(!window.matchMedia)return!1;const e=["(",["-webkit-","-moz-","-o-","-ms-"].join("touch-enabled),("),"heartz",")"].join("");return window.matchMedia(e).matches}get downEventName(){return this.isTouch()?"touchstart":"mousedown"}get moveEventName(){return this.isTouch()?"touchmove":"mousemove"}listenForInteractions(){const e=this.downEventListener.bind(this),t=this.touchEndEventListener.bind(this),i=this.moveEventListener.bind(this);this.osmdSheetMusicContainer.addEventListener("mousedown",e),this.osmdSheetMusicContainer.addEventListener("touchend",t),document.addEventListener(this.moveEventName,i),this.EventCallbackMap.setValue("mousedown",[this.osmdSheetMusicContainer,e]),this.EventCallbackMap.setValue("touchend",[this.osmdSheetMusicContainer,t]),this.EventCallbackMap.setValue(this.moveEventName,[document,i])}downEventListener(e){const t=(new Date).getTime(),i=t-this.lastClick;clearTimeout(this.clickTimeout);let s=0,n=0;this.isTouch()&&e instanceof TouchEvent?(s=e.touches[0].pageX,n=e.touches[0].pageY):e instanceof MouseEvent&&(s=e.pageX,n=e.pageY);const r=this.getOffsetCoordinates(s,n);if(i<this.DOUBLE_CLICK_WINDOW&&i>0)this.doubleClick(r.x,r.y);else{const e=this;this.clickTimeout=setTimeout((function(){clearTimeout(this.clickTimeout),e.isTouch()?e.touchDown(r.x,r.y,void 0):e.click(r.x,r.y)}),this.DOUBLE_CLICK_WINDOW)}this.lastClick=t}moveEventListener(e){let t=0,i=0;if(this.isTouch()&&e instanceof TouchEvent){var s,n;let r;e.touches&&e.touches.length>0?r=e.touches[0]:e.changedTouches&&e.changedTouches.length>0&&(r=e.changedTouches[0]),t=null===(s=r)||void 0===s?void 0:s.clientX,i=null===(n=r)||void 0===n?void 0:n.clientY}else e instanceof MouseEvent&&(t=e.clientX,i=e.clientY);const r=this.getOffsetCoordinates(t,i);this.move(r.x,r.y)}touchEndEventListener(e){var t,i;let s;e.touches&&e.touches.length>0?s=e.touches[0]:e.changedTouches&&e.changedTouches.length>0&&(s=e.changedTouches[0]);const n=this.getOffsetCoordinates(null===(t=s)||void 0===t?void 0:t.pageX,null===(i=s)||void 0===i?void 0:i.pageY);this.touchUp(n.x,n.y)}resizeEventListener(){this.displaySizeChanged(this.osmdSheetMusicContainer.clientWidth,this.osmdSheetMusicContainer.clientHeight)}getOffsetCoordinates(e,t){const i=e-this.fullOffsetLeft+this.fullScrollLeft,s=t-this.fullOffsetTop+this.fullScrollTop;return new z(i,s)}}class an{static fillDynamicsList(e,t,i){for(let s=0;s<t.StaffLinkedExpressions.length;s++)for(let n=0,r=t.StaffLinkedExpressions[s].length;n<r;++n){const r=t.StaffLinkedExpressions[s][n];if(void 0!==r.InstantaneousDynamic||void 0!==r.StartingContinuousDynamic){if(r.StaffNumber=s,void 0!==r.StartingContinuousDynamic&&r.StartingContinuousDynamic.isWedge()&&void 0!==r.StartingContinuousDynamic.EndMultiExpression){const e=r.AbsoluteTimestamp,t=r.StartingContinuousDynamic.EndMultiExpression.AbsoluteTimestamp;if(e.Equals(t))continue}if(void 0!==r.InstantaneousDynamic){i[s].push(new E(r.InstantaneousDynamic,r.StaffNumber));const t=this.getOtherStaffIndexIfLinkedStavesAreDetected(e,s,r.InstantaneousDynamic.Placement);t>=0&&i[t].push(new E(r.InstantaneousDynamic,t))}if(void 0!==r.StartingContinuousDynamic){i[s].push(new E(r.StartingContinuousDynamic,r.StaffNumber));const t=this.getOtherStaffIndexIfLinkedStavesAreDetected(e,s,r.StartingContinuousDynamic.Placement);t>=0&&i[t].push(new E(r.StartingContinuousDynamic,t))}}}}static getOtherStaffIndexIfLinkedStavesAreDetected(e,t,i){const s=e.getStaffFromIndex(t),n=s.ParentInstrument.Staves.indexOf(s),r=s.ParentInstrument.Staves.length;return r>1&&0===n&&i===d.Below?t+1:r>1&&1===n&&i===d.Above?t-1:-1}static fillDynamicExpressions(e){const t=e.DynListStaves,i=e.getCompleteNumberOfStaves(),s=e.TimestampSortedDynamicExpressionsList;for(let n=0;n<i;n++)t.push([]);for(let n=0,r=e.SourceMeasures.length;n<r;++n){const i=e.SourceMeasures[n];an.fillDynamicsList(e,i,t)}for(let n=0;n<t.length;n++)for(let e=0,i=t[n].length;e<i;++e){const i=t[n][e];(void 0===i.instantaneousDynamicExpression||v.dynamicToRelativeVolumeDict.containsKey(i.instantaneousDynamicExpression.DynEnum))&&s.push(i)}s.sort(E.Compare)}calculate(e){an.fillDynamicExpressions(e)}}const ln=class{constructor(e,t=V.OSMDOptionsStandard(),i=new xe){if(this.version="1.8.9-dev",this.cursorsOptions=[],this.cursors=[],this.zoom=1,this.zoomUpdated=!1,this.loadUrlTimeout=5e3,this.rules=i,"string"==typeof e?this.container=document.getElementById(e):e&&"appendChild"in e&&(this.container=e),!this.container)throw new Error("Please pass a valid div container to OpenSheetMusicDisplay");void 0===t.autoResize&&(t.autoResize=!0),this.backendType=B.SVG,this.setOptions(t),this.interactionManager=new on(this.container),this.renderingManager=new nn(this.interactionManager,this.rules)}get cursor(){return this.cursors[0]}get Cursor(){return this.cursor}get RenderingManager(){return this.renderingManager}set PlaybackManager(e){this.renderingManager&&(this.renderingManager.PlaybackManager=e)}get PlaybackManager(){var e;return null===(e=this.renderingManager)||void 0===e?void 0:e.PlaybackManager}isUrl(e){return e.length<2083}isMxl(e){return"PK"===e.substr(0,4)}processMxl(e,t,i){qs.MXLtoXMLstring(e).then((e=>{t(this.processStringXml(e))}),(e=>{s.error(new Error("[OSMD] Invalid MXL file: "+e)),i(new Error("[OSMD] Invalid MXL file: "+e))}))}processStringXml(e){const t=new DOMParser;if(""===e.substr(0,3))return s.debug("[OSMD] UTF with BOM detected, truncate first three bytes and pass along: "+e),t.parseFromString(e.substr(3),"application/xml");if(e.substr(0,6).includes("<?xml")){const i=this.OnXMLRead(e);return s.debug("[OSMD] Finally parsing XML content, length: "+i.length),t.parseFromString(i,"application/xml")}}load(e,i="Untitled Score"){this.reset();const n=this;return new Promise((function(i,r){new Promise((function(i,r){if("string"==typeof e){const o=e.trim();if(n.isMxl(o))s.debug("[OSMD] This is a zip file, unpack it first: "+o),n.processMxl(o,i,r);else{const e=n.processStringXml(o);if(e)i(e);else if(n.isUrl(o))t.ajax(o).then((e=>{n.isMxl(e)?n.processMxl(e,i,r):i(n.processStringXml(e))}),(e=>{throw r(e),e}));else{const e=new Error("[OSMD] osmd.load(string): Could not process string. Did not find <?xml at beginning.");console.error(e.message),r(e)}}}else if(e instanceof Document)i(e);else{const e=new Error("[OSMD] osmd.load(): content is not string or Document. Could not load.");console.error(e.message),r(e)}})).then((function(e){e&&e.nodeName||r(new Error("OpenSheetMusicDisplay: The document which was provided is invalid"));const t=e.childNodes;let o;s.debug("[OSMD] load(), Document url: "+e.URL);for(let i=0,s=t.length;i<s;i+=1){const e=t[i];if(e.nodeType===Node.ELEMENT_NODE&&"score-partwise"===e.nodeName.toLowerCase()){o=e;break}}o||(console.error("Could not parse MusicXML, no valid partwise element found"),r(new Error("OpenSheetMusicDisplay: Document is not a valid 'partwise' MusicXML")));const a=new k(o),l=new an,h=new $s,u=new Js([l,h],n.rules);n.sheet=u.createMusicSheet(a,"Untitled Score"),void 0===n.sheet&&r(new Error("given music sheet was incomplete or could not be loaded.")),s.info(`[OSMD] Loaded sheet ${n.sheet.TitleString} successfully.`),n.needBackendUpdate=!0,n.updateGraphic(),i()})).catch((function(e){s.debug("Content XML Promise was rejected"),r(e)}))}))}updateGraphic(){const e=new bs(this.rules);this.graphic=new Ie(this.sheet,e),this.drawingParameters.drawCursors&&this.cursors.forEach((e=>{e.init(this.sheet.MusicPartManager,this.graphic)})),this.drawingParameters.DrawingParametersEnum===A.leadsheet&&(this.graphic.LeadSheet=!0),this.renderingManager.setMusicSheet(this.graphic),this.interactionManager.Initialize()}render(){var e;if(!this.graphic)throw new Error("OpenSheetMusicDisplay: Before rendering a music sheet, please load a MusicXML file");null===(e=this.drawer)||void 0===e||e.clear(),this.Sheet.SourceMeasures[0].ImplicitMeasure&&(this.rules.MinMeasureToDrawNumber>1&&(this.rules.MinMeasureToDrawIndex=this.rules.MinMeasureToDrawNumber),this.rules.MaxMeasureToDrawNumber>0&&(this.rules.MaxMeasureToDrawIndex=this.rules.MaxMeasureToDrawNumber));let t=this.container.offsetWidth;this.rules.RenderSingleHorizontalStaffline&&(t=this.rules.SheetMaximumWidth),this.sheet.pageWidth=t/this.zoom/10,this.renderingManager.MainViewingRegion.WidthInUnits=this.sheet.pageWidth,this.rules.PageFormat&&!this.rules.PageFormat.IsUndefined?(this.rules.PageHeight=this.sheet.pageWidth/this.rules.PageFormat.aspectRatio,s.debug("[OSMD] PageHeight: "+this.rules.PageHeight)):(s.debug("[OSMD] endless/undefined pageformat, id: "+this.rules.PageFormat.idString),this.rules.PageHeight=100001),this.graphic.reCalculate(),this.drawingParameters.drawCursors&&(this.graphic.Cursors.length=0),this.createOrRefreshRenderBackend(),this.needBackendUpdate=!1,this.drawer.setZoom(this.zoom);for(const i of this.sheet.SourceMeasures)i.WasRendered=!1;this.drawer.drawSheet(this.graphic),this.enableOrDisableCursors(this.drawingParameters.drawCursors),this.drawingParameters.drawCursors&&this.cursors.forEach((e=>{e.update()})),this.zoomUpdated=!1,this.interactionManager.displaySizeChanged(this.container.clientWidth,this.container.clientHeight),this.rules.RenderCount++}createOrRefreshRenderBackend(){if(this.drawer&&this.drawer.Backends){this.drawer.Backends[0]&&this.drawer.Backends[0].removeAllChildrenFromContainer(this.container);for(const e of this.drawer.Backends)e.free();this.drawer.Backends.clear()}this.drawingParameters.Rules=this.rules,this.drawer=new Ht(this.drawingParameters),this.drawer.drawableBoundingBoxElement=this.DrawBoundingBox,this.drawer.bottomLineVisible=this.drawBottomLine,this.drawer.skyLineVisible=this.drawSkyLine;let e,t=this.container.offsetWidth;this.rules.RenderSingleHorizontalStaffline&&(t=10*(this.EngravingRules.PageLeftMargin+this.graphic.MusicPages[0].PositionAndShape.Size.width+this.EngravingRules.PageRightMargin)*this.zoom);const i=32767;for(const n of this.graphic.MusicPages){if(n.PageNumber>this.rules.MaxPageToDrawNumber)break;const r=this.createBackend(this.backendType,n),o=" exceeds CanvasBackend limit of 32767. Cutting off score.";r.getOSMDBackendType()===B.Canvas&&t>i&&(s.warn("[OSMD] Warning: width of "+t+o),t=i),this.rules.PageFormat&&!this.rules.PageFormat.IsUndefined?e=t/this.rules.PageFormat.aspectRatio:(e=n.PositionAndShape.Size.height,e+=this.rules.PageBottomMargin,r.getOSMDBackendType()===B.Canvas&&(e+=.1),e+=n.PositionAndShape.BorderTop,this.rules.RenderTitle&&(e+=this.rules.TitleTopDistance),e*=10*this.zoom),r.getOSMDBackendType()===B.Canvas&&e>i&&(s.warn("[OSMD] Warning: height of "+e+o),e=Math.min(e,i)),r.resize(t,e),r.clear(),r.getContext().setFillStyle(this.rules.DefaultColorMusic),r.getContext().setStrokeStyle(this.rules.DefaultColorMusic),this.drawer.Backends.push(r),this.graphic.drawer=this.drawer}}exportSVG(){for(const t of null===(e=this.drawer)||void 0===e?void 0:e.Backends){var e;t instanceof Xt&&t.export()}}IsReadyToRender(){return void 0!==this.graphic}clear(){var e;null===(e=this.drawer)||void 0===e||e.clear(),this.reset()}dispose(){this.disposeResizeListener&&this.disposeResizeListener(),this.InteractionManager&&this.InteractionManager.Dispose()}setOptions(e){if(this.rules||(this.rules=new xe),this.drawingParameters||e.drawingParameters?e.drawingParameters&&(this.drawingParameters?this.drawingParameters.DrawingParametersEnum=A[e.drawingParameters.toLowerCase()]:this.drawingParameters=new Ot(A[e.drawingParameters],this.rules)):this.drawingParameters=new Ot(A.default,this.rules),null==e)return void s.warn("warning: osmd.setOptions() called without an options parameter, has no effect.\nexample usage: osmd.setOptions({drawCredits: false, drawPartNames: false})");this.OnXMLRead=function(e){return e},e.onXMLRead&&(this.OnXMLRead=e.onXMLRead);let t=!this.drawer||!this.drawer.Backends||this.drawer.Backends.length<1;if(void 0!==e.backend){const i=V.BackendTypeFromString(e.backend);t=t||this.backendType!==i,this.backendType=i}this.needBackendUpdate=t,void 0!==e.autoBeam&&(this.rules.AutoBeamNotes=e.autoBeam);const i=e.autoBeamOptions;if(i&&(void 0===i.maintain_stem_directions&&(i.maintain_stem_directions=!1),this.rules.AutoBeamOptions=i,i.groups&&i.groups.length))for(const s of i.groups)if(2!==s.length)throw new Error("Each fraction in autoBeamOptions.groups must be of length 2, e.g. [3,4] for beaming three fourths");void 0!==e.percussionOneLineCutoff&&(this.rules.PercussionOneLineCutoff=e.percussionOneLineCutoff),0!==this.rules.PercussionOneLineCutoff&&void 0!==e.percussionForceVoicesOneLineCutoff&&(this.rules.PercussionForceVoicesOneLineCutoff=e.percussionForceVoicesOneLineCutoff),void 0!==e.alignRests&&(this.rules.AlignRests=e.alignRests),void 0!==e.coloringMode&&this.setColoringMode(e),void 0!==e.coloringEnabled&&(this.rules.ColoringEnabled=e.coloringEnabled),void 0!==e.colorStemsLikeNoteheads&&(this.rules.ColorStemsLikeNoteheads=e.colorStemsLikeNoteheads),e.disableCursor&&(this.drawingParameters.drawCursors=!1),e.drawHiddenNotes&&(this.drawingParameters.drawHiddenNotes=!0),void 0!==e.drawCredits&&(this.drawingParameters.DrawCredits=e.drawCredits),void 0!==e.drawComposer&&(this.drawingParameters.DrawComposer=e.drawComposer),void 0!==e.drawTitle&&(this.drawingParameters.DrawTitle=e.drawTitle),void 0!==e.drawSubtitle&&(this.drawingParameters.DrawSubtitle=e.drawSubtitle),void 0!==e.drawLyricist&&(this.drawingParameters.DrawLyricist=e.drawLyricist),void 0!==e.drawMetronomeMarks&&(this.rules.MetronomeMarksDrawn=e.drawMetronomeMarks),void 0!==e.drawPartNames&&(this.drawingParameters.DrawPartNames=e.drawPartNames,e.drawPartAbbreviations||(this.rules.RenderPartAbbreviations=e.drawPartNames)),void 0!==e.drawPartAbbreviations&&(this.rules.RenderPartAbbreviations=e.drawPartAbbreviations),!1===e.drawFingerings&&(this.rules.RenderFingerings=!1),void 0!==e.drawMeasureNumbers&&(this.rules.RenderMeasureNumbers=e.drawMeasureNumbers),e.drawMeasureNumbersOnlyAtSystemStart&&(this.rules.RenderMeasureNumbersOnlyAtSystemStart=e.drawMeasureNumbersOnlyAtSystemStart),void 0!==e.drawLyrics&&(this.rules.RenderLyrics=e.drawLyrics),void 0!==e.drawTimeSignatures&&(this.rules.RenderTimeSignatures=e.drawTimeSignatures),void 0!==e.drawSlurs&&(this.rules.RenderSlurs=e.drawSlurs),void 0!==e.measureNumberInterval&&(this.rules.MeasureNumberLabelOffset=e.measureNumberInterval),void 0!==e.useXMLMeasureNumbers&&(this.rules.UseXMLMeasureNumbers=e.useXMLMeasureNumbers),void 0!==e.fingeringPosition&&(this.rules.FingeringPosition=c.PlacementEnumFromString(e.fingeringPosition)),void 0!==e.fingeringInsideStafflines&&(this.rules.FingeringInsideStafflines=e.fingeringInsideStafflines),void 0!==e.newSystemFromXML&&(this.rules.NewSystemAtXMLNewSystemAttribute=e.newSystemFromXML),void 0!==e.newSystemFromNewPageInXML&&(this.rules.NewSystemAtXMLNewPageAttribute=e.newSystemFromNewPageInXML),void 0!==e.newPageFromXML&&(this.rules.NewPageAtXMLNewPageAttribute=e.newPageFromXML),void 0!==e.fillEmptyMeasuresWithWholeRest&&(this.rules.FillEmptyMeasuresWithWholeRest=e.fillEmptyMeasuresWithWholeRest),void 0!==e.followCursor&&(this.FollowCursor=e.followCursor),void 0!==e.setWantedStemDirectionByXml&&(this.rules.SetWantedStemDirectionByXml=e.setWantedStemDirectionByXml),e.darkMode?(this.rules.applyDefaultColorMusic("#FFFFFF"),this.rules.PageBackgroundColor="#000000"):!1===e.darkMode&&(this.rules.applyDefaultColorMusic("#000000"),this.rules.PageBackgroundColor=void 0),e.defaultColorMusic&&this.rules.applyDefaultColorMusic(e.defaultColorMusic),e.defaultColorNotehead&&(this.rules.DefaultColorNotehead=e.defaultColorNotehead),e.defaultColorRest&&(this.rules.DefaultColorRest=e.defaultColorRest),e.defaultColorStem&&(this.rules.DefaultColorStem=e.defaultColorStem),e.defaultColorLabel&&(this.rules.DefaultColorLabel=e.defaultColorLabel),e.defaultColorTitle&&(this.rules.DefaultColorTitle=e.defaultColorTitle),e.defaultFontFamily&&(this.rules.DefaultFontFamily=e.defaultFontFamily),e.defaultFontStyle&&(this.rules.DefaultFontStyle=e.defaultFontStyle),e.drawUpToMeasureNumber>=0&&(this.rules.MaxMeasureToDrawIndex=Math.max(e.drawUpToMeasureNumber-1,0),this.rules.MaxMeasureToDrawNumber=e.drawUpToMeasureNumber),e.drawFromMeasureNumber>=0&&(this.rules.MinMeasureToDrawIndex=Math.max(e.drawFromMeasureNumber-1,0),this.rules.MinMeasureToDrawNumber=e.drawFromMeasureNumber),e.drawUpToPageNumber&&(this.rules.MaxPageToDrawNumber=e.drawUpToPageNumber),e.drawUpToSystemNumber&&(this.rules.MaxSystemToDrawNumber=e.drawUpToSystemNumber),e.tupletsRatioed&&(this.rules.TupletsRatioed=!0),e.tupletsBracketed&&(this.rules.TupletsBracketed=!0),e.tripletsBracketed&&(this.rules.TripletsBracketed=!0),e.autoResize?(this.resizeHandlerAttached||this.autoResize(),this.autoResizeEnabled=!0):!1===e.autoResize&&(this.autoResizeEnabled=!1),void 0!==e.pageFormat&&this.setPageFormat(e.pageFormat),void 0!==e.pageBackgroundColor&&(this.rules.PageBackgroundColor=e.pageBackgroundColor),void 0!==e.performanceMode&&(this.rules.PerformanceMode=e.performanceMode),void 0!==e.renderSingleHorizontalStaffline&&(this.rules.RenderSingleHorizontalStaffline=e.renderSingleHorizontalStaffline),void 0!==e.spacingFactorSoftmax&&(this.rules.SoftmaxFactorVexFlow=e.spacingFactorSoftmax),void 0!==e.spacingBetweenTextLines&&(this.rules.SpacingBetweenTextLines=e.spacingBetweenTextLines),void 0!==e.stretchLastSystemLine&&(this.rules.StretchLastSystemLine=e.stretchLastSystemLine),void 0!==e.autoGenerateMultipleRestMeasuresFromRestMeasures&&(this.rules.AutoGenerateMultipleRestMeasuresFromRestMeasures=e.autoGenerateMultipleRestMeasuresFromRestMeasures),void 0!==e.cursorsOptions?this.cursorsOptions=e.cursorsOptions:this.cursorsOptions=[{type:R.Standard,color:this.EngravingRules.DefaultColorCursor,alpha:.5,follow:!0}],void 0!==e.preferredSkyBottomLineBatchCalculatorBackend&&(this.rules.PreferredSkyBottomLineBatchCalculatorBackend=e.preferredSkyBottomLineBatchCalculatorBackend),void 0!==e.skyBottomLineBatchMinMeasures&&(this.rules.SkyBottomLineBatchMinMeasures=e.skyBottomLineBatchMinMeasures)}setColoringMode(e){if(e.coloringMode===fe.XML)return void(this.rules.ColoringMode=fe.XML);const t=[H.C,H.D,H.E,H.F,H.G,H.A,H.B];let s;if(e.coloringMode===fe.CustomColorSet){if(!e.coloringSetCustom||8!==e.coloringSetCustom.length)throw new Error("Invalid amount of colors: With coloringModes.customColorSet, you have to provide a coloringSetCustom parameter (array) with 8 strings (C to B, rest note).");for(const t of e.coloringSetCustom)if(!/^\#[0-9a-fA-F]{6}$/.test(t))throw new Error("One of the color strings in options.coloringSetCustom was not a valid HTML Hex color:\n"+t);s=e.coloringSetCustom}else if(e.coloringMode===fe.AutoColoring){s=[];const e=Object.keys(U);for(let t=0;t<e.length;t++)s.push(U[e[t]])}const n=new i;for(let i=0;i<t.length;i++)n.setValue(t[i],s[i]);n.setValue(-1,s.last()),this.rules.ColoringSetCurrent=n,this.rules.ColoringMode=e.coloringMode}setLogLevel(e){switch(e){case"trace":s.setLevel(s.levels.TRACE);break;case"debug":s.setLevel(s.levels.DEBUG);break;case"info":s.setLevel(s.levels.INFO);break;case"warn":s.setLevel(s.levels.WARN);break;case"error":s.setLevel(s.levels.ERROR);break;case"silent":s.setLevel(s.levels.SILENT);break;default:s.warn(`Could not set log level to ${e}. Using warn instead.`),s.setLevel(s.levels.WARN)}}getLogLevel(){return s.getLevel()}reset(){this.drawingParameters.drawCursors&&this.cursors.forEach((e=>{e.hide()})),this.sheet=void 0,this.graphic=void 0,this.zoom=1,this.rules.RenderCount=0}autoResize(){const e=this;this.handleResize((()=>{}),(()=>{var t;(null===(t=this.graphic)||void 0===t?void 0:t.GetCalculator)instanceof bs&&(this.graphic.GetCalculator.beamsNeedUpdate=!0),e.IsReadyToRender()&&e.render()}))}handleResize(e,t){let i,s;const n=this;function r(){n.AutoResizeEnabled&&(i=(new Date).getTime(),s||(e(),i=(new Date).getTime(),s=window.setTimeout(o,200)))}function o(){s=void 0,window.clearTimeout(s),(new Date).getTime()-i<200?s=window.setTimeout(o,200):t()}window.attachEvent?window.attachEvent("onresize",r):window.addEventListener("resize",r),this.disposeResizeListener=()=>{window.detachEvent?window.detachEvent("onresize",r):window.removeEventListener("resize",r),this.resizeHandlerAttached=!1},this.resizeHandlerAttached=!0,window.setTimeout(e,0),window.setTimeout(t,1)}enableOrDisableCursors(e){if(this.drawingParameters.drawCursors=e,e){var t;for(let e=0;e<this.cursorsOptions.length;e++){var i,s,n,r,o;const t=null!==(i=null===(s=this.cursors[e])||void 0===s?void 0:s.Hidden)&&void 0!==i&&i,u=null===(n=this.cursors[e])||void 0===n?void 0:n.Iterator;null===(r=this.cursors[e])||void 0===r||r.hide();let c=null===(o=this.drawer)||void 0===o?void 0:o.Backends[0];if(c&&this.rules.RestoreCursorAfterRerender&&this.cursors[e]){const t=this.cursors[e].updateCurrentPage();c=this.drawer.Backends[t-1]}var a,l,h;if(c&&c.getRenderElement())this.cursors[e]&&(null===(a=this.PlaybackManager)||void 0===a||a.removeListener(this.cursors[e]),this.cursors[e].Dispose()),this.cursors[e]=new I(c.getRenderElement(),this,this.cursorsOptions[e]);this.sheet&&this.graphic&&this.cursors[e]&&this.cursors[e].init(this.sheet.MusicPartManager,this.graphic),this.rules.RestoreCursorAfterRerender&&(u&&(this.cursors[e].iterator=u),t?null===(l=this.cursors[e])||void 0===l||l.hide():null===(h=this.cursors[e])||void 0===h||h.show())}null===(t=this.renderingManager.PlaybackManager)||void 0===t||t.addListener(this.cursor)}else this.cursors.forEach((e=>{e.hide()}))}createBackend(e,t){let i;return i=void 0===e||e===B.SVG?new Xt(this.rules):new Ki(this.rules),i.graphicalMusicPage=t,i.initialize(this.container,this.zoom),i}static StringToPageFormat(e){let t=Te.UndefinedPageFormat;if(e.match("^[0-9]+x[0-9]+$")){const i=e.split("x"),s=Number.parseInt(i[0],10),n=Number.parseInt(i[1],10);s>0&&s<32768&&n>0&&n<32768&&(t=new Te(s,n,`customPageFormat${e}`))}return e=(e=(e=e.replace(" ","_")).replace("Landscape","L")).replace("Portrait","P"),ln.PageFormatStandards.hasOwnProperty(e)?(t=ln.PageFormatStandards[e],t):t}setPageFormat(e){const t=ln.StringToPageFormat(e);this.needBackendUpdate=!t.Equals(this.rules.PageFormat),this.rules.PageFormat=t}setCustomPageFormat(e,t){if(e>0&&t>0){const i=new Te(e,t);this.rules.PageFormat=i}}set DrawSkyLine(e){this.drawSkyLine=e,this.drawer&&(this.drawer.skyLineVisible=e)}get DrawSkyLine(){return this.drawer.skyLineVisible}set DrawBottomLine(e){this.drawBottomLine=e,this.drawer&&(this.drawer.bottomLineVisible=e)}get DrawBottomLine(){return this.drawer.bottomLineVisible}set DrawBoundingBox(e){this.setDrawBoundingBox(e,!0)}get DrawBoundingBox(){return this.drawBoundingBox}setDrawBoundingBox(e,t=!1){this.drawBoundingBox=e,this.drawer&&(this.drawer.drawableBoundingBoxElement=e),t&&this.render()}get AutoResizeEnabled(){return this.autoResizeEnabled}set AutoResizeEnabled(e){this.autoResizeEnabled=e}get Zoom(){return this.zoom}set Zoom(e){var t;this.zoom=e,this.zoomUpdated=!0,(null===(t=this.graphic)||void 0===t?void 0:t.GetCalculator)instanceof bs&&(this.graphic.GetCalculator.beamsNeedUpdate=this.zoomUpdated)}set FollowCursor(e){this.followCursor=e}get FollowCursor(){return this.followCursor}set TransposeCalculator(e){yi.transposeCalculator=e}get TransposeCalculator(){return yi.transposeCalculator}get Sheet(){return this.sheet}get Drawer(){return this.drawer}get GraphicSheet(){return this.graphic}get DrawingParameters(){return this.drawingParameters}get EngravingRules(){return this.rules}get InteractionManager(){return this.interactionManager}get Version(){return this.version}};e("O",ln).PageFormatStandards={A3_L:new Te(420,297,"A3_L"),A3_P:new Te(297,420,"A3_P"),A4_L:new Te(297,210,"A4_L"),A4_P:new Te(210,297,"A4_P"),A5_L:new Te(210,148,"A5_L"),A5_P:new Te(148,210,"A5_P"),A6_L:new Te(148,105,"A6_L"),A6_P:new Te(105,148,"A6_P"),Endless:Te.UndefinedPageFormat,Letter_L:new Te(279.4,215.9,"Letter_L"),Letter_P:new Te(215.9,279.4,"Letter_P")},H.C,H.D,H.E,H.F,H.G,H.A,H.B}}}));