import{D as e,l as t,V as i,N as s,_ as n,p as r,j as o}from"./node_modules-dbbb91f3.js";class a{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 l=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 l(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 l((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 l(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(;te;)t.Numerator++;if(this.numerator>this.denominator){const i=new l(this.numerator-1,this.denominator,this.wholeValue);for(;i.Denominator>e;)i.Numerator--;if(i.Denominatorl.maximumAllowedNumber){const e=this.denominator/l.maximumAllowedNumber;this.numerator=Math.round(this.numerator/e),this.denominator=Math.round(this.denominator/e)}if(this.numerator>l.maximumAllowedNumber){const e=this.numerator/l.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)(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))(c||{});const d=class extends u{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&&(d.isStringInStringList(d.listContinuousDynamicIncreasing,e)||d.isStringInStringList(d.listContinuousDynamicDecreasing,e))}getInterpolatedDynamic(e){const t=this.StartMultiExpression.AbsoluteTimestamp;let i;if(i=this.EndMultiExpression?this.EndMultiExpression.AbsoluteTimestamp:h.plus(this.startMultiExpression.SourceMeasureParent.AbsoluteTimestamp,this.startMultiExpression.SourceMeasureParent.Duration),e.lt(t))return-1;if(i.lt(e))return-2;const s=h.minus(e,t).RealValue/h.minus(i,t).RealValue;return Math.max(0,Math.min(99.9,this.startVolume+(this.endVolume-this.startVolume)*s))}isWedge(){return!this.label}setType(){d.isStringInStringList(d.listContinuousDynamicIncreasing,this.label)?this.dynamicType=0:d.isStringInStringList(d.listContinuousDynamicDecreasing,this.label)&&(this.dynamicType=1)}};let f=d;f.listContinuousDynamicIncreasing=["crescendo","cresc","cresc.","cres."],f.listContinuousDynamicDecreasing=["decrescendo","decresc","decr.","diminuendo","dim.","dim"];var m=(e=>(e[e.crescendo=0]="crescendo",e[e.diminuendo=1]="diminuendo",e))(m||{}),p=(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))(p||{});class g{constructor(e,t){this.message=e,t&&(this.message+=" "+t.toString())}}class S{constructor(e){this.message=e}}class y{constructor(e){this.message=e}}const b=class extends u{constructor(e,t,i,s,n){super(i),super.parentMeasure=n,this.dynamicEnum=P[e.toLowerCase()],this.soundDynamic=t,this.staffNumber=s}static staticConstructor(){b.dynamicToRelativeVolumeDict.setValue(13,1),b.dynamicToRelativeVolumeDict.setValue(12,126/127),b.dynamicToRelativeVolumeDict.setValue(11,125/127),b.dynamicToRelativeVolumeDict.setValue(10,124/127),b.dynamicToRelativeVolumeDict.setValue(9,122/127),b.dynamicToRelativeVolumeDict.setValue(8,108/127),b.dynamicToRelativeVolumeDict.setValue(7,76/127),b.dynamicToRelativeVolumeDict.setValue(14,.5),b.dynamicToRelativeVolumeDict.setValue(16,.5),b.dynamicToRelativeVolumeDict.setValue(17,.5),b.dynamicToRelativeVolumeDict.setValue(18,.5),b.dynamicToRelativeVolumeDict.setValue(19,.5),b.dynamicToRelativeVolumeDict.setValue(20,.5),b.dynamicToRelativeVolumeDict.setValue(21,.5),b.dynamicToRelativeVolumeDict.setValue(22,.5),b.dynamicToRelativeVolumeDict.setValue(23,.5),b.dynamicToRelativeVolumeDict.setValue(6,60/127),b.dynamicToRelativeVolumeDict.setValue(5,28/127),b.dynamicToRelativeVolumeDict.setValue(4,12/127),b.dynamicToRelativeVolumeDict.setValue(3,10/127),b.dynamicToRelativeVolumeDict.setValue(2,7/127),b.dynamicToRelativeVolumeDict.setValue(1,5/127),b.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 b.dynamicToRelativeVolumeDict.getValue(this.dynamicEnum)}static isInputStringInstantaneousDynamic(e){return!!e&&b.isStringInStringList(b.listInstantaneousDynamics,e)}getDynamicExpressionSymbol(e){switch(e){case"p":return p.p;case"f":return p.f;case"s":return p.s;case"z":return p.z;case"m":return p.m;case"r":return p.r;default:throw new y("unknown DynamicExpressionSymbolEnum: "+e)}}calculateLength(){return t.debug("[Andrea] instantaneousDynamicExpression: not implemented: calculateLength!"),0}};let M=b;M.dynamicToRelativeVolumeDict=new e,M.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||{});M.staticConstructor();class E{constructor(e,t){e instanceof f?this.continuousDynamicExpression=e:e instanceof M&&(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 v{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 L extends v{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 L(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 x=(e=>(e[e.NONE=0]="NONE",e[e.COMMON=1]="COMMON",e[e.CUT=2]="CUT",e))(x||{});class T{constructor(e,i,s){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 h(0,1),this.currentEnrolledMeasureTimestamp=new h(0,1),this.currentRelativeInMeasureTimestamp=new h(0,1),this.currentVerticalContainerInMeasureTimestamp=new h(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=this.JumpResponsibleRepetition.StartIndex&&t.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&this.resetRepetitionIterationCount(t)}for(let o=0,a=this.repetitionIterationCountDictKeys.length;o=this.JumpResponsibleRepetition.StartIndex&&a.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&(4!==(null==(i=null==(t=null==(e=this.JumpResponsibleRepetition)?void 0:e.BackwardJumpInstructions)?void 0:t[0])?void 0:i.type)&&5!==(null==(r=null==(n=null==(s=this.JumpResponsibleRepetition)?void 0:s.BackwardJumpInstructions)?void 0:n[0])?void 0:r.type)||this.dcResetDone||(this.resetRepetitionIterationCount(a),this.dcResetDone=!0)))}}handleRepetitionsAtMeasureEnd(){var e,t,i;for(let s=0,n=this.currentMeasure.LastRepetitionInstructions.length;s-1&&this.getRepetitionIterationCount(r)=this.JumpResponsibleRepetition.StartIndex&&r.EndIndex<=this.JumpResponsibleRepetition.EndIndex&&4===(null==(i=null==(t=null==(e=this.JumpResponsibleRepetition)?void 0:e.BackwardJumpInstructions)?void 0:t[0])?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;t0&&(this.currentDynamicEntryIndex>=e.length||e[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.gte(this.CurrentSourceTimestamp));)this.currentDynamicEntryIndex--;for(;this.currentDynamicEntryIndex0&&(this.currentTempoEntryIndex>=t.length||t[this.currentTempoEntryIndex].AbsoluteTimestamp.gte(this.CurrentSourceTimestamp));)this.currentTempoEntryIndex--;for(;this.currentTempoEntryIndex0){this.currentVoiceEntryIndex--;const e=this.currentMeasure.VerticalSourceStaffEntryContainers[this.currentVoiceEntryIndex];this.currentVoiceEntries=this.getVoiceEntries(e),this.currentVerticalContainerInMeasureTimestamp=e.Timestamp,this.currentRelativeInMeasureTimestamp=this.currentVerticalContainerInMeasureTimestamp,this.currentTimeStamp=h.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 h(-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=h.plus(this.currentMeasure.AbsoluteTimestamp,t.Timestamp),this.activateCurrentDynamicOrTempoInstructions();const i=this.musicSheet.SelectionEnd;i&&this.currentTimeStamp.lt(i)&&(this.endReached=!1)}}recursiveMove(){var e,t,i,s;if(this.currentVoiceEntryIndex++,0===this.currentVoiceEntryIndex&&(this.handleRepetitionsAtMeasureBegin(),this.activateCurrentRhythmInstructions()),this.currentVoiceEntryIndex>=0&&this.currentVoiceEntryIndex=0&&this.currentMeasureIndex0){if(!e)return!0;for(let e=0,i=t.length;ei){const e=this.openSheetMusicDisplay.Sheet.SourceMeasures[i];this.openSheetMusicDisplay.Sheet.SelectionEnd=h.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(){if(this.hidden||void 0===this.hidden||null===this.hidden)return;this.updateCurrentPage();const e=this.Iterator;let t,i=e.CurrentVisibleVoiceEntries(),s=e.CurrentMeasureIndex,n=0,r=0,o=0;if(0!==i.length||e.FrontReached||e.EndReached||(e.moveToPrevious(),i=e.CurrentVisibleVoiceEntries(),e.moveToNext()),e.FrontReached&&0===i.length){e.moveToNext(),i=e.CurrentVisibleVoiceEntries();const s=this.findVisibleGraphicalMeasure(e.CurrentMeasureIndex);n=s.PositionAndShape.AbsolutePosition.x,t=s.ParentMusicSystem,e.moveToPrevious()}else if(e.EndReached||!e.CurrentVoiceEntries||0===i.length){e.moveToPrevious(),i=e.CurrentVisibleVoiceEntries(),s=e.CurrentMeasureIndex;const r=this.findVisibleGraphicalMeasure(e.CurrentMeasureIndex);n=r.PositionAndShape.AbsolutePosition.x+r.PositionAndShape.Size.width,t=r.ParentMusicSystem,e.moveToNext()}else if(e.CurrentMeasure.isReducedToMultiRest){const i=this.findVisibleGraphicalMeasure(e.CurrentMeasureIndex),s=i.parentSourceMeasure.multipleRestMeasures,r=e.CurrentMeasure.multipleRestMeasureNumber/(s+1),o=i.PositionAndShape.Size.width-i.beginInstructionsWidth;n=i.PositionAndShape.AbsolutePosition.x+i.beginInstructionsWidth+r*o,t=i.ParentMusicSystem}else{const e=i.map((e=>this.getStaffEntryFromVoiceEntry(e)));let s=e.sort(((e,t)=>{var i,s,n,r;return(null==(s=null==(i=null==e?void 0:e.PositionAndShape)?void 0:i.AbsolutePosition)?void 0:s.x)<=(null==(r=null==(n=null==t?void 0:t.PositionAndShape)?void 0:n.AbsolutePosition)?void 0:r.x)?-1:1}))[0];window.DYFirstTrackName&&(s=e.find((e=>e.sourceStaffEntry.ParentStaff.ParentInstrument.Name===window.DYFirstTrackName))),s&&(n=s.PositionAndShape.AbsolutePosition.x,t=s.parentMeasure.ParentMusicSystem)}if(!(null==t?void 0:t.StaffLines[0]))return;r=t.PositionAndShape.AbsolutePosition.y+t.StaffLines[0].PositionAndShape.RelativePosition.y;let a=t.PositionAndShape.AbsolutePosition.y;const l=t.StaffLines[t.StaffLines.length-1];l&&(a+=l.PositionAndShape.RelativePosition.y+l.StaffHeight),o=a-r;const h=this.findVisibleGraphicalMeasure(s);if(!h)return;const u=h.PositionAndShape;if(!this.activeMeasureNum||h.MeasureNumber===this.activeMeasureNum){if(this.updateWidthAndStyle(u,n,r,o),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{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 h(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?void 0: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 I=(e=>(e.allon="allon",e.compact="compact",e.compacttight="compacttight",e.default="default",e.leadsheet="leadsheet",e.preview="preview",e.thumbnail="thumbnail",e))(I||{}),A=(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))(A||{}),R=(e=>(e[e.Never=0]="Never",e[e.Always=1]="Always",e[e.Auto=2]="Auto",e))(R||{}),N=(e=>(e[e.No=0]="No",e[e.YesVisible=1]="YesVisible",e[e.YesInvisible=2]="YesInvisible",e))(N||{}),C=(e=>(e[e.SVG=0]="SVG",e[e.Canvas=1]="Canvas",e))(C||{}),B=(e=>(e[e.Plain=0]="Plain",e[e.WebGL=1]="WebGL",e))(B||{});class D{static OSMDOptionsStandard(){return{autoResize:!0,backend:"svg",drawingParameters:I.default}}static BackendTypeFromString(e){return e&&"canvas"===e.toLowerCase()?1:0}}class V{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;i0){let i;for(let s=0,n=t.length;ss?1:0}getFirstNonNullStaffEntry(){for(let e=0,t=this.staffEntries.length;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))(F||{});const O=new e;O.setValue(0,"Thistle"),O.setValue(1,"Aqua"),O.setValue(2,"Azure"),O.setValue(3,"Bisque"),O.setValue(4,"CadetBlue"),O.setValue(5,"DarkBlue"),O.setValue(6,"DarkGoldenRod"),O.setValue(7,"BlanchedAlmond"),O.setValue(8,"Chartreuse"),O.setValue(9,"DarkGreen"),O.setValue(10,"DarkOrange"),O.setValue(11,"FireBrick"),O.setValue(12,"DarkSalmon"),O.setValue(13,"DarkSeaGreen"),O.setValue(14,"DarkOrchid"),O.setValue(15,"Aquamarine"),O.setValue(16,"DarkKhaki"),O.setValue(17,"ForestGreen"),O.setValue(18,"AliceBlue"),O.setValue(19,"DeepPink"),O.setValue(20,"Coral"),O.setValue(21,"DarkOliveGreen"),O.setValue(22,"Chocolate"),O.setValue(23,"DodgerBlue"),O.setValue(24,"Blue"),O.setValue(25,"Beige"),O.setValue(26,"Crimson"),O.setValue(27,"Fuchsia"),O.setValue(28,"Brown"),O.setValue(29,"BlanchedAlmond"),O.setValue(30,"CornflowerBlue"),O.setValue(31,"Cornsilk"),O.setValue(32,"DarkGrey");var _=(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=(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))(G||{}),W=(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))(W||{});class U{constructor(e,t,i=0,s=F.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 X{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}static get Empty(){return new X}static pointsAreEqual(e,t){return e.x===t.x&&e.y===t.y}ToString(){return"["+this.x+", "+this.y+"]"}}var z=(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))(z||{}),H=(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))(H||{});const Y=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+Y.octXmlDiff)+Y.HalfTonesFromAccidental(i),n||(this.frequency=Y.calcFrequency(this),this.nextFrequency=Y.calcFrequency(this,"next"),this.prevFrequency=Y.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=Y.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 Y.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 Y){const t=e;n=t.octave-1,s=t.fundamentalNote-9+t.AccidentalHalfTones}else if("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)){if(i[l].includes(r)){o=parseFloat(l);break}}let a=s+o;"next"===t&&a++,"prev"===t&&a--;return 442*Math.pow(2,n)*Math.pow(2,a/12)}static calcFractionalKey(e){return Math.log(e/440)/Math.LN10*Y.halftoneFactor+57}static fromFrequency(e){const t=Y.calcFractionalKey(e)+.5,i=Math.floor(t/12)-Y.octXmlDiff,s=Math.floor(t)%12;let n=s,r=2;return-1===this.pitchEnumValues.indexOf(n)&&(n=s-1,r=0),new Y(n,i,r)}static fromHalftone(e){const t=Math.floor(e/12)-Y.octXmlDiff,i=e%12;let s=i,n=2;return-1===this.pitchEnumValues.indexOf(s)&&(s=i-1,n=0),new Y(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 Y.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 Y.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=Y.AccidentalFromHalfTones(this.halfTone-(this.fundamentalNote+12*(this.octave+Y.octXmlDiff)));break;case 0:case 4:this.fundamentalNote=this.getNextFundamentalNote(this.fundamentalNote),this.accidental=Y.AccidentalFromHalfTones(this.halfTone-(this.fundamentalNote+12*(this.octave+Y.octXmlDiff)));break;default:return}}ToString(){let e=Y.accidentalVexflow(this.accidental);return e||(e=""),"Key: "+Y.getNoteEnumString(this.fundamentalNote)+e+", Note: "+this.fundamentalNote+", octave: "+this.octave.toString()}ToStringShort(e=0){let t=Y.accidentalVexflow(this.accidental);t||(t="");const i=this.octave+e;return Y.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.FundamentalNoteY.pitchEnumValues.length-1?(i=Y.pitchEnumValues[t+e-Y.pitchEnumValues.length],s++):i=Y.pitchEnumValues[t+e],new Y(i,s,2)}getLowerPitchByTransposeFactor(e){const t=Y.pitchEnumValues.indexOf(this.fundamentalNote);let i,s=this.octave;return t-e<0?(i=Y.pitchEnumValues[Y.pitchEnumValues.length+t-e],s--):i=Y.pitchEnumValues[t-e],new Y(i,s,2)}getNextFundamentalNote(e){let t=Y.pitchEnumValues.indexOf(e);return t=(t+1)%Y.pitchEnumValues.length,Y.pitchEnumValues[t]}getPreviousFundamentalNote(e){const t=Y.pitchEnumValues.indexOf(e);return t>0?Y.pitchEnumValues[t-1]:Y.pitchEnumValues[Y.pitchEnumValues.length-1]}};let j=Y;j.pitchEnumValues=[0,2,4,5,7,9,11],j.halftoneFactor=12/(Math.LN2/Math.LN10),j.octXmlDiff=3;class K extends v{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 K(1,0,4);default:return new K(0,0,2)}}static getAllPossibleClefs(){const e=[];for(let t=0;t<=2;t++){const i=new K(0,t,2);e.push(i)}for(let t=-2;t<=0;t++){const i=new K(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 j(z.G,1+this.octaveOffset,H.NONE),this.referenceCyPosition=5-this.line+2;break;case 1:this.clefPitch=new j(z.F,0+this.octaveOffset,H.NONE),this.referenceCyPosition=5-this.line+1.5;break;case 2:this.clefPitch=new j(z.C,1+this.octaveOffset,H.NONE),this.referenceCyPosition=5-this.line;break;case 3:this.clefPitch=new j(z.C,2,H.NONE),this.referenceCyPosition=2;break;case 4:this.clefPitch=new j(z.G,0,H.NONE),this.referenceCyPosition=0;break;default:throw new S("clefType")}}}var J=(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))(J||{}),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))(q||{});const $=class extends v{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 $(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 $(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=0}getAlterationForPitch(e){return this.keyType>0&&this.alteratedNotes.indexOf(e.FundamentalNote)<=this.keyType?H.SHARP:this.keyType<0&&this.alteratedNotes.indexOf(e.FundamentalNote)<=Math.abs(this.keyType)?H.FLAT:H.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 Q=$;Q.sharpPositionList=[z.F,z.C,z.G,z.D,z.A,z.E,z.B],Q.flatPositionList=[z.B,z.E,z.A,z.D,z.G,z.C,z.F];var Z=(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))(Z||{});class ee{constructor(e=0,t=0){this.width=e,this.height=t}}class te{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 te(e.x,e.y,t.width,t.height)}get Location(){return new X(this.x,this.y)}get Size(){return new ee(this.width,this.height)}}class ie{isInstanceOfClass(e){let t=this.constructor.prototype;for(;t;){if(e===t.constructor.name)return!0;t=t.__proto__}return!1}}class se extends ie{get PositionAndShape(){return this.boundingBox}set PositionAndShape(e){this.boundingBox=e}}class ne extends se{}class re{constructor(e=void 0,t=void 0,i=!1){this.isSymbol=!1,this.relativePositionHasBeenSet=!1,this.xBordersHaveBeenSet=!1,this.yBordersHaveBeenSet=!1,this.absolutePosition=new X,this.relativePosition=new X,this.size=new ee,this.marginSize=new ee,this.upperLeftCorner=new X,this.upperLeftMarginCorner=new X,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.borderMarginRightthis.borderTop?this.borderTop:this.borderMarginTop}set BorderMarginTop(e){this.borderMarginTop=e,this.calculateMarginRectangle()}get BorderMarginBottom(){return this.borderMarginBottom-1&&this.parent.ChildElements.splice(e,1)}this.parent=e,(null==(s=null==(i=this.parent)?void 0:i.ChildElements)?void 0:s.indexOf(this))>-1?t.error("BoundingBox of "+this.dataObject.constructor.name+" already in children list of "+this.parent.dataObject.constructor.name+"'s BoundingBox"):null==(r=null==(n=this.parent)?void 0:n.ChildElements)||r.push(this)}get DataObject(){return this.dataObject}get Center(){return new X(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.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 S("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){if(this.AbsolutePosition.x+this.borderLeft<=e.x&&e.x<=this.AbsolutePosition.x+this.borderRight){if(this.AbsolutePosition.y+this.borderTop<=e.y&&e.y<=this.AbsolutePosition.y+this.borderBottom)return!0}return!1}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){if(this.AbsolutePosition.x+this.borderMarginLeft<=e.x&&e.x<=this.AbsolutePosition.x+this.borderMarginRight){if(this.AbsolutePosition.y+this.borderMarginTop<=e.y&&e.y<=this.AbsolutePosition.y+this.borderMarginBottom)return!0}return!1}computeNonOverlappingPosition(e,t,i){this.RelativePosition=new X(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 S("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(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))(oe||{});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 ae{static contains2(e,t){for(let i=0;i(e[e.Down=0]="Down",e[e.Right=1]="Right",e[e.RightDown=2]="RightDown",e))(he||{}),ue=(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))(ue||{});class ce{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 de=(e=>(e[e.XML=0]="XML",e[e.AutoColoring=1]="AutoColoring",e[e.CustomColorSet=2]="CustomColorSet",e))(de||{}),fe=(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))(fe||{}),me=(e=>(e[e.TimesNewRoman=0]="TimesNewRoman",e[e.Kokila=1]="Kokila",e[e.Gonville=2]="Gonville",e))(me||{});const pe={0:"Times New Roman",1:"Kokila",2:"Gonville"};var ge=(e=>(e.SIMPLE="",e.HAMMERON="H",e.PULLOFF="P",e.SLIDE="S",e.TAPPING="T",e))(ge||{});class Se{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=j.getNoteEnumString(s.FundamentalNote);s.Accidental!==H.NONE&&(n+=e.getTextForAccidental(s.Accidental));const r={adds:[],alts:[],subs:[]};for(const h of e.ChordDegrees)if(h){let t="";switch(h.alteration!==H.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+=j.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))?t:""}}class ye{constructor(e,t,i){this.value=e,this.alteration=t,this.text=i}}class be{constructor(e,t,i){this.alternateName=e,this.chordKind=t,this.degrees=i}static createCustomChord(e,t,i){return new be(e,t,i)}static renameCustomChord(e,t,i){for(const s of i)s.alternateName===e&&(s.alternateName=t)}}var Me=(e=>(e[e.add=0]="add",e[e.alter=1]="alter",e[e.subtract=2]="subtract",e))(Me||{}),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 se{constructor(e,t,i,s=void 0){super(),this.DrawnAccidental=H.NONE,this.lineShift=0,this.sourceNote=e,this.parentVoiceEntry=t,this.PositionAndShape=new re(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.ToStringShort(e)}get ToStringShortGet(){return this.ToStringShort(0)}}const ve=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*ve.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=he.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=ve.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=ve.unit/2,this.BeamSpaceWidth=ve.unit/3,this.BeamForwardLength=1.25*ve.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=ue.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 e,this.resetChordAccidentalTexts(this.ChordAccidentalTexts,!1),this.ChordSymbolLabelTexts=new e,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*ve.unit,this.MeasureNumberLabelOffset=2,this.MeasureNumberLabelXOffset=-.5,this.TupletsRatioed=!1,this.TupletsBracketed=!1,this.TripletsBracketed=!1,this.TupletsBracketedUseXMLValue=!0,this.TupletNumberLabelHeight=1.5*ve.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=ue.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=ve.unit/2,this.SystemRepetitionEndingLineWidth=.12,this.SystemDotWidth=ve.unit/2,this.DistanceBetweenVerticalSystemLines=.35,this.DistanceBetweenDotAndLine=.7,this.RepeatEndStartPadding=2,this.OctaveShiftLineWidth=.12,this.OctaveShiftVerticalLineLength=ve.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=R.Never,this.RestCollisionYPadding=0,this.FillEmptyMeasuresWithWholeRest=N.No,this.ArpeggiosGoAcrossVoices=!1,this.RenderArpeggios=!0,this.RenderSlurs=!0,this.RenderGlissandi=!0,this.ColoringMode=de.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=fe.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=c.AboveOrBelow,this.FingeringPositionFromXML=!0,this.FingeringPositionGrace=c.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=xe.UndefinedPageFormat,this.PageBackgroundColor=void 0,this.UsePageBackgroundColorForTabNotes=!0,this.PerformanceMode=!1,this.RenderSingleHorizontalStaffline=!1,this.SpacingBetweenTextLines=0,this.NoteToGraphicalNoteMap=new e,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(i){t.info("EngravingRules()",i)}this.MpatMode&&(this.NewPartAndSystemAfterFinalBarline=!0)}setPreferredSkyBottomLineBackendAutomatically(e=-1){var t,i,s,n;let r="",o="";"object"==typeof globalThis&&(r=null!=(i=null==(t=globalThis.navigator)?void 0:t.vendor)?i:"",o=null!=(n=null==(s=globalThis.navigator)?void 0:s.userAgent)?n:"");let a=!1;(this.DisableWebGLInSafariAndIOS&&/apple/i.test(r)||this.DisableWebGLInFirefox&&o.includes("Firefox"))&&(a=!0),this.PreferredSkyBottomLineBatchCalculatorBackend=B.Plain,a||e>=this.SkyBottomLineWebGLMinMeasures&&(this.PreferredSkyBottomLineBatchCalculatorBackend=B.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 e,this.NoteToGraphicalNoteMapObjectCount=0}resetChordAccidentalTexts(e,t){e.setValue(H.SHARP,t?"♯":"#"),e.setValue(H.FLAT,t?"♭":"b"),e.setValue(H.DOUBLEFLAT,t?"𝄫":"bb"),e.setValue(H.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(H.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(be.createCustomChord(e,Pe[t],r))}}renameChord(e,t){be.renameCustomChord(e,t,this.CustomChords)}resetChordNames(){const e=this.ChordAccidentalTexts.getValue(H.SHARP),t=this.ChordAccidentalTexts.getValue(H.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{var i,s,n,r;return(null!=(s=null==(i=t.sourceNote.Pitch)?void 0:i.getHalfTone())?s:0)-(null!=(r=null==(n=e.sourceNote.Pitch)?void 0:n.getHalfTone())?r:0)})),this.notes}sortForVexflow(){return this.notes.sort(((e,t)=>{var i,s,n;return(null!=(s=null==(i=e.sourceNote.Pitch)?void 0:i.getHalfTone())?s:0)-(null!=(n=t.sourceNote.Pitch.getHalfTone())?n:0)})),this.notes}color(){}}class we{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=0;s--){const e=null==(i=this.measureList[s])?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;s0)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=0;t--){if(this.verticalGraphicalStaffEntryContainers[t].AbsoluteTimestamp.lt(e)){const i=new k(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=ae.binarySearch(this.verticalGraphicalStaffEntryContainers,new k(0,e),k.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=h.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=0;)s=this.measureList[--i][e];return this.measureList[i][e]}getMeasureIndex(e,t,i){for(t=0;t{var t;return void 0!==(null==(t=e.parentStaffEntry)?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+ot.PositionAndShape.RelativePosition.x&&(s=t):s=t)}}catch(n){t.info("GraphicalMusicSheet.getStaffEntry",n)}return s}GetPreviousVisibleContainerIndex(e){for(let t=e-1;t>=0;t--){const e=this.verticalGraphicalStaffEntryContainers[t].StaffEntries;for(let i=0,s=e.length;i=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));s1}isVisible(){return this.ParentStaff.ParentInstrument.Visible}getGraphicalMeasureDurationFromStaffEntries(){let e=new h(0,1);const t=[];for(let i=0,s=this.staffEntries.length;i0&&n.Add(t.notes[0].graphicalNoteLength);e.lt(n)&&(e=h.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 Re=(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))(Re||{});class Ne{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 Ce{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 Ce,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 Ce;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 X;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 Be{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 De{constructor(e,t=7){this.parentVoiceEntry=e,this.type=t,this.notes=[]}addNote(e){this.notes.push(e),e.Arpeggio=this}}var Ve=(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))(Ve||{});class ke{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 Fe{constructor(e){this.notes=[],this.XMLNumber=1,this.AddNote(e),this.StartNote=e,this.Direction=oe.NotYetDefined}get Notes(){return this.notes}get Duration(){const e=new h;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()2:(t.warn("notehead: sourceNote and filledXmlAttribute undefined."),s=!0)),this.filled=s}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 t.info("unsupported/unhandled xml notehead '"+e+"'. Using normal notehead."),2}}}var We=(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))(We||{});class Ue{static translateText(e,t){if(!this.defaultTextTranslation)return t}}var Xe=(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))(Xe||{});class ze{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 h(1,1024);case"512th":return new h(1,512);case"256th":return new h(1,256);case"128th":return new h(1,128);case"64th":return new h(1,64);case"32th":case"32nd":return new h(1,32);case"16th":return new h(1,16);case"eighth":return new h(1,8);case"quarter":return new h(1,4);case"half":return new h(1,2);case"whole":return new h(1,1);case"breve":return new h(2,1);case"long":return new h(4,1);case"maxima":return new h(8,1);default:{const e=Ue.translateText("ReaderErrorMessages/NoteDurationError","Invalid note duration.");throw new g(e)}}}}ze.NoteTypeXmlValues=["","1024th","512th","256th","128th","64th","32nd","16th","eigth","quarter","half","whole","breve","long","maxima"];class He{constructor(e){this.placement=c.Above,this.accidentalAbove=H.NONE,this.accidentalBelow=H.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 Ye=(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))(Ye||{});class je{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 h.plus(this.timestamp,this.parentMeasure.AbsoluteTimestamp)}}class Ke{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 h.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(;e0)return!0}return!1}hasTie(){for(let e=0,t=this.VoiceEntries.length;et.parentRepetition.StartIndex)return-1}if(0===e.alignment&&0===t.alignment){if(e.parentRepetition.EndIndext.parentRepetition.EndIndex)return-1}}return 0}}class qe{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(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))($e||{}),Qe=(e=>(e[e.Begin=0]="Begin",e[e.End=1]="End",e))(Qe||{});let Ze=null;class et{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=Re.SingleThin,this.firstInstructionsStaffEntries=new Array(e),this.lastInstructionsStaffEntries=new Array(e),this.rules=t,this.TempoInBPM=0;for(let i=0;i1)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 Ke(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 je(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.push(n),s=new Ke(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 je(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.splice(o+1,0,n),s=new Ke(n,i),n.StaffEntries[t]=s;break}if(0===o){const n=new je(this,e.clone(),this.completeNumberOfStaves);this.verticalSourceStaffEntryContainers.splice(o,0,n),s=new Ke(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 ht(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=0;n--){const e=this.verticalSourceStaffEntryContainers[n][i+s];if(void 0!==e&&e.hasTie()&&t.lt(h.plus(e.Timestamp,e.calculateMaxNoteLength()))){t=h.plus(e.Timestamp,e.calculateMaxNoteLength());break}}}}s.push(t)}for(let n=0,r=s.length;n0)return!0}return!1}beginsWithLineRepetition(){for(let e=0,t=this.FirstRepetitionInstructions.length;e=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;if(this.firstRepetitionInstructions.length>0||this.lastRepetitionInstructions.length>0)return!1;let o=!0,a=!1;for(const l of this.verticalSourceStaffEntryContainers)if(l)for(const e of l.StaffEntries)if(e&&e.ParentStaff.ParentInstrument.Visible){if(e.ChordContainers.length>0)return!1;e.ParentStaff.hasLyrics&&(a=!0);for(const t of e.VoiceEntries){for(const e of t.Notes)if(!e.isRest()){o=!1;break}if(!o)break}}if(!o||a||this.hasMoodExpressions||this.tempoExpressions.length>0)return!1;for(const l of this.staffLinkedExpressions)if(l.length>0)return!1;for(const l of this.lastInstructionsStaffEntries)for(let e=0,t=null==l?void 0:l.Instructions.length;e=0;t--)for(let i=0;i(e[e.Fingering=0]="Fingering",e[e.String=1]="String",e))(rt||{});class ot{}class at{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===q.Percussion;this.MidiKey=e?at.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.Shape;switch(e.Pitch.Octave){case 1:switch(e.Pitch.FundamentalNote){case z.D:return 44;case z.E:return 35;case z.F:return 36;case z.G:return 41;case z.A:return 43;case z.B:return s===We.TRIANGLE?54:47;default:return i}case 2:switch(e.Pitch.FundamentalNote){case z.C:return s===We.X?37:38;case z.D:return s===We.X?59:48;case z.E:switch(s){case We.X:return 42;case We.CIRCLEX:return 46;case We.TRIANGLE:return 56;default:return 50}case z.F:return s===We.DIAMOND?53:51;case z.G:switch(s){case We.CIRCLEX:case We.DIAMOND:return 46;default:return 42}case z.A:return 49;case z.B:return 57;default:return i}case 3:return e.Pitch.FundamentalNote===z.C?s===We.CIRCLEX?52:55:i;default:return i}}}class lt{constructor(e){this.notes=[],this.TimestampShift=new h,this.parentVoiceEntry=e;for(const t of e.Notes)this.Notes.push(new at(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 ht{constructor(t,i,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 e,this.wantedStemDirection=-1,this.stemDirectionXml=-1,this.stemDirection=-1,this.timestamp=t,this.parentVoice=i,this.parentSourceStaffEntry=s,this.isGrace=r,this.graceAfterMainNote=!1,this.graceNoteSlash=o,this.graceSlur=a,r||i.VoiceEntries.push(this),n&&void 0!==s){const e=s.VoiceEntries;-1===e.indexOf(this)&&e.push(this)}this.mainPlaybackEntry=new lt(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 at(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;e0)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 ut=(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))(ut||{}),ct=(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))(ct||{}),dt=(e=>(e[e.MeasureBegin=0]="MeasureBegin",e[e.MeasureEnd=1]="MeasureEnd",e))(dt||{});class ft extends ne{constructor(e,t,i,s,n=void 0){super(),this.CenteringXShift=0,this.label=e,this.boundingBox=new re(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!=(t=null==(e=this.rules)?void 0:e.LabelMarginBorderFactor)?t:.1,s=this.Label.text.split(/[\n\r]+/g),n=s.length;let r=0;for(let l=0;l0&&this.TextLines.length>1&&(o+=this.rules.SpacingBetweenTextLines*n/10);const a=this.PositionAndShape;switch(this.Label.textAlignment){case ue.CenterBottom:a.BorderTop=-o,a.BorderLeft=-r/2,a.BorderBottom=0,a.BorderRight=r/2;break;case ue.CenterCenter:a.BorderTop=-o/2,a.BorderLeft=-r/2,a.BorderBottom=o/2,a.BorderRight=r/2;break;case ue.CenterTop:a.BorderTop=0,a.BorderLeft=-r/2,a.BorderBottom=o,a.BorderRight=r/2;break;case ue.LeftBottom:a.BorderTop=-o,a.BorderLeft=0,a.BorderBottom=0,a.BorderRight=r;break;case ue.LeftCenter:a.BorderTop=-o/2,a.BorderLeft=0,a.BorderBottom=o/2,a.BorderRight=r;break;case ue.LeftTop:a.BorderTop=0,a.BorderLeft=0,a.BorderBottom=o,a.BorderRight=r;break;case ue.RightBottom:a.BorderTop=-o,a.BorderLeft=-r,a.BorderBottom=0,a.BorderRight=0;break;case ue.RightCenter:a.BorderTop=-o/2,a.BorderLeft=-r,a.BorderBottom=o/2,a.BorderRight=0;break;case ue.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 mt{constructor(e="",t=ue.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=pe[e]}get font(){return this.fontEnumValue}ToString(){return this.text}}const pt={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},gt=["纯律","纯律结束"],St=["跳过下一个","b","#","§","º","X"],yt=["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."],bt="结束范围速度",Mt="a tempo",Pt=[bt],Et="仅文本速度 ";function vt(e){return 0===e.indexOf("速度 ")}function Lt(e){return 0===e.indexOf(Et)}function xt(e){return yt.includes(e)}function Tt(e){return[...Object.keys(pt),...gt,...Pt,...St].map((e=>e.trim().toLocaleUpperCase())).includes(e.toLocaleUpperCase().trim())}function wt(e){return[ue.CenterTop,ue.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 re(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,_.Cursor)}this.drawingParameters.drawScrollIndicator&&this.drawScrollIndicator();const t=Math.min(this.graphicalMusicSheet.MusicPages.length,this.rules.MaxPageToDrawNumber);for(let i=0;ie[0])).filter(Boolean))||[],i=[];let n=!1;for(let r=0;re.x-t.x)))?void 0:d[0])?void 0:f.measure;break}}}catch(w){console.log("🚀 ~ error",w)}let n=0;if(s)n=(null==(m=s.stave)?void 0:m.end_x)||0;else{n=(null==(p=y.sourceNote.SourceMeasure.VerticalMeasureList[0])?void 0:p.getVFStave()).end_x}const r=0;M.ScreenPosition.x=n,M.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(b.text)&&(M.ScreenPosition.y=10*(e.PositionAndShape.Parent.AbsolutePosition.y+e.PositionAndShape.Parent.BorderTop+e.PositionAndShape.Parent.BorderMarginTop)),["play","listen"].includes(b.text.toLocaleLowerCase())&&b.textAlignment===ue.LeftBottom&&(M.ScreenPosition.y=10*(e.PositionAndShape.Parent.AbsolutePosition.y-1+e.PositionAndShape.Parent.BorderBottom));const L=["ffp","p-f","sfzp","szf","sffzp"];for(let I=0;I0&&(wt(e.Label.textAlignment)||[ue.CenterBottom].includes(e.Label.textAlignment))){let t=-1,i=!1;for(const s of(null==E?void 0:E.AbstractExpressions)||[])if(s.Label===e?t=null==(g=null==s?void 0:s.parentMeasure)?void 0:g.measureListIndex:(null==(S=s.expression)?void 0:S.TempoInBpm)&&(i=s.expression.TempoInBpm>0),i&&t>-1){M.ScreenPosition.y-=40;break}}const T=!/^\d+$/.test(e.Label.text);(!i&&!e.Label.isNotRender||T)&&this.renderLabel(e,t,M)}calculateLabel(e){var t,i;const s=new Nt,n=e.Label;s.ScreenPosition=this.applyScreenTransformation(e.PositionAndShape.AbsolutePosition),s.FontHeightInPixel=this.calculatePixelDistance(n.fontHeight);const r=this.calculatePixelDistance(e.PositionAndShape.Size.width);switch(s.BitmapWidth=Math.ceil(r),s.BitmapHeight=e.TextLines?Math.ceil(s.FontHeightInPixel*(.2+e.TextLines.length)):10,n.textAlignment){case ue.LeftTop:break;case ue.LeftCenter:s.ScreenPosition.y-=s.BitmapHeight/2;break;case ue.LeftBottom:s.ScreenPosition.y-=s.BitmapHeight;break;case ue.CenterTop:s.ScreenPosition.x-=s.BitmapWidth/2;break;case ue.CenterCenter:s.ScreenPosition.x-=s.BitmapWidth/2,s.ScreenPosition.y-=s.BitmapHeight/2;break;case ue.CenterBottom:s.ScreenPosition.x-=s.BitmapWidth/2,s.ScreenPosition.y-=s.BitmapHeight,"筒音作5"===n.text&&"jianpu"===this.rules.DYMusicScoreType&&(s.ScreenPosition.x=80);break;case ue.RightTop:s.ScreenPosition.x-=s.BitmapWidth;break;case ue.RightCenter:s.ScreenPosition.x-=s.BitmapWidth,s.ScreenPosition.y-=s.BitmapHeight/2;break;case ue.RightBottom:s.ScreenPosition.x-=s.BitmapWidth,s.ScreenPosition.y-=s.BitmapHeight;break;default:throw new S("")}const o=e.PositionAndShape.Parent.DataObject,a=[1,3,7,9,15,20,22,24,28,30,36,41];this.rules.DYMusicScoreId&&"1722157850347765762"===this.rules.DYMusicScoreId&&("."===n.text&&(s.ScreenPosition.x=142,s.ScreenPosition.y=134),"T"===n.text&&(this.needSpecialArrTs.push(s),1===(null==(i=null==(t=null==o?void 0:o.measures)?void 0:t[0])?void 0:i.MeasureNumber)?s.ScreenPosition.y+=20:s.ScreenPosition.y-=20));for(let l in this.needSpecialArrTs)a.includes(Number(l))&&(this.needSpecialArrTs[l].ScreenPosition.x-=20);return s}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 te(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,_.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,_.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,_.Notes),null==(t=e.SVGNode)||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,_.Notes)}}drawSymbol(e,t,i,s=1,n=_.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,_.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 te(e.AbsolutePosition.x+e.BorderMarginLeft,e.AbsolutePosition.y+e.BorderMarginTop,e.BorderMarginRight-e.BorderMarginLeft,e.BorderMarginBottom-e.BorderMarginTop);i&&(this.drawLineAsHorizontalRectangle(new U(new X(e.AbsolutePosition.x-1,e.AbsolutePosition.y),new X(e.AbsolutePosition.x+1,e.AbsolutePosition.y),.1,F.BaseWritingColor,t),n-1),this.drawLineAsVerticalRectangle(new U(new X(e.AbsolutePosition.x,e.AbsolutePosition.y-1),new X(e.AbsolutePosition.x,e.AbsolutePosition.y+1),.1,F.BaseWritingColor,t),n-1)),r=this.applyScreenTransformationForRect(r);const o=this.renderRectangle(r,_.Background,n,t,.5);if(s){const e=new mt(s),t=new Nt;t.BitmapWidth=r.width,t.BitmapHeight=r.height,t.FontHeightInPixel=r.height,t.ScreenPosition=new X(r.x,r.y+12),this.renderLabel(new ft(e,.8,ue.CenterCenter,this.rules),n,t)}return o}drawMarkedAreas(e){for(const t of e.GraphicalMarkedAreas)t&&(t.systemRectangle&&this.drawRectangle(t.systemRectangle,_.Background),t.settings&&(t.settings.SVGNode=this.drawLabel(t.settings,_.Comment)),t.labelRectangle&&this.drawRectangle(t.labelRectangle,_.Background),t.label&&(t.label.SVGNode=this.drawLabel(t.label,_.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 U(new X(i,s),new X(i+n,s),4,F.Highlighted),_.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 X(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 U(new X(t,i),new X(t+e.BorderRight,i),4,F.ErrorUnderlay),_.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 se{constructor(e,t,i){super(),this.expression=t,this.parentMeasure=i,this.boundingBox=new re(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,i=this.PositionAndShape.RelativePosition.x+this.PositionAndShape.BorderMarginLeft,s=this.PositionAndShape.RelativePosition.x+this.PositionAndShape.BorderMarginRight;let n=0;switch(this.Placement){case c.Above:n=this.PositionAndShape.RelativePosition.y+this.PositionAndShape.BorderMarginTop,e.updateSkyLineInRange(i,s,n);break;case c.Below:n=this.PositionAndShape.RelativePosition.y+this.PositionAndShape.BorderMarginBottom,e.updateBottomLineInRange(i,s,n);break;default:t.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(){var e;const i=this.parentStaffLine.SkyBottomLineCalculator,s=this.IsVerbal?this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginLeft:0,n=this.IsVerbal?this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginRight:0;switch(!this.IsSoftAccent&&!this.IsVerbal&&this.lines.length<2&&t.warn("Not enough lines for SkyBottomLine calculation"),this.IsVerbal||this.ContinuousDynamic.DynamicType!==m.crescendo&&this.ContinuousDynamic.DynamicType!==m.diminuendo&&t.warn("GraphicalContinuousDynamicExpression.updateSkyBottomLine(): unhandled continuous dynamic type. start measure: "+(null==(e=this.startMeasure)?void 0:e.MeasureNumber)),this.Placement){case c.Above:if(this.IsSoftAccent)i.updateSkyLineWithWedge(this.lines[0].Start,this.lines[0].End),i.updateSkyLineWithWedge(this.lines[2].End,this.lines[2].Start),i.updateSkyLineWithLine(this.lines[0].End,this.lines[2].End,this.lines[0].End.y);else if(this.IsVerbal){const e=this.label.PositionAndShape.BorderMarginTop+this.label.PositionAndShape.RelativePosition.y;i.updateSkyLineInRange(s,n,e)}else this.ContinuousDynamic.DynamicType===m.crescendo?i.updateSkyLineWithWedge(this.lines[0].Start,this.lines[0].End):this.ContinuousDynamic.DynamicType===m.diminuendo&&i.updateSkyLineWithWedge(this.lines[0].End,this.lines[0].Start);break;case c.Below:if(this.IsVerbal){const e=this.label.PositionAndShape.BorderMarginBottom+this.label.PositionAndShape.RelativePosition.y;i.updateBottomLineInRange(s,n,e)}else this.ContinuousDynamic.DynamicType===m.crescendo?i.updateBottomLineWithWedge(this.lines[1].Start,this.lines[1].End):this.ContinuousDynamic.DynamicType===m.diminuendo&&i.updateBottomLineWithWedge(this.lines[1].End,this.lines[1].Start);break;default:t.error("Placement for GraphicalContinuousDynamicExpression is unknown")}}createCrescendoLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeLineWidth){const r=new X(e,i),o=new X(t,i-s/2),a=new X(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 X(e,i),o=new X(t,i-s/2),a=new X(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 X(e,i-s/2),a=new X(e,i+s/2),l=new X(t,i-n/2),h=new X(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 X(e,i-s/2),o=new X(e,i+s/2),a=new X(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 X(e,i-s/2),a=new X(e,i+s/2),l=new X(t,i-n/2),h=new X(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 X(e,i-s/2),o=new X(e,i+s/2),a=new X(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===m.crescendo?this.createFirstHalfCrescendoLines(e,t,i,n,r):this.ContinuousDynamic.DynamicType===m.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===m.crescendo?this.createSecondHalfCrescendoLines(e,t,i,s,n,r):this.ContinuousDynamic.DynamicType===m.diminuendo&&this.createSecondHalfDiminuendoLines(e,t,i,s,r)}createLines(e,t,i,s=this.rules.WedgeOpeningLength,n=this.rules.WedgeLineWidth){this.ContinuousDynamic.DynamicType===m.crescendo?this.createCrescendoLines(e,t,i,s,n):this.ContinuousDynamic.DynamicType===m.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===m.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){if(this.IsVerbal)return;Math.abs(this.lines[0].End.x-this.lines[0].Start.x)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 U(e,t,s),r=new U(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 U(e,t,n),o=new U(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=I.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=c.Left,this.drawHiddenNotes=!1,this.rules=t,this.rules||(this.rules=new Le),this.DrawingParametersEnum=e}set DrawingParametersEnum(e){switch(this.drawingParametersEnum=e,e){case I.allon:this.setForAllOn();break;case I.thumbnail:this.setForThumbnail();break;case I.leadsheet:this.setForLeadsheet();break;case I.compact:this.setForCompactMode();break;case I.compacttight:this.setForCompactTightMode();break;case I.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 u(i),s),this.label=t,this.sourceMultiExpression=n}updateSkyBottomLine(){const e=this.parentStaffLine.SkyBottomLineCalculator,i=this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginLeft,s=this.label.PositionAndShape.RelativePosition.x+this.label.PositionAndShape.BorderMarginRight;switch(this.Placement){case c.Above:const n=this.label.PositionAndShape.BorderMarginTop+this.label.PositionAndShape.RelativePosition.y;e.updateSkyLineInRange(i,s,n);break;case c.Below:const r=this.label.PositionAndShape.BorderMarginBottom+this.label.PositionAndShape.RelativePosition.y;e.updateBottomLineInRange(i,s,r);break;default:t.error("Placement for GraphicalUnknownExpression is unknown")}}}const Gt=i.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;ie.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(/>\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,s,n;"gonville"===this.rules.DefaultVexFlowNoteFont&&(i.Flow.DEFAULT_FONT_STACK=[null==(t=i.Flow.Fonts)?void 0:t.Gonville,null==(s=i.Flow.Fonts)?void 0:s.Bravura,null==(n=i.Flow.Fonts)?void 0:n.Custom]),i.Flow.STAVE_LINE_THICKNESS=this.rules.StaffLineWidth*zt,i.Flow.STEM_WIDTH=this.rules.StemWidth*zt,i.Flow.DEFAULT_NOTATION_FONT_SCALE=this.rules.VexFlowDefaultNotationFontScale,i.Flow.DEFAULT_TAB_FONT_SCALE=this.rules.VexFlowDefaultTabFontScale,this.pageIdx=0;for(const i of e.MusicPages){if(i.PageNumber>this.rules.MaxPageToDrawNumber)break;const e=this.backends[this.pageIdx];e.graphicalMusicPage=i,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,s,n,r;const o=null==(i=window.GYM)?void 0:i.vfcurveItem;for(let l=0;l(!e.index||e.index===l)&&e.MeasureNumberXML==i.staffEntries[i.staffEntries.length-1].parentMeasure.MeasureNumber));e&&(i.bezierEndControlPt.y+=(null==(s=null==e?void 0:e.bezierEndControlPt)?void 0:s.y)?e.bezierEndControlPt.y:0,i.bezierEndPt.y+=(null==(n=null==e?void 0:e.bezierEndPt)?void 0:n.y)?e.bezierEndPt.y:0,i.bezierStartControlPt.y+=(null==(r=null==e?void 0:e.bezierStartControlPt)?void 0:r.y)?e.bezierStartControlPt.y:0)}catch(a){console.log(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 X(e.Line.Start.x+t.x,e.Line.Start.y),s=new X(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 X(e.bezierStartPt.x+t.x,e.bezierStartPt.y+t.y),n=new X(e.bezierStartControlPt.x+t.x,e.bezierStartControlPt.y+t.y),r=new X(e.bezierEndControlPt.x+t.x,e.bezierStartControlPt.y+t.y),o=new X(e.bezierEndPt.x+t.x,e.bezierStartPt.y+t.y)):(s=new X(e.bezierStartPt.x+t.x,e.bezierStartPt.y+t.y),n=new X(e.bezierStartControlPt.x+t.x,e.bezierStartControlPt.y+t.y),r=new X(e.bezierEndControlPt.x+t.x,e.bezierEndControlPt.y+t.y),o=new X(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===c.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 i=this.backend.getContext();try{e.draw(i)}catch(n){t.warn("VexFlowMusicSheetDrawer.drawMeasure",n)}let s=0;for(const t of e.staffEntries)this.drawStaffEntry(t),s=this.drawBuzzRolls(t,s)}drawBuzzRolls(e,t){var i;for(const s of e.graphicalVoiceEntries)for(const e of s.notes)if(null==(i=e.sourceNote.TremoloInfo)?void 0:i.tremoloUnmeasured){const i=this.rules.TremoloBuzzRollThickness,s=.9,n=.5,r=e;let o,a;const l=r.vfnote[0].getStemDirection();let h;this.backend instanceof Xt&&(h=r.getStemSVG());if(void 0!==(null==h?void 0:h.getBbox)){const e=h.getBBox();o=new X(e.x/10,e.y/10),a=e.height/10}else a=r.vfnote[0].getStemLength()/10,o=new X(r.vfnote[0].getStem().x_begin/10,r.vfnote[0].getStem().y_top/10),1===l&&(o.y-=a);let u=o.y+a/3;r.vfnote[0].getBeamCount()>1&&(u=o.y+a/2,-1===l&&(u-=n+.2));const c=o.x-.5,d=u,f=[],m=[new X(0,-i),new X(s-i,0),new X(-s+i,-n),new X(0,-i),new X(s,0),new X(0,i),new X(-s+i,0),new X(s-i,n),new X(0,i),new X(-s,0)];let p=new X(c,d);f.push(p);for(const e of m)p=f.last(),f.push(new X(p.x+e.x,p.y-e.y));this.DrawPath(f,r.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 void console.log("VexFlowMusicSheetDrawer.drawOverlayLine: invalid page number / music page number doesn't correspond to an existing backend.");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 X(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;a0){const t=this.rules.SamplingUnit;let r,a,l=new X(o.x,o.y),h=new X(n[0]/t+o.x,o.y);this.drawLine(l,h,s),e[0]>=0&&(r=new X(n[0]/t+o.x,o.y),a=new X(n[0]/t+o.x,o.y+e[n[0]]),this.drawLine(r,a,s));for(let i=1;i0)for(const t of e.FingeringEntries)t.SVGNode=this.drawLabel(t,_.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,_.Notes)}this.rules.RenderLyrics&&e.LyricsEntries.length>0&&this.drawLyrics(e.LyricsEntries,_.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)||i.classList.add("lyrics")}))}drawInstrumentBrace(e,t){e.draw(this.backend.getContext())}drawGroupBracket(e,t){e.draw(this.backend.getContext())}drawOctaveShifts(e){for(const s of e.OctaveShifts)if(s){const e=s,n=this.backend.getContext(),r=e.getTextBracket();this.rules.DefaultColorMusic&&(r.render_options.color=this.rules.DefaultColorMusic),r.setContext(n);try{r.draw()}catch(i){t.warn(i)}}}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){var t,i;const s=[];let n=0;for(const h of e.measures)s.push(h.measureNumber);const r={},o={},a={};for(const h of e.AbstractExpressions)if(h instanceof _t&&s.includes(h.parentMeasure.MeasureNumber)){const e=this.getDotId(h),t=this.getDotId(h,"x");o[e]||(o[e]=[]),a[t]||(a[t]=[]),this.hasDot(h.Label.PositionAndShape.RelativePosition,o[e],!0)||(o[e].push(h.Label.PositionAndShape.RelativePosition),a[t].push(h.Label.PositionAndShape.RelativePosition)),r[e]=h.Label.PositionAndShape.RelativePosition}let l=0;for(const h of e.AbstractExpressions){const e=null==(t=h.parentMeasure)?void 0:t.MeasureNumber;if(h instanceof _t&&s.includes(e)){const t=null==(i=h.parentMeasure.verticalMeasureList[0])?void 0:i.stave,s=(null==t?void 0:t.end_x)-(null==t?void 0:t.x),r=this.getDotId(h,"x");if(1===(a[r]||[]).length&&l!==e){const e=h.Label.PositionAndShape.AbsolutePosition.y;n=0===n?e:Math.min(n,e)}1!==(a[r]||[]).length&&s/10{var t;return"StaveSection"===(null==(t=null==e?void 0:e.attrs)?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,_.Notes,n)}drawContinuousDynamic(e){var t,i;if(e.IsVerbal){const t=e.Label;t.SVGNode=this.drawLabel(t,_.Notes)}else{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==(t=null==e?void 0:e.parentMeasure)?void 0:t.MeasureNumberXML)&&(null==r||r.setAttribute("data-mnum",String(e.parentMeasure.MeasureNumberXML)));for(const t of e.Lines){const s=new X(e.ParentStaffLine.PositionAndShape.AbsolutePosition.x+t.Start.x,e.ParentStaffLine.PositionAndShape.AbsolutePosition.y+t.Start.y),n=new X(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)?i:"#000000",t.Width)}n.closeGroup()}}renderLabel(e,t,i){return this._renderLabel(e,i)}_renderLabel(e,t){var i,s,n;if(!e.Label.print)return;const r=e.Label.fontHeight*zt,{font:o}=e.Label;let a;this.rules.ColoringEnabled&&(a=e.Label.colorDefault,e.ColorXML&&(a=e.ColorXML),e.Label.color&&(a=e.Label.color.toString()),a||(a=this.rules.DefaultColorLabel));let l,{fontStyle:h,fontFamily:u}=e.Label;h||(h=this.rules.DefaultFontStyle),u||(u=this.rules.DefaultFontFamily);for(let c=0;c<(null==(i=e.TextLines)?void 0:i.length);c++){const i=e.TextLines[c],u=this.calculatePixelDistance(i.xOffset),d=new X(t.ScreenPosition.x+u,t.ScreenPosition.y),f=this.backend.renderText(r,h,o,i.text,t.FontHeightInPixel,d,a,e.Label.fontFamily,null==(s=e.Label)?void 0:s.lyricExtendNoteId,null==(n=e.Label)?void 0:n.lyricVerseNumber);void 0!==i.trackIndex&&f.setAttribute("data-trackIdx",i.trackIndex),l?l.appendChild(f):l=f,t.ScreenPosition.y=t.ScreenPosition.y+t.FontHeightInPixel,e.TextLines.length>1&&(t.ScreenPosition.y+=this.rules.SpacingBetweenTextLines)}return l}renderRectangle(e,t,i,s,n){return this.backend.renderRectangle(e,i,s,n)}applyScreenTransformation(e){return new X(e.x*zt,e.y*zt)}applyScreenTransformationForRect(e){return new te(e.x*zt,e.y*zt,e.width*zt,e.height*zt)}}class Yt extends Ie{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.length)>0}}const jt=i.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 h(2,1));else if(e>=1)i.push("w"),s.Sub(new h(1,1));else if(e<1&&e>=.5){if(t&&e>.5)return["w"];i.push("h"),s.Sub(new h(1,2))}else if(e<.5&&e>=.25){if(t&&e>.25)return["h"];i.push("q"),s.Sub(new h(1,4))}else if(e<.25&&e>=.125){if(t&&e>.125)return["q"];i.push("8"),s.Sub(new h(1,8))}else if(e<.125&&e>=.0625){if(t&&e>.0625)return["8"];i.push("16"),s.Sub(new h(1,16))}else if(e<.0625&&e>=.03125){if(t&&e>.03125)return["16"];i.push("32"),s.Sub(new h(1,32))}else if(e<.03125&&e>=.015625){if(t&&e>.015625)return["32"];i.push("64"),s.Sub(new h(1,64))}else{if(t)return["64"];i.push("128"),s.Sub(new h(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===J.F&&(r=2),i.ClefType===J.C&&(r=2));const o=z[e.FundamentalNote].toLowerCase(),a=j.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 J.C:case J.F:i+=2;case J.G:}return new j(e.FundamentalNote,i,H.NONE)}static NoteHeadCode(e){const t=e.Filled?"2":"1";switch(e.Shape){case We.NORMAL:return"";case We.DIAMOND:return"/D"+t;case We.TRIANGLE:return"/T"+t;case We.TRIANGLE_INVERTED:return"/TI";case We.X:return"/X"+t;case We.CIRCLEX:return"/X3";case We.RECTANGLE:return"/R"+t;case We.SQUARE:return"/S"+t;case We.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,n,r,o,a,l,u,c,d,f,m,p,g,S,y,b,M,P;e.sortForVexflow();const E=e.notes,v=e.parentStaffEntry.parentMeasure.parentSourceMeasure.Rules,L=E[0];let x,T=[];const w=[],I=L.graphicalNoteLength,A=void 0!==L.sourceNote.NoteTuplet;let R,N=Kt.durations(I,A)[0];Kt.idx+=1,void 0!==L.sourceNote.TypeLength&&L.sourceNote.TypeLength!==I&&0!==L.sourceNote.TypeLength.RealValue&&(N=Kt.durations(L.sourceNote.TypeLength,A)[0],L.numberOfDots=L.sourceNote.DotsXml);let C,B,D=L.numberOfDots,V=!1,k=0,F=!1;for(const s of E){if(D=1&&t.length-1>=d+1&&(h=null==(o=null==(r=t[d-1])?void 0:r.graphicalVoiceEntries[0])?void 0:o.parentVoiceEntry,c=null==(l=null==(a=t[d+1])?void 0:a.graphicalVoiceEntries[0])?void 0:l.parentVoiceEntry,h&&c)){const e=h.Notes[0],t=c.Notes[0];if((null==(u=e.NoteBeam)?void 0:u.Notes.includes(t))&&1!==t.ParentStaffEntry.ParentStaff.StafflineCount){const e=h.Notes.last().Pitch,t=s.Clef(),i=Kt.pitch(Kt.restToNotePitch(e.getTransposedPitch(-2),t.ClefType),!1,t);4===e.FundamentalNote&&(T=[i[0]])}}}}(s.sourceNote.IsWholeMeasureRest||I.RealValue===s.sourceNote.SourceMeasure.ActiveTimeSignature.RealValue)&&(T="staff"===v.DYMusicScoreType?["d/5"]:["R/5"],N="w",D=0,V=!0,k=v.WholeRestXShiftVexflow*zt);if([...s.sourceNote.ParentStaff.Voices].filter((e=>1!=(null==e?void 0:e.VoiceId))).length){const e=s.parentVoiceEntry.parentStaffEntry.graphicalVoiceEntries,t=s.parentVoiceEntry.parentVoiceEntry.ParentVoice.VoiceId;let i,n;for(const r of e)for(const e of r.notes){if(e===s||e.sourceNote.isRest()||!e.sourceNote.PrintObject){s.lineShift=-2;continue}const r=e.parentVoiceEntry.parentVoiceEntry.WantedStemDirection,o=1===t||5===t,a=o?1:-1,l=e.sourceNote.Pitch.getHalfTone();(!i||1===a&&l>i||-1===a&&l0){let e=3;const t=s.Clef();switch(t.ClefType){case J.F:e=5;break;case J.C:e=4}C=j.fromHalftone(i),T=[Kt.pitch(C,!0,t,void 0,e)[0]]}}break}s.sourceNote.Notehead&&(s.sourceNote.Notehead.Shape,We.SLASH);const e=s.vfpitch;if(null==(d=null==(c=e[2])?void 0:c.Parent)?void 0:d.Instructions)for(let t=0,i=e[2].Parent.Instructions.length;t0&&v.RenderLyrics&&v.LyricsUseXPaddingForLongLyrics){const t=e.parentStaffEntry.parentMeasure,s=[];for(let i=t.staffEntries.indexOf(e.parentStaffEntry)+1;i.25){i=!1;break}if(a.LyricsEntries.length>0)break;n+=32*h.minus(t,o).RealValue,o=t}}if(v.RenderLyrics&&v.LyricsUseXPaddingForLongLyrics&&t.length>0&&i){let i=!1,s=0;for(const e of E)if(e.sourceNote.Length.RealValue<=.125){i=!0;break}let r=!1;for(const o of t){const t=v.LyricsXPaddingWidthThreshold;let a=o.GraphicalLabel.PositionAndShape.Size.width;if(o.hasDashFromLyricWord()&&(a+=.5),a>t){s+=a-t;const o=e.parentStaffEntry,l=o.parentMeasure.staffEntries,h=l.indexOf(o)===l.length-1;h&&(n+=v.LyricsXPaddingReductionForLastNoteInMeasure),i||(n+=v.LyricsXPaddingReductionForLongNotes),!v.LyricsXPaddingForLastNoteInMeasure&&h||a>t+n&&(r=!0,s-=n);break}}r&&(B.paddingRight=10*v.LyricsXPaddingFactorForLongLyrics*s)}}const G=e.notes[0].lineShift;if(0!==G&&(B.getKeyProps()[0].line+=G),E.length>1)for(let s=0;s1&&1==e.notes[0].sourceNote.ParentVoiceEntry.ParentVoice.VoiceId&&(B.getKeyProps()[0].line=4.5);const W=null==(y=window.GYM)?void 0:y.customBassDrum;if(W&&B.isRest()&&("q"===B.getDuration()&&(B.getKeyProps()[0].line=W),"h"===B.getDuration()&&(B.getKeyProps()[0].line=W-1)),B.getKeyProps().forEach((({line:t},i)=>e.notes[i].staffLine=t)),(v.LedgerLineWidth||v.LedgerLineStrokeStyle)&&(B.ledgerLineStyle||(B.ledgerLineStyle={}),v.LedgerLineWidth&&(B.ledgerLineStyle.lineWidth=v.LedgerLineWidth),v.LedgerLineStrokeStyle&&(B.ledgerLineStyle.strokeStyle=v.LedgerLineStrokeStyle)),v.ColoringEnabled){const t=v.DefaultColorStem;let i=e.parentVoiceEntry.StemColor;!i&&t&&(i=t);const s={fillStyle:i,strokeStyle:i};i&&(B.setStemStyle(s),B.flag&&v.ColorFlags&&B.setFlagStyle(s))}if(B.x_shift=k,e.parentVoiceEntry.IsGrace&&e.notes[0].sourceNote.NoteBeam&&(e.parentVoiceEntry.WantedStemDirection=e.notes[0].sourceNote.NoteBeam.Notes[0].ParentVoiceEntry.WantedStemDirection),e.parentVoiceEntry){let t=e.parentVoiceEntry.WantedStemDirection;const i=(null==(b=window.GYM)?void 0:b.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 ct.Up:B.setStemDirection(jt.Stem.UP),e.parentVoiceEntry.StemDirection=ct.Up;break;case ct.Down:B.setStemDirection(jt.Stem.DOWN),e.parentVoiceEntry.StemDirection=ct.Down}}for(let s=0,h=E.length;s0&&"single"===t){const t=new jt.Tremolo(e);t.extra_stroke_scale=v.TremoloStrokeScale,t.y_spacing_scale=v.TremoloYSpacingScale,B&&"w"===B.duration&&B.stem.setExtension(-9),B.addModifier(s,t)}if(e>0&&"start"===t&&this.noteTremoloList.push(B),e>0&&"stop"===t){this.noteTremoloList.push(B);if(this.noteTremoloList.filter((e=>"w"===e.duration)).length===this.noteTremoloList.length)try{if(this.noteTremoloList[0].keyProps&&this.noteTremoloList[1].keyProps){null==(M=(this.noteTremoloList[0].keyProps[0].line>this.noteTremoloList[1].keyProps[0].line?this.noteTremoloList[1]:this.noteTremoloList[0]).stem)||M.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,B.addModifier(s,t),this.noteTremoloList=[]}this.glissandoList.length&&(B.setVibrato(this.glissandoList[0].vfnote[0]),this.glissandoList=[]),"start"===E[s].sourceNote.glissandoType&&this.glissandoList.push(E[s])}if(this.slideNote){try{B.setSlideNote(this.slideNote)}catch(U){console.error(U)}this.slideNote=null}if("start"===e.notes[0].sourceNote.slideType&&(this.slideNote=B),.25===_.Length.RealValue&&_.Notehead&&!1===_.Notehead.Filled){const e=B.getKeyProps();for(let t=0;t1){let e=B.getKeyProps().filter((e=>!e.code&&e.line>3));(null==(P=window.GYM)?void 0:P.stemDirectionNote)||e.length!==T.length||B.setStemDirection(-1)}"jianpu"===v.DYMusicScoreType&&window&&window.sett&&window.sett.keySignature&&B.addAccidental(0,new jt.Accidental("#"));try{const e=["b","#","§","º","X"],t={b:"b","#":"#","§":"n","º":"bb",X:"##"};for(const i of E){const s=i.sourceNote.voiceEntry.Timestamp;for(const n of i.sourceNote.SourceMeasure.StaffLinkedExpressions)for(const i of n){const n=h.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&&B.addAnnotation(0,new jt.Annotation(e));break}}}}catch(U){}return B}static generateArticulations(e,t,i){var s,n,r,o,a,l;if(e&&"GhostNote"!==e.getAttribute("type"))for(const h of t.sourceNote.ParentVoiceEntry.Articulations){let u,d=jt.Modifier.Position.ABOVE;e.getStemDirection()===jt.Stem.UP&&(d=jt.Modifier.Position.BELOW);const f=h.articulationEnum;switch(i.ArticulationPlacementFromXML&&(h.placement===c.Above?d=jt.Modifier.Position.ABOVE:h.placement===c.Below&&(d=jt.Modifier.Position.BELOW)),f){case ut.accent:{u=new jt.Articulation("a>");const e=t.sourceNote.NoteSlurs;for(const s of e)s.StartNote===t.sourceNote&&(s.PlacementXml===c.Above?u.setYShift(10*-i.SlurStartArticulationYOffsetOfArticulation):s.PlacementXml===c.Below&&u.setYShift(10*i.SlurStartArticulationYOffsetOfArticulation));break}case ut.breathmark:u=new jt.Articulation("abr"),h.placement===c.Above&&(d=jt.Modifier.Position.ABOVE),u.breathMarkDistance=i.BreathMarkDistance;break;case ut.downbow:u=new jt.Articulation("am"),void 0===h.placement&&(d=jt.Modifier.Position.ABOVE,h.placement=c.Above);break;case ut.fermata:u=new jt.Articulation("a@a"),d=jt.Modifier.Position.ABOVE,h.placement=c.Above;break;case ut.marcatodown:u=new jt.Articulation("a|");break;case ut.marcatoup:u=new jt.Articulation("a^"),d=jt.Modifier.Position.ABOVE;break;case ut.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"),d=jt.Modifier.Position.BELOW,h.placement=c.Below;break}case ut.lefthandpizzicato:u=new jt.Articulation("a+");break;case ut.naturalharmonic:u=new jt.Articulation("ah");break;case ut.snappizzicato:u=new jt.Articulation("ao");break;case ut.staccatissimo:u=new jt.Articulation("av");break;case ut.staccato:u=new jt.Articulation("a.");break;case ut.tenuto:u=new jt.Articulation("a-");break;case ut.upbow:u=new jt.Articulation("a|"),void 0===h.placement&&(d=jt.Modifier.Position.ABOVE,h.placement=c.Above);break;case ut.strongaccent:u=new jt.Articulation("a^")}if(u){if(!e.hasStem()&&!e.isRest()&&f==ut.accent&&e.getLineNumber()>=3&&(d=jt.Modifier.Position.ABOVE,(null==(n=null==(s=null==e?void 0:e.modifiers)?void 0:s.filter((e=>["TREMOLO"].includes(e.getCategory().toLocaleUpperCase()))))?void 0:n.length)&&u.setYShift(-16)),f===ut.strongaccent){d=jt.Modifier.Position.ABOVE;(null==(r=window.GYM)?void 0:r.customArtPosition)&&(1===e.getStemDirection()?d=jt.Modifier.Position.ABOVE:(d=jt.Modifier.Position.BELOW,u=new jt.Articulation("a|")))}(null==(o=window.GYM)?void 0:o.customAccentItem)&&f===ut.accent&&(d=jt.Modifier.Position.ABOVE);if(!(null==(a=window.GYM)?void 0:a.customLefthandpizzicatoItem)||f!==ut.lefthandpizzicato&&f!==ut.naturalharmonic||(d=jt.Modifier.Position.ABOVE),f===ut.tenuto&&"w"===e.getDuration()){(null==(l=window.GYM)?void 0:l.customTenutoItem)&&(d=jt.Modifier.Position.ABOVE)}f===ut.tenuto&&"jianpu"===i.DYMusicScoreType&&(d=jt.Modifier.Position.ABOVE,u.setYShift(-15),u.setXShift(3)),f===ut.staccatissimo&&"jianpu"===i.DYMusicScoreType&&(d=jt.Modifier.Position.ABOVE),u.setPosition(d),e.addModifier(0,u)}}}static generateOrnaments(e,i){let s,n=jt.Modifier.Position.ABOVE;switch(i.placement===c.Below&&(n=jt.Modifier.Position.BELOW),i.GetOrnament){case Ye.DelayedInvertedTurn:s=new jt.Ornament("turn_inverted"),s.setDelayed(!0);break;case Ye.DelayedTurn:s=new jt.Ornament("turn"),s.setDelayed(!0);break;case Ye.InvertedMordent:s=new jt.Ornament("mordent"),s.setDelayed(!1);break;case Ye.InvertedTurn:s=new jt.Ornament("turn_inverted"),s.setDelayed(!1);break;case Ye.Mordent:s=new jt.Ornament("mordent_inverted"),s.setDelayed(!1);break;case Ye.Trill:s=new jt.Ornament("tr"),s.setDelayed(!1);break;case Ye.Turn:s=new jt.Ornament("turn"),s.setDelayed(!1);break;default:return void t.warn("unhandled OrnamentEnum type: "+i.GetOrnament)}s&&(i.AccidentalBelow!==H.NONE&&s.setLowerAccidental(j.accidentalVexflow(i.AccidentalBelow)),i.AccidentalAbove!==H.NONE&&s.setUpperAccidental(j.accidentalVexflow(i.AccidentalAbove)),s.setPosition(n),e.addModifier(0,s))}static StrokeTypeFromArpeggioType(e){switch(e){case Ve.ARPEGGIO_DIRECTIONLESS:return jt.Stroke.Type.ARPEGGIO_DIRECTIONLESS;case Ve.BRUSH_DOWN:return jt.Stroke.Type.BRUSH_UP;case Ve.BRUSH_UP:return jt.Stroke.Type.BRUSH_DOWN;case Ve.RASQUEDO_DOWN:return jt.Stroke.Type.RASQUEDO_UP;case Ve.RASQUEDO_UP:return jt.Stroke.Type.RASQUEDO_DOWN;case Ve.ROLL_DOWN:return jt.Stroke.Type.ROLL_UP;case Ve.ROLL_UP:return jt.Stroke.Type.ROLL_DOWN;default:return jt.Stroke.Type.ARPEGGIO_DIRECTIONLESS}}static CreateTabNote(e){const i=[],s=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 s=c.sourceNote;let r={str:s.StringNumberTab,fret:s.FretNumber};c.sourceNote instanceof Yt||(t.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}),i.push(r),s.BendArray&&s.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(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 u{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 S("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 h.plus(this.ParentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp,this.ParentMultiTempoExpression.Timestamp)}getAbsoluteFloatTimestamp(){return h.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 u{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 u{constructor(e,t,i,s){super(t),this.label=e,this.staffNumber=s,void 0===i&&(i=ue.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 h.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=c.Above;return this.expressions.length>0&&(this.expressions[0].expression instanceof M||this.expressions[0].expression instanceof f||this.expressions[0].expression instanceof si||this.expressions[0].expression instanceof ni)&&(e=this.expressions[0].expression.Placement),e}getFontstyleOfFirstEntry(){var e;let t=fe.Regular;if(this.expressions.length>0)if(this.expressions[0].expression instanceof f)t=fe.Italic;else if(this.expressions[0].expression instanceof si)t=fe.Italic;else if(this.expressions[0].expression instanceof ni){t=null!=(e=this.expressions[0].expression.fontStyle)?e:fe.Regular}return t}addExpression(e,t){e instanceof M?(this.instantaneousDynamic&&this.removeExpressionFromEntryList(this.InstantaneousDynamic),this.instantaneousDynamic=e,this.instantaneousDynamic.ParentMultiExpression=this):e instanceof f?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=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=h.plus(this.parentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp,this.parentMultiTempoExpression.Timestamp);if(e.lt(t))return-1;if(this.absoluteEndTimestamp.lt(e))return-2;const i=h.minus(e,t).RealValue/h.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 h.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=c.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=fe.Regular;return this.expressions[0].Expression instanceof ei?e=fe.Bold:this.expressions[0].Expression instanceof li&&(e=fe.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.RealValue0){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;n0&&(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=1){const t=this.currentSystemParams.currentSystem.GraphicalMeasures[this.currentSystemParams.currentSystem.GraphicalMeasures.length-1];let i=0;const s=e[e.length-1];s.endLine===Re.DotsBoldBoldDots&&(s.endLine=Re.DotsThinBold,i=t[0].getLineWidth(Re.DotsBoldBoldDots)/2-t[0].getLineWidth(Re.DotsThinBold)),this.currentSystemParams.currentSystemFixWidth-=i;for(let e=0,n=t.length;e1){r=!0;break}}let o=0;for(let a=0;a=0&&this.measureList[s]){const t=null==(u=this.measureList[s][0])?void 0:u.parentSourceMeasure;(null==t?void 0:t.ImplicitMeasure)&&(null==t?void 0:t.RhythmPrinted)&&(e=!1)}e&&(t.addRhythmAtBegin(f,i),t.parentSourceMeasure.RhythmPrinted=f,y=!0)}return(g||S||y)&&(m+=t.beginInstructionsWidth,y&&(m+=this.rules.RhythmRightMargin)),m}addInstructionsAtMeasureEnd(e,t,i){if(!e||!e.Instructions||0===e.Instructions.length)return 0;for(let s=0,n=e.Instructions.length;s0&&(this.currentSystemParams.systemMeasures.push({beginLine:Re.None,endLine:Re.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;s1){const e=Math.min(this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length-1,i.measureListIndex+i.multipleRestMeasures-1);i=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[e]}}finally{}const s=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures,n=s[this.measureListIndex];let r=!1;return n.allRests&&(r=null==(t=null==(e=s[this.measureListIndex+n.multipleRestMeasures-1])?void 0:e.endsWithLineRepetition)?void 0:t.call(e)),this.nextMeasureBeginsLineRepetition()&&this.thisMeasureEndsLineRepetition()?Re.DotsBoldBoldDots:this.thisMeasureEndsLineRepetition()||r?Re.DotsThinBold:this.nextMeasureHasKeyInstructionChange()||this.thisMeasureEndsWordRepetition()||this.nextMeasureBeginsWordRepetition()?Re.DoubleThin:i&&void 0!==i.endingBarStyleEnum?i.endingBarStyleEnum:Re.SingleThin}getLineWidth(e,t,i){let s=e.getLineWidth(t);return t===Re.DotsBoldBoldDots&&(s/=2),i&&t===Re.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=this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length||!this.measureList[e])return!1;for(let t=0,i=this.measureList[e].length;t=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;t1)for(let o=1;or&&(r=i)}for(let o=0;othis.rules.PageHeight-this.rules.PageBottomMargin&&(n++,n<=4&&console.log(`warning: could not fit a single system on page ${t.PageNumber} and measure number ${s.GraphicalMeasures[0][0].MeasureNumber}.\n The PageFormat may be too small for this sheet."\n Will not give further warnings for all pages, only total.`))}else{const n=this.musicSystems[o-1],a=n.StaffLines[n.StaffLines.length-1],l=a.PositionAndShape;let h=this.findRequiredDistanceWithSkyBottomLine(n,s);h=Math.max(r,h),h+=this.rules.MinSkyBottomDistBetweenSystems,"GYM"===(null==(e=null==window?void 0:window.appName)?void 0:e.toLocaleUpperCase())&&(h=h<16?16:h);const u=this.hasExpressionCounts(s);u.TempoCount>0&&this.rules.MetronomeMarksDrawn&&(h+=2),u.OtherCount>0&&this.rules.MetronomeMarksDrawn&&(h+=2),h=Math.max(h,this.rules.MinimumDistanceBetweenSystems+a.StaffHeight);const c=i+l.RelativePosition.y+h,d=c+s.PositionAndShape.BorderMarginBottom;if(this.rules.NewPageAtXMLNewPageAttribute&&n.breaksPage||!(d0&&console.log(`total amount of pages that couldn't fit a single music system: ${n} of ${t.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=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 e,this.currentAlterationsComparedToKeyInstructionList=[],this.currentInMeasureNoteAlterationsDict=new e}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!==H.NONE&&this.currentInMeasureNoteAlterationsDict.remove(i);const s=this.currentInMeasureNoteAlterationsDict.getValue(i);if(t.Accidental===H.NONE&&(t=.5===Math.abs(s)?new j(t.FundamentalNote,t.Octave,H.NONE):new j(t.FundamentalNote,t.Octave,H.NATURAL)),this.isAlterAmbiguousAccidental(t.Accidental)&&!t.AccidentalXml)return;yi.symbolFactory.addGraphicalAccidental(e,t)}}else if(t.Accidental!==H.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 j(t.FundamentalNote,t.Octave,H.NATURAL),this.currentAlterationsComparedToKeyInstructionList.splice(this.currentAlterationsComparedToKeyInstructionList.indexOf(i),1),yi.symbolFactory.addGraphicalAccidental(e,t))}isAlterAmbiguousAccidental(e){return e===H.SLASHFLAT||e===H.QUARTERTONEFLAT}reactOnKeyInstructionChange(){const e=this.activeKeyInstruction.AlteratedNotes;let t;t=this.activeKeyInstruction.Key>0?H.SHARP:H.FLAT,this.keySignatureNoteAlterationsDict.clear(),this.currentAlterationsComparedToKeyInstructionList.length=0;for(let i=-9;i<9;i++)for(let s=0;s0)s=l-1,t.push({startIndex:i,endIndex:s}),i=l;else{n.HasEndLine&&this.rules.NewPartAndSystemAfterFinalBarline&&(s=l,t.push({startIndex:i,endIndex:s}),i=l+1)}}i0?Number(t):6,f===t||d+l>s&&f%2==0?(r.push(f),d=i,f=1):f++}else d>s?(r.push(f),d=i,f=1):f++;p=i>s?m+1:Math.ceil(p),u===p?c+=1:(n.push(c),u=p,c=1)}n.push(c),r.push(f),r=r.filter(Boolean)}return r.length>1&&1===r[r.length-1]&&(r[r.length-2]=r[r.length-2]-1,r[r.length-1]=r[r.length-1]+1),console.log(r,n),this.buildPreparedMusicSystems(r)}buildPreparedMusicSystems(e){let t=!1;this.currentSystemParams=new fi,this.currentSystemParams.currentSystem=this.initMusicSystem();for(let i=0,s=this.measureList.length;i0&&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;l0){r.isReducedToMultiRest=!0,r.multipleRestMeasureNumber=1,a++,h.multipleRestMeasureNumber=a,h.isReducedToMultiRest=!0;for(let e=0;e1){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===J.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(),we.transformRelativeToAbsolutePosition(this.graphicalMusicSheet)}calculateXLayout(e,t){var i;if(this.graphicalMusicSheet.MeasureList.length>0){let e,t=0,s=1;for(let i=0;it&&(t=n);const r=this.graphicalMusicSheet.ParentMusicSheet.MeasureWidthFactor;for(const t of e)if(null==t?void 0: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;t1;if(1===t&&i.Measures[0].parentSourceMeasure.ImplicitMeasure&&(o=!1),o)return;0!==r.MeasureNumber&&1!==r.MeasureNumber||(s=r.MeasureNumber),n=r!==i.Measures[0]&&this.rules.MeasureNumberLabelXOffset?this.rules.MeasureNumberLabelXOffset:0;const a=this.rules.UseXMLMeasureNumbers&&1===r.MeasureNumber&&1!==r.parentSourceMeasure.getPrintedMeasureNumber();((r.MeasureNumber===s||r.MeasureNumber>=s+this.rules.MeasureNumberLabelOffset)&&!r.parentSourceMeasure.ImplicitMeasure||a)&&((1!==r.MeasureNumber||1===r.MeasureNumber&&r!==i.Measures[0]||a)&&this.calculateSingleMeasureNumberPlacement(r,i,e,n),s=r.MeasureNumber)}}calculateSingleMeasureNumberPlacement(e,t,i,s=0){var n,r,o,a;const l=/^\d+$/.test((null==(r=null==(n=null==e?void 0:e.parentSourceMeasure)?void 0:n.rehearsalExpression)?void 0:r.label)||"")||(null==(a=null==(o=null==e?void 0:e.stave)?void 0:o.modifiers)?void 0:a.some((e=>{var t;return"StaveSection"===(null==(t=null==e?void 0:e.attrs)?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 mt(h);u.isNotRender=l;const c=new ft(u,this.rules.MeasureNumberLabelHeight,ue.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 X(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;h0){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;i0){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;t0||e.UnknownList.length>0){let i="";for(let t=0,s=e.EntriesList.length;t-50){let e=h/10;e+=this.rules.PlaceWordsInsideStafflineYOffset,d.PositionAndShape.RelativePosition.y=e}new _t(n,d,c,null==(r=a[s])?void 0:r.parentSourceMeasure,e)}}clearRecreatedObjects(){for(let e=0,t=this.staffEntriesWithGraphicalTies.length;ee.length-1&&(t.debug("minimum measure to draw index out of range. resetting min measure index to limit."),this.rules.MinMeasureToDrawIndex=e.length-1);const i=[];for(let t=this.rules.MinMeasureToDrawIndex,o=e.length;t0){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 Ae&&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 Ae&&(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,i,s,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,i=void 0,e=void 0;continue}if(h.NoteTuplet===s)continue;let u=h.TypeLength;if(u||(t.warn("note missing TypeLength"),u=h.NoteTuplet.Fractions[0]),h.NoteTuplet!==i&&o[l.VoiceId][h.NoteTuplet.TupletLabelNumber]&&o[l.VoiceId][h.NoteTuplet.TupletLabelNumber][u.RealValue]){h.NoteTuplet.RenderTupletNumber=!1,s=h.NoteTuplet;continue}h.NoteTuplet.TupletLabelNumber===n&&u.Equals(e)&&!h.NoteTuplet.Bracket||(n=h.NoteTuplet.TupletLabelNumber,e=u,r=0),i=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)),s=i}}}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===c.Below?(a=o.getBottomLineMaxInRange(s,n),i.PositionAndShape.RelativePosition=new X(t.x,a-i.PositionAndShape.BorderMarginTop)):(a=o.getSkyLineMinInRange(s,n),i.PositionAndShape.RelativePosition=new X(t.x,a-i.PositionAndShape.BorderMarginBottom))}calculateGraphicalContinuousDynamic(e,i){var s;const n=e.IsSoftAccent,r=e.ParentStaffLine.ParentStaff.idInMusicSheet,o=this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(e.ContinuousDynamic.EndMultiExpression.SourceMeasureParent,r);if(!o)return void t.warn("MusicSheetCalculator.calculateGraphicalContinuousDynamic: No endMeasure found");e.EndMeasure=o;const a=e.ParentStaffLine,l=o.ParentStaffLine,u=l&&a===l;let d=!1;l?d=null==l?void 0:l.isPartOfMultiStaffInstrument():a&&(d=null==a?void 0:a.isPartOfMultiStaffInstrument());const f=h.createFromFraction(e.ContinuousDynamic.EndMultiExpression.AbsoluteTimestamp),p=this.graphicalMusicSheet.GetVerticalContainerFromTimestamp(f),g=p.getFirstNonNullStaffEntry().parentMeasure,S=g.PositionAndShape.AbsolutePosition.x+g.PositionAndShape.BorderRight;let y=new h(0,0,0);for(const t of p.StaffEntries){const e=null==(s=null==t?void 0:t.sourceStaffEntry)?void 0:s.calculateMaxNoteLength(!1);(null==e?void 0:e.gt(y))&&(y=e)}const b=!n&&e.ContinuousDynamic.DynamicType===m.diminuendo,M=this.getRelativePositionInStaffLineFromTimestamp(f,r,l,d,0,b),P=h.plus(f,y).clone();e.ContinuousDynamic.EndMultiExpression.EndOffsetFraction&&this.rules.UseEndOffsetForExpressions&&P.Add(e.ContinuousDynamic.EndMultiExpression.EndOffsetFraction);const E=this.getRelativePositionInStaffLineFromTimestamp(P,r,l,d,0,e.ContinuousDynamic.DynamicType===m.diminuendo),v=this.rules.SoftAccentWedgePadding,L=p.getFirstNonNullStaffEntry().PositionAndShape.Size.width,x=this.rules.SoftAccentSizeFactor;n?(i.x-=L/2*x+v,M.x=i.x+L/2*x):E.x>M.x&&E.xI){const t=w.StaffLines[e].PositionAndShape.RelativePosition.y-a.PositionAndShape.RelativePosition.y-this.rules.StaffHeight;O=this.rules.StaffHeight+t/2}else O=this.rules.WedgePlacementBelowY;O-=this.rules.WedgeOpeningLength/2,u||(_=O);let t=A.getBottomLineMaxInRange(B,V);if(t>O&&(O=t),I_&&(_=t),_+=this.rules.WedgeOpeningLength/2,_+=this.rules.WedgeVerticalMargin),O+=this.rules.WedgeOpeningLength/2,O+=this.rules.WedgeVerticalMargin}else if(R===c.Above){if(1===a.ParentStaff.ParentInstrument.Staves.length)O=this.rules.WedgePlacementAboveY;else{let e=0;I>0&&(e=I-1);const t=w.StaffLines[e];O=-(a.PositionAndShape.RelativePosition.y-t.PositionAndShape.RelativePosition.y-this.rules.StaffHeight)/2}O+=this.rules.WedgeOpeningLength/2,u||(_=O);let e=A.getSkyLineMinInRange(B,V);if(e1&&I>0){const e=a.findClosestStaffEntry(B),t=a.findClosestStaffEntry(V);e&&t&&e.parentVerticalContainer}u||(e=l.SkyBottomLineCalculator.getSkyLineMinInRange(D,k),e<_&&(_=e),_-=this.rules.WedgeOpeningLength/2),O-=this.rules.WedgeOpeningLength/2,O-=this.rules.WedgeVerticalMargin,u||(_-=this.rules.WedgeVerticalMargin)}if(e.Lines.clear(),n)e.createFirstHalfCrescendoLines(B,V,O),e.createSecondHalfDiminuendoLines(D,k,O),e.calcPsi();else if(u&&!n)e.createLines(B,V,O),e.calcPsi();else{e.createFirstHalfLines(B,V,O),e.calcPsi();for(let t=0;tn&&(n=e),n+=this.rules.WedgeOpeningLength/2,n+=this.rules.WedgeVerticalMargin}else if(R===c.Above){const e=s.SkyBottomLineCalculator.getSkyLineMinInRange(D,k);e<_&&(n=e),n-=this.rules.WedgeOpeningLength/2}e.ContinuousDynamic.DynamicType===m.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(f.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===c.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 X(t.x,a)}else if(e.Placement===c.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.BorderMarginBottome.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 d=n===c.Below?p.getBottomLineMaxInRange(f,m)+a:p.getSkyLineMinInRange(f,m)-a,h.PositionAndShape.RelativePosition=new X(t.x,d),n===c.Below?p.updateBottomLineInRange(f,m,h.PositionAndShape.BorderMarginBottom+d):p.updateSkyLineInRange(f,m,h.PositionAndShape.BorderMarginTop+d),h}calculateTempoExpressionsForMultiTempoExpression(e,i,s,n){Si={};const r=h.plus(e.AbsoluteTimestamp,i.Timestamp),o=this.graphicalMusicSheet.MeasureList[s];let a=new X;if(i.ContinuousTempo||i.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;e0){l=o[e].ParentStaffLine,h=o[e].PositionAndShape.RelativePosition.x,u=e;break}if(a=this.getRelativePositionInStaffLineFromTimestamp(r,u,l,l.isPartOfMultiStaffInstrument(),h),i.EntriesList.length>0&&i.EntriesList[0].Expression instanceof ei){if(i.EntriesList[0].Expression.Placement=c.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 i.EntriesList){let o=ue.CenterBottom;this.rules.CompactMode&&(o=ue.LeftBottom);const h=this.calculateLabel(l,a,r.label,i.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||t.warn("Adding staffline didn't work"),r.Expression.Enum===ti.metronomeMark&&(Si[s]=r.Expression)}else r.Expression;if(n===e.TempoExpressions.length-1)for(const e of Object.values(Si))this.createMetronomeMark(e,s);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-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!==ct.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-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 X(e.RelativePosition.x,0))}layoutVoiceEntries(e,t){if(e.PositionAndShape.RelativePosition=new X(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(){var e;let t=0;for(const i of this.graphicalMusicSheet.ParentMusicSheet.Instruments)if((null==(e=i.NameLabel)?void 0:e.print)&&i.Voices.length>0&&i.Voices[0].Visible){let e=i.NameLabel;this.rules.RenderPartNames||(e=new mt("",e.textAlignment,e.font));const s=new ft(e,this.rules.InstrumentLabelTextHeight,ue.LeftCenter,this.rules);s.setLabelPositionAndShapeBorders(),t=Math.max(t,s.PositionAndShape.MarginSize.width)}return this.rules.RenderPartNames?t:0}calculateSheetLabelBoundingBoxes(){var e;const t=this.graphicalMusicSheet.ParentMusicSheet,i=this.rules.DefaultColorTitle;if(void 0!==t.Title&&this.rules.RenderTitle){const e=new ft(t.Title,this.rules.SheetTitleHeight,ue.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 ft(t.Subtitle,this.rules.SheetSubtitleHeight,ue.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 ft(t.Composer,this.rules.SheetComposerHeight,ue.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 ft(t.Lyricist,this.rules.SheetAuthorHeight,ue.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 ft(t.Copyright,this.rules.SheetCopyrightHeight,ue.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[0];if(s&&s.FirstInstructionsStaffEntries.length>0){const e=s.FirstInstructionsStaffEntries[0];let n,r;for(let t=0,i=e.Instructions.length;t0&&1===e.graphicalVoiceEntries[0].notes.length){const i=e.graphicalVoiceEntries[0].notes[0];!i.sourceNote.Pitch&&new h(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;if(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 X;const u=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length,c=this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(e),d=Math.min(Math.floor(c),u-1),f=Math.min(Math.ceil(c),u-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,u=a.PositionAndShape.RelativePosition.x+a.parentMeasure.PositionAndShape.RelativePosition.x;const c=e.RealValue>a.getAbsoluteTimestamp().RealValue;n>0?u=a.PositionAndShape.RelativePosition.x+t:r&&(o.getAbsoluteTimestamp().RealValue===e.RealValue||c)&&(s=o.PositionAndShape.RelativePosition.x+o.PositionAndShape.BorderLeft+t,u=s);let d=0;if(o!==a){const t=o.getAbsoluteTimestamp(),i=a.getAbsoluteTimestamp();d=h.minus(e,t).RealValue/h.minus(i,t).RealValue}o.parentMeasure.ParentStaffLine!==a.parentMeasure.ParentStaffLine&&(o.parentMeasure.ParentStaffLine===i?u=i.PositionAndShape.Size.width:s=i.PositionAndShape.RelativePosition.x),l=new X(s+(u-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){var t,i;this.rules.RenderSingleHorizontalStaffline&&(e.PositionAndShape.BorderRight=e.PositionAndShape.Size.width,e.PositionAndShape.calculateBoundingBox(),this.graphicalMusicSheet.ParentMusicSheet.pageWidth=e.PositionAndShape.Size.width);let s=10,n=-1;if(e.MusicSystems.length>0){const t=e.MusicSystems[0];s=t.PositionAndShape.RelativePosition.y+t.PositionAndShape.BorderTop;const i=e.MusicSystems[e.MusicSystems.length-1];n=i.PositionAndShape.RelativePosition.y+i.PositionAndShape.BorderBottom}const r=this.graphicalMusicSheet.Title;if(r&&this.rules.RenderTitle){r.PositionAndShape.Parent=e.PositionAndShape;const t=new X;t.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth/2,this.rules.RenderSingleHorizontalStaffline&&(t.x=e.PositionAndShape.BorderMarginLeft+r.PositionAndShape.Size.width),t.y=this.rules.TitleTopDistance+this.rules.SheetTitleHeight,r.PositionAndShape.RelativePosition=t,e.Labels.push(r)}if(this.graphicalMusicSheet.Subtitle&&this.rules.RenderTitle&&this.rules.RenderSubtitle){const i=this.graphicalMusicSheet.Subtitle;i.PositionAndShape.Parent=e.PositionAndShape;const s=new X;s.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth/2,this.rules.RenderSingleHorizontalStaffline&&(s.x=e.PositionAndShape.BorderMarginLeft+r.PositionAndShape.Size.width+i.PositionAndShape.Size.width/2),s.y=this.rules.TitleTopDistance+this.rules.SheetTitleHeight+this.rules.SheetMinimumDistanceBetweenTitleAndSubtitle;const n=null==(t=i.TextLines)?void 0:t.length;n>1&&(s.y+=i.PositionAndShape.BorderBottom*(n-1)/n),i.PositionAndShape.RelativePosition=s,e.Labels.push(i)}const o=this.graphicalMusicSheet.Composer;let a;const l=this.graphicalMusicSheet.Composer&&this.rules.RenderComposer&&this.graphicalMusicSheet.Lyricist&&this.rules.RenderLyricist?2:0;if(o&&this.rules.RenderComposer){o.PositionAndShape.Parent=e.PositionAndShape,o.setLabelPositionAndShapeBorders();const t=new X;t.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth-this.rules.PageRightMargin,this.rules.RenderSingleHorizontalStaffline&&(t.x=e.PositionAndShape.BorderMarginLeft+2*r.PositionAndShape.Size.width),t.y=s,t.y-=this.rules.SystemComposerDistance;const n=null==(i=o.TextLines)?void 0:i.length;n>1&&(t.y-=o.PositionAndShape.BorderBottom*(n-1)/n),a=t.y,t.y-=l,o.PositionAndShape.RelativePosition=t,e.Labels.push(o)}const h=this.graphicalMusicSheet.Lyricist;if(h&&this.rules.RenderLyricist){h.PositionAndShape.Parent=e.PositionAndShape,h.setLabelPositionAndShapeBorders();const t=new X;t.x=this.graphicalMusicSheet.ParentMusicSheet.pageWidth-this.rules.PageRightMargin,t.y=s,t.y-=this.rules.SystemLyricistDistance,t.y+=h.PositionAndShape.BorderBottom,t.y=Math.min(t.y,null!=a?a:Number.MAX_SAFE_INTEGER),t.y+=l,h.PositionAndShape.RelativePosition=t,e.Labels.push(h)}const u=this.graphicalMusicSheet.Copyright;if(u&&this.rules.RenderCopyright){u.PositionAndShape.Parent=e.PositionAndShape,u.setLabelPositionAndShapeBorders();const t=new X;t.x=e.PositionAndShape.Size.width/2,t.y=n+this.rules.SheetCopyrightMargin,t.y-=u.PositionAndShape.BorderTop,u.PositionAndShape.RelativePosition=t,e.Labels.push(u)}}createGraphicalTies(){for(let e=0;e=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===c.NotYetDefined){const t=e.Notes[0].ParentVoiceEntry.ParentVoice.VoiceId;2!==t&&6!==t||(e.TieDirection=c.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===c.NotYetDefined&&(i.Notes[0]===e?i.TieDirection=c.Above:i.TieDirection=c.Below)}}createAccidentalCalculators(){const e=[],t=this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();if(t)for(let i=0;i1)return;p=yi.symbolFactory.createGraphicalMeasure(e,m)}if(p.hasError=e.getErrorInMeasure(a),e.FirstInstructionsStaffEntries[a])for(let h=0,S=e.FirstInstructionsStaffEntries[a].Instructions.length;h0){const t=u.Instructions[0];yi.symbolFactory.createInStaffClef(e,t)}this.rules.RenderChordSymbols&&(null==(f=u.ChordContainers)?void 0:f.length)>0&&(u.ParentStaff.ParentInstrument.HasChordSymbols=!0,yi.symbolFactory.createChordSymbols(u,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=1&&0===p.staffEntries.length){const t=new Ke(new je(p.parentSourceMeasure,p.parentSourceMeasure.AbsoluteTimestamp,p.parentSourceMeasure.CompleteNumberOfStaves),m);if(0===m.Voices.length){const e=new Oe(p.ParentStaff.ParentInstrument,-1);m.Voices.push(e)}const i=new ht(new h(0,1),m.Voices[0],t);let s=e.Duration;0===s.RealValue&&(s=e.ActiveTimeSignature.clone());const n=new Ie(i,t,s,void 0,e,!0);n.IsWholeMeasureRest=!0,n.PrintObject=this.rules.FillEmptyMeasuresWithWholeRest===N.YesVisible,i.addNote(n);const r=yi.symbolFactory.createStaffEntry(t,p);p.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 K,$t.NONE,this.rules);yi.stafflineNoteCalculator.trackNote(a),o.notes.push(a)}p.hasOnlyRests=!0;for(const h of p.staffEntries)if(p.hasOnlyRests=h.hasOnlyRests(),!p.hasOnlyRests)break;return p}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!==q.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;t0&&!this.rules.PercussionUseCajon2NoteSystem&&e[t]&&(-1===this.rules.PercussionOneLineCutoff||yi.stafflineNoteCalculator.getStafflineUniquePositionCount(t)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;e0&&this.layoutArticulationMarks(t.Articulations,t,i)}}}}}}calculateOrnaments(){for(let e=0,t=this.musicSystems.length;e0&&t.LyricVersesNumbers.sort()}for(let e=0,i=this.musicSystems.length;e=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 mt("-");n.colorDefault=this.rules.DefaultColorLyrics;let r=this.rules.LyricsHeight;i-t<.8&&(r*=.8,s-=.1*r);const o=new ft(n,r,ue.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 X(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;a0)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 X(t,s),r=new X(i,s),o=new U(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 mt("-");n.colorDefault=this.rules.DefaultColorLyrics;const r=new ft(n,this.rules.LyricsHeight,ue.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 X(t,s);r.PositionAndShape.RelativePosition=o;const a=new mt("-"),l=new ft(a,this.rules.LyricsHeight,ue.CenterBottom,this.rules);l.setLabelPositionAndShapeBorders(),e.LyricsDashes.push(l),l.PositionAndShape.Parent=e.PositionAndShape;const h=new X(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=0;r--)if(null==(n=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r])?void 0:n.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[r].StaffEntries[t]}getFirstRightNotNullStaffEntryFromContainer(e,t,i){var s,n;if(null==(s=this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e])?void 0:s.StaffEntries[t])return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[e].StaffEntries[t];for(let r=e+1;r0||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=ct.Up):void(e.WantedStemDirection=ct.Down);e.ParentVoice instanceof _e?e.WantedStemDirection=ct.Down:e.ParentSourceStaffEntry.VoiceEntries.length>1&&(e.WantedStemDirection=ct.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!==ct.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 mt(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;t0&&this.Voices[0].Visible}set Visible(e){for(let t=0,i=this.Voices.length;t-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,Re.SingleThin,dt.MeasureBegin,this,n,r);this.SystemLines.push(o),o.PositionAndShape.RelativePosition=new X(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 X(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 X(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;t1){let e,i;for(let s=0,n=this.staffLines.length;sthis.maxLabelLength&&(this.maxLabelLength=e.PositionAndShape.Size.width,t=r))}this.updateMusicSystemStaffLineXPosition(t)}setMusicSystemLabelsYPosition(){this.labels.forEach(((e,t)=>{let i=0,s=0;for(let n=0;n0&&(t.PositionAndShape.RelativePosition=new X(0,i/s+2))}))}checkStaffEntriesForStaffEntryLink(){let e=!1,t=!1;for(let i=0;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;t0){const e=null==(i=window.GYM)?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 dt.MeasureBegin:if(e===Re.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 dt.MeasureEnd:switch(e){case Re.DotsBoldBoldDots:this.stave.setEndBarType(Ai.Barline.type.REPEAT_BOTH);break;case Re.DotsThinBold:this.stave.setEndBarType(Ai.Barline.type.REPEAT_END);break;case Re.DoubleThin:this.stave.setEndBarType(Ai.Barline.type.DOUBLE);break;case Re.ThinBold:this.stave.setEndBarType(Ai.Barline.type.END);break;case Re.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 $e.Segno:t=Ai.Repetition.type.SEGNO_LEFT,i=Ai.StaveModifier.Position.LEFT;break;case $e.Coda:t=Ai.Repetition.type.CODA_LEFT,i=Ai.StaveModifier.Position.LEFT;break;case $e.DaCapo:t=Ai.Repetition.type.DC;break;case $e.DalSegno:t=Ai.Repetition.type.DS;break;case $e.Fine:t=Ai.Repetition.type.FINE;break;case $e.ToCoda:t=Ai.Repetition.type.TO_CODA;break;case $e.DaCapoAlFine:t=Ai.Repetition.type.DC_AL_FINE;break;case $e.DaCapoAlCoda:t=Ai.Repetition.type.DC_AL_CODA;break;case $e.DalSegnoAlFine:t=Ai.Repetition.type.DS_AL_FINE;break;case $e.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){var t;let i=Ai.Volta.type.BEGIN;if(e.type===$e.Ending){switch(e.alignment){case Qe.Begin:i=this.parentSourceMeasure.endsRepetitionEnding()?Ai.Volta.type.BEGIN_END:Ai.Volta.type.BEGIN;break;case Qe.End:if(this.parentSourceMeasure.beginsRepetitionEnding())return;i=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;if(o0){t.trace(`Ghost Found in between (measure ${this.MeasureNumber})`);const i=this.createGhostGves(e);s.splice(o,0,...i),o+=i.length}}else{const e=h.minus(n,this.parentSourceMeasure.AbsoluteTimestamp);if(e.RealValue>0){t.trace(`Ghost Found at start (measure ${this.MeasureNumber})`);const i=this.createGhostGves(e);s.splice(0,0,...i),o+=i.length}}i=r}const n=h.plus(this.parentSourceMeasure.AbsoluteTimestamp,this.parentSourceMeasure.Duration),r=h.minus(n,i);if(r.RealValue>0){t.trace(`Ghost Found at end (measure ${this.MeasureNumber})`);const e=this.createGhostGves(r);s=s.concat(e)}return s}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 i in this.beams)if(this.beams.hasOwnProperty(i)){let s=this.vfbeams[i];s||(s=this.vfbeams[i]=[]);for(const n of this.beams[i]){let i=!1;for(const e of n[0].Notes)if(e.Length.RealValue>=new h(1,4).RealValue&&(!e.TypeLength||e.TypeLength.RealValue>.125)){i=!0;break}if(i){t.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===ct.Undefined);let u,c=!1;const d=[];for(const t of a){const i=t.vfStaveNote;i&&(r.push(i),e.push(i)),t.parentVoiceEntry.IsGrace&&(c=!0),t.parentVoiceEntry.StemColor&&this.rules.ColoringEnabled&&d.push(t.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){u=d[0];for(const e of d)if(e!==u){u=void 0;break}e.setStyle({fillStyle:u,strokeStyle:u})}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),s.push(e)}else t.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 u=l.vfStaveNote,d=l.notes[0],f={vfStaveNote:u,sourceNote:d.sourceNote},m=c.relInMeasureTimestamp.isOnBeat(a),p=n.length>=2,g=d.sourceNote.Length.RealValue-new h(1,4).RealValue>-h.FloatInaccuracyTolerance,S=l.parentVoiceEntry.IsGrace||g||e.contains(u);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>=Xe.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 ke(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 ke(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,u={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]));u.groups=e}for(const h of o){const e=[];for(const i of h)e.push(i.vfStaveNote);const t=Ai.Beam.generateBeams(e,u);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 i=this.vftuplets[e];i||(i=this.vftuplets[e]=[]);for(const s of this.tuplets[e]){const e=[],n=s[1];for(const t of n)e.push(t.vfStaveNote);if(e.length>1){const t=s[0],n=t.Notes[0][0].NormalNotes,r=t.shouldBeBracketed(this.rules.TupletsBracketedUseXMLValue,this.rules.TupletsBracketed,this.rules.TripletsBracketed,this.isTabMeasure,this.rules.TabTupletsBracketed);let o=Ai.Tuplet.LOCATION_TOP;t.tupletLabelNumberPlacement===c.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=t.Notes[0][0];(null==e?void 0:e.hasTabEffects())&&(a-=10*this.rules.TabTupletYOffsetEffects)}const l=new Ai.Tuplet(e,{bracketed:r,location:o,notes_occupied:n,num_notes:t.TupletLabelNumber,ratioed:this.rules.TupletsRatioed,y_offset:a});i.push(l)}else t.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;e0&&(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!==c.Left&&this.rules.FingeringPosition!==c.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 i=e.parentVoiceEntry.Arpeggio;if(e.notes&&e.notes.length>1){const t=Jt.StrokeTypeFromArpeggioType(i.type),s=new Ai.Stroke(t,{all_voices:this.rules.ArpeggiosGoAcrossVoices});this.rules.RenderArpeggios&&e.vfStaveNote.addStroke(0,s)}else t.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])continue;switch(i[0].getStemDirection()){case Ai.Stem.UP:t.parentVoiceEntry.StemDirection=ct.Up;break;case Ai.Stem.DOWN:t.parentVoiceEntry.StemDirection=ct.Down}}}createArticulations(){for(let e=0,t=this.staffEntries.length;ei){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===c.AboveOrBelow&&(this.isUpperStaffOfInstrument()?o=c.Above:this.isLowerStaffOfInstrument()&&(o=c.Below)),s.placement!==c.NotYetDefined&&(o=s.placement);let a,l=this.rules.FingeringOffsetX;switch(o){default:case c.Left:a=Ai.StaveModifier.Position.LEFT,l-=r.baseFingeringXOffset*zt;break;case c.Right:a=Ai.StaveModifier.Position.RIGHT,l+=r.baseFingeringXOffset*zt;break;case c.Above:a=Ai.StaveModifier.Position.ABOVE;break;case c.Below:a=Ai.StaveModifier.Position.BELOW;break;case c.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=c.Above):(a=Ai.StaveModifier.Position.BELOW,o=c.Below)}const h=new Ai.FretHandFinger(s.value);if(h.setPosition(a),h.setOffsetX(l),o===c.Above||o===c.Below){const e=o===c.Above?-1:1,r=o===c.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(){let e=0,t=0;const i=this.stave.getModifiers();for(const s of i)5===s.getPosition()?e+=s.getWidth()+s.getPadding(void 0):6===s.getPosition()&&(t+=s.getWidth()+s.getPadding(void 0));this.beginInstructionsWidth=(null!=e?e:0)/zt,this.endInstructionsWidth=(null!=t?t:0)/zt}addStaveTie(e,t){this.vfTies.push(e),t.vfTie=e,t.Tie.TieDirection===c.Below&&e.setDirection(1)}}class Bi extends se{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 re(this,i.PositionAndShape)):this.PositionAndShape=new re(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.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 h(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;t0&&(e=t)}return e}findStaffEntryMaxNoteLength(){let e=new h(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=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.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.ParentStaffLine.SkyBottomLineCalculator;if(!t)return;const[i,s]=this.getAbsoluteStartAndEnd();return t.getBottomLineMaxInRange(i,s)}getAbsoluteStartAndEnd(){let e=this.PositionAndShape.AbsolutePosition.x;e-=this.parentMeasure.ParentStaffLine.PositionAndShape.AbsolutePosition.x;return[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.BorderLefte.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=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 se{constructor(e,t,i,s,n,r){super(),this.chordSymbolContainer=e,this.boundingBox=new re(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=Se.calculateChordText(this.chordSymbolContainer,t,i);this.graphicalLabel=new ft(new mt(s),e,this.rules.ChordSymbolTextAlignment,this.rules,this.boundingBox),this.graphicalLabel.PositionAndShape.RelativePosition=new X(this.rules.ChordSymbolRelativeXOffset,0),this.graphicalLabel.Label.colorDefault=this.rules.DefaultColorChordSymbol}}const Fi=i.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)?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;t1){const t=Jt.StrokeTypeFromArpeggioType(i.type),s=new Fi.Stroke(t,{all_voices:this.rules.ArpeggiosGoAcrossVoices});this.rules.RenderArpeggios&&e.vfStaveNote.addStroke(0,s)}else t.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 t of e.vfGhostNotes)this.vfVoices[i.VoiceId].addTickable(t);else this.vfVoices[i.VoiceId].addTickable(e.vfStaveNote)}else if(e.vfGhostNotes)for(const t of e.vfGhostNotes)this.vfVoices[i.VoiceId].addTickable(t);else this.vfVoices[i.VoiceId].addTickable(e.vfStaveNote)}}}}class _i extends se{constructor(e){super(),this.parentStaffLine=e;const t=e.PositionAndShape;this.boundingBox=new re(this,t),this.boundingBox.BorderRight=6,this.boundingBox.BorderBottom=4.5,this.boundingBox.BorderLeft=-1.5,this.boundingBox.BorderTop=-1.5}}class Gi extends se{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 re(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)if(5===this.ParentStaff.StafflineCount)this.staffHeight=this.bottomLineOffset=6*this.ParentStaff.ParentInstrument.GetMusicSheet.Rules.TabStaffInterlineHeight;else 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 X(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;i0){const e=o.map((e=>e.PositionAndShape.Center.y)),t=Math.max(...e),n=(null==(i=window.GYM)?void 0:i.noNeedContinuousDynamic)||!1,r=(null==(s=window.GYM)?void 0:s.noNeedGraphicalContinuousDynamic)||!1;for(let i=0;i0?o[i-1]:void 0;if(e){const t=this.getOverlap(s.PositionAndShape,e.PositionAndShape);s.squeeze(-(t.x+this.rules.DynamicExpressionSpacer))}if(t){const e=this.getOverlap(t.PositionAndShape,s.PositionAndShape);s.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 X(s-i,r-n)}getOverlap(e,t){return new X(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=i.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==(t=null==a?void 0:a.classList)||t.add("vf-measure"),null==a||a.setAttribute("data-num",String(null==(i=null==this?void 0:this.parentSourceMeasure)?void 0:i.MeasureNumberXML));const l=e.openGroup();null==(s=null==l?void 0:l.classList)||s.add("vf-stave"),null==l||l.setAttribute("id",null==(r=null==(n=this.stave)?void 0:n.attrs)?void 0:r.id),this.stave.setContext(e).draw(),e.closeGroup();const h=e.openGroup();null==(o=null==h?void 0:h.classList)||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(){var e,t;for(const i of this.staffEntries){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==(t=null==(e=i.graphicalVoiceEntries[0])?void 0:e.notes[0])?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=i.Flow;class Ki extends Wt{constructor(e){super(),this.rules=e}getVexflowBackendType(){return ji.Renderer.Backends.CANVAS}getOSMDBackendType(){return C.Canvas}getCanvasSize(){var e;return null==(e=document.getElementById("osmdCanvasPage"+this.graphicalMusicPage.PageNumber))?void 0:e.offsetHeight}initialize(e,t){this.zoom=t,this.canvas=document.createElement("canvas"),this.graphicalMusicPage||(this.graphicalMusicPage=new le(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 le(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 i=this.StaffLineParent.Measures;if(e.length!==i.length)if(t.warn("SkyBottomLineCalculator: lengths of calculation result array and measure array do not match"),e.length(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 i=new Ki(this.StaffLineParent.ParentMusicSystem.rules);for(const a of this.StaffLineParent.Measures){a.PositionAndShape.calculateAbsolutePositionsRecursive(0,0);const e=a.getVFStave();let s=e.getWidth();if(s>0||a.IsExtraGraphicalMeasure||(t.warn("SkyBottomLineCalculator: width not > 0 in measure "+a.MeasureNumber),s=50),!(s>=50)&&a.IsExtraGraphicalMeasure)continue;i.initializeHeadless(s);const n=i.getContext(),r=i.getCanvas();s=r.width;const l=r.height;"jianpu"===this.mRules.DYMusicScoreType||e.setY(e.y+100);const h=e.getWidth();e.setWidth(s),a.format(),e.setWidth(h);try{a.draw(n)}catch(o){t.warn("SkyBottomLineCalculator.calculateLines.draw",o)}const u=n.getImageData(0,0,s,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;t0){f[t]=e;break}}for(let e=l;e>0;e--){const i=e*s*c+t*c;if(u.data[i+3]>0){m[t]=e;break}}}for(let t=0;t(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=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=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;re))}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;ie.length&&(i=e.length);for(let n=t;nMath.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))e.length&&(i=e.length);for(let n=t;n=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(),o=n.y/zt,a=n.height/zt+o,[l,h]=s;if(ot.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=r(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++)nh[u]&&(h[u]=n),n+=s/this.mRules.SamplingUnit}}else for(;u<=c;u++)oh[u]&&(h[u]=a)}}calculateLinesForMeasure(e,t){var i,s,n;const r=t.getBBox(),o=Math.max(Math.round(e.PositionAndShape.Size.width*this.mRules.SamplingUnit),1),a=r.height/zt,l=t.getElementsByClassName("vf-stave")[0].getBBox();let h=(null==l?void 0:l.height)/zt,u=(null==l?void 0:l.y)/zt;const c=e.getVFStave();let d=((null==(i=c.options)?void 0:i.num_lines)?c.options.num_lines:5)-1,f=-1,m=0;const p=[d];for(const E of null==(s=c.options)?void 0:s.line_config)E.visible?(-1===f&&(f=m),p.push(m)):d--,m++;-1===f&&(f=0),d=p.pop()-f;const g=null==(n=c.options)?void 0:n.spacing_between_lines_px,S=d*g/zt;h-S>.2&&(h=S,u=f*g/zt);const y=u+h,b=new Array(o).fill(u),M=new Array(o).fill(y),P=[b,M];if(a>h)for(const E of t.children)this.recursiveUpdate(E,{top:u,bottom:y},r,[b,M]);return P}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++)nthis.mBottomLine[i]&&(this.mBottomLine[i]=r)}t.clear(),e.remove()}}const $i=i.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=4&&e.Parent.Notes[0].Length.Denominator>4&&ue.LeftBottom;const a=new mt(e.Text);a.isLyricText=!0,a.lyricExtendNoteId=null==(r=null==(n=null==e?void 0:e.Parent)?void 0:n.Notes[0])?void 0:r.NoteToGraphicalNoteObjectId,a.lyricVerseNumber=null==e?void 0:e.verseNumber;const l=this.graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules;this.graphicalLabel=new ft(a,i,o,l,t.PositionAndShape),this.graphicalLabel.Label.colorDefault=l.DefaultColorLyrics,this.graphicalLabel.PositionAndShape.RelativePosition=new X(0,s),this.graphicalLabel.setLabelPositionAndShapeBorders(),this.graphicalLabel.PositionAndShape.Size.width1&&e10*(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 mt(this.Expression);this.label=new ft(s,this.rules.ContinuousDynamicTextHeight,ue.CenterCenter,this.rules,this.PositionAndShape),this.label.Label.fontStyle=fe.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?new X:new X(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=i.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=h.minus(e.staffEntries[e.staffEntries.length-1].getAbsoluteTimestamp(),e.staffEntries[0].getAbsoluteTimestamp()),s=h.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,d=a.endY;const f=e.SlurTangentMinAngle,m=e.SlurTangentMaxAngle;let p;if(this.placement===c.Above){u-=e.SlurNoteHeadYOffset,d-=e.SlurNoteHeadYOffset;const t=new X(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 X(this.staffEntries[this.staffEntries.length-1].parentMeasure.PositionAndShape.RelativePosition.x+this.staffEntries[this.staffEntries.length-1].PositionAndShape.RelativePosition.x,d);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 X((a.x-t.x)/2+t.x,(a.y-t.y)/2+t.y);p.push(e)}const c=Math.atan((d-u)/(h-l)),g=new X(0,0);let S=new X(h-l,-(d-u));const y=Ce.getRotationMatrix(c),b=y.getTransposeMatrix();S=y.vectorMultiplication(S);const M=this.calculateTranslatedAndRotatedPointListAbove(p,l,u,y),P=this.calculateMaxLeftSlope(M,g,S),E=this.calculateMaxRightSlope(M,g,S),v=g.y-g.x*P,L=S.y-S.x*E,x=new X;let T=!1;Math.abs(Math.abs(P)-Math.abs(E))<1e-4?(x.x=S.x/2,x.y=0,T=!0):(x.x=(L-v)/(P-E),x.y=P*x.x+v);const w=this.calculateHeightWidthRatio(S.x,M),I=0,A=0;let R=f,N=-f;if(!T){const e=this.calculateAngles(f,P,E,m);R=e.startAngle,N=e.endAngle}const C=this.calculateControlPoints(S.x,R,N,M,w,u,d);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 X(l,u-I),this.bezierStartControlPt=new X(B.x,B.y-I),this.bezierEndControlPt=new X(D.x,D.y-A),this.bezierEndPt=new X(h,d-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=k&&(r.SkyLine[s]=Math.min(r.SkyLine[s],i.y)),s++,s=k&&(r.BottomLine[s]=Math.max(r.BottomLine[s],i.y)),s++,s0)return void(this.placement=c.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===ct.Up?c.Below:c.Above,this.rules.SlurPlacementAtStems&&(this.placement=n===ct.Up?c.Above:c.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?c.Above:c.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=i.BottomLine.length&&(o=i.BottomLine.length-1);for(let a=r;ah&&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 X;f.x=e*c*Math.cos(t*hs.degreesToRadiansFactor),f.y=e*c*Math.sin(t*hs.degreesToRadiansFactor);const m=new X;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;i<0?r-=20:r+=20;return{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(t){this.staffPitchListMapping=new e,this.baseLineNote=z.B,this.baseLineOctave=1,this.rules=t}trackNote(e){if(!(e instanceof Vi)||e.Clef().ClefType!==J.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;sthis.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===z.C&&(o=z.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 j(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=z.E;break;case 2:o=z.G;break;case 3:o=z.B;break;case 4:o=z.D,a=3;break;default:o=z.C}else switch(e%5){case 1:o=z.F;break;case 2:o=z.D;break;case 3:o=z.B,a=0;break;case 4:o=z.G,a=0;break;default:o=z.A}const s=new j(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=ct.Up:n.parentVoiceEntry.parentVoiceEntry.WantedStemDirection=ct.Down)}}return n}getStafflineUniquePositionCount(e){return this.staffPitchListMapping.containsKey(e)?this.staffPitchListMapping.getValue(e).length:0}}class ds extends se{constructor(e,t){super(),this.getPedal=e,this.setSymbol(),this.PositionAndShape=new re(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,s=!1,n=!1){switch(super(e,t),this.vfStyle=i.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=i.Flow.PedalMarking.Styles.TEXT,this.EndSymbolPositionAndShape=new re(this,t);break;case It.PEDAL_MIXED:this.vfStyle=s&&n?i.Flow.PedalMarking.Styles.BRACKET_OPEN_BOTH:s?i.Flow.PedalMarking.Styles.BRACKET_OPEN_BEGIN:n?i.Flow.PedalMarking.Styles.MIXED_OPEN_END:i.Flow.PedalMarking.Styles.MIXED;break;case It.PEDAL_BRACKET:default:this.vfStyle=s&&n?i.Flow.PedalMarking.Styles.BRACKET_OPEN_BOTH:s?i.Flow.PedalMarking.Styles.BRACKET_OPEN_BEGIN:n?i.Flow.PedalMarking.Styles.BRACKET_OPEN_END:i.Flow.PedalMarking.Styles.BRACKET}}setStartNote(e){if(!e)return!1;for(const t of e.graphicalVoiceEntries){const e=t;if(null==e?void 0: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?void 0: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 i.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?void 0: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===oe.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===oe.Down?1:-1;h=s.PositionAndShape.AbsolutePosition.y+t*e.GlissandoStafflineStartYDistanceToNote}const u=new X(o,l),c=new X(a,h);void 0===this.Width&&(this.Width=e.GlissandoDefaultWidth),this.Line=new U(u,c,this.Width)}}class ps extends ms{}class gs extends se{constructor(e,t){super(),this.getWavyLine=e,this.PositionAndShape=new re(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?void 0: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?void 0: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 i.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=i.Flow;class bs extends yi{constructor(e){var t,s,n,r,o,a,l,h;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.toLowerCase())?i.Flow.DEFAULT_FONT_STACK=[null==(s=i.Flow.Fonts)?void 0:s.Gonville,null==(n=i.Flow.Fonts)?void 0:n.Bravura,null==(r=i.Flow.Fonts)?void 0:r.Custom]:"petaluma"===(null==(o=this.rules.DefaultVexFlowNoteFont)?void 0:o.toLowerCase())&&(i.Flow.DEFAULT_FONT_STACK=[null==(a=i.Flow.Fonts)?void 0:a.Petaluma,null==(l=i.Flow.Fonts)?void 0:l.Gonville,null==(h=i.Flow.Fonts)?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])continue;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 i=[];for(const t of e)(null==t?void 0:t.isVisible())&&i.push(t);if(0===i.length)return 0;e=i;const s=[],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 t of h.staffEntries)e+=t.setMaxAccidentals();h.parentSourceMeasure.ImplicitMeasure&&(r=Math.max(h.staffEntries.length,r),o=Math.max(h.staffEntries.length+e,o));const i=h.vfVoices,a=[];for(const t in i)if(i.hasOwnProperty(t)){const e=i[t];h.hasOnlyRests&&!e.ticksUsed.equals(e.totalTicks)&&(e.ticksUsed=e.totalTicks),a.push(e),s.push(e)}0!==a.length?n.joinVoices(a):t.debug("Found a measure with no voices. Continuing anyway.",i)}let a=12;const l=e[0].parentSourceMeasure;if(s.length>0){if(a=n.preCalculateMinTotalWidth(s)/zt*this.rules.VoiceSpacingMultiplierVexflow+this.rules.VoiceSpacingAddendVexflow+.3*r,null==l?void 0: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===Re.ThinBold||t===Re.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(s,t.getVFStave())},i=(e,t)=>{n.formatToStave(s,t.getVFStave(),{align_rests:!0,context:void 0})};for(const s of e){if(this.rules.AlignRests===R.Never)s.formatVoices=t;else if(this.rules.AlignRests===R.Always)s.formatVoices=i;else if(this.rules.AlignRests===R.Auto){let e=!1;for(const t of s.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}s.formatVoices=e?i:t}if(s===e[0]){const e=s;e.formatVoices(a*zt,e)}}}for(const t of e)if(t)for(const e of t.staffEntries)e.calculateXPosition();for(const h of e){if(!h)continue;const e=h.vfVoices,i=[];for(const t in e)e.hasOwnProperty(t)&&i.push(e[t]);0!==i.length?n.joinVoices(i):t.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,ce.IsCenterAligned(e)&&(c+=1));const t=u.ParentLyricWord.GetLyricWord.Syllables;t.length>1&&u.LyricsEntry.SyllableIndex4&&(v*=1.1)}}else i[h]&&(v=p/g);P=Math.max(E,v),l=Math.max(l,P);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.multitrack))for(const n of e)n&&0!==n.staffEntries.length&&(s=this.calculateElongationFactorFromStaffEntries(n.staffEntries,t,s,n.MeasureNumber),s=1);s=Math.min(s,this.rules.MaximumLyricsElongationFactor);return 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=2&&(d=h.vfnote[0],m=h.vfnote[1]);let p=0;if(u&&u.vfnote&&u.vfnote.length>=2&&(f=u.vfnote[0],p=u.vfnote[1]),t){if(d){const t=new ys.StaveTie({first_indices:[m],first_note:d}),i=h.parentVoiceEntry.parentStaffEntry.parentMeasure;if(f){"w"===f.getDuration()&&(null==(n=null==(s=f.keyProps)?void 0:s[0])?void 0:n.line)>=3&&f.setStemDirection(-1);let e=(null==(r=window.GYM)?void 0:r.tieDirection)||0;1===Math.abs(e)&&((null==(a=null==(o=f.keyProps)?void 0:o[0])?void 0:a.line)>=3?f.setStemDirection(-e):f.setStemDirection(e)),null==t||t.setDirection(f.getStemDirection())}if(i.vfTies.length>0){const e=i.vfTies[0].direction;null==t||t.setDirection(e?-e:1)}i.addStaveTie(t,e)}if(f){const t=new ys.StaveTie({last_indices:[p],last_note:f}),i=u.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(d||f){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:[m],first_note:d,last_indices:[p],last_note:f},n)}else t=new ys.TabTie({first_indices:[m],first_note:d,last_indices:[p],last_note:f},e.Tie.Type);else{t=new ys.StaveTie({first_indices:[m],first_note:d,last_indices:[p],last_note:f});const i=e.Tie.getTieDirection(h.sourceNote);i===c.Below?t.setDirection(1):i===c.Above&&t.setDirection(-1)}const s=u.parentVoiceEntry.parentStaffEntry.parentMeasure,n=(null==(l=window.GYM)?void 0:l.graceCustom)||!1;n&&t.setDirection(n.direction),s.addStaveTie(t,e)}}calculateDynamicExpressionsForMultiExpression(e,i,s){if(ithis.rules.MaxMeasureToDrawIndex)return;const n=e.AbsoluteTimestamp,r=this.graphicalMusicSheet.MeasureList[i],o=r[s].ParentStaffLine,a=r[s];if(!o)return;const l=e.StartingContinuousDynamic,h=void 0!==l&&!l.IsStartOfSoftAccent,u=this.getRelativePositionInStaffLineFromTimestamp(n,s,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 i=new Wi(l,o,a.parentSourceMeasure);if(i.StartMeasure=a,i.IsSoftAccent=e.StartingContinuousDynamic.IsStartOfSoftAccent,!i.IsVerbal&&l.EndMultiExpression)try{this.calculateGraphicalContinuousDynamic(i,u),i.updateSkyBottomLine()}catch(c){}else i.IsVerbal?this.calculateGraphicalVerbalContinuousDynamic(i,u):t.warn("This continuous dynamic is not covered. measure"+e.SourceMeasureParent.MeasureNumber)}}createMetronomeMark(e,t){var i,s,n,r,o,a,l,h;const u=Math.max(e.ParentMultiTempoExpression.SourceMeasureParent.MeasureNumber-1,0),d=t||u,f=Math.max(e.StaffNumber-1,0),m=this.graphicalMusicSheet.MeasureList[d][f].getVFStave();let p="q";if(e.beatUnit){const t=ze.getNoteDurationFromType(e.beatUnit);p=Jt.durations(t,!1)[0]}let g=this.rules.MetronomeMarkYShift,S=!1;const y=[];if(e.parentMeasure){for(const t of e.parentMeasure.StaffLinkedExpressions)for(const e of t)e&&e instanceof ni&&y.push(e);for(const t of e.parentMeasure.TempoExpressions){const s=(null==(i=t.InstantaneousTempo)?void 0:i.Enum)===ti.metronomeMark;if(!e.beatUnit&&t.InstantaneousTempo.beatUnit){const t=ze.getNoteDurationFromType(e.beatUnit);p=Jt.durations(t,!1)[0]}if(t.getPlacementOfFirstEntry()===c.Above&&!s){S=!0;break}}}S&&(g-=1.4);const b=null==(s=this.graphicalMusicSheet.MeasureList[0][0].ParentStaffLine)?void 0:s.SkyLine;let M=e.TempoInBpm,P="",E="",v="";for(const c of this.graphicalMusicSheet.MeasureList[d][f].parentSourceMeasure.TempoExpressions){if(E=c.CombinedExpressionsText,Tt(c.CombinedExpressionsText)){P=c.CombinedExpressionsText;break}if(vt(c.CombinedExpressionsText)||Lt(c.CombinedExpressionsText)){P=c.CombinedExpressionsText.replace(Et,"").replace("速度 ",""),M=c.sourceMeasure.TempoInBPM,vt(c.CombinedExpressionsText)&&(v=p);break}}const L={bpm:e.TempoInBpm,dots:e.dotted,duration:p,name:P};P&&(L.bpm=M/1,vt(E)?L.duration=v:M!==pt[P]&&pt[P]||(L.duration=""));const x=(null==(a=null==(o=null==(r=null==(n=this.graphicalMusicSheet.MeasureList[d][f])?void 0:n.vfVoices)?void 0:r[1])?void 0:o.boundingBox)?void 0:a.y)||0;if(this.rules.MetronomeMarksDrawn){if(b){const e=(null==(h=null==(l=this.graphicalMusicSheet.MeasureList[0])?void 0:l[f])?void 0:h.ParentStaffLine).Measures.map((e=>e.MeasureNumber-1));if(x&&e.includes(d)&&(vt(E)||Lt(E))){const e=b.slice(0,9);let t=Math.min(...e);t=t<0?t-1:t,g+=t}e.includes(d)&&y.length?b[0]=Math.min(b[0],-4.5+g-4):b[0]=Math.min(b[0],-4.5+g)}m.options.line_config.reduce(((e,t)=>(t.visible&&e++,e)),0)<5&&(g-=2),m.setTempo(L,g*zt);let e=-3;m.getModifiers()[m.getModifiers().length-1].setShiftX(e)}}calculateRehearsalMark(e){var t,i,s,n,r,o,a,l,h;const u=e.rehearsalExpression;if(!u)return;const c=null==(s=null==(i=null==(t=e.VerticalMeasureList)?void 0:t[0])?void 0:i.getVFStave)?void 0:s.call(i);if(!c)return;const d=-this.rules.RehearsalMarkYOffsetDefault-this.rules.RehearsalMarkYOffset;let f=this.rules.RehearsalMarkXOffsetDefault+this.rules.RehearsalMarkXOffset;e.IsSystemStartMeasure&&(f+=this.rules.RehearsalMarkXOffsetSystemStartMeasure);const m=this.rules.RehearsalMarkFontSize,p=c.getModifiers(),g=p.find((e=>"repetitions"===e.getCategory().toLocaleLowerCase()));if(g&&g.setShiftY(g.y_shift-10),c.setSection(u.label,d,f,m),null==(o=null==(r=null==(n=e.VerticalMeasureList)?void 0:n[0])?void 0:r.ParentStaffLine)?void 0:o.AbstractExpressions){const t=p.find((e=>"stavesection"===e.getCategory().toLocaleLowerCase()));for(let i of(null==(h=null==(l=null==(a=null==e?void 0:e.VerticalMeasureList)?void 0:a[0])?void 0:l.ParentStaffLine)?void 0:h.AbstractExpressions)||[])i instanceof _t&&(t&&(i.Label.PositionAndShape.RelativePosition.y-=.5),g&&(i.Label.PositionAndShape.RelativePosition.y-=1.7))}}calculateSingleOctaveShift(e,i,s,n){var r;const o=i.OctaveShiftStart,a=o.ParentStartMultiExpression.Timestamp,l=null==(r=o.ParentEndMultiExpression)?void 0:r.Timestamp,h=this.rules.MinMeasureToDrawIndex,u=this.rules.MaxMeasureToDrawIndex;let c,d,f=this.graphicalMusicSheet.MeasureList[s][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.MeasureNumberu||c.parentSourceMeasure.measureListIndexu)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 i=d.findGraphicalStaffEntryFromTimestamp(a);i||(i=d.staffEntries[0]);let s=c.findGraphicalStaffEntryFromTimestamp(l);if(s||(s=c.staffEntries[c.staffEntries.length-1]),e.setStartNote(i),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=0;t--){const i=e.Measures[t];if(i.staffEntries.length>0)return i}}calculateSinglePedal(e,i,s,n){var r;const o=i.PedalStart,a=o.ParentStartMultiExpression.Timestamp,l=null==(r=o.ParentEndMultiExpression)?void 0:r.Timestamp,h=this.rules.MinMeasureToDrawIndex,u=this.rules.MaxMeasureToDrawIndex;let c,d,f=this.graphicalMusicSheet.MeasureList[s][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.MeasureNumberu||c.parentSourceMeasure.measureListIndexu)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;iu+1&&(c=this.graphicalMusicSheet.getLastGraphicalMeasureFromIndex(n,!0)),d=o.ParentEndMultiExpression?this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(o.ParentStartMultiExpression.SourceMeasureParent,n):this.graphicalMusicSheet.MeasureList[h][n],d.MeasureNumberu||c.parentSourceMeasure.measureListIndexu)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];e.setEndNote(s);if(m.ParentMusicSystem.Id-f.ParentMusicSystem.Id>0)for(let e=f.ParentMusicSystem.Id;em){const e=m;m=p,p=e}n.SkyBottomLineCalculator.updateBottomLineInRange(p,m,g+e)}for(const i of n.Pedals){const e=i,t=e.getPedalMarking();if(g>t.line+3+(n.StaffLines.length-1)){const i=t.render_options.text_margin_right/10;let s,r=e.startVfVoiceEntry.PositionAndShape.AbsolutePosition.x-i;e.setLine(g-3-(n.StaffLines.length-1));let h=null==(o=e.endVfVoiceEntry)?void 0:o.PositionAndShape;if(h||(h=e.endMeasure.PositionAndShape),e.EndSymbolPositionAndShape){const e=c.render_options.glyph_point_size/20;s=r+3.4;const t=h.AbsolutePosition.x-i,o=t+1.5;n.SkyBottomLineCalculator.updateBottomLineInRange(r,s,g+e),n.SkyBottomLineCalculator.updateBottomLineInRange(t,o,g+e)}else{const o=t.render_options.bracket_height/10;if(t.EndsStave)s=h.AbsolutePosition.x+h.Size.width-i;else switch(c.style){case u.BRACKET_OPEN_END:case u.BRACKET_OPEN_BOTH:case u.MIXED_OPEN_END:s=h.AbsolutePosition.x+h.BorderRight-i;break;default:s=h.AbsolutePosition.x+h.BorderLeft-i}const d=null==(l=null==(a=e.endVfVoiceEntry)?void 0:a.parentStaffEntry)?void 0:l.vfClefBefore;if(d){s+=d.getWidth()/10}if(r>s){const e=r;r=s,s=e}n.SkyBottomLineCalculator.updateBottomLineInRange(r,s,g+o)}}}}calculateOctaveShiftSkyBottomLine(e,i,s,n){if(!i)return void t.warn("octaveshift: no endStaffEntry");let r=i.PositionAndShape;s.graphicalEndAtMeasureEnd&&(r=i.parentMeasure.PositionAndShape);let o=e.PositionAndShape.Size.width,a=r.Size.width;e.hasOnlyRests()?o=-o:o/=2,s.graphicalEndAtMeasureEnd||(i.hasOnlyRests()?a*=2:a/=2,e===i&&(a*=2));let l=e.PositionAndShape.AbsolutePosition.x-o,h=r.AbsolutePosition.x+a;if(l>h){const e=l;l=h,h=e}s.PositionAndShape.Size.width=h-l;const u=s.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 t=n.SkyBottomLineCalculator.getBottomLineMaxInRange(l,h);if(t===1/0)return;u.start.getStave().options.bottom_text_position=t,e.parentMeasure!==i.parentMeasure&&(u.stop.getStave().options.bottom_text_position=t),n.SkyBottomLineCalculator.updateBottomLineInRange(l,h,t+1.5*c)}}calculateWordRepetitionInstruction(e,t){let i;const s=this.graphicalMusicSheet.MeasureList[t];for(let n=0,r=s.length;ne.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);t.LyricsEntries.push(n);if(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=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=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 h(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 h.plus(e,h.minus(t.to,t.from))}get Parts(){return this.parts}get MusicSheet(){return this.musicSheet}getIterator(e){return e?new T(this.musicSheet,e,void 0):new T(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 Ps(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 Ps(e.CurrentEnrolledTimestamp.clone(),e.CurrentSourceTimestamp.clone(),void 0,0),this.timestamps.push(i)}e.moveToNext()}}}class Ps{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 Es{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 vs extends Es{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 h.createFromFraction(this.musicSheet.SourceMeasures[this.startIndex].AbsoluteTimestamp)}setStartIndex(e){this.startIndex=e}setEndIndex(e){this.endIndex=e}}class Ls extends Es{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,i){const s=new xs(new vs(this.musicSheet2,i,i));this.endingParts.push(s);for(const r of e)try{this.endingIndexDict[r]=s,s.endingIndices.push(r),this.numberOfEndings0&&(s=1),n.Add(new h(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 Be,this.staves=[],this.playbackDataDict=new e,this.transpose=0,this.defaultStartTempoInBpm=0,this.drawErroneousMeasures=!1,this.hasBeenOpenedForTheFirstTime=!1,this.currentEnrolledPosition=new h(0,1),this.MeasureWidthFactor=1,this.soundTempos=new Map,this.userStartTempoInBPM=100,this.playbackSettings=new Ts(new h(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 mt(e)}get SubtitleString(){return this.subtitle?this.subtitle.text:""}set SubtitleString(e){this.Subtitle=new mt(e)}get ComposerString(){return this.composer?this.composer.text:""}set ComposerString(e){this.Composer=new mt(e)}get LyricistString(){return this.lyricist?this.lyricist.text:""}set LyricistString(e){this.Lyricist=new mt(e)}get CopyrightString(){return this.copyright?this.copyright.text:""}set CopyrightString(e){this.Copyright=new mt(e,ue.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||(t.debug("warning: sheet.Rules was undefined. Creating new EngravingRules."),this.rules=new Le),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;e0){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 t.info("MusicSheet.FirstMeasureNumber: ",e),0}}get LastMeasureNumber(){try{return this.getLastSourceMeasure().MeasureNumber}catch(e){return t.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 h.createFromFraction(e.CurrentEnrolledTimestamp)}get SheetEndTimestamp(){const e=this.getLastSourceMeasure();return h.plus(e.AbsoluteTimestamp,e.Duration)}getSourceMeasureFromTimeStamp(e){for(let t=0,i=this.sourceMeasures.length;t0&&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=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?fe.Italic:fe.Regular}}class Rs{constructor(e){this.openLyricWords={},this.musicSheet=e}addLyricEntry(e,t){var i,s;if(e){const r=e;for(let e=0,o=r.length;e0)for(let e=r;e0){const o=e.elements();for(let e=0,a=o.length;e0&&i.Articulations[0].articulationEnum!==ut.staccato&&i.Articulations.splice(0,0,o);else if("breathmark"===l)t===c.NotYetDefined&&(o.placement=c.Above);else if("strongaccent"===l){const e=null==(n=null==a?void 0:a.attribute("type"))?void 0:n.value;"up"===e?o.articulationEnum=ut.marcatoup:"down"===e&&(o.articulationEnum=ut.marcatodown)}else if(e===ut.softaccent){const e=i.ParentSourceStaffEntry.ParentStaff.Id-1;t===c.NotYetDefined&&(t=c.Above,e>0&&(t=c.Below));const s=i.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure,n=new ri(s,i.Timestamp);n.StartingContinuousDynamic=new f(m.crescendo,t,e,s,null,-1),n.StartingContinuousDynamic.IsStartOfSoftAccent=!0,n.StartingContinuousDynamic.StartMultiExpression=n,n.StartingContinuousDynamic.EndMultiExpression=n,n.EndingContinuousDynamic=new f(m.diminuendo,t,e,s,null,-1),n.EndingContinuousDynamic.StartMultiExpression=n,n.EndingContinuousDynamic.EndMultiExpression=n,s.StaffLinkedExpressions[e].push(n)}if(!i.hasArticulation(o))switch(i.Articulations.push(o),o.articulationEnum){case ut.staccato:case ut.staccatissimo:i.DurationModifier=o;break;case ut.accent:case ut.strongaccent:i.VolumeModifier=o}}}catch(r){const e="Invalid note articulation.";return void t.debug("addArticulationExpression",e,r)}}}}addFermata(e,t){var i;let s=ut.fermata;e.attributes().length>0&&e.attribute("type")&&"inverted"===e.attribute("type").value&&(s=ut.invertedfermata);let n=c.Above;"below"===(null==(i=e.attribute("placement"))?void 0:i.value)&&(n=c.Below),t.Articulations.push(new Ns(s,n))}addTechnicalArticulations(e,t,i){var s,n;const r={bend:ut.bend,"down-bow":ut.downbow,"open-string":ut.naturalharmonic,"snap-pizzicato":ut.snappizzicato,stopped:ut.lefthandpizzicato,"up-bow":ut.upbow,harmonic:ut.naturalharmonic};for(const l in r){if(!r.hasOwnProperty(l))continue;const i=r[l],o=e.element(l);if(o){let e;"above"===(null==(s=o.attribute("placement"))?void 0:s.value)&&(e=c.Above),"below"===(null==(n=o.attribute("placement"))?void 0:n.value)&&(e=c.Below);const r=new Ns(i,e);t.hasArticulation(r)||t.Articulations.push(r)}}const o=e.elements("fingering");for(const l of o){const e=this.createTechnicalInstruction(l,i);e.type=rt.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=rt.String,i.StringInstruction=e,t.TechnicalInstructions.push(e)}}createTechnicalInstruction(e,t){const i=new ot;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=c.NotYetDefined){if(t!==c.NotYetDefined)return t;if(!e)return c.NotYetDefined;switch(e.value){case"above":return c.Above;case"below":return c.Below;case"left":return c.Left;case"right":return c.Right;default:return c.NotYetDefined}}addOrnament(e,t){if(e){let i;const s={"delayed-inverted-turn":Ye.DelayedInvertedTurn,"delayed-turn":Ye.DelayedTurn,"inverted-mordent":Ye.InvertedMordent,"inverted-turn":Ye.InvertedTurn,mordent:Ye.Mordent,"trill-mark":Ye.Trill,turn:Ye.Turn};for(const t in s){if(!s.hasOwnProperty(t))continue;const n=e.element(t);if(n){i=new He(s[t]);const e=n.attribute("placement");if(e){"below"===e.value&&(i.placement=c.Below)}}}if(i){const s=e.elements("accidental-mark");if(s){let e=c.Below,t=H.NONE;const n=s;for(let s=0,r=n.length;s0&&(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,i,s,n,r,o,a,l,h,u,c,d,f,m,p,g,S,y,b,M,P,E,v){this.currentStaffEntry=a,this.currentMeasure=l;try{this.currentNote=o?this.addRestNote(e.element("rest"),i,n,s,r,f,m,b,e):this.addSingleNote(e,i,n,s,r,c,d,f,m,p,g,S,y,b,P,E,v),this.currentNote.DotsXml=M;const t=e.elements("lyric");void 0!==this.lyricsReader&&t&&(this.lyricsReader.addLyricEntry(t,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=Ve.ARPEGGIO_DIRECTIONLESS;const i=r.attribute("direction");if(i)switch(i.value){case"up":t=Ve.ROLL_UP;break;case"down":t=Ve.ROLL_DOWN;break;default:t=Ve.ARPEGGIO_DIRECTIONLESS}e=new De(this.currentVoiceEntry,t),this.currentVoiceEntry.Arpeggio=e}}e.addNote(this.currentNote)}const o=l.elements("tied");o.length>0&&this.addTie(o,h,u,ge.SIMPLE);const c=l.element("technical");if(c){const e=c.elements("hammer-on");e.length>0&&this.addTie(e,h,u,ge.HAMMERON);const t=c.elements("pull-off");t.length>0&&this.addTie(t,h,u,ge.PULLOFF)}}void 0===e.element("time-modification")||a||this.handleTimeModificationNode(e)}catch(L){t.warn(L);const e=Ue.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 it(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 Ke(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];h.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,i,s,n,r,o,a,l,u,c,d,f,m,p,S,y,b){var M;let P,E,v,L,x=0,T=H.NONE,w=z.C,I=z.C,A=0,R=0;const N=e.elements();for(let h=0,X=N.length;h{const t=e.getAttribute("begin"),i=e.getAttribute("end");_.push({begin:t?t/1e3:0,end:i?i/1e3:0})})),this.addNoteInfo(D,s,l,u,r,I,R,p,p,_),D.TypeLength=n,D.IsGraceNote=c,D.StemDirectionXml=d,D.TremoloInfo=f,D.PlaybackInstrumentId=E,(void 0!==v&&"normal"!==v||void 0!==L)&&(D.Notehead=new Ge(D,v,L)),D.NoteheadColorXml=p,D.NoteheadColor=p,D.PlaybackInstrumentId=E,D.TremoloType=S,D.glissandoType=y,D.slideType=b,this.currentVoiceEntry.addNote(D),d===ct.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 u;const c=h.createFromFraction(t),d=e.element("display-step"),f=e.element("display-octave");let m,p,g;d&&f&&(m=z[d.value.toUpperCase()],p=parseInt(f.value,10),g=new j(m,p,H.NONE,void 0,!0));const S=new Ie(this.currentVoiceEntry,this.currentStaffEntry,c,g,this.currentMeasure,!0);let y=[];const b=e.element("times")||l.element("times"),M=null==(u=null==b?void 0:b.elem)?void 0:u.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,i){var s;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;o&&("begin"===a?(n===(null==(s=this.openBeams.last())?void 0:s.BeamNumber)?(this.beamNumberOffset++,n+=this.beamNumberOffset):this.openBeams.last()&&this.handleOpenBeam(),this.openBeams.push(new ke(n,this.beamNumberOffset))):n+=this.beamNumberOffset);let l=!1;if(!(n>0&&n<=this.openBeams.length&&this.openBeams[n-1]))return void t.debug("[OSMD] invalid beamnumber");for(let e=0,t=this.openBeams[n-1].Notes.length;e1){let n=e.element("time-modification");n&&(n=n.element("actual-notes"));const r=t;for(let t=0,o=r.length;t1&&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=c.Below:i.tupletLabelNumberPlacement=c.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===ct.Down?i.tupletLabelNumberPlacement=c.Below:i.tupletLabelNumberPlacement=c.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=Ue.translateText("ReaderErrorMessages/TupletNoteDurationError","Invalid tuplet note duration.");throw this.musicSheet.SheetErrors.pushMeasureError(e),new g(e)}o&&(this.openTupletNumber++,r=this.openTupletNumber);let h=this.tupletDict[r];h||(h=this.tupletDict[r]=new nt(t,s),h.BracketedXmlValue=i,h.ShowNumberNoneGivenInXml=a,h.tupletLabelNumberPlacement=c.Above);const u=n.attribute("placement");u&&("below"===u.value?h.tupletLabelNumberPlacement=c.Below:h.tupletLabelNumberPlacement=c.Above,h.PlacementFromXml=!0);const d=[];d.push(this.currentNote),h.Notes.push(d),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=c.Below:t.tupletLabelNumberPlacement=c.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===ct.Down?t.tupletLabelNumberPlacement=c.Below:t.tupletLabelNumberPlacement=c.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?void 0:t.value)||"none"!==t.value)}handleTimeModificationNode(e){if(this.tupletDict[this.openTupletNumber])try{const t=this.tupletDict[this.openTupletNumber],i=ae.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=Ue.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;ae.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 st(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=Ue.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=c.NotYetDefined;const i=e.attribute("placement");i&&("above"===i.value?t=c.Above:"below"===i.value&&(t=c.Below));const s=e.attribute("orientation");return s&&("over"===s.value?t=c.Above:"under"===s.value&&(t=c.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;t0?n.RealValue>0?(d=h.multiply(h.minus(n,r),d),this.directionTimestamp=h.plus(d,n)):this.directionTimestamp=h.createFromFraction(d):this.offsetDivisions<0&&(n.RealValue>0?(d=h.multiply(h.minus(n,r),d),this.directionTimestamp=h.minus(n,d)):this.directionTimestamp=h.createFromFraction(d));const f=e.element("direction-type");let m;if(f&&(m=f.element("wedge"),m)){const e=m.attribute("default-y");e&&(u=this.readPosition(e))}this.WedgeYPosXml=u;const p=e.attribute("placement");if(p)try{const e=p.value;"below"===e?this.placement=c.Below:"above"===e&&(this.placement=c.Above)}catch(g){const e=Ue.translateText("ReaderErrorMessages/ExpressionPlacementError","Invalid expression placement -> set to default.");t.debug("ExpressionReader.readExpressionParameters",e,g),this.musicSheet.SheetErrors.pushMeasureError(e),this.placement=c.Below}if(this.placement===c.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=Ue.translateText("ReaderErrorMessages/ExpressionPlacementError","Invalid expression placement. Set to default.");t.debug("ExpressionReader.readExpressionParameters",e,g),this.musicSheet.SheetErrors.pushMeasureError(e),this.placement=c.Below}this.placement===c.NotYetDefined&&(i.Staves.length>1?this.placement=c.Below:i.HasLyrics?this.placement=c.Above:this.placement=c.Below)}read(e,i,s,n=void 0,r=0,o){let a=!1,l=!1;const u=e.element("sound");if(u){const e=u.attribute("tempo"),s=u.attribute("dynamics");if(e){const s=e.value.match(/^(\d+)(\.\d+)?$/);(null==s?void 0:s.length)>0?this.soundTempo=Math.round(Number.parseFloat(e.value)):(t.info("invalid xml tempo: "+e.value),this.soundTempo=100),i.TempoInBPM=this.soundTempo,0===this.musicSheet.DefaultStartTempoInBpm&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),this.musicSheet.HasBPMInfo=!0,a=!0}if(s){const e=s.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){i.metronomeNoteIndex=r;const e=d.element("beat-unit"),t=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=h.createFromFraction(s));const r=parseFloat(n.value);!o&&this.createNewTempoExpressionIfNeeded(i);const a=new ei(void 0,this.placement,this.staffNumber,r,this.currentMultiTempoExpression,!0);a.parentMeasure=i,this.soundTempo=r,i.TempoInBPM=1*this.soundTempo,0===this.musicSheet.DefaultStartTempoInBpm&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),1===i.MeasureNumberXML&&0===this.musicSheet.SourceMeasures.length&&(this.musicSheet.DefaultStartTempoInBpm=this.soundTempo),this.musicSheet.HasBPMInfo=!0,a.dotted=t,a.beatUnit=e.value,this.currentMultiTempoExpression.addExpression(a,""),this.currentMultiTempoExpression.CombinedExpressionsText="test"}}else if(d=c.element("dynamics"),d){const t=void 0!==e.element("notations");this.interpretInstantaneousDynamics(d,i,s,t)}else if(d=c.element("words"),d){const e=c.elements("words");let t="";for(const i of e)t+=i.value;if(d.value=t,d.value&&d.value.toLocaleLowerCase().includes("compound_tempo")&&(d.value=""),a||vt(d.value)||Lt(d.value)){this.createNewTempoExpressionIfNeeded(i),this.currentMultiTempoExpression.CombinedExpressionsText=d.value,(vt(d.value)||Lt(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,i,s)}else d=c.element("wedge"),d?this.interpretWedge(e,d,i,n,i.MeasureNumber):(d=c.element("rehearsal"),d&&this.interpretRehearsalMark(d,i,s,i.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(h.plus(e.AbsoluteTimestamp,t))}addOctaveShift(e,i,s){var n;let r=1;const o=e.element("staff");if(o)try{r=parseInt(o.value,10)}catch(l){const e=Ue.translateText("ReaderErrorMessages/OctaveShiftStaffError","Invalid octave shift staff number. Set to default");this.musicSheet.SheetErrors.pushMeasureError(e),r=1,t.debug("ExpressionReader.addOctaveShift",e,l)}const a=e.element("direction-type");if(a){const o=a.element("octave-shift"),h=this.readPlacement(e);if(void 0!==o&&o.hasAttributes)try{const e=this.readNumber(o);if(o.attribute("size")){const a=parseInt(o.attribute("size").value,10);let l=0;8===a?l=1:15===a&&(l=2);let u=null==(n=o.attribute("type"))?void 0:n.value;if(u||(h===c.Above?u="down":h===c.Below&&(u="up")),"up"===u||"down"===u){const t=new qt(u,l);t.StaffNumber=r,this.getMultiExpression=this.createNewMultiExpressionIfNeeded(i,e),this.getMultiExpression.OctaveShiftStart=t,t.ParentStartMultiExpression=this.getMultiExpression,this.openOctaveShift=t}else if("stop"===u){if(this.openOctaveShift){this.getMultiExpression=this.createNewMultiExpressionIfNeeded(i,this.openOctaveShift.numberXml,s);this.getMultiExpression.OctaveShiftEnd=this.openOctaveShift,this.openOctaveShift.ParentEndMultiExpression=this.getMultiExpression,this.openOctaveShift=void 0}}else u||t.debug("octave-shift missing type in xml")}}catch(l){const e=Ue.translateText("ReaderErrorMessages/OctaveShiftError","Error while reading octave shift.");this.musicSheet.SheetErrors.pushMeasureError(e),t.debug("ExpressionReader.addOctaveShift",e,l)}}}addPedalMarking(e,i,s){var n,r,o;const a=e.element("direction-type");if(a){const e=a.element("pedal");if(void 0!==e&&e.hasAttributes){let a=!1,h=!1;try{switch("yes"===(null==(n=e.attribute("line"))?void 0:n.value)?h=!0:"no"===(null==(r=e.attribute("line"))?void 0:r.value)?(h=!1,a=!0):"yes"===(null==(o=e.attribute("sign"))?void 0:o.value)?a=!0:(a=!1,h=!0),e.attribute("type").value){case"start":this.openPedal&&this.openPedal.IsLine&&this.endOpenPedal(i),this.createNewMultiExpressionIfNeeded(i,-1),this.openPedal=new ks(h,a),this.getMultiExpression.PedalStart=this.openPedal,this.openPedal.ParentStartMultiExpression=this.getMultiExpression;break;case"stop":this.openPedal&&this.endOpenPedal(i,s);break;case"change":this.openPedal&&this.openPedal.IsLine&&(this.openPedal.ChangeEnd=!0,this.createNewMultiExpressionIfNeeded(i,-1),this.getMultiExpression.PedalEnd=this.openPedal,this.openPedal.ParentEndMultiExpression=this.getMultiExpression,this.createNewMultiExpressionIfNeeded(i,-1),this.openPedal=new ks(h,a),this.openPedal.ChangeBegin=!0,this.getMultiExpression.PedalStart=this.openPedal,this.openPedal.ParentStartMultiExpression=this.getMultiExpression)}}catch(l){const e=Ue.translateText("ReaderErrorMessages/PedalError","Error while reading pedal.");this.musicSheet.SheetErrors.pushMeasureError(e),t.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,i,s,n){if(e&&e.hasAttributes)try{switch(e.attribute("type").value){case"start":this.createNewMultiExpressionIfNeeded(i,-1),this.openWavyLine=new Fs(this.placement),this.getMultiExpression.WavyLineStart=this.openWavyLine,this.openWavyLine.ParentStartMultiExpression=this.getMultiExpression;break;case"stop":this.openWavyLine&&(this.createNewMultiExpressionIfNeeded(i,-1,s),this.getMultiExpression.WavyLineEnd=this.openWavyLine,this.openWavyLine.ParentEndMultiExpression=this.getMultiExpression,this.openWavyLine=void 0)}}catch(r){const e=Ue.translateText("ReaderErrorMessages/WavyLineError","Error while reading wavy-line.");this.musicSheet.SheetErrors.pushMeasureError(e),t.debug("ExpressionReader.addWavyLine",e,r)}}initialize(){this.placement=c.NotYetDefined,this.soundTempo=0,this.soundDynamic=0,this.offsetDivisions=0}readPlacement(e){var t;const i=null==(t=e.attribute("placement"))?void 0:t.value;return"above"===i?c.Above:"below"===i?c.Below:c.NotYetDefined}readExpressionPlacement(e,i){try{const t=this.readPosition(e);t<0?this.placement=c.Below:t>0&&(this.placement=c.Above)}catch(s){t.debug("ExpressionReader.readExpressionParameters",i,s)}}readPosition(e){try{const t=parseInt(e.value,10);return t<0?this.placement=c.Below:t>0&&(this.placement=c.Above),t}catch(i){t.debug("ExpressionReader.readExpressionParameters",i)}}interpretInstantaneousDynamics(e,t,i,s){var n,r,o;if(e.hasElements){e.hasAttributes&&e.attribute("default-x")&&(this.directionTimestamp=h.createFromFraction(i));const l=this.readNumber(e);let u=null==(n=e.elements()[0])?void 0:n.name;if("other-dynamics"===u&&(u=e.elements()[0].value),u){if(null==(r=t.Rules)?void 0:r.IgnoreRepeatedDynamics){let e;try{e=P[u]}catch(a){const e=Ue.translateText("ReaderErrorMessages/DynamicError","Error while reading dynamic.");return void this.musicSheet.SheetErrors.pushMeasureError(e)}if((null==(o=this.activeInstantaneousDynamic)?void 0:o.DynEnum)===e)return}s?this.createNewMultiExpressionIfNeeded(t,l,h.createFromFraction(i)):this.createNewMultiExpressionIfNeeded(t,l);const e=new M(u,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 M(u,0,c.NotYetDefined,1,t)}}}interpretWords(e,t,i){var s;const n=e.value;if(t.Rules.IgnoreBracketsWords&&(/^\(\s*\)$/.test(n)||/^\[\s*\]$/.test(n)))return;let r;const o=e.attribute("font-style");let a,l,u;o&&(a=o.value,"italic"===a&&(r=fe.Italic));const c=e.attribute("font-weight");c&&(l=c.value,"bold"===l&&(r=fe.Bold,"italic"===a&&(r=fe.BoldItalic)));const d=e.attribute("color");let f;if(d&&(u=d.value),t.Rules.PlaceWordsInsideStafflineFromXml){const t=null==(s=e.attribute("default-y"))?void 0:s.value;(null==t?void 0:t.length)>0&&(f=Number.parseInt(t,10))}if(n.length>0){if(e.hasAttributes&&e.attribute("default-x")&&(this.directionTimestamp=h.createFromFraction(i)),this.checkIfWordsNodeIsRepetitionInstruction(n))return;this.fillMultiOrTempoExpression(n,t,i,r,u,f),this.initialize()}}readNumber(e){var t;let i=1;const s=null==(t=e.attribute("number"))?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=h.createFromFraction(s));const a=this.readNumber(t),l=null==(o=null==(r=t.attribute("type"))?void 0:r.value)?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===m[l]||("stop"===l?(this.createNewMultiExpressionIfNeeded(i,a,s),this.getMultiExpression.EndOffsetFraction=new h(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,h.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,h.createFromFraction(this.directionTimestamp)),e.TempoExpressions.push(this.currentMultiTempoExpression))}addWedge(e,i,s){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 f(m[o],this.placement,this.staffNumber,i,this.activeInstantaneousDynamic,r);this.lastWedge=e,this.lastWedge.YPosXml=this.WedgeYPosXml,this.openContinuousDynamicExpressions.push(e);let t=this.getMultiExpression;t||(t=this.createNewMultiExpressionIfNeeded(i,r)),t.StartingContinuousDynamic=e,e.StartMultiExpression=t,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,i,s)}catch(n){const e="ReaderErrorMessages/WedgeError, Error while reading Crescendo / Diminuendo.";this.musicSheet.SheetErrors.pushMeasureError(e),t.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;e0)for(let c=0,d=i.TempoExpressions.length;c0&&!this.hasDigit(t)&&this.globalStaffIndex>0){if(e.EntriesList[0].label.indexOf(t)>=0)return!1;break}}let h=ue.CenterBottom;this.musicSheet.Rules.CompactMode&&(h=ue.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,i,s){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){t.debug("VoiceGenerator.addSlur number: ",n)}let a=c.NotYetDefined;const l=r.attribute("placement");l&&l.value&&("above"===l.value?a=c.Above:"below"===l.value&&(a=c.Below));const h=r.attribute("orientation");if(h&&h.value&&("over"===h.value?a=c.Above:"under"===h.value&&(a=c.Below)),"start"===e){let e=new Cs;this.openSlurDict[o]=e,e.StartNote=i,e.idx=s,e.PlacementXml=a}else if("stop"===e){const e=this.openSlurDict[o];if(e){const t=r.name;if("slide"===t||"glissando"===t){const t=e.StartNote,s=new Fe(t);s.AddNote(i),s.EndNote=i,i.NoteGlissando=s,delete this.openSlurDict[o]}else{if(e.idx=s,e.EndNote=i,!i.isDuplicateSlur(e)){i.NoteSlurs.push(e);e.StartNote.NoteSlurs.push(e)}delete this.openSlurDict[o]}}}}}catch(r){const e=Ue.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=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 b=new h(0,1),M=new h(0,1),P=!1;this.maxTieNoteFraction=new h(0,1);let E=!1;const v=[];let L=!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)){const t=parseInt(null==(n=T.attribute("number"))?void 0:n.value,10);Number.isInteger(t)&&(e.MeasureNumberXML=t)}let A;for(let n=0;n0&&(A=I[n-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 i=T.element("divisions");if(i&&(this.divisions=parseInt(i.value,10),isNaN(this.divisions))){const e=Ue.translateText("ReaderErrorMessages/DivisionError","Invalid divisions value at Instrument: ");if(t.debug("InstrumentReader.readNextXmlMeasure",e),this.divisions=this.readDivisionsFromNotes(),!(this.divisions>0))throw P=!0,new g(e+this.instrument.Name);this.musicSheet.SheetErrors.push(e+this.instrument.Name)}if(!T.element("divisions")&&0===this.divisions&&0===this.currentXmlMeasureIndex){const e=Ue.translateText("ReaderErrorMessages/DivisionError","Invalid divisions value at Instrument: ");if(this.divisions=this.readDivisionsFromNotes(),!(this.divisions>0))throw P=!0,new g(e+this.instrument.Name);this.musicSheet.SheetErrors.push(e+this.instrument.Name)}this.addAbstractInstruction(T,s,A,b.clone()),b.Equals(new h(0,1))&&this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex],T)&&this.saveAbstractInstructionList(this.instrument.Staves.length,!0),this.isAttributesNodeAtEndOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex],T,b)&&this.saveClefInstructionAtEndOfMeasure();const n=T.elements("staff-details");for(const e of n){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 r=T.element("measure-style");if(r){const t=r.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){console.log("multirest parse error: "+x)}}}}else if("note"===T.name){let e=!0;"no"===(null==(r=T.attribute("print-object"))?void 0:r.value)&&(e=!1);const n=this.getNoteStaff(T);this.currentStaff=this.instrument.Staves[n-1];const o=void 0!==T.element("chord");if(T.element("voice")){const e=parseInt(T.element("voice").value,10);this.currentVoiceGenerator=this.getOrCreateVoiceGenerator(e,n-1)}else o&&this.currentVoiceGenerator||(this.currentVoiceGenerator=this.getOrCreateVoiceGenerator(1,n-1));let a,l=0,u=new h(0,1),c=2;if(T.element("duration")){if(l=parseInt(T.element("duration").value,10),isNaN(l)){const e=Ue.translateText("ReaderErrorMessages/NoteDurationError","Invalid Note Duration.");this.musicSheet.SheetErrors.pushMeasureError(e),t.debug("InstrumentReader.readNextXmlMeasure",e);continue}if(u=new h(l,4*this.divisions),0===l?u=this.getNoteDurationFromTypeNode(T):a=this.getNoteDurationFromTypeNode(T),T.element("time-modification")){u=this.getNoteDurationForTuplet(T);const e=T.element("time-modification");(null==e?void 0:e.element("normal-notes"))&&(c=parseInt(e.element("normal-notes").value,10))}}const d=void 0!==T.element("rest"),f=T.combinedElement("notations"),m=void 0!==T.element("grace")||0===l||o&&E;let p=!1,g=!1;if(m){const e=T.element("duration"),t=T.element("grace");if(t&&t.attributes()&&t.attribute("slash")){"yes"===t.attribute("slash").value&&(p=!0)}e||(u=this.getNoteDurationFromTypeNode(T)),f&&f.element("slur")&&(g=!0)}const[S,y]=this.getCueNoteAndNoteTypeXml(T),[P,L,x]=this.getStemDirectionAndColors(T);let w,I=0,A="",R="",N="";if(f){const e=f.element("ornaments");if(e){w=this.getTremoloInfo(e),this.getWavyLines(e,T,b,M);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||(u=new h(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,b,M,this.currentMeasure.MeasureNumber,!1),t.addWavyLine(e,this.currentMeasure,b,M))}}const t=f.elements("glissando");t.find((e=>"start"===e.attribute("type").value))&&(R="start");const i=f.elements("slide");i.find((e=>"start"===e.attribute("type").value))&&(N="start")}const C=o?M.clone():b.clone();this.currentStaffEntry=this.currentMeasure.findOrCreateStaffEntry(C,this.inSourceMeasureInstrumentIndex+n-1,this.currentStaff).staffEntry,(!this.currentVoiceGenerator.hasVoiceEntry()||!o&&!m&&!E||m&&!E||m&&!o||!m&&E)&&this.currentVoiceGenerator.createVoiceEntry(C,this.currentStaffEntry,this.activeKey,this.ActiveRhythm,m,p,g),m||o||(M=b.clone(),b.Add(u)),o&&void 0!==this.currentStaffEntry&&this.currentStaffEntry.ParentStaff!==this.currentStaff&&(this.currentStaffEntry=this.currentVoiceGenerator.checkForStaffEntryLink(this.inSourceMeasureInstrumentIndex+n-1,this.currentStaff,this.currentStaffEntry,this.currentMeasure));const B=void 0!==this.currentStaffEntry&&void 0!==this.currentStaffEntry.Timestamp&&this.currentStaffEntry.Timestamp.Equals(new h(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,u,a,y,c,d,this.currentStaffEntry,this.currentMeasure,i,this.maxTieNoteFraction,o,s,e,S,m,P,w,L,x,D,A,R,N),void 0!==f&&f.element("dynamics")){const e=this.expressionReaders[this.readExpressionStaffNumber(T)-1];e&&(e.readExpressionParameters(T,this.instrument,this.divisions,b,M,this.currentMeasure.MeasureNumber,!1),e.read(T,this.currentMeasure,M,void 0,v.length))}E=m}else if("forward"===T.name){const e=parseInt(T.element("duration").value,10);b.Add(new h(e,4*this.divisions))}else if("backup"===T.name){const e=parseInt(T.element("duration").value,10);b.Sub(new h(e,4*this.divisions)),b.IsNegative()&&(b=new h(0,1)),M.Sub(new h(e,4*this.divisions)),M.IsNegative()&&(M=new h(0,1))}else if("direction"===T.name){const t=T.elements("direction-type"),i=T.element("direction-type");let s=Math.min(1,b.RealValue);void 0!==this.activeRhythm&&this.activeRhythm.Rhythm&&(s/=this.activeRhythm.Rhythm.RealValue);let n=!1;if(this.repetitionInstructionReader&&(n=this.repetitionInstructionReader.handleRepetitionInstructionsFromWordsOrSymbols(i,s)),!n){let s=this.expressionReaders[0];const n=this.readExpressionStaffNumber(T)-1;if(nnull==e?void 0:e.toLocaleLowerCase())).includes(null==(o=n.value)?void 0:o.toLocaleLowerCase())&&(this.currentGradualChangeMeasure=this.currentMeasure,this.currentMeasure.speedInfo={startWord:null==(a=n.value)?void 0:a.toLocaleLowerCase(),startXmlNoteIndex:v.length,endXmlNoteIndex:0,resetXmlNoteIndex:0,startMeasureListIndex:this.currentXmlMeasureIndex,endMeasureListIndex:0,resetMeasureListIndex:0},this.xmlNotes=[]),n.value.startsWith(bt)&&(null==(l=this.currentGradualChangeMeasure)?void 0:l.speedInfo)&&(this.currentGradualChangeMeasure.speedInfo={...this.currentGradualChangeMeasure.speedInfo,endXmlNoteIndex:this.xmlNotes.length,endMeasureListIndex:this.currentXmlMeasureIndex}),(null==(u=n.value)?void 0:u.toLocaleLowerCase())==="a tempo".toLocaleLowerCase()&&(null==(c=this.currentGradualChangeMeasure)?void 0:c.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=[]}L=!(!n.value||"hiddenspeed"!==n.value.toLocaleLowerCase()),n.value&&n.value.toLocaleLowerCase().includes("compound_tempo")&&(e.CompoundTempo=(null==(m=null==(f=null==(d=n.value.split("("))?void 0:d[1])?void 0:f.split(")"))?void 0:m[0])||"",this.preCompoundTempo=e.CompoundTempo)}if(t.find((e=>e.element("metronome")))&&(null==(p=this.currentGradualChangeMeasure)?void 0:p.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,b,M,this.currentMeasure.MeasureNumber,!1),s.read(T,this.currentMeasure,b,M.clone(),v.length,L)}}}else if("barline"===T.name){if(this.repetitionInstructionReader){this.repetitionInstructionReader.handleLineRepetitionInstructions(T)&&(this.currentMeasure.HasEndLine=!0)}const e=T.attribute("location"),t=null!=(S=null==e?void 0:e.value)?S:"right";if(n===I.length-1||"right"===t){const e=null==(y=T.element("bar-style"))?void 0:y.value;e&&(this.currentMeasure.endingBarStyleXml=e,this.currentMeasure.endingBarStyleEnum=Ne.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){t.debug("InstrumentReader.readTempoInstruction",x)}else if("harmony"===T.name){const e=this.getNoteStaff(T);this.currentStaff=this.instrument.Staves[e-1];const t=b.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)if(this.voiceGeneratorsDict.hasOwnProperty(e)){this.voiceGeneratorsDict[e].checkForOpenBeam()}if(this.currentXmlMeasureIndex===this.xmlMeasureList.length-1){for(let e=0;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(P)throw new g(x.Message);const e=Ue.translateText("ReaderErrorMessages/MeasureError","Error while reading Measure.");this.musicSheet.SheetErrors.pushMeasureError(e),t.debug("InstrumentReader.readNextXmlMeasure",e,x)}return this.previousMeasure=this.currentMeasure,this.currentXmlMeasureIndex+=1,!0}getStemDirectionAndColors(e){let t,i=ct.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;t0?this.musicSheet.SourceMeasures[0]:this.currentMeasure;const i=new K(J.G,0,2);let s;t.FirstInstructionsStaffEntries[e]?(s=t.FirstInstructionsStaffEntries[e],s.removeFirstInstructionOfTypeClefInstruction()):(s=new Ke(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 Q(void 0,0,Z.major);for(let i=this.inSourceMeasureInstrumentIndex;i0&&"backup"===i[s-1].name)return!0;let n=-1;for(let r=0;r0||n<0}isAttributesNodeAtEndOfMeasure(e,t,i){var s;if(i.Equals(null==(s=this.ActiveRhythm)?void 0:s.Rhythm))return!0;const n=e.elements().slice();let r=0;for(let a=0;ao}getNoteDurationFromTypeNode(e){const t=e.element("type");if(t){const e=t.value;return ze.getNoteDurationFromType(e)}return new h(0,4*this.divisions)}addAbstractInstruction(e,i,s,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 h=0,d=o.length;hthis.currentClefNumber&&(r=this.currentClefNumber),this.currentClefNumber=r+1}catch(c){a=Ue.translateText("ReaderErrorMessages/ClefError","Invalid clef. Using default."),this.musicSheet.SheetErrors.pushMeasureError(a),r=1,this.currentClefNumber=r+1}const g=new K(i,d,s);this.abstractInstructions.push([r,g,n])}if(void 0!==e.element("key")&&this.instrument.MidiInstrumentId!==q.Percussion){let i=0;const s=e.element("key").element("fifths");if(s)try{i=parseInt(s.value,10)}catch(l){a=Ue.translateText("ReaderErrorMessages/KeyError","Invalid key. Set to default."),this.musicSheet.SheetErrors.pushMeasureError(a),i=0,t.debug("InstrumentReader.addAbstractInstruction",a,l)}let r=Z.none,o=e.element("key");if(o&&(o=o.element("mode")),o)try{r=Z[o.value]}catch(l){a=Ue.translateText("ReaderErrorMessages/KeyError","Invalid key/mode. Set to default."),this.musicSheet.SheetErrors.pushMeasureError(a),r=Z.major,t.debug("InstrumentReader.addAbstractInstruction",a,l)}const h=new Q(void 0,i,r);this.abstractInstructions.push([1,h,n])}if(e.element("time")){const i=e.element("time");let s=x.NONE,r=!0;if(void 0!==i&&i.hasAttributes){const e=i.attribute("symbol");e&&("common"===e.value?s=x.COMMON:"cut"===e.value&&(s=x.CUT));const t=i.attribute("print-object");t&&"no"===t.value&&(r=!1)}let o=0,u=0;const c=i&&void 0!==i.element("senza-misura"),d=e.elements("time"),f=[],m=[];for(let e=0,t=d.length;e0&&void 0!==m&&f.length===m.length){const e=f.length,t=new Array(e);let i=0;for(let s=0;s=0;i--){const s=this.abstractInstructions[i],n=s[0],r=s[1],o=s[2];if(r instanceof K){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 K){const e=new Ke(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 Ke(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 Ke(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 Ke(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 Ke(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 Q){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=0;e--){const t=this.abstractInstructions[e][0],i=this.abstractInstructions[e][1];if(i instanceof K){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 Ke(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 h(i,4*this.divisions)}readExpressionStaffNumber(e){let i=1;if(e.element("staff")){const n=e.element("staff");if(n)try{i=parseInt(n.value,10)}catch(s){const e=Ue.translateText("ReaderErrorMessages/ExpressionStaffError","Invalid Expression staff number. Set to default.");this.musicSheet.SheetErrors.pushMeasureError(e),i=1,t.debug("InstrumentReader.readExpressionStaffNumber",e,s)}}return i}readDivisionsFromNotes(){let e=0,i=this.currentXmlMeasureIndex,s=!1;for(;!s;){const r=this.xmlMeasureList[i].elements();for(let i=0,o=r.length;i0){s=!0;break}}if(0===e&&(i++,i===this.xmlMeasureList.length)){const e=Ue.translateText("ReaderErrorMEssages/DivisionsError","Invalid divisions value at Instrument: ");throw new g(e+this.instrument.Name)}}return e}getCueNoteAndNoteTypeXml(e){let t=!1;e.element("cue")&&(t=!0);const i=e.element("type");let s=Xe.UNDEFINED;if(i){const e=i.attribute("size");"cue"===(null==e?void 0:e.value)&&(t=!0),s=ze.StringToNoteType(i.value)}return[t,s]}getStemDirectionType(e){switch(e.value){case"down":return ct.Down;case"up":return ct.Up;case"double":return ct.Double;case"none":return ct.None;default:return ct.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 i=1;return this.instrument.Staves.length>1&&e.element("staff")&&(i=parseInt(e.element("staff").value,10),isNaN(i)&&(t.debug("InstrumentReader.readNextXmlMeasure.get staff number"),i=1)),i}}class Ws{}Ws.MidiInstrument={banjo:q.Banjo,blockfloete:q.Recorder,brass:q.Trombone,bratsche:q.Viola,cello:q.Cello,clarinet:q.Clarinet,contrabass:q.Contrabass,"steel drum":q.Steel_Drums,drums:q.Percussion,flute:q.Flute,floete:q.Flute,frenchhorn:q.French_Horn,gitarre:q.Acoustic_Guitar_nylon,guitar:q.Acoustic_Guitar_nylon,harfe:q.Orchestral_Harp,harp:q.Orchestral_Harp,klarinette:q.Clarinet,klavier:q.Acoustic_Grand_Piano,kontrabass:q.Contrabass,oboe:q.Oboe,organ:q.Church_Organ,orgel:q.Church_Organ,orgue:q.Church_Organ,percussion:q.Percussion,piano:q.Acoustic_Grand_Piano,piccolo:q.Piccolo,posaune:q.Trombone,recorder:q.Recorder,sax:q.Tenor_Sax,schlagwerk:q.Percussion,schlagzeug:q.Percussion,steeldrum:q.Steel_Drums,streicher:q.String_Ensemble_1,strings:q.String_Ensemble_1,tpt:q.Trumpet,trombone:q.Trombone,trompete:q.Trumpet,trumpet:q.Trumpet,tuba:q.Tuba,unnamed:q.Acoustic_Grand_Piano,viola:q.Viola,violin:q.Violin,"violon-c":q.Cello,"violon.":q.Violin,voice:q.Synth_Voice,woodblock:q.Woodblock,alt:q.Synth_Voice,alto:q.Synth_Voice,bariton:q.Synth_Voice,baritone:q.Synth_Voice,bass:q.Synth_Voice,sopran:q.Synth_Voice,tenor:q.Synth_Voice},Ws.MidiInstrumentSounds={"brass.alphorn":q.French_Horn,"brass.alto-horn":q.French_Horn,"brass.baritone-horn":q.French_Horn,"brass.bugle":q.Trumpet,"brass.bugle.alto":q.Trumpet,"brass.bugle.baritone":q.Trombone,"brass.bugle.contrabass":q.Trombone,"brass.bugle.euphonium-bugle":q.French_Horn,"brass.bugle.mellophone-bugle":q.French_Horn,"brass.bugle.soprano":q.Trumpet,"brass.cimbasso":q.Trombone,"brass.conch-shell":q.Flute,"brass.cornet":q.Trumpet,"brass.cornet.soprano":q.Trumpet,"brass.cornett":q.Trumpet,"brass.cornett.tenor":q.Trumpet,"brass.cornettino":q.Trumpet,"brass.didgeridoo":q.Flute,"brass.euphonium":q.French_Horn,"brass.fiscorn":q.French_Horn,"brass.flugelhorn":q.French_Horn,"brass.french-horn":q.French_Horn,"brass.group":q.Brass_Section,"brass.group.synth":q.Synth_Brass_1,"brass.helicon":q.French_Horn,"brass.horagai":q.Trumpet,"brass.kuhlohorn":q.French_Horn,"brass.mellophone":q.French_Horn,"brass.natural-horn":q.French_Horn,"brass.ophicleide":q.French_Horn,"brass.posthorn":q.French_Horn,"brass.saxhorn":q.French_Horn,"brass.sousaphone":q.Tuba,"brass.trombone":q.Trombone,"brass.trombone.alto":q.Trombone,"brass.trombone.bass":q.Trombone,"brass.trombone.contrabass":q.Trombone,"brass.trombone.tenor":q.Trombone,"brass.trumpet":q.Trumpet,"brass.trumpet.baroque":q.Trumpet,"brass.trumpet.bass":q.Trombone,"brass.trumpet.bflat":q.Trumpet,"brass.trumpet.c":q.Trumpet,"brass.trumpet.d":q.Trumpet,"brass.trumpet.piccolo":q.Trumpet,"brass.trumpet.pocket":q.Trumpet,"brass.trumpet.slide":q.Trumpet,"brass.trumpet.tenor":q.Trumpet,"brass.tuba":q.Tuba,"brass.tuba.bass":q.Tuba,"brass.tuba.subcontrabass":q.Tuba,"brass.vienna-horn":q.French_Horn,"brass.wagner-tuba":q.French_Horn,"drum.ashiko":q.Shakuhachi,"drum.bass-drum":q.Percussion,"drum.bongo":q.Percussion,"drum.bougarabou":q.Percussion,"drum.buffalo-drum":q.Percussion,"drum.cajon":q.Percussion,"drum.chenda":q.Percussion,"drum.chu-daiko":q.Percussion,"drum.conga":q.Percussion,"drum.cuica":q.Percussion,"drum.dabakan":q.Percussion,"drum.daff":q.Percussion,"drum.dafli":q.Percussion,"drum.daibyosi":q.Percussion,"drum.damroo":q.Percussion,"drum.darabuka":q.Percussion,"drum.def":q.Percussion,"drum.dhol":q.Percussion,"drum.dholak":q.Percussion,"drum.djembe":q.Percussion,"drum.doira":q.Percussion,"drum.dondo":q.Percussion,"drum.doun-doun-ba":q.Percussion,"drum.duff":q.Percussion,"drum.dumbek":q.Percussion,"drum.fontomfrom":q.Percussion,"drum.frame-drum":q.Percussion,"drum.frame-drum.arabian":q.Percussion,"drum.geduk":q.Percussion,"drum.ghatam":q.Percussion,"drum.gome":q.Percussion,"drum.group":q.Percussion,"drum.group.chinese":q.Percussion,"drum.group.ewe":q.Percussion,"drum.group.indian":q.Percussion,"drum.group.set":q.Percussion,"drum.hand-drum":q.Percussion,"drum.hira-daiko":q.Percussion,"drum.ibo":q.Percussion,"drum.igihumurizo":q.Percussion,"drum.inyahura":q.Percussion,"drum.ishakwe":q.Percussion,"drum.jang-gu":q.Percussion,"drum.kagan":q.Percussion,"drum.kakko":q.Percussion,"drum.kanjira":q.Percussion,"drum.kendhang":q.Percussion,"drum.kendhang.ageng":q.Percussion,"drum.kendhang.ciblon":q.Percussion,"drum.kenkeni":q.Percussion,"drum.khol":q.Percussion,"drum.kick-drum":q.Percussion,"drum.kidi":q.Percussion,"drum.ko-daiko":q.Percussion,"drum.kpanlogo":q.Percussion,"drum.kudum":q.Percussion,"drum.lambeg":q.Percussion,"drum.lion-drum":q.Percussion,"drum.log-drum":q.Percussion,"drum.log-drum.african":q.Percussion,"drum.log-drum.native":q.Percussion,"drum.log-drum.nigerian":q.Percussion,"drum.madal":q.Percussion,"drum.maddale":q.Percussion,"drum.mridangam":q.Percussion,"drum.naal":q.Percussion,"drum.nagado-daiko":q.Percussion,"drum.nagara":q.Percussion,"drum.naqara":q.Percussion,"drum.o-daiko":q.Percussion,"drum.okawa":q.Percussion,"drum.okedo-daiko":q.Percussion,"drum.pahu-hula":q.Percussion,"drum.pakhawaj":q.Percussion,"drum.pandeiro":q.Percussion,"drum.pandero":q.Percussion,"drum.powwow":q.Percussion,"drum.pueblo":q.Percussion,"drum.repinique":q.Percussion,"drum.riq":q.Percussion,"drum.rototom":q.Percussion,"drum.sabar":q.Percussion,"drum.sakara":q.Percussion,"drum.sampho":q.Percussion,"drum.sangban":q.Percussion,"drum.shime-daiko":q.Percussion,"drum.slit-drum":q.Percussion,"drum.slit-drum.krin":q.Percussion,"drum.snare-drum":q.Percussion,"drum.snare-drum.electric":q.Synth_Drum,"drum.sogo":q.Percussion,"drum.surdo":q.Percussion,"drum.tabla":q.Percussion,"drum.tabla.bayan":q.Percussion,"drum.tabla.dayan":q.Percussion,"drum.tabor":q.Percussion,"drum.taiko":q.Taiko_Drum,"drum.talking":q.Percussion,"drum.tama":q.Percussion,"drum.tamborim":q.Percussion,"drum.tamborita":q.Percussion,"drum.tambourine":q.Percussion,"drum.tamte":q.Percussion,"drum.tangku":q.Percussion,"drum.tan-tan":q.Percussion,"drum.taphon":q.Percussion,"drum.tar":q.Percussion,"drum.tasha":q.Percussion,"drum.tenor-drum":q.Percussion,"drum.teponaxtli":q.Percussion,"drum.thavil":q.Percussion,"drum.the-box":q.Percussion,"drum.timbale":q.Percussion,"drum.timpani":q.Timpani,"drum.tinaja":q.Percussion,"drum.toere":q.Percussion,"drum.tombak":q.Percussion,"drum.tom-tom":q.Melodic_Tom,"drum.tom-tom.synth":q.Melodic_Tom,"drum.tsuzumi":q.Percussion,"drum.tumbak":q.Percussion,"drum.uchiwa-daiko":q.Percussion,"drum.udaku":q.Percussion,"drum.udu":q.Percussion,"drum.zarb":q.Percussion,"effect.applause":q.Applause,"effect.gunshot":q.Gunshot,"effect.helicopter":q.Helicopter,"effect.telephone-ring":q.Telephone_Ring,"keyboard.accordion":q.Accordion,"keyboard.bandoneon":q.Accordion,"keyboard.celesta":q.Celesta,"keyboard.clavichord":q.Harpsichord,"keyboard.clavichord.synth":q.Harpsichord,"keyboard.concertina":q.Accordion,"keyboard.fortepiano":q.Acoustic_Grand_Piano,"keyboard.harmonium":q.Drawbar_Organ,"keyboard.harpsichord":q.Harpsichord,"keyboard.ondes-martenot":q.Pad_3_polysynth,"keyboard.organ":q.Church_Organ,"keyboard.organ.drawbar":q.Percussive_Organ,"keyboard.organ.percussive":q.Rock_Organ,"keyboard.organ.pipe":q.Church_Organ,"keyboard.organ.reed":q.Church_Organ,"keyboard.organ.rotary":q.Rock_Organ,"keyboard.piano":q.Acoustic_Grand_Piano,"keyboard.piano.electric":q.Electric_Grand_Piano,"keyboard.piano.grand":q.Acoustic_Grand_Piano,"keyboard.piano.honky-tonk":q.Honky_tonk_Piano,"keyboard.piano.prepared":q.Acoustic_Grand_Piano,"keyboard.piano.toy":q.Honky_tonk_Piano,"keyboard.piano.upright":q.Acoustic_Grand_Piano,"keyboard.virginal":q.Acoustic_Grand_Piano,"metal.adodo":q.Xylophone,"metal.anvil":q.Xylophone,"metal.babendil":q.Xylophone,"metal.bells.agogo":q.Agogo,"metal.bells.almglocken":q.Tubular_Bells,"metal.bells.bell-plate":q.Tubular_Bells,"metal.bells.bell-tree":q.Tubular_Bells,"metal.bells.carillon":q.Tubular_Bells,"metal.bells.chimes":q.Tinkle_Bell,"metal.bells.chimta":q.Tubular_Bells,"metal.bells.chippli":q.Tubular_Bells,"metal.bells.church":q.Tubular_Bells,"metal.bells.cowbell":q.Percussion,"metal.bells.dawuro":q.Percussion,"metal.bells.gankokwe":q.Percussion,"metal.bells.ghungroo":q.Percussion,"metal.bells.hatheli":q.Percussion,"metal.bells.jingle-bell":q.Percussion,"metal.bells.khartal":q.Percussion,"metal.bells.mark-tree":q.Percussion,"metal.bells.sistrum":q.Percussion,"metal.bells.sleigh-bells":q.Percussion,"metal.bells.temple":q.Percussion,"metal.bells.tibetan":q.Percussion,"metal.bells.tinklebell":q.Percussion,"metal.bells.trychel":q.Percussion,"metal.bells.wind-chimes":q.Percussion,"metal.bells.zills":q.Percussion,"metal.berimbau":q.Flute,"metal.brake-drums":q.Percussion,"metal.crotales":q.Percussion,"metal.cymbal.bo":q.Percussion,"metal.cymbal.ceng-ceng":q.Percussion,"metal.cymbal.chabara":q.Percussion,"metal.cymbal.chinese":q.Percussion,"metal.cymbal.ching":q.Percussion,"metal.cymbal.clash":q.Percussion,"metal.cymbal.crash":q.Percussion,"metal.cymbal.finger":q.Percussion,"metal.cymbal.hand":q.Percussion,"metal.cymbal.kesi":q.Percussion,"metal.cymbal.manjeera":q.Percussion,"metal.cymbal.reverse":q.Percussion,"metal.cymbal.ride":q.Percussion,"metal.cymbal.sizzle":q.Percussion,"metal.cymbal.splash":q.Percussion,"metal.cymbal.suspended":q.Percussion,"metal.cymbal.tebyoshi":q.Percussion,"metal.cymbal.tibetan":q.Percussion,"metal.cymbal.tingsha":q.Percussion,"metal.flexatone":q.Percussion,"metal.gong":q.Percussion,"metal.gong.ageng":q.Percussion,"metal.gong.agung":q.Percussion,"metal.gong.chanchiki":q.Percussion,"metal.gong.chinese":q.Percussion,"metal.gong.gandingan":q.Percussion,"metal.gong.kempul":q.Percussion,"metal.gong.kempyang":q.Percussion,"metal.gong.ketuk":q.Percussion,"metal.gong.kkwenggwari":q.Percussion,"metal.gong.luo":q.Percussion,"metal.gong.singing":q.Percussion,"metal.gong.thai":q.Percussion,"metal.guira":q.Percussion,"metal.hang":q.Percussion,"metal.hi-hat":q.Percussion,"metal.jaw-harp":q.Percussion,"metal.kengong":q.Percussion,"metal.murchang":q.Percussion,"metal.musical-saw":q.Percussion,"metal.singing-bowl":q.Percussion,"metal.spoons":q.Percussion,"metal.steel-drums":q.Percussion,"metal.tamtam":q.Percussion,"metal.thundersheet":q.Percussion,"metal.triangle":q.Percussion,"metal.washboard":q.Percussion,"pitched-percussion.angklung":q.Xylophone,"pitched-percussion.balafon":q.Xylophone,"pitched-percussion.bell-lyre":q.Xylophone,"pitched-percussion.bells":q.Tubular_Bells,"pitched-percussion.bianqing":q.Xylophone,"pitched-percussion.bianzhong":q.Xylophone,"pitched-percussion.bonang":q.Xylophone,"pitched-percussion.cimbalom":q.Xylophone,"pitched-percussion.crystal-glasses":q.Xylophone,"pitched-percussion.dan-tam-thap-luc":q.Xylophone,"pitched-percussion.fangxiang":q.Xylophone,"pitched-percussion.gandingan-a-kayo":q.Xylophone,"pitched-percussion.gangsa":q.Xylophone,"pitched-percussion.gender":q.Xylophone,"pitched-percussion.giying":q.Xylophone,"pitched-percussion.glass-harmonica":q.Xylophone,"pitched-percussion.glockenspiel":q.Glockenspiel,"pitched-percussion.glockenspiel.alto":q.Glockenspiel,"pitched-percussion.glockenspiel.soprano":q.Glockenspiel,"pitched-percussion.gyil":q.Xylophone,"pitched-percussion.hammer-dulcimer":q.Dulcimer,"pitched-percussion.handbells":q.Tubular_Bells,"pitched-percussion.handchimes":q.Tubular_Bells,"pitched-percussion.kalimba":q.Kalimba,"pitched-percussion.kantil":q.Xylophone,"pitched-percussion.khim":q.Xylophone,"pitched-percussion.kulintang":q.Xylophone,"pitched-percussion.kulintang-a-kayo":q.Xylophone,"pitched-percussion.kulintang-a-tiniok":q.Xylophone,"pitched-percussion.likembe":q.Xylophone,"pitched-percussion.luntang":q.Xylophone,"pitched-percussion.marimba":q.Marimba,"pitched-percussion.marimba.bass":q.Marimba,"pitched-percussion.mbira":q.Marimba,"pitched-percussion.mbira.array":q.Marimba,"pitched-percussion.metallophone":q.Xylophone,"pitched-percussion.metallophone.alto":q.Xylophone,"pitched-percussion.metallophone.bass":q.Xylophone,"pitched-percussion.metallophone.soprano":q.Xylophone,"pitched-percussion.music-box":q.Glockenspiel,"pitched-percussion.pelog-panerus":q.Xylophone,"pitched-percussion.pemade":q.Xylophone,"pitched-percussion.penyacah":q.Xylophone,"pitched-percussion.ranat.ek":q.Xylophone,"pitched-percussion.ranat.ek-lek":q.Xylophone,"pitched-percussion.ranat.thum":q.Xylophone,"pitched-percussion.ranat.thum-lek":q.Xylophone,"pitched-percussion.reyong":q.Xylophone,"pitched-percussion.sanza":q.Xylophone,"pitched-percussion.saron-barung":q.Xylophone,"pitched-percussion.saron-demong":q.Xylophone,"pitched-percussion.saron-panerus":q.Xylophone,"pitched-percussion.slendro-panerus":q.Xylophone,"pitched-percussion.slentem":q.Xylophone,"pitched-percussion.tsymbaly":q.Xylophone,"pitched-percussion.tubes":q.Tubular_Bells,"pitched-percussion.tubular-bells":q.Tubular_Bells,"pitched-percussion.vibraphone":q.Vibraphone,"pitched-percussion.xylophone":q.Xylophone,"pitched-percussion.xylophone.alto":q.Xylophone,"pitched-percussion.xylophone.bass":q.Xylophone,"pitched-percussion.xylophone.soprano":q.Xylophone,"pitched-percussion.xylorimba":q.Xylophone,"pitched-percussion.yangqin":q.Xylophone,"pluck.archlute":q.Acoustic_Guitar_nylon,"pluck.autoharp":q.Orchestral_Harp,"pluck.baglama":q.Orchestral_Harp,"pluck.bajo":q.Acoustic_Guitar_steel,"pluck.balalaika":q.Acoustic_Guitar_steel,"pluck.balalaika.alto":q.Acoustic_Guitar_steel,"pluck.balalaika.bass":q.Acoustic_Guitar_steel,"pluck.balalaika.contrabass":q.Acoustic_Guitar_steel,"pluck.balalaika.piccolo":q.Acoustic_Guitar_steel,"pluck.balalaika.prima":q.Acoustic_Guitar_steel,"pluck.balalaika.secunda":q.Acoustic_Guitar_steel,"pluck.bandola":q.Acoustic_Guitar_steel,"pluck.bandura":q.Acoustic_Guitar_steel,"pluck.bandurria":q.Acoustic_Guitar_steel,"pluck.banjo":q.Banjo,"pluck.banjo.tenor":q.Banjo,"pluck.banjolele":q.Banjo,"pluck.barbat":q.Acoustic_Guitar_steel,"pluck.bass":q.Electric_Bass_finger,"pluck.bass.acoustic":q.Acoustic_Bass,"pluck.bass.bolon":q.Electric_Bass_finger,"pluck.bass.electric":q.Electric_Bass_finger,"pluck.bass.fretless":q.Fretless_Bass,"pluck.bass.guitarron":q.Acoustic_Bass,"pluck.bass.synth":q.Synth_Bass_1,"pluck.bass.synth.lead":q.Synth_Bass_2,"pluck.celtic-harp":q.Orchestral_Harp,"pluck.charango":q.Acoustic_Guitar_nylon,"pluck.chitarra-battente":q.Acoustic_Guitar_nylon,"pluck.cithara":q.Acoustic_Guitar_nylon,"pluck.cittern":q.Acoustic_Guitar_nylon,"pluck.cuatro":q.Acoustic_Guitar_nylon,"pluck.dulcimer":q.Dulcimer,"pluck.dutar":q.Acoustic_Grand_Piano,"pluck.duxianqin":q.Dulcimer,"pluck.ektara":q.Acoustic_Guitar_nylon,"pluck.guitar":q.Acoustic_Guitar_nylon,"pluck.guitar.acoustic":q.Acoustic_Guitar_nylon,"pluck.guitar.electric":q.Electric_Guitar_clean,"pluck.guitar.nylon-string":q.Electric_Guitar_clean,"pluck.guitar.pedal-steel":q.Electric_Guitar_clean,"pluck.guitar.portuguese":q.Acoustic_Guitar_nylon,"pluck.guitar.requinto":q.Acoustic_Guitar_nylon,"pluck.guitar.resonator":q.Acoustic_Guitar_nylon,"pluck.guitar.steel-string":q.Acoustic_Guitar_steel,"pluck.harp":q.Orchestral_Harp,"pluck.harp-guitar":q.Orchestral_Harp,"pluck.huapanguera":q.Orchestral_Harp,"pluck.lute":q.Acoustic_Grand_Piano,"pluck.lyre":q.Orchestral_Harp,"pluck.mandobass":q.Acoustic_Guitar_nylon,"pluck.mandocello":q.Acoustic_Guitar_nylon,"pluck.mandola":q.Acoustic_Guitar_nylon,"pluck.mandolin":q.Acoustic_Guitar_nylon,"pluck.mandolin.octave":q.Acoustic_Guitar_nylon,"pluck.setar":q.Acoustic_Guitar_nylon,"pluck.shamisen":q.Shamisen,"pluck.sitar":q.Sitar,"pluck.synth":q.Electric_Bass_pick,"pluck.synth.charang":q.Electric_Bass_pick,"pluck.synth.chiff":q.Electric_Bass_pick,"pluck.synth.stick":q.Electric_Bass_pick,"pluck.tambura":q.Acoustic_Grand_Piano,"pluck.ukulele":q.Banjo,"pluck.ukulele.tenor":q.Banjo,"strings.arpeggione":q.Cello,"strings.cello":q.Cello,"strings.cello.piccolo":q.Cello,"strings.contrabass":q.Contrabass,"strings.fiddle":q.Fiddle,"strings.fiddle.hardanger":q.Fiddle,"strings.group":q.String_Ensemble_1,"strings.group.synth":q.Synth_Strings_1,"strings.octobass":q.Contrabass,"strings.tromba-marina":q.Contrabass,"strings.vielle":q.Violin,"strings.viol":q.Violin,"strings.viol.alto":q.Violin,"strings.viol.bass":q.Violin,"strings.viol.tenor":q.Violin,"strings.viol.treble":q.Violin,"strings.viol.violone":q.Violin,"strings.viola":q.Viola,"strings.viola-damore":q.Viola,"strings.violin":q.Violin,"strings.violono.piccolo":q.Violin,"strings.violotta":q.Viola,"synth.group":q.Pad_3_polysynth,"synth.group.fifths":q.Pad_3_polysynth,"synth.group.orchestra":q.Orchestra_Hit,"synth.pad":q.Pad_1_new_age,"synth.pad.bowed":q.Pad_1_new_age,"synth.pad.choir":q.Pad_4_choir,"synth.pad.halo":q.Acoustic_Grand_Piano,"synth.pad.polysynth":q.Pad_3_polysynth,"voice.alto":q.Voice_Oohs,"voice.baritone":q.Voice_Oohs,"voice.bass":q.Voice_Oohs,"voice.female":q.Synth_Voice,"voice.kazoo":q.Flute,"voice.male":q.Voice_Oohs,"voice.mezzo-soprano":q.Voice_Oohs,"voice.soprano":q.Voice_Oohs,"voice.synth":q.Synth_Voice,"voice.tenor":q.Voice_Oohs,"voice.vocals":q.Choir_Aahs,"wind.flutes.flute":q.Flute,"wind.flutes.flute.alto":q.Flute,"wind.flutes.flute.bass":q.Flute,"wind.flutes.flute.contra-alto":q.Flute,"wind.flutes.flute.contrabass":q.Flute,"wind.flutes.flute.double-contrabass":q.Flute,"wind.flutes.flute.irish":q.Flute,"wind.flutes.flute.piccolo":q.Piccolo,"wind.flutes.flute.subcontrabass":q.Flute,"wind.flutes.ocarina":q.Ocarina,"wind.flutes.panpipes":q.Pan_Flute,"wind.flutes.recorder":q.Acoustic_Grand_Piano,"wind.flutes.recorder.alto":q.Recorder,"wind.flutes.recorder.bass":q.Recorder,"wind.flutes.recorder.contrabass":q.Recorder,"wind.flutes.recorder.descant":q.Recorder,"wind.flutes.recorder.garklein":q.Recorder,"wind.flutes.recorder.great-bass":q.Recorder,"wind.flutes.recorder.sopranino":q.Recorder,"wind.flutes.recorder.soprano":q.Recorder,"wind.flutes.recorder.tenor":q.Recorder,"wind.flutes.shakuhachi":q.Shakuhachi,"wind.flutes.whistle":q.Whistle,"wind.flutes.whistle.alto":q.Whistle,"wind.flutes.whistle.low-irish":q.Whistle,"wind.flutes.whistle.shiva":q.Whistle,"wind.flutes.whistle.slide":q.Whistle,"wind.flutes.whistle.tin":q.Whistle,"wind.flutes.whistle.tin.bflat":q.Whistle,"wind.flutes.whistle.tin.c":q.Whistle,"wind.flutes.whistle.tin.d":q.Whistle,"wind.group":q.Flute,"wind.pipes.bagpipes":q.Bag_pipe,"wind.reed.basset-horn":q.Bassoon,"wind.reed.bassoon":q.Bassoon,"wind.reed.bombarde":q.Bassoon,"wind.reed.clarinet":q.Clarinet,"wind.reed.clarinet.a":q.Clarinet,"wind.reed.clarinet.alto":q.Clarinet,"wind.reed.clarinet.bass":q.Clarinet,"wind.reed.clarinet.basset":q.Clarinet,"wind.reed.clarinet.bflat":q.Clarinet,"wind.reed.clarinet.contra-alto":q.Clarinet,"wind.reed.clarinet.contrabass":q.Clarinet,"wind.reed.clarinet.d":q.Clarinet,"wind.reed.clarinet.eflat":q.Clarinet,"wind.reed.clarinet.g":q.Clarinet,"wind.reed.clarinet.piccolo":q.Clarinet,"wind.reed.clarinet.piccolo.aflat":q.Clarinet,"wind.reed.clarinette-damour":q.Clarinet,"wind.reed.contrabass":q.Clarinet,"wind.reed.contrabassoon":q.Clarinet,"wind.reed.cornamuse":q.Bag_pipe,"wind.reed.english-horn":q.English_Horn,"wind.reed.harmonica":q.Harmonica,"wind.reed.harmonica.bass":q.Harmonica,"wind.reed.oboe":q.Oboe,"wind.reed.oboe.bass":q.Oboe,"wind.reed.oboe.piccolo":q.Oboe,"wind.reed.oboe-da-caccia":q.Oboe,"wind.reed.oboe-damore":q.Oboe,"wind.reed.saxonette":q.Soprano_Sax,"wind.reed.saxophone":q.Alto_Sax,"wind.reed.saxophone.alto":q.Alto_Sax,"wind.reed.saxophone.aulochrome":q.Alto_Sax,"wind.reed.saxophone.baritone":q.Baritone_Sax,"wind.reed.saxophone.bass":q.Baritone_Sax,"wind.reed.saxophone.contrabass":q.Baritone_Sax,"wind.reed.saxophone.melody":q.Baritone_Sax,"wind.reed.saxophone.mezzo-soprano":q.Alto_Sax,"wind.reed.saxophone.sopranino":q.Soprano_Sax,"wind.reed.saxophone.sopranissimo":q.Soprano_Sax,"wind.reed.saxophone.soprano":q.Soprano_Sax,"wind.reed.saxophone.subcontrabass":q.Baritone_Sax,"wind.reed.saxophone.tenor":q.Tenor_Sax,"wood.bones":q.Woodblock,"wood.castanets":q.Woodblock,"wood.claves":q.Woodblock,"wood.drum-sticks":q.Woodblock,"wood.gourd":q.Woodblock,"wood.granite-block":q.Woodblock,"wood.guban":q.Woodblock,"wood.guiro":q.Woodblock,"wood.hyoushigi":q.Woodblock,"wood.ipu":q.Woodblock,"wood.jam-block":q.Woodblock,"wood.kaekeeke":q.Woodblock,"wood.kagul":q.Woodblock,"wood.kalaau":q.Woodblock,"wood.kashiklar":q.Woodblock,"wood.kubing":q.Woodblock,"wood.pan-clappers":q.Woodblock,"wood.sand-block":q.Woodblock,"wood.slapstick":q.Woodblock,"wood.stir-drum":q.Woodblock,"wood.temple-block":q.Woodblock,"wood.tic-toc-block":q.Woodblock,"wood.tonetang":q.Woodblock,"wood.wood-block":q.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===q.Acoustic_Grand_Piano||e===q.Bright_Acoustic_Piano||e===q.Electric_Grand_Piano||e===q.Electric_Piano_1||e===q.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(i){t.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)}}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 i="",s=!1,n="",r="",o="";const a=[];let l="";const h=e.element("bar-style");h&&(o=h.value),i=e.attributes().length>0&&e.attribute("location")?e.attribute("location").value:"right";const u=e.elements();for(let e=0,t=u.length;e2&&(l=e);const i=e.split("[,+]");for(let t=0,s=i.length;t0)if("left"===i){if("start"===r){const e=new qe(this.currentMeasureIndex,$e.Ending,Qe.Begin,void 0,a,l);this.addInstruction(this.repetitionInstructions,e)}if("forward"===n){const e=new qe(this.currentMeasureIndex,$e.StartLine);this.addInstruction(this.repetitionInstructions,e)}}else{if("stop"===r){const e=new qe(this.currentMeasureIndex,$e.Ending,Qe.End,void 0,a,l);this.addInstruction(this.repetitionInstructions,e)}if("backward"===n){const e=new qe(this.currentMeasureIndex,$e.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 qe(s,$e.DalSegnoAlFine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,e+" al coda",!0)){const e=new qe(s,$e.DalSegnoAlCoda);return this.addInstruction(this.repetitionInstructions,e),!0}const n="d\\.\\s?c\\.";if(Xs.StringContainsSeparatedWord(t,n+" al fine",!0)){const e=new qe(s,$e.DaCapoAlFine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,n+" al coda",!0)){const e=new qe(s,$e.DaCapoAlCoda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,n)||Xs.StringContainsSeparatedWord(t,"da\\s?capo",!0)){const e=new qe(s,$e.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 qe(s,$e.DalSegnoAlCoda):new qe(s,$e.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 qe(s,$e.ToCoda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"fine",!0)){const e=new qe(s,$e.Fine);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"coda",!0)){const e=new qe(s,$e.Coda);return this.addInstruction(this.repetitionInstructions,e),!0}if(Xs.StringContainsSeparatedWord(t,"segno",!0)){const e=new qe(s,$e.Segno);return this.addInstruction(this.repetitionInstructions,e),!0}}else{if(e.element("segno")){const e=new qe(s,$e.Segno);return this.addInstruction(this.repetitionInstructions,e),!0}if(e.element("coda")){const e=new qe(s,$e.Coda);return this.addInstruction(this.repetitionInstructions,e),!0}}return!1}removeRedundantInstructions(){let e=0,t=0,i=0,s=0;for(let n=0;n0&&this.findInstructionInPreviousMeasure(n,r.measureIndex,$e.ToCoda)&&(r.type=$e.None),0===t&&0===i&&(r.type=$e.ToCoda,r.alignment=Qe.End,r.measureIndex--);break;case $e.Segno:if(e-s>0){let e=!1;for(let s=0,n=this.repetitionInstructions.length;s0?$e.DalSegnoAlCoda:$e.DalSegno,r.type=$e.None,e=!0;break;case $e.DalSegno:case $e.DalSegnoAlFine:case $e.DalSegnoAlCoda:r.type=$e.None,e=!0}if(e)break}if(e)break;r.type=i-t>0?$e.DalSegnoAlCoda:$e.DalSegno,r.alignment=Qe.End,r.measureIndex--}}if(this.backwardSearchForPreviousIdenticalInstruction(n,r)||r.type===$e.None)this.repetitionInstructions.splice(n,1),n--;else switch(r.type){case $e.Fine:break;case $e.ToCoda:i++;break;case $e.Coda:t++;break;case $e.Segno:e++;break;case $e.DalSegnoAlFine:case $e.DalSegnoAlCoda:s++}}this.repetitionInstructions.sort(Je.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;s0;)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 qe(t,$e.BackJumpLine,Qe.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){t.error("RepetitionCalculator: calculateRepetitions2",a)}}let r=!1;const o=this.musicSheet.SourceMeasures.length-1;for(const t of this.musicSheet.Repetitions)if(0===t.StartIndex&&t.EndIndex===o){r=!0;break}if(!r){const e=new Ls(this.musicSheet,!0);e.FromWords=!0,e.startMarker=new qe(0,$e.StartLine),e.startMarker.parentRepetition=e,this.musicSheet.SourceMeasures[0].FirstRepetitionInstructions.push(e.startMarker),e.endMarker=new qe(o,$e.BackJumpLine),e.endMarker.parentRepetition=e,e.BackwardJumpInstructions.push(e.endMarker),e.UserNumberOfRepetitions=e.DefaultNumberOfRepetitions,this.musicSheet.Repetitions.push(e)}for(let t=0,h=this.musicSheet.SourceMeasures.length;t1&&e.FirstRepetitionInstructions.sort(Je.Compare),e.LastRepetitionInstructions.length>1&&e.LastRepetitionInstructions.sort(Je.Compare)}}handleRepetitionInstructions(e){var t,i,s,n,r,o,a;let l;switch(e.type){case $e.StartLine:l=this.createNewRepetition(this.currentMeasureIndex),e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.FromWords=!1,l.RepetitonUnderConstruction.startMarker=e,null==(t=this.currentMeasure)||t.FirstRepetitionInstructions.push(e);break;case $e.BackJumpLine:l=this.getOrCreateCurrentRepetition2(!1),e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),null==(i=this.currentMeasure)||i.LastRepetitionInstructions.push(e),0===l.RepetitonUnderConstruction.EndingParts.length&&this.finalizeRepetition(l);break;case $e.Ending:l=this.getOrCreateCurrentRepetition(),e.parentRepetition=l.RepetitonUnderConstruction;if(e.endingIndices.contains(1)&&e.alignment===Qe.Begin){if(l.RepetitonUnderConstruction.BackwardJumpInstructions.length>0||l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)){l=void 0;for(let e=this.openRepetitions.length-1;e>=0;e--){const t=this.openRepetitions[e];if(0===t.RepetitonUnderConstruction.BackwardJumpInstructions.length)for(l=t;this.openRepetitions.length-1>e;){const e=this.openRepetitions.last();this.finalizeRepetition(e)}}void 0===l&&(l=this.createNewRepetition(0),l.RepetitonUnderConstruction.startMarker=new qe(0,$e.None))}void 0===l.RepetitonUnderConstruction.forwardJumpInstruction&&(l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(this.currentMeasureIndex-1,$e.ForwardJump,Qe.End,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[this.currentMeasureIndex-1].LastRepetitionInstructions.push(l.RepetitonUnderConstruction.forwardJumpInstruction))}if(e.alignment===Qe.Begin)l.RepetitonUnderConstruction.setEndingsStartIndex(e.endingIndices,this.currentMeasureIndex),null==(s=this.currentMeasure)||s.FirstRepetitionInstructions.push(e);else for(let t=0,i=e.endingIndices.length;t0&&Math.abs(l.RepetitonUnderConstruction.BackwardJumpInstructions.last().measureIndex-this.currentMeasureIndex)<=1)break;if(this.openRepetitions.length&&(null==(a=null==(o=null==(r=this.openRepetitions)?void 0:r.find((e=>e.RepetitonUnderConstruction.startMarker.type===$e.StartLine)))?void 0:o.RepetitonUnderConstruction)?void 0:a.StartIndex)===this.currentMeasureIndex)break;l=this.createNewRepetition(this.currentMeasureIndex),e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.FromWords=!0,l.SegnoFound=!0,l.RepetitonUnderConstruction.startMarker=e,this.currentMeasure.FirstRepetitionInstructions.push(e);break;case $e.Fine:if(0===this.openRepetitions.length)break;if(l=this.getCurrentRepetition(!0),void 0===l)break;e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.FromWords=!0,void 0===l.RepetitonUnderConstruction.forwardJumpInstruction?(l.FineFound=!0,l.RepetitonUnderConstruction.forwardJumpInstruction=e,l.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.currentMeasure.LastRepetitionInstructions.push(e)):this.currentMeasure.LastRepetitionInstructions.push(new qe(this.currentMeasureIndex,$e.Fine,Qe.End,void 0));break;case $e.ToCoda:if(0===this.openRepetitions.length)break;if(l=this.getCurrentRepetition(!0),void 0===l)break;void 0===l.RepetitonUnderConstruction.forwardJumpInstruction&&(e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.FromWords=!0,l.ToCodaFound=!0,l.RepetitonUnderConstruction.forwardJumpInstruction=e,this.currentMeasure.LastRepetitionInstructions.push(e));break;case $e.Coda:if(0===this.openRepetitions.length)break;l=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=l.RepetitonUnderConstruction,l.WaitingForCoda?(l.CodaFound=!0,l.RepetitonUnderConstruction.setEndingStartIndex(2,this.currentMeasureIndex),this.currentMeasure.LastRepetitionInstructions.push(e),this.finalizeRepetition(l),this.currentMeasureIndex>0&&(this.musicSheet.SourceMeasures[this.currentMeasureIndex-1].printNewSystemXml=!0)):l.ToCodaFound||(0===l.RepetitonUnderConstruction.BackwardJumpInstructions.length?(l.ToCodaFound=!0,l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(this.currentMeasureIndex,$e.ToCoda,Qe.End,l.RepetitonUnderConstruction),this.currentMeasure.LastRepetitionInstructions.push(l.RepetitonUnderConstruction.forwardJumpInstruction)):this.currentMeasure.LastRepetitionInstructions.push(new qe(this.currentMeasureIndex,$e.Coda,Qe.Begin,void 0)));break;case $e.DaCapo:l=this.getOrCreateCurrentRepetition(),l.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&this.finalizeRepetition(l),0!==l.RepetitonUnderConstruction.StartIndex&&(l=this.createNewRepetition(0)),e.parentRepetition=l.RepetitonUnderConstruction,l.RepetitonUnderConstruction.FromWords=!0,l.RepetitonUnderConstruction.startMarker=new qe(0,$e.None,Qe.Begin,l.RepetitonUnderConstruction),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e),0===l.RepetitonUnderConstruction.EndingParts.length&&this.finalizeRepetition(l);break;case $e.DalSegno:if(l=this.getOrCreateCurrentRepetition2(!0),l.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&(this.finalizeRepetition(l),l=this.createNewRepetition(0),l.RepetitonUnderConstruction.FromWords=!0,l.RepetitonUnderConstruction.startMarker=new qe(0,$e.None,Qe.Begin,l.RepetitonUnderConstruction)),e.parentRepetition=l.RepetitonUnderConstruction,!l.SegnoFound){const t=this.findInstructionInMainListBackwards($e.Segno,e.measureIndex);t>=0&&(l.SegnoFound=!0,l.RepetitonUnderConstruction.startMarker=new qe(t,$e.Segno,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.startMarker))}l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)&&l.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case $e.DalSegnoAlFine:if(0===this.openRepetitions.length)break;if(l=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=l.RepetitonUnderConstruction,!l.SegnoFound){const t=this.findInstructionInMainListBackwards($e.Segno,e.measureIndex);t>=0&&(l.SegnoFound=!0,l.RepetitonUnderConstruction.startMarker=new qe(t,$e.Segno,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.startMarker))}if(!l.FineFound){const t=this.findInstructionInMainListBackwards($e.Fine,e.measureIndex);t>=0&&(l.FineFound=!0,l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.Fine,Qe.Begin,l.RepetitonUnderConstruction),l.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction))}l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||l.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case $e.DaCapoAlFine:if(l=this.getOrCreateCurrentRepetition(),l.RepetitonUnderConstruction.BackwardJumpInstructions.length>0&&(this.finalizeRepetition(l),l=this.createNewRepetition(0)),void 0!==l.RepetitonUnderConstruction.startMarker&&0!==l.RepetitonUnderConstruction.StartIndex&&(l=this.createNewRepetition(0)),l.RepetitonUnderConstruction.startMarker=new qe(0,$e.None,Qe.Begin,l.RepetitonUnderConstruction),l.RepetitonUnderConstruction.FromWords=!0,e.parentRepetition=l.RepetitonUnderConstruction,!l.FineFound){const t=this.findInstructionInMainListBackwards($e.Fine,e.measureIndex);t>=0&&(l.FineFound=!0,l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.Fine,Qe.Begin,l.RepetitonUnderConstruction),l.RepetitonUnderConstruction.setEndingStartIndex(2,-2),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction))}l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||l.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case $e.DalSegnoAlCoda:if(0===this.openRepetitions.length)break;if(l=this.getOrCreateCurrentRepetition2(!0),e.parentRepetition=l.RepetitonUnderConstruction,!l.SegnoFound){const t=this.findInstructionInMainListBackwards($e.Segno,e.measureIndex);t>=0&&(l.SegnoFound=!0,l.RepetitonUnderConstruction.startMarker=new qe(t,$e.Segno,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].FirstRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.startMarker))}if(!l.ToCodaFound){const t=this.findInstructionInMainListBackwards($e.ToCoda,e.measureIndex);if(t>=0)l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.ToCoda,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction),l.ToCodaFound=!0;else{const t=this.findInstructionInMainListBackwards($e.Coda,e.measureIndex);t>=0&&(l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.ToCoda,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction),l.ToCodaFound=!0)}}l.ToCodaFound&&(l.WaitingForCoda=!0),l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||l.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case $e.DaCapoAlCoda:if(l=this.getOrCreateCurrentRepetition(),(l.RepetitonUnderConstruction.BackwardJumpInstructions.length>0||0===l.RepetitonUnderConstruction.EndingParts.length)&&(this.finalizeRepetition(l),l=this.createNewRepetition(0)),void 0!==l.RepetitonUnderConstruction.startMarker&&0!==l.RepetitonUnderConstruction.StartIndex&&(l=this.createNewRepetition(0)),l.RepetitonUnderConstruction.startMarker=new qe(0,$e.None,Qe.Begin,l.RepetitonUnderConstruction),l.RepetitonUnderConstruction.FromWords=!0,e.parentRepetition=l.RepetitonUnderConstruction,!l.ToCodaFound){const t=this.findInstructionInMainListBackwards($e.ToCoda,e.measureIndex);if(t>=0)l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.ToCoda,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction),l.ToCodaFound=!0;else{const t=this.findInstructionInMainListBackwards($e.Coda,e.measureIndex);t>=0&&(l.RepetitonUnderConstruction.forwardJumpInstruction=new qe(t,$e.ToCoda,Qe.Begin,l.RepetitonUnderConstruction),this.musicSheet.SourceMeasures[t].LastRepetitionInstructions.splice(0,0,l.RepetitonUnderConstruction.forwardJumpInstruction),l.ToCodaFound=!0)}}l.ToCodaFound&&(l.WaitingForCoda=!0),l.RepetitonUnderConstruction.EndingIndexDict.hasOwnProperty(1)||l.RepetitonUnderConstruction.setEndingEndIndex(1,this.currentMeasureIndex),l.RepetitonUnderConstruction.BackwardJumpInstructions.push(e),this.currentMeasure.LastRepetitionInstructions.push(e);break;case $e.None:break;default:throw new S("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,n,r;const o=e.RepetitonUnderConstruction,a=!!(null==(t=o.BackwardJumpInstructions)?void 0:t.some((e=>{var t;return e.measureIndex===(null==(t=this.currentMeasure)?void 0:t.measureListIndex)})))&&"结束句"===(null==(s=null==(i=this.repetitionInstructions)?void 0:i.find((e=>{var t;return(null==e?void 0:e.measureIndex)===(null==(t=this.currentMeasure)?void 0:t.measureListIndex)})))?void 0:s.originalVal);if(o.BackwardJumpInstructions.length>0){let e=!0;const t=this.getLastFinalizedRepetition();if(void 0!==t&&o.coversIdenticalMeasures(t)){if(o.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(o)}e=!1,o.removeFromRepetitionInstructions()}else a?e=!1:this.musicSheet.Repetitions.push(o);if(e){o.startMarker.type===$e.None&&this.musicSheet.SourceMeasures[o.StartIndex].FirstRepetitionInstructions.push(o.startMarker);let e=(null==window?void 0:window.DYCustomRepeatCount)>o.DefaultNumberOfRepetitions?null==window?void 0:window.DYCustomRepeatCount:o.DefaultNumberOfRepetitions;!this.hasNextRepeat&&this.currentMeasureIndex(null==e?void 0:e.measureIndex)>=(null==o?void 0:o.EndIndex))))?void 0:r.some((e=>2==(null==e?void 0:e.type)||4==(null==e?void 0:e.type)))),this.hasNextRepeat&&(e=o.DefaultNumberOfRepetitions),o.UserNumberOfRepetitions=e||o.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];i0)return this.openRepetitions.last();const e=this.createNewRepetition(0);return e.RepetitonUnderConstruction.startMarker=new qe(0,$e.None,Qe.Begin,e.RepetitonUnderConstruction),e}getOrCreateCurrentRepetition2(e){let t;if(this.openRepetitions.length){if(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(;i0){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,i,s){for(const r of this.voiceMeasureReadPlugins)try{r.measureReadCalculations(e,i,s)}catch(n){t.info("VoiceGenerator.addSingleNote: ",n)}}}class Js{constructor(e=void 0,t=new Le){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,i){try{return this._createMusicSheet(e,i)}catch(s){return void t.error("MusicSheetReader.CreateMusicSheet",s)}}_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 g("Undefined root element");this.pushSheetLabels(e,t);const r=e.element("part-list");if(!r)throw new g("Undefined partListNode");const o=e.elements("part"),a=r.elements();this.initializeReading(a,o,i);let l=!0;this.currentFraction=new h(0,1);let u=!1,c=e.element("identification");for(c&&(c=c.element("encoding")),c&&(c=c.element("software")),void 0!==c&&"Guitar Pro 5"===c.value&&(u=!0);l;){void 0!==this.currentMeasure&&this.currentMeasure.HasEndLine&&this.rules.NewPartAndSystemAfterFinalBarline&&(s=0),this.currentMeasure=new et(this.completeNumberOfStaves,this.musicSheet.Rules);for(const e of i)try{l=l&&e.readNextXmlMeasure(this.currentMeasure,this.currentFraction,u)}catch(d){const e=Ue.translateText("ReaderErrorMessages/InstrumentError","Error while reading instruments.");throw new g(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 h=0,f=this.afterSheetReadingModules.length;hi){if(this.areRhythmInstructionsMixed(t)&&e.SymbolEnum!==x.NONE)continue;i=e.Rhythm.RealValue,s=t.indexOf(e)}}if(t.length>0&&t.length0)&&t++,this.currentMeasure.Duration=r,this.currentMeasure.ActiveTimeSignature=i,this.currentMeasure.MeasureNumber=t;for(let o=0;oe.Denominator){const i=t.Denominator/e.Denominator;e.expand(i)}}checkIfMeasureIsImplicit(e,t){return!(this.previousMeasure||!e.lt(t))||!!this.previousMeasure&&h.plus(this.previousMeasure.Duration,e).Equals(t)}allInstrumentsHaveSameDuration(e,t){let i=0;for(let s=0,n=e.length;s=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;i0){const e=t[0].elements("rights");if(e.length>0)for(let t=0,i=e.length;to||d)if(a||d){if(u||"right"===c)h?h+="\n"+n:h=n;else if(r||"right"!==c&&"left"!==c)l?l+="\n"+n:l=n;else if("left"===c){this.musicSheet.Lyricist||(this.musicSheet.Lyricist=new mt(n));break}}else a=n}}}}if(!this.musicSheet.Title&&a&&(this.musicSheet.Title=new mt(this.trimString(a))),!this.musicSheet.Subtitle&&l&&(this.musicSheet.Subtitle=new mt(this.trimString(l))),h){let e=!1;if(this.musicSheet.Composer){(null!=(n=h.match("\n"))?n:[]).length+1>=(null!=(r=this.musicSheet.Composer.text.match("\n"))?r:[]).length+1&&(e=!0)}else e=!0;e&&(this.musicSheet.Composer=new mt(this.trimString(h)))}}readTitleAndComposerFromCreditsLegacy(e){var t,i,s;const n=this.computeSystemYCoordinates(e);if(0===n)return;let r,o,a,l=1,h=0;const u=e.elements("credit");for(let c=0,d=u.length;cn||p){if(!this.musicSheet.Title&&!p){const e=null==(s=u.attribute("font-size"))?void 0:s.value;if(e){const t=parseFloat(e);l0&&o.MidiInstrumentId!==q.Percussion&&(i.midiInstrumentID=Math.max(0,parseInt(n.value,10)-1));else if("midi-unpitched"===n.name)i.fixedKey=Math.max(0,parseInt(n.value,10));else if("volume"===n.name)try{const e=parseFloat(n.value);i.volume=e/127}catch(r){t.debug("ExpressionReader.readExpressionParameters","read volume",r)}else if("pan"===n.name)try{const e=parseFloat(n.value);i.pan=e/64}catch(r){t.debug("ExpressionReader.readExpressionParameters","read pan",r)}}catch(r){t.info("MusicSheetReader.createInstrumentGroups midi settings: ",r)}}}}catch(r){t.info("MusicSheetReader.createInstrumentGroups: ",r)}}if(0===o.SubInstruments.length){const e=new Us(o);o.SubInstruments.push(e)}s[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=Ue.translateText("ReaderErrorMessages/InstrumentError","Error while reading Instruments");throw new g(e,o)}for(let t=0,a=this.musicSheet.Instruments.length;t0){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=Ue.translateText("ReaderErrorMessages/StaffError","Invalid number of staves.");throw new g(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=Ue.translateText("ReaderErrorMessages/StaffError","Invalid number of Staves.");throw new g(e)}return t}}class qs{static MXLtoIXmlElement(e){const t=new o;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 V(t.documentElement);return Promise.resolve(i)}),(e=>{throw e})).then((e=>e),(e=>{throw new Error("extractSheetFromMxl: "+e.message)}))}static MXLtoXMLstring(e){const i=new o;return i.loadAsync(e).then((e=>i.file("META-INF/container.xml").async("text")),(e=>{throw t.error(e),e})).then((e=>{const t=(new DOMParser).parseFromString(e,"text/xml").getElementsByTagName("rootfile")[0].getAttribute("full-path");return i.file(t).async("text")}),(e=>{throw e}))}}class $s{calculate(e){const t=new T(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=h.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 re(void 0),this.displaySizeInPixel=e,this.RelativeDisplaySize=t,this.RelativeDisplayPosition=i,this.WidthInUnits=s}static createWithRelativeDefaults(e,t){return new Qs(e,new ee(1,1),new X(0,0),t)}static createWithDefaults(){return new Qs(new ee(1,1),new ee(1,1),new X(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 ee(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 ee(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 ee(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 X(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(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){var s,n;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){const t=e.parentStaffEntry.parentVerticalContainer.AbsoluteTimestamp;this.renderingManager.setStartPosition(t),void 0!==(null==(s=e.notes[0])?void 0:s.sourceNote.Pitch)&&(null==(n=this.renderingManager.PlaybackManager)||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 X(t,i);this.handleUserDisplayInteraction(s,e,en.SingleTouch)}}unitPosDoubleTouched(e,t,i){if(!this.DoubleTouchDisabled){const s=new X(t,i);this.handleUserDisplayInteraction(s,e,en.DoubleTouch)}}unitPosTouchDown(e,t,i){const s=new X(t,i);this.handleUserDisplayInteraction(s,e,en.TouchDown),this.yOffsetMouseDown=e.y}unitPosTouchUp(e,t,i){const s=new X(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 X(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 ee(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 X(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 X(this.mainViewingRegion.UpperLeftPositionInUnits.x,e)}unlockFromCursorIfNecessary(e){if(!1===this.LockDisplayToCursor||this.ZoomActive)return;if(this.displayInteractionManager.ZoomGestureActive||this.displayInteractionManager.WasZoomGestureActive)return;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 X(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)||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(t){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 e,this.DOUBLE_CLICK_WINDOW=200,this.lastClick=0,this.osmdSheetMusicContainer=t,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(i0)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){let s;e.touches&&e.touches.length>0?s=e.touches[0]:e.changedTouches&&e.changedTouches.length>0&&(s=e.changedTouches[0]),t=null==s?void 0:s.clientX,i=null==s?void 0:s.clientY}else e instanceof MouseEvent&&(t=e.clientX,i=e.clientY);const s=this.getOffsetCoordinates(t,i);this.move(s.x,s.y)}touchEndEventListener(e){let t;e.touches&&e.touches.length>0?t=e.touches[0]:e.changedTouches&&e.changedTouches.length>0&&(t=e.changedTouches[0]);const i=this.getOffsetCoordinates(null==t?void 0:t.pageX,null==t?void 0:t.pageY);this.touchUp(i.x,i.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 X(i,s)}}class an{static fillDynamicsList(e,t,i){for(let s=0;s=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===c.Below?t+1:r>1&&1===n&&i===c.Above?t-1:-1}static fillDynamicExpressions(e){const t=e.DynListStaves,i=e.getCompleteNumberOfStaves(),s=e.TimestampSortedDynamicExpressionsList;for(let n=0;n{i(this.processStringXml(e))}),(e=>{t.error(new Error("[OSMD] Invalid MXL file: "+e)),s(new Error("[OSMD] Invalid MXL file: "+e))}))}processStringXml(e){const i=new DOMParser;if(""===e.substr(0,3))return t.debug("[OSMD] UTF with BOM detected, truncate first three bytes and pass along: "+e),i.parseFromString(e.substr(3),"application/xml");if(e.substr(0,6).includes("{s.isMxl(e)?s.processMxl(e,i,n):i(s.processStringXml(e))}),(e=>{throw n(e),e}));else{const e=new Error("[OSMD] osmd.load(string): Could not process string. Did not find {e.init(this.sheet.MusicPartManager,this.graphic)})),this.drawingParameters.DrawingParametersEnum===I.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)||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 i=this.container.offsetWidth;this.rules.RenderSingleHorizontalStaffline&&(i=this.rules.SheetMaximumWidth),this.sheet.pageWidth=i/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,t.debug("[OSMD] PageHeight: "+this.rules.PageHeight)):(t.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 t of this.sheet.SourceMeasures)t.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,i=this.container.offsetWidth;this.rules.RenderSingleHorizontalStaffline&&(i=10*(this.EngravingRules.PageLeftMargin+this.graphic.MusicPages[0].PositionAndShape.Size.width+this.EngravingRules.PageRightMargin)*this.zoom);const s=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()===C.Canvas&&i>s&&(t.warn("[OSMD] Warning: width of "+i+o),i=s),this.rules.PageFormat&&!this.rules.PageFormat.IsUndefined?e=i/this.rules.PageFormat.aspectRatio:(e=n.PositionAndShape.Size.height,e+=this.rules.PageBottomMargin,r.getOSMDBackendType()===C.Canvas&&(e+=.1),e+=n.PositionAndShape.BorderTop,this.rules.RenderTitle&&(e+=this.rules.TitleTopDistance),e*=10*this.zoom),r.getOSMDBackendType()===C.Canvas&&e>s&&(t.warn("[OSMD] Warning: height of "+e+o),e=Math.min(e,s)),r.resize(i,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(){var e;for(const t of null==(e=this.drawer)?void 0:e.Backends)t instanceof Xt&&t.export()}IsReadyToRender(){return void 0!==this.graphic}clear(){var e;null==(e=this.drawer)||e.clear(),this.reset()}dispose(){this.disposeResizeListener&&this.disposeResizeListener(),this.InteractionManager&&this.InteractionManager.Dispose()}setOptions(e){if(this.rules||(this.rules=new Le),this.drawingParameters||e.drawingParameters?e.drawingParameters&&(this.drawingParameters?this.drawingParameters.DrawingParametersEnum=I[e.drawingParameters.toLowerCase()]:this.drawingParameters=new Ot(I[e.drawingParameters],this.rules)):this.drawingParameters=new Ot(I.default,this.rules),null==e)return void t.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 i=!this.drawer||!this.drawer.Backends||this.drawer.Backends.length<1;if(void 0!==e.backend){const t=D.BackendTypeFromString(e.backend);i=i||this.backendType!==t,this.backendType=t}this.needBackendUpdate=i,void 0!==e.autoBeam&&(this.rules.AutoBeamNotes=e.autoBeam);const s=e.autoBeamOptions;if(s&&(void 0===s.maintain_stem_directions&&(s.maintain_stem_directions=!1),this.rules.AutoBeamOptions=s,s.groups&&s.groups.length))for(const t of s.groups)if(2!==t.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=u.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:A.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(t){if(t.coloringMode===de.XML)return void(this.rules.ColoringMode=de.XML);const i=[z.C,z.D,z.E,z.F,z.G,z.A,z.B];let s;if(t.coloringMode===de.CustomColorSet){if(!t.coloringSetCustom||8!==t.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 e of t.coloringSetCustom){if(!/^\#[0-9a-fA-F]{6}$/.test(e))throw new Error("One of the color strings in options.coloringSetCustom was not a valid HTML Hex color:\n"+e)}s=t.coloringSetCustom}else if(t.coloringMode===de.AutoColoring){s=[];const e=Object.keys(W);for(let t=0;t{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.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){var t,i,s,n,r,o,a,l,h;if(this.drawingParameters.drawCursors=e,e){for(let e=0;e{e.hide()}))}createBackend(e,t){let i;return i=void 0===e||e===C.SVG?new Xt(this.rules):new Ki(this.rules),i.graphicalMusicPage=t,i.initialize(this.container,this.zoom),i}static StringToPageFormat(e){let t=xe.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 xe(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 xe(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.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}};let hn=ln;hn.PageFormatStandards={A3_L:new xe(420,297,"A3_L"),A3_P:new xe(297,420,"A3_P"),A4_L:new xe(297,210,"A4_L"),A4_P:new xe(210,297,"A4_P"),A5_L:new xe(210,148,"A5_L"),A5_P:new xe(148,210,"A5_P"),A6_L:new xe(148,105,"A6_L"),A6_P:new xe(105,148,"A6_P"),Endless:xe.UndefinedPageFormat,Letter_L:new xe(279.4,215.9,"Letter_L"),Letter_P:new xe(215.9,279.4,"Letter_P")},z.C,z.D,z.E,z.F,z.G,z.A,z.B;export{h as F,Mt as G,hn as O,Xs as S,vt as a,xt as b,Tt as i};