MusicSheetCalculator.ts 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  2. import {StaffLine} from "./StaffLine";
  3. import {GraphicalMusicSheet} from "./GraphicalMusicSheet";
  4. import {EngravingRules} from "./EngravingRules";
  5. import {Tie} from "../VoiceData/Tie";
  6. import {Fraction} from "../../Common/DataObjects/Fraction";
  7. import {Note} from "../VoiceData/Note";
  8. import {MusicSheet} from "../MusicSheet";
  9. import {StaffMeasure} from "./StaffMeasure";
  10. import {ClefInstruction} from "../VoiceData/Instructions/ClefInstruction";
  11. import {LyricWord} from "../VoiceData/Lyrics/LyricsWord";
  12. import {SourceMeasure} from "../VoiceData/SourceMeasure";
  13. import {GraphicalMusicPage} from "./GraphicalMusicPage";
  14. import {GraphicalNote} from "./GraphicalNote";
  15. import {Beam} from "../VoiceData/Beam";
  16. import {OctaveEnum} from "../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  17. import {LyricsEntry} from "../VoiceData/Lyrics/LyricsEntry";
  18. import {VoiceEntry} from "../VoiceData/VoiceEntry";
  19. import {OrnamentContainer} from "../VoiceData/OrnamentContainer";
  20. import {ArticulationEnum} from "../VoiceData/VoiceEntry";
  21. import {Tuplet} from "../VoiceData/Tuplet";
  22. import {MusicSystem} from "./MusicSystem";
  23. import {GraphicalTie} from "./GraphicalTie";
  24. import {RepetitionInstruction} from "../VoiceData/Instructions/RepetitionInstruction";
  25. import {MultiExpression} from "../VoiceData/Expressions/MultiExpression";
  26. import {StaffEntryLink} from "../VoiceData/StaffEntryLink";
  27. import {MusicSystemBuilder} from "./MusicSystemBuilder";
  28. import {MultiTempoExpression} from "../VoiceData/Expressions/MultiTempoExpression";
  29. import {Repetition} from "../MusicSource/Repetition";
  30. import {PointF2D} from "../../Common/DataObjects/PointF2D";
  31. import {SourceStaffEntry} from "../VoiceData/SourceStaffEntry";
  32. import {BoundingBox} from "./BoundingBox";
  33. import {Instrument} from "../Instrument";
  34. import {GraphicalLabel} from "./GraphicalLabel";
  35. import {TextAlignment} from "../../Common/Enums/TextAlignment";
  36. import {VerticalGraphicalStaffEntryContainer} from "./VerticalGraphicalStaffEntryContainer";
  37. import {KeyInstruction} from "../VoiceData/Instructions/KeyInstruction";
  38. import {AbstractNotationInstruction} from "../VoiceData/Instructions/AbstractNotationInstruction";
  39. import {ClefEnum} from "../VoiceData/Instructions/ClefInstruction";
  40. import {TechnicalInstruction} from "../VoiceData/Instructions/TechnicalInstruction";
  41. import {Pitch} from "../../Common/DataObjects/Pitch";
  42. import {LinkedVoice} from "../VoiceData/LinkedVoice";
  43. import {ColDirEnum} from "./BoundingBox";
  44. import {IGraphicalSymbolFactory} from "../Interfaces/IGraphicalSymbolFactory";
  45. import {ITextMeasurer} from "../Interfaces/ITextMeasurer";
  46. import {ITransposeCalculator} from "../Interfaces/ITransposeCalculator";
  47. import {OctaveShiftParams} from "./OctaveShiftParams";
  48. import {AccidentalCalculator} from "./AccidentalCalculator";
  49. import {MidiInstrument} from "../VoiceData/Instructions/ClefInstruction";
  50. import {Staff} from "../VoiceData/Staff";
  51. import {OctaveShift} from "../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  52. import {Logging} from "../../Common/Logging";
  53. import Dictionary from "typescript-collections/dist/lib/Dictionary";
  54. import {CollectionUtil} from "../../Util/CollectionUtil";
  55. /**
  56. * Class used to do all the calculations in a MusicSheet, which in the end populates a GraphicalMusicSheet.
  57. */
  58. export abstract class MusicSheetCalculator {
  59. public static transposeCalculator: ITransposeCalculator;
  60. protected static textMeasurer: ITextMeasurer;
  61. protected staffEntriesWithGraphicalTies: GraphicalStaffEntry[] = [];
  62. protected staffEntriesWithOrnaments: GraphicalStaffEntry[] = [];
  63. protected staffEntriesWithChordSymbols: GraphicalStaffEntry[] = [];
  64. protected staffLinesWithLyricWords: StaffLine[] = [];
  65. protected staffLinesWithGraphicalExpressions: StaffLine[] = [];
  66. protected graphicalMusicSheet: GraphicalMusicSheet;
  67. protected rules: EngravingRules;
  68. protected symbolFactory: IGraphicalSymbolFactory;
  69. constructor(symbolFactory: IGraphicalSymbolFactory) {
  70. this.symbolFactory = symbolFactory;
  71. }
  72. public static get TextMeasurer(): ITextMeasurer {
  73. return MusicSheetCalculator.textMeasurer;
  74. }
  75. public static set TextMeasurer(value: ITextMeasurer) {
  76. MusicSheetCalculator.textMeasurer = value;
  77. }
  78. protected get leadSheet(): boolean {
  79. return this.graphicalMusicSheet.LeadSheet;
  80. }
  81. private static addTieToTieTimestampsDict(tieTimestampListDict: Dictionary<Tie, Fraction[]>, note: Note): void {
  82. note.NoteTie.initializeBoolList();
  83. let tieTimestampList: Fraction[] = [];
  84. for (let m: number = 0; m < note.NoteTie.Fractions.length; m++) {
  85. let musicTimestamp: Fraction;
  86. if (m === 0) {
  87. musicTimestamp = Fraction.plus(note.calculateNoteLengthWithoutTie(), note.getAbsoluteTimestamp());
  88. } else {
  89. musicTimestamp = Fraction.plus(tieTimestampList[m - 1], note.NoteTie.Fractions[m - 1]);
  90. }
  91. tieTimestampList.push(musicTimestamp);
  92. }
  93. tieTimestampListDict.setValue(note.NoteTie, tieTimestampList);
  94. }
  95. private static setMeasuresMinStaffEntriesWidth(measures: StaffMeasure[], minimumStaffEntriesWidth: number): void {
  96. for (let idx: number = 0, len: number = measures.length; idx < len; ++idx) {
  97. let measure: StaffMeasure = measures[idx];
  98. measure.minimumStaffEntriesWidth = minimumStaffEntriesWidth;
  99. }
  100. }
  101. public initialize(graphicalMusicSheet: GraphicalMusicSheet): void {
  102. this.graphicalMusicSheet = graphicalMusicSheet;
  103. this.rules = graphicalMusicSheet.ParentMusicSheet.rules;
  104. this.prepareGraphicalMusicSheet();
  105. //this.calculate();
  106. }
  107. public prepareGraphicalMusicSheet(): void {
  108. //this.graphicalMusicSheet.SystemImages.length = 0;
  109. let musicSheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
  110. this.staffEntriesWithGraphicalTies = [];
  111. this.staffEntriesWithOrnaments = [];
  112. this.staffEntriesWithChordSymbols = [];
  113. this.staffLinesWithLyricWords = [];
  114. this.staffLinesWithGraphicalExpressions = [];
  115. this.graphicalMusicSheet.Initialize();
  116. let measureList: StaffMeasure[][] = this.graphicalMusicSheet.MeasureList;
  117. let accidentalCalculators: AccidentalCalculator[] = this.createAccidentalCalculators();
  118. let activeClefs: ClefInstruction[] = this.graphicalMusicSheet.initializeActiveClefs();
  119. let lyricWords: LyricWord[] = [];
  120. let completeNumberOfStaves: number = musicSheet.getCompleteNumberOfStaves();
  121. let openOctaveShifts: OctaveShiftParams[] = [];
  122. let tieTimestampListDictList: Dictionary<Tie, Fraction[]>[] = [];
  123. for (let i: number = 0; i < completeNumberOfStaves; i++) {
  124. let tieTimestampListDict: Dictionary<Tie, Fraction[]> = new Dictionary<Tie, Fraction[]>();
  125. tieTimestampListDictList.push(tieTimestampListDict);
  126. openOctaveShifts.push(undefined);
  127. }
  128. for (let idx: number = 0, len: number = musicSheet.SourceMeasures.length; idx < len; ++idx) {
  129. let sourceMeasure: SourceMeasure = musicSheet.SourceMeasures[idx];
  130. let graphicalMeasures: StaffMeasure[] = this.createGraphicalMeasuresForSourceMeasure(
  131. sourceMeasure,
  132. accidentalCalculators,
  133. lyricWords,
  134. tieTimestampListDictList,
  135. openOctaveShifts,
  136. activeClefs
  137. );
  138. measureList.push(graphicalMeasures);
  139. }
  140. this.handleStaffEntries();
  141. this.calculateVerticalContainersList();
  142. this.setIndecesToVerticalGraphicalContainers();
  143. }
  144. public calculate(): void {
  145. this.clearSystemsAndMeasures();
  146. this.clearRecreatedObjects();
  147. this.createGraphicalTies();
  148. this.calculateSheetLabelBoundingBoxes();
  149. this.calculateXLayout(this.graphicalMusicSheet, this.maxInstrNameLabelLength());
  150. this.graphicalMusicSheet.MusicPages.length = 0;
  151. this.calculateMusicSystems();
  152. this.graphicalMusicSheet.MusicPages[0].PositionAndShape.BorderMarginBottom += 9;
  153. GraphicalMusicSheet.transformRelativeToAbsolutePosition(this.graphicalMusicSheet);
  154. }
  155. public calculateXLayout(graphicalMusicSheet: GraphicalMusicSheet, maxInstrNameLabelLength: number): void {
  156. let minLength: number = 0;
  157. let maxInstructionsLength: number = this.rules.MaxInstructionsConstValue;
  158. if (this.graphicalMusicSheet.MeasureList.length > 0) {
  159. let measures: StaffMeasure[] = this.graphicalMusicSheet.MeasureList[0];
  160. let minimumStaffEntriesWidth: number = this.calculateMeasureXLayout(measures);
  161. MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
  162. minLength = minimumStaffEntriesWidth * 1.2 + maxInstrNameLabelLength + maxInstructionsLength;
  163. for (let i: number = 1; i < this.graphicalMusicSheet.MeasureList.length; i++) {
  164. measures = this.graphicalMusicSheet.MeasureList[i];
  165. minimumStaffEntriesWidth = this.calculateMeasureXLayout(measures);
  166. MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
  167. minLength = Math.max(minLength, minimumStaffEntriesWidth * 1.2 + maxInstructionsLength);
  168. }
  169. }
  170. this.graphicalMusicSheet.MinAllowedSystemWidth = minLength;
  171. }
  172. protected calculateMeasureXLayout(measures: StaffMeasure[]): number {
  173. throw new Error("abstract, not implemented");
  174. }
  175. protected calculateSystemYLayout(): void {
  176. throw new Error("abstract, not implemented");
  177. }
  178. protected initStaffMeasuresCreation(): void {
  179. throw new Error("abstract, not implemented");
  180. }
  181. protected handleBeam(graphicalNote: GraphicalNote, beam: Beam, openBeams: Beam[]): void {
  182. throw new Error("abstract, not implemented");
  183. }
  184. protected createGraphicalTieNote(beams: Beam[], activeClef: ClefInstruction,
  185. octaveShiftValue: OctaveEnum,
  186. graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction, numberOfDots: number,
  187. openTie: Tie, isLastTieNote: boolean): void {
  188. throw new Error("abstract, not implemented");
  189. }
  190. protected handleVoiceEntryLyrics(lyricsEntries: Dictionary<number, LyricsEntry>, voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry,
  191. openLyricWords: LyricWord[]): void {
  192. throw new Error("abstract, not implemented");
  193. }
  194. protected handleVoiceEntryOrnaments(ornamentContainer: OrnamentContainer, voiceEntry: VoiceEntry,
  195. graphicalStaffEntry: GraphicalStaffEntry): void {
  196. throw new Error("abstract, not implemented");
  197. }
  198. protected handleVoiceEntryArticulations(articulations: ArticulationEnum[],
  199. voiceEntry: VoiceEntry,
  200. graphicalStaffEntry: GraphicalStaffEntry): void {
  201. throw new Error("abstract, not implemented");
  202. }
  203. protected handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet, openTuplets: Tuplet[]): void {
  204. throw new Error("abstract, not implemented");
  205. }
  206. protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[],
  207. graphicalStaffEntry: GraphicalStaffEntry, hasPitchedNote: boolean, isGraceStaffEntry: boolean): void {
  208. throw new Error("abstract, not implemented");
  209. }
  210. protected layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
  211. throw new Error("abstract, not implemented");
  212. }
  213. protected handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number,
  214. measureIndex: number): void {
  215. throw new Error("abstract, not implemented");
  216. }
  217. protected updateStaffLineBorders(staffLine: StaffLine): void {
  218. throw new Error("abstract, not implemented");
  219. }
  220. protected calculateMeasureNumberPlacement(musicSystem: MusicSystem): void {
  221. throw new Error("abstract, not implemented");
  222. }
  223. protected layoutGraphicalTie(tie: GraphicalTie, tieIsAtSystemBreak: boolean): void {
  224. throw new Error("abstract, not implemented");
  225. }
  226. protected calculateSingleStaffLineLyricsPosition(staffLine: StaffLine, lyricVersesNumber: number[]): void {
  227. throw new Error("abstract, not implemented");
  228. }
  229. protected calculateSingleOctaveShift(sourceMeasure: SourceMeasure, multiExpression: MultiExpression,
  230. measureIndex: number, staffIndex: number): void {
  231. throw new Error("abstract, not implemented");
  232. }
  233. protected calculateWordRepetitionInstruction(repetitionInstruction: RepetitionInstruction,
  234. measureIndex: number): void {
  235. throw new Error("abstract, not implemented");
  236. }
  237. protected calculateMoodAndUnknownExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  238. throw new Error("abstract, not implemented");
  239. }
  240. protected clearRecreatedObjects(): void {
  241. Logging.debug("clearRecreatedObjects not implemented");
  242. }
  243. protected handleStaffEntryLink(graphicalStaffEntry: GraphicalStaffEntry,
  244. staffEntryLinks: StaffEntryLink[]): void {
  245. Logging.debug("handleStaffEntryLink not implemented");
  246. }
  247. protected calculateMusicSystems(): void {
  248. if (this.graphicalMusicSheet.MeasureList === undefined) {
  249. return;
  250. }
  251. let allMeasures: StaffMeasure[][] = this.graphicalMusicSheet.MeasureList;
  252. if (allMeasures === undefined) {
  253. return;
  254. }
  255. let visibleMeasureList: StaffMeasure[][] = [];
  256. for (let idx: number = 0, len: number = allMeasures.length; idx < len; ++idx) {
  257. let staffMeasures: StaffMeasure[] = allMeasures[idx];
  258. let visibleStaffMeasures: StaffMeasure[] = [];
  259. for (let idx2: number = 0, len2: number = staffMeasures.length; idx2 < len2; ++idx2) {
  260. let staffMeasure: StaffMeasure = allMeasures[idx][idx2];
  261. if (staffMeasure.isVisible()) {
  262. visibleStaffMeasures.push(staffMeasure);
  263. }
  264. }
  265. visibleMeasureList.push(visibleStaffMeasures);
  266. }
  267. let numberOfStaffLines: number = 0;
  268. for (let idx: number = 0, len: number = visibleMeasureList.length; idx < len; ++idx) {
  269. let gmlist: StaffMeasure[] = visibleMeasureList[idx];
  270. numberOfStaffLines = Math.max(gmlist.length, numberOfStaffLines);
  271. break;
  272. }
  273. if (numberOfStaffLines === 0) {
  274. return;
  275. }
  276. let musicSystemBuilder: MusicSystemBuilder = new MusicSystemBuilder();
  277. musicSystemBuilder.initialize(this.graphicalMusicSheet, visibleMeasureList, numberOfStaffLines, this.symbolFactory);
  278. musicSystemBuilder.buildMusicSystems();
  279. this.checkMeasuresForWholeRestNotes();
  280. if (!this.leadSheet) {
  281. this.calculateBeams();
  282. this.optimizeRestPlacement();
  283. this.calculateStaffEntryArticulationMarks();
  284. this.calculateTieCurves();
  285. }
  286. this.calculateSkyBottomLines();
  287. this.calculateTupletNumbers();
  288. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  289. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  290. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  291. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  292. this.calculateMeasureNumberPlacement(musicSystem);
  293. }
  294. }
  295. if (!this.leadSheet) {
  296. this.calculateSlurs();
  297. }
  298. if (!this.leadSheet) {
  299. this.calculateOrnaments();
  300. }
  301. this.updateSkyBottomLines();
  302. this.calculateChordSymbols();
  303. if (!this.leadSheet) {
  304. this.calculateDynamicExpressions();
  305. this.optimizeStaffLineDynamicExpressionsPositions();
  306. this.calculateMoodAndUnknownExpressions();
  307. this.calculateOctaveShifts();
  308. this.calculateWordRepetitionInstructions();
  309. }
  310. this.calculateRepetitionEndings();
  311. if (!this.leadSheet) {
  312. this.calculateTempoExpressions();
  313. }
  314. this.calculateLyricsPosition();
  315. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  316. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  317. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  318. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  319. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  320. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  321. this.updateStaffLineBorders(staffLine);
  322. }
  323. }
  324. }
  325. this.calculateComments();
  326. this.calculateSystemYLayout();
  327. this.calculateMarkedAreas();
  328. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  329. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  330. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  331. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  332. musicSystem.setMusicSystemLabelsYPosition();
  333. if (!this.leadSheet) {
  334. musicSystem.setYPositionsToVerticalLineObjectsAndCreateLines(this.rules);
  335. musicSystem.createSystemLeftLine(this.rules.SystemThinLineWidth, this.rules.SystemLabelsRightMargin);
  336. musicSystem.createInstrumentBrackets(this.graphicalMusicSheet.ParentMusicSheet.Instruments, this.rules.StaffHeight);
  337. musicSystem.createGroupBrackets(this.graphicalMusicSheet.ParentMusicSheet.InstrumentalGroups, this.rules.StaffHeight, 0);
  338. musicSystem.alignBeginInstructions();
  339. } else if (musicSystem === musicSystem.Parent.MusicSystems[0]) {
  340. musicSystem.createSystemLeftLine(this.rules.SystemThinLineWidth, this.rules.SystemLabelsRightMargin);
  341. }
  342. musicSystem.calculateBorders(this.rules);
  343. }
  344. let distance: number = graphicalMusicPage.MusicSystems[0].PositionAndShape.BorderTop;
  345. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  346. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  347. // let newPosition: PointF2D = new PointF2D(musicSystem.PositionAndShape.RelativePosition.x,
  348. // musicSystem.PositionAndShape.RelativePosition.y - distance);
  349. musicSystem.PositionAndShape.RelativePosition =
  350. new PointF2D(musicSystem.PositionAndShape.RelativePosition.x, musicSystem.PositionAndShape.RelativePosition.y - distance);
  351. }
  352. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  353. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  354. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  355. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  356. staffLine.addActivitySymbolClickArea();
  357. }
  358. }
  359. if (graphicalMusicPage === this.graphicalMusicSheet.MusicPages[0]) {
  360. this.calculatePageLabels(graphicalMusicPage);
  361. }
  362. graphicalMusicPage.PositionAndShape.calculateTopBottomBorders();
  363. }
  364. }
  365. protected updateSkyBottomLine(staffLine: StaffLine): void {
  366. Logging.debug("updateSkyBottomLine not implemented");
  367. }
  368. protected calculateSkyBottomLine(staffLine: StaffLine): void {
  369. Logging.debug("calculateSkyBottomLine not implemented");
  370. }
  371. protected calculateMarkedAreas(): void {
  372. Logging.debug("calculateMarkedAreas not implemented");
  373. }
  374. protected calculateComments(): void {
  375. Logging.debug("calculateComments not implemented");
  376. }
  377. protected optimizeStaffLineDynamicExpressionsPositions(): void {
  378. return;
  379. }
  380. protected calculateChordSymbols(): void {
  381. return;
  382. }
  383. protected layoutMeasureWithWholeRest(rest: GraphicalNote, gse: GraphicalStaffEntry,
  384. measure: StaffMeasure): void {
  385. return;
  386. }
  387. protected layoutBeams(staffEntry: GraphicalStaffEntry): void {
  388. return;
  389. }
  390. protected layoutArticulationMarks(articulations: ArticulationEnum[], voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  391. return;
  392. }
  393. protected layoutOrnament(ornaments: OrnamentContainer, voiceEntry: VoiceEntry,
  394. graphicalStaffEntry: GraphicalStaffEntry): void {
  395. return;
  396. }
  397. protected calculateRestNotePlacementWithinGraphicalBeam(graphicalStaffEntry: GraphicalStaffEntry,
  398. restNote: GraphicalNote,
  399. previousNote: GraphicalNote,
  400. nextStaffEntry: GraphicalStaffEntry,
  401. nextNote: GraphicalNote): void {
  402. return;
  403. }
  404. protected calculateTupletNumbers(): void {
  405. return;
  406. }
  407. protected calculateSlurs(): void {
  408. return;
  409. }
  410. protected calculateDynamicExpressionsForSingleMultiExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  411. return;
  412. }
  413. protected calcGraphicalRepetitionEndingsRecursively(repetition: Repetition): void {
  414. return;
  415. }
  416. protected layoutSingleRepetitionEnding(start: StaffMeasure, end: StaffMeasure, numberText: string,
  417. offset: number, leftOpen: boolean, rightOpen: boolean): void {
  418. return;
  419. }
  420. protected calculateTempoExpressionsForSingleMultiTempoExpression(sourceMeasure: SourceMeasure, multiTempoExpression: MultiTempoExpression,
  421. measureIndex: number): void {
  422. return;
  423. }
  424. protected clearSystemsAndMeasures(): void {
  425. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  426. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  427. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  428. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  429. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  430. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  431. for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
  432. let graphicalMeasure: StaffMeasure = staffLine.Measures[idx4];
  433. if (graphicalMeasure.FirstInstructionStaffEntry !== undefined) {
  434. let index: number = graphicalMeasure.PositionAndShape.ChildElements.indexOf(
  435. graphicalMeasure.FirstInstructionStaffEntry.PositionAndShape
  436. );
  437. if (index > -1) {
  438. graphicalMeasure.PositionAndShape.ChildElements.splice(index, 1);
  439. }
  440. graphicalMeasure.FirstInstructionStaffEntry = undefined;
  441. graphicalMeasure.beginInstructionsWidth = 0.0;
  442. }
  443. if (graphicalMeasure.LastInstructionStaffEntry !== undefined) {
  444. let index: number = graphicalMeasure.PositionAndShape.ChildElements.indexOf(
  445. graphicalMeasure.LastInstructionStaffEntry.PositionAndShape
  446. );
  447. if (index > -1) {
  448. graphicalMeasure.PositionAndShape.ChildElements.splice(index, 1);
  449. }
  450. graphicalMeasure.LastInstructionStaffEntry = undefined;
  451. graphicalMeasure.endInstructionsWidth = 0.0;
  452. }
  453. }
  454. staffLine.Measures = [];
  455. staffLine.PositionAndShape.ChildElements = [];
  456. }
  457. musicSystem.StaffLines.length = 0;
  458. musicSystem.PositionAndShape.ChildElements = [];
  459. }
  460. graphicalMusicPage.MusicSystems = [];
  461. graphicalMusicPage.PositionAndShape.ChildElements = [];
  462. }
  463. this.graphicalMusicSheet.MusicPages = [];
  464. }
  465. protected handleVoiceEntry(voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry,
  466. accidentalCalculator: AccidentalCalculator, openLyricWords: LyricWord[],
  467. tieTimestampListDict: Dictionary<Tie, Fraction[]>, activeClef: ClefInstruction,
  468. openTuplets: Tuplet[], openBeams: Beam[],
  469. octaveShiftValue: OctaveEnum, grace: boolean = false, linkedNotes: Note[] = undefined,
  470. sourceStaffEntry: SourceStaffEntry = undefined): OctaveEnum {
  471. let graphicalNotes: GraphicalNote[] = graphicalStaffEntry.findOrCreateGraphicalNotesListFromVoiceEntry(voiceEntry);
  472. for (let idx: number = 0, len: number = voiceEntry.Notes.length; idx < len; ++idx) {
  473. let note: Note = voiceEntry.Notes[idx];
  474. if (sourceStaffEntry !== undefined && sourceStaffEntry.Link !== undefined && linkedNotes !== undefined && linkedNotes.indexOf(note) > -1) {
  475. continue;
  476. }
  477. let graphicalNote: GraphicalNote;
  478. let numberOfDots: number = note.calculateNumberOfNeededDots();
  479. if (grace) {
  480. graphicalNote = this.symbolFactory.createGraceNote(note, numberOfDots, graphicalStaffEntry, activeClef, octaveShiftValue);
  481. } else {
  482. graphicalNote = this.symbolFactory.createNote(note, numberOfDots, graphicalStaffEntry, activeClef, octaveShiftValue);
  483. }
  484. if (note.NoteTie !== undefined) {
  485. MusicSheetCalculator.addTieToTieTimestampsDict(tieTimestampListDict, note);
  486. }
  487. if (note.Pitch !== undefined) {
  488. this.checkNoteForAccidental(graphicalNote, accidentalCalculator, activeClef, octaveShiftValue, grace);
  489. }
  490. this.resetYPositionForLeadSheet(graphicalNote.PositionAndShape);
  491. graphicalStaffEntry.addGraphicalNoteToListAtCorrectYPosition(graphicalNotes, graphicalNote);
  492. graphicalStaffEntry.PositionAndShape.ChildElements.push(graphicalNote.PositionAndShape);
  493. graphicalNote.PositionAndShape.calculateBoundingBox();
  494. if (!this.leadSheet) {
  495. if (note.NoteBeam !== undefined) {
  496. this.handleBeam(graphicalNote, note.NoteBeam, openBeams);
  497. }
  498. if (note.NoteTuplet !== undefined) {
  499. this.handleTuplet(graphicalNote, note.NoteTuplet, openTuplets);
  500. }
  501. }
  502. }
  503. if (voiceEntry.Articulations.length > 0) {
  504. this.handleVoiceEntryArticulations(voiceEntry.Articulations, voiceEntry, graphicalStaffEntry);
  505. }
  506. if (voiceEntry.TechnicalInstructions.length > 0) {
  507. this.checkVoiceEntriesForTechnicalInstructions(voiceEntry, graphicalStaffEntry);
  508. }
  509. if (voiceEntry.LyricsEntries.size() > 0) {
  510. this.handleVoiceEntryLyrics(voiceEntry.LyricsEntries, voiceEntry, graphicalStaffEntry, openLyricWords);
  511. }
  512. if (voiceEntry.OrnamentContainer !== undefined) {
  513. this.handleVoiceEntryOrnaments(voiceEntry.OrnamentContainer, voiceEntry, graphicalStaffEntry);
  514. }
  515. return octaveShiftValue;
  516. }
  517. protected handleVoiceEntryGraceNotes(graceEntries: VoiceEntry[], graphicalGraceEntries: GraphicalStaffEntry[], graphicalStaffEntry: GraphicalStaffEntry,
  518. accidentalCalculator: AccidentalCalculator, activeClef: ClefInstruction,
  519. octaveShiftValue: OctaveEnum, lyricWords: LyricWord[],
  520. tieTimestampListDict: Dictionary<Tie, Fraction[]>,
  521. tuplets: Tuplet[], beams: Beam[]): void {
  522. if (graceEntries !== undefined) {
  523. for (let idx: number = 0, len: number = graceEntries.length; idx < len; ++idx) {
  524. let graceVoiceEntry: VoiceEntry = graceEntries[idx];
  525. let graceStaffEntry: GraphicalStaffEntry = this.symbolFactory.createGraceStaffEntry(
  526. graphicalStaffEntry,
  527. graphicalStaffEntry.parentMeasure
  528. );
  529. graphicalGraceEntries.push(graceStaffEntry);
  530. graphicalStaffEntry.PositionAndShape.ChildElements.push(graceStaffEntry.PositionAndShape);
  531. this.handleVoiceEntry(
  532. graceVoiceEntry, graceStaffEntry, accidentalCalculator, lyricWords,
  533. tieTimestampListDict, activeClef, tuplets,
  534. beams, octaveShiftValue, true
  535. );
  536. }
  537. }
  538. }
  539. protected handleOpenTies(measure: StaffMeasure, beams: Beam[], tieTimestampListDict: Dictionary<Tie, Fraction[]>,
  540. activeClef: ClefInstruction, octaveShiftParams: OctaveShiftParams): void {
  541. CollectionUtil.removeDictElementIfTrue(tieTimestampListDict, function (openTie: Tie, tieTimestamps: Fraction[]): boolean {
  542. // for (let m: number = tieTimestampListDict.size() - 1; m >= 0; m--) {
  543. // let keyValuePair: KeyValuePair<Tie, Fraction[]> = tieTimestampListDict.ElementAt(m);
  544. // let openTie: Tie = keyValuePair.Key;
  545. // let tieTimestamps: Fraction[] = keyValuePair.Value;
  546. let absoluteTimestamp: Fraction = undefined;
  547. let k: number;
  548. let removeTie: boolean = false;
  549. for (; k < tieTimestamps.length; k++) {
  550. if (!openTie.NoteHasBeenCreated[k]) {
  551. absoluteTimestamp = tieTimestamps[k];
  552. if (absoluteTimestamp >= Fraction.plus(measure.parentSourceMeasure.AbsoluteTimestamp, measure.parentSourceMeasure.Duration)) {
  553. continue;
  554. }
  555. let graphicalStaffEntry: GraphicalStaffEntry = undefined;
  556. if (absoluteTimestamp !== undefined) {
  557. for (let idx: number = 0, len: number = measure.staffEntries.length; idx < len; ++idx) {
  558. let gse: GraphicalStaffEntry = measure.staffEntries[idx];
  559. if (gse.getAbsoluteTimestamp() === absoluteTimestamp) {
  560. graphicalStaffEntry = gse;
  561. break;
  562. }
  563. }
  564. if (graphicalStaffEntry === undefined) {
  565. graphicalStaffEntry = this.createStaffEntryForTieNote(measure, absoluteTimestamp, openTie);
  566. }
  567. }
  568. if (graphicalStaffEntry !== undefined) {
  569. let octaveShiftValue: OctaveEnum = OctaveEnum.NONE;
  570. if (octaveShiftParams !== undefined) {
  571. if (graphicalStaffEntry.getAbsoluteTimestamp() >= octaveShiftParams.getAbsoluteStartTimestamp &&
  572. graphicalStaffEntry.getAbsoluteTimestamp() <= octaveShiftParams.getAbsoluteEndTimestamp) {
  573. octaveShiftValue = octaveShiftParams.getOpenOctaveShift.Type;
  574. }
  575. }
  576. let isLastTieNote: boolean = k === tieTimestamps.length - 1;
  577. let tieFraction: Fraction = openTie.Fractions[k];
  578. let numberOfDots: number = openTie.Start.calculateNumberOfNeededDots();
  579. this.createGraphicalTieNote(
  580. beams, activeClef, octaveShiftValue, graphicalStaffEntry, tieFraction, numberOfDots, openTie, isLastTieNote
  581. );
  582. let tieStartNote: Note = openTie.Start;
  583. if (isLastTieNote && tieStartNote.ParentVoiceEntry.Articulations.length === 1 &&
  584. tieStartNote.ParentVoiceEntry.Articulations[0] === ArticulationEnum.fermata) {
  585. this.symbolFactory.addFermataAtTiedEndNote(tieStartNote, graphicalStaffEntry);
  586. }
  587. openTie.NoteHasBeenCreated[k] = true;
  588. if (openTie.allGraphicalNotesHaveBeenCreated()) {
  589. removeTie = true;
  590. //tieTimestampListDict.remove(openTie);
  591. }
  592. }
  593. }
  594. }
  595. return removeTie;
  596. });
  597. }
  598. protected resetYPositionForLeadSheet(psi: BoundingBox): void {
  599. if (this.leadSheet) {
  600. psi.RelativePosition = new PointF2D(psi.RelativePosition.x, 0.0);
  601. }
  602. }
  603. protected layoutVoiceEntries(graphicalStaffEntry: GraphicalStaffEntry): void {
  604. graphicalStaffEntry.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
  605. let isGraceStaffEntry: boolean = graphicalStaffEntry.staffEntryParent !== undefined;
  606. if (!this.leadSheet) {
  607. let graphicalStaffEntryNotes: GraphicalNote[][] = graphicalStaffEntry.notes;
  608. for (let idx4: number = 0, len4: number = graphicalStaffEntryNotes.length; idx4 < len4; ++idx4) {
  609. let graphicalNotes: GraphicalNote[] = graphicalStaffEntryNotes[idx4];
  610. if (graphicalNotes.length === 0) {
  611. continue;
  612. }
  613. let voiceEntry: VoiceEntry = graphicalNotes[0].sourceNote.ParentVoiceEntry;
  614. let hasPitchedNote: boolean = graphicalNotes[0].sourceNote.Pitch !== undefined;
  615. this.layoutVoiceEntry(voiceEntry, graphicalNotes, graphicalStaffEntry, hasPitchedNote, isGraceStaffEntry);
  616. }
  617. }
  618. }
  619. protected maxInstrNameLabelLength(): number {
  620. let maxLabelLength: number = 0.0;
  621. for (let instrument of this.graphicalMusicSheet.ParentMusicSheet.Instruments) {
  622. if (instrument.Voices.length > 0 && instrument.Voices[0].Visible) {
  623. let graphicalLabel: GraphicalLabel = new GraphicalLabel(instrument.NameLabel, this.rules.InstrumentLabelTextHeight, TextAlignment.LeftCenter);
  624. graphicalLabel.setLabelPositionAndShapeBorders();
  625. maxLabelLength = Math.max(maxLabelLength, graphicalLabel.PositionAndShape.MarginSize.width);
  626. }
  627. }
  628. return maxLabelLength;
  629. }
  630. protected calculateSheetLabelBoundingBoxes(): void {
  631. let musicSheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
  632. if (musicSheet.Title !== undefined) {
  633. let title: GraphicalLabel = new GraphicalLabel(musicSheet.Title, this.rules.SheetTitleHeight, TextAlignment.CenterBottom);
  634. this.graphicalMusicSheet.Title = title;
  635. title.setLabelPositionAndShapeBorders();
  636. }
  637. if (musicSheet.Subtitle !== undefined) {
  638. let subtitle: GraphicalLabel = new GraphicalLabel(musicSheet.Subtitle, this.rules.SheetSubtitleHeight, TextAlignment.CenterCenter);
  639. this.graphicalMusicSheet.Subtitle = subtitle;
  640. subtitle.setLabelPositionAndShapeBorders();
  641. }
  642. if (musicSheet.Composer !== undefined) {
  643. let composer: GraphicalLabel = new GraphicalLabel(musicSheet.Composer, this.rules.SheetComposerHeight, TextAlignment.RightCenter);
  644. this.graphicalMusicSheet.Composer = composer;
  645. composer.setLabelPositionAndShapeBorders();
  646. }
  647. if (musicSheet.Lyricist !== undefined) {
  648. let lyricist: GraphicalLabel = new GraphicalLabel(musicSheet.Lyricist, this.rules.SheetAuthorHeight, TextAlignment.LeftCenter);
  649. this.graphicalMusicSheet.Lyricist = lyricist;
  650. lyricist.setLabelPositionAndShapeBorders();
  651. }
  652. }
  653. protected checkMeasuresForWholeRestNotes(): void {
  654. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  655. let musicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  656. for (let idx2: number = 0, len2: number = musicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  657. let musicSystem: MusicSystem = musicPage.MusicSystems[idx2];
  658. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  659. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  660. for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
  661. let measure: StaffMeasure = staffLine.Measures[idx4];
  662. if (measure.staffEntries.length === 1) {
  663. let gse: GraphicalStaffEntry = measure.staffEntries[0];
  664. if (gse.notes.length > 0 && gse.notes[0].length > 0) {
  665. let graphicalNote: GraphicalNote = gse.notes[0][0];
  666. if (graphicalNote.sourceNote.Pitch === undefined && (new Fraction(1, 2)).lt(graphicalNote.sourceNote.Length)) {
  667. this.layoutMeasureWithWholeRest(graphicalNote, gse, measure);
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. }
  675. }
  676. protected optimizeRestNotePlacement(graphicalStaffEntry: GraphicalStaffEntry, measure: StaffMeasure): void {
  677. if (graphicalStaffEntry.notes.length === 0) {
  678. return;
  679. }
  680. let voice1Notes: GraphicalNote[] = graphicalStaffEntry.notes[0];
  681. if (voice1Notes.length === 0) {
  682. return;
  683. }
  684. let voice1Note1: GraphicalNote = voice1Notes[0];
  685. let voice1Note1IsRest: boolean = voice1Note1.sourceNote.Pitch === undefined;
  686. if (graphicalStaffEntry.notes.length === 2) {
  687. let voice2Note1IsRest: boolean = false;
  688. let voice2Notes: GraphicalNote[] = graphicalStaffEntry.notes[1];
  689. if (voice2Notes.length > 0) {
  690. let voice2Note1: GraphicalNote = voice2Notes[0];
  691. voice2Note1IsRest = voice2Note1.sourceNote.Pitch === undefined;
  692. }
  693. if (voice1Note1IsRest && voice2Note1IsRest) {
  694. this.calculateTwoRestNotesPlacementWithCollisionDetection(graphicalStaffEntry);
  695. } else if (voice1Note1IsRest || voice2Note1IsRest) {
  696. this.calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(graphicalStaffEntry);
  697. }
  698. } else if (voice1Note1IsRest && graphicalStaffEntry !== measure.staffEntries[0] &&
  699. graphicalStaffEntry !== measure.staffEntries[measure.staffEntries.length - 1]) {
  700. let staffEntryIndex: number = measure.staffEntries.indexOf(graphicalStaffEntry);
  701. let previousStaffEntry: GraphicalStaffEntry = measure.staffEntries[staffEntryIndex - 1];
  702. let nextStaffEntry: GraphicalStaffEntry = measure.staffEntries[staffEntryIndex + 1];
  703. if (previousStaffEntry.notes.length === 1) {
  704. let previousNote: GraphicalNote = previousStaffEntry.notes[0][0];
  705. if (previousNote.sourceNote.NoteBeam !== undefined && nextStaffEntry.notes.length === 1) {
  706. let nextNote: GraphicalNote = nextStaffEntry.notes[0][0];
  707. if (nextNote.sourceNote.NoteBeam !== undefined && previousNote.sourceNote.NoteBeam === nextNote.sourceNote.NoteBeam) {
  708. this.calculateRestNotePlacementWithinGraphicalBeam(
  709. graphicalStaffEntry, voice1Note1, previousNote,
  710. nextStaffEntry, nextNote
  711. );
  712. graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
  713. }
  714. }
  715. }
  716. }
  717. }
  718. protected getRelativePositionInStaffLineFromTimestamp(timestamp: Fraction, verticalIndex: number, staffLine: StaffLine,
  719. multiStaffInstrument: boolean, firstVisibleMeasureRelativeX: number = 0.0): PointF2D {
  720. let relative: PointF2D = new PointF2D();
  721. let leftStaffEntry: GraphicalStaffEntry = undefined;
  722. let rightStaffEntry: GraphicalStaffEntry = undefined;
  723. let numEntries: number = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
  724. let index: number = this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(timestamp);
  725. let leftIndex: number = <number>Math.min(Math.floor(index), numEntries - 1);
  726. let rightIndex: number = <number>Math.min(Math.ceil(index), numEntries - 1);
  727. if (leftIndex < 0 || verticalIndex < 0) {
  728. return relative;
  729. }
  730. leftStaffEntry = this.getFirstLeftNotNullStaffEntryFromContainer(leftIndex, verticalIndex, multiStaffInstrument);
  731. rightStaffEntry = this.getFirstRightNotNullStaffEntryFromContainer(rightIndex, verticalIndex, multiStaffInstrument);
  732. if (leftStaffEntry !== undefined && rightStaffEntry !== undefined) {
  733. let measureRelativeX: number = leftStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x;
  734. if (firstVisibleMeasureRelativeX > 0) {
  735. measureRelativeX = firstVisibleMeasureRelativeX;
  736. }
  737. let leftX: number = leftStaffEntry.PositionAndShape.RelativePosition.x + measureRelativeX;
  738. let rightX: number = rightStaffEntry.PositionAndShape.RelativePosition.x + rightStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x;
  739. if (firstVisibleMeasureRelativeX > 0) {
  740. rightX = rightStaffEntry.PositionAndShape.RelativePosition.x + measureRelativeX;
  741. }
  742. let timestampQuotient: number = 0.0;
  743. if (leftStaffEntry !== rightStaffEntry) {
  744. let leftTimestamp: Fraction = leftStaffEntry.getAbsoluteTimestamp();
  745. let rightTimestamp: Fraction = rightStaffEntry.getAbsoluteTimestamp();
  746. let leftDifference: Fraction = Fraction.minus(timestamp, leftTimestamp);
  747. timestampQuotient = leftDifference.RealValue / Fraction.minus(rightTimestamp, leftTimestamp).RealValue;
  748. }
  749. if (leftStaffEntry.parentMeasure.ParentStaffLine !== rightStaffEntry.parentMeasure.ParentStaffLine) {
  750. if (leftStaffEntry.parentMeasure.ParentStaffLine === staffLine) {
  751. rightX = staffLine.PositionAndShape.Size.width;
  752. } else {
  753. leftX = staffLine.PositionAndShape.RelativePosition.x;
  754. }
  755. }
  756. relative = new PointF2D(leftX + (rightX - leftX) * timestampQuotient, 0.0);
  757. }
  758. return relative;
  759. }
  760. protected getRelativeXPositionFromTimestamp(timestamp: Fraction): number {
  761. let numEntries: number = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
  762. let index: number = this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(timestamp);
  763. let discreteIndex: number = <number>Math.max(0, Math.min(Math.round(index), numEntries - 1));
  764. let gse: GraphicalStaffEntry = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[discreteIndex].getFirstNonNullStaffEntry();
  765. let posX: number = gse.PositionAndShape.RelativePosition.x + gse.parentMeasure.PositionAndShape.RelativePosition.x;
  766. return posX;
  767. }
  768. protected calculatePageLabels(page: GraphicalMusicPage): void {
  769. let firstSystemAbsoluteTopMargin: number = 10;
  770. if (page.MusicSystems.length > 0) {
  771. let firstMusicSystem: MusicSystem = page.MusicSystems[0];
  772. firstSystemAbsoluteTopMargin = firstMusicSystem.PositionAndShape.RelativePosition.y + firstMusicSystem.PositionAndShape.BorderTop;
  773. }
  774. if (this.graphicalMusicSheet.Title !== undefined) {
  775. let title: GraphicalLabel = this.graphicalMusicSheet.Title;
  776. title.PositionAndShape.Parent = page.PositionAndShape;
  777. page.PositionAndShape.ChildElements.push(title.PositionAndShape);
  778. let relative: PointF2D = new PointF2D();
  779. relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth / 2;
  780. relative.y = this.rules.TitleTopDistance + this.rules.SheetTitleHeight;
  781. title.PositionAndShape.RelativePosition = relative;
  782. page.Labels.push(title);
  783. }
  784. if (this.graphicalMusicSheet.Subtitle !== undefined) {
  785. let subtitle: GraphicalLabel = this.graphicalMusicSheet.Subtitle;
  786. subtitle.PositionAndShape.Parent = page.PositionAndShape;
  787. page.PositionAndShape.ChildElements.push(subtitle.PositionAndShape);
  788. let relative: PointF2D = new PointF2D();
  789. relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth / 2;
  790. relative.y = this.rules.TitleTopDistance + this.rules.SheetTitleHeight + this.rules.SheetMinimumDistanceBetweenTitleAndSubtitle;
  791. subtitle.PositionAndShape.RelativePosition = relative;
  792. page.Labels.push(subtitle);
  793. }
  794. if (this.graphicalMusicSheet.Composer !== undefined) {
  795. let composer: GraphicalLabel = this.graphicalMusicSheet.Composer;
  796. composer.PositionAndShape.Parent = page.PositionAndShape;
  797. page.PositionAndShape.ChildElements.push(composer.PositionAndShape);
  798. composer.setLabelPositionAndShapeBorders();
  799. let relative: PointF2D = new PointF2D();
  800. relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth - this.rules.PageRightMargin;
  801. relative.y = firstSystemAbsoluteTopMargin - this.rules.SystemComposerDistance;
  802. composer.PositionAndShape.RelativePosition = relative;
  803. page.Labels.push(composer);
  804. }
  805. if (this.graphicalMusicSheet.Lyricist !== undefined) {
  806. let lyricist: GraphicalLabel = this.graphicalMusicSheet.Lyricist;
  807. lyricist.PositionAndShape.Parent = page.PositionAndShape;
  808. page.PositionAndShape.ChildElements.push(lyricist.PositionAndShape);
  809. lyricist.setLabelPositionAndShapeBorders();
  810. let relative: PointF2D = new PointF2D();
  811. relative.x = this.rules.PageLeftMargin;
  812. relative.y = firstSystemAbsoluteTopMargin - this.rules.SystemComposerDistance;
  813. lyricist.PositionAndShape.RelativePosition = relative;
  814. page.Labels.push(lyricist);
  815. }
  816. }
  817. protected createGraphicalTies(): void {
  818. for (let measureIndex: number = 0; measureIndex < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; measureIndex++) {
  819. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[measureIndex];
  820. for (let staffIndex: number = 0; staffIndex < sourceMeasure.CompleteNumberOfStaves; staffIndex++) {
  821. for (let j: number = 0; j < sourceMeasure.VerticalSourceStaffEntryContainers.length; j++) {
  822. let sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[j].StaffEntries[staffIndex];
  823. if (sourceStaffEntry !== undefined) {
  824. let startStaffEntry: GraphicalStaffEntry = this.graphicalMusicSheet.findGraphicalStaffEntryFromMeasureList(
  825. staffIndex, measureIndex, sourceStaffEntry
  826. );
  827. for (let idx: number = 0, len: number = sourceStaffEntry.VoiceEntries.length; idx < len; ++idx) {
  828. let voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
  829. for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
  830. let note: Note = voiceEntry.Notes[idx2];
  831. if (note.NoteTie !== undefined) {
  832. let tie: Tie = note.NoteTie;
  833. this.handleTie(tie, startStaffEntry, staffIndex, measureIndex);
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. }
  841. }
  842. private createAccidentalCalculators(): AccidentalCalculator[] {
  843. let accidentalCalculators: AccidentalCalculator[] = [];
  844. let firstSourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();
  845. if (firstSourceMeasure !== undefined) {
  846. for (let i: number = 0; i < firstSourceMeasure.CompleteNumberOfStaves; i++) {
  847. let accidentalCalculator: AccidentalCalculator = new AccidentalCalculator(this.symbolFactory);
  848. accidentalCalculators.push(accidentalCalculator);
  849. if (firstSourceMeasure.FirstInstructionsStaffEntries[i] !== undefined) {
  850. for (let idx: number = 0, len: number = firstSourceMeasure.FirstInstructionsStaffEntries[i].Instructions.length; idx < len; ++idx) {
  851. let abstractNotationInstruction: AbstractNotationInstruction = firstSourceMeasure.FirstInstructionsStaffEntries[i].Instructions[idx];
  852. if (abstractNotationInstruction instanceof KeyInstruction) {
  853. let keyInstruction: KeyInstruction = <KeyInstruction>abstractNotationInstruction;
  854. accidentalCalculator.ActiveKeyInstruction = keyInstruction;
  855. }
  856. }
  857. }
  858. }
  859. }
  860. return accidentalCalculators;
  861. }
  862. private calculateVerticalContainersList(): void {
  863. let numberOfEntries: number = this.graphicalMusicSheet.MeasureList[0].length;
  864. for (let i: number = 0; i < this.graphicalMusicSheet.MeasureList.length; i++) {
  865. for (let j: number = 0; j < numberOfEntries; j++) {
  866. let measure: StaffMeasure = this.graphicalMusicSheet.MeasureList[i][j];
  867. for (let idx: number = 0, len: number = measure.staffEntries.length; idx < len; ++idx) {
  868. let graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx];
  869. let verticalContainer: VerticalGraphicalStaffEntryContainer =
  870. this.graphicalMusicSheet.getOrCreateVerticalContainer(graphicalStaffEntry.getAbsoluteTimestamp());
  871. if (verticalContainer !== undefined) {
  872. verticalContainer.StaffEntries[j] = graphicalStaffEntry;
  873. graphicalStaffEntry.parentVerticalContainer = verticalContainer;
  874. } else {
  875. ;
  876. }
  877. }
  878. }
  879. }
  880. }
  881. private setIndecesToVerticalGraphicalContainers(): void {
  882. for (let i: number = 0; i < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length; i++) {
  883. this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].Index = i;
  884. }
  885. }
  886. private createGraphicalMeasuresForSourceMeasure(sourceMeasure: SourceMeasure, accidentalCalculators: AccidentalCalculator[],
  887. openLyricWords: LyricWord[],
  888. tieTimestampListDictList: Dictionary<Tie, Fraction[]>[],
  889. openOctaveShifts: OctaveShiftParams[], activeClefs: ClefInstruction[]): StaffMeasure[] {
  890. this.initStaffMeasuresCreation();
  891. let verticalMeasureList: StaffMeasure[] = [];
  892. let openBeams: Beam[] = [];
  893. let openTuplets: Tuplet[] = [];
  894. let staffEntryLinks: StaffEntryLink[] = [];
  895. for (let staffIndex: number = 0; staffIndex < sourceMeasure.CompleteNumberOfStaves; staffIndex++) {
  896. let measure: StaffMeasure = this.createGraphicalMeasure(
  897. sourceMeasure, tieTimestampListDictList[staffIndex], openTuplets, openBeams,
  898. accidentalCalculators[staffIndex], activeClefs, openOctaveShifts, openLyricWords, staffIndex, staffEntryLinks
  899. );
  900. verticalMeasureList.push(measure);
  901. }
  902. this.graphicalMusicSheet.sourceToGraphicalMeasureLinks.setValue(sourceMeasure, verticalMeasureList);
  903. return verticalMeasureList;
  904. }
  905. private createGraphicalMeasure(sourceMeasure: SourceMeasure, tieTimestampListDict: Dictionary<Tie, Fraction[]>, openTuplets: Tuplet[], openBeams: Beam[],
  906. accidentalCalculator: AccidentalCalculator, activeClefs: ClefInstruction[],
  907. openOctaveShifts: OctaveShiftParams[], openLyricWords: LyricWord[], staffIndex: number,
  908. staffEntryLinks: StaffEntryLink[]): StaffMeasure {
  909. let staff: Staff = this.graphicalMusicSheet.ParentMusicSheet.getStaffFromIndex(staffIndex);
  910. let measure: StaffMeasure = this.symbolFactory.createStaffMeasure(sourceMeasure, staff);
  911. measure.hasError = sourceMeasure.getErrorInMeasure(staffIndex);
  912. if (sourceMeasure.FirstInstructionsStaffEntries[staffIndex] !== undefined) {
  913. for (let idx: number = 0, len: number = sourceMeasure.FirstInstructionsStaffEntries[staffIndex].Instructions.length; idx < len; ++idx) {
  914. let instruction: AbstractNotationInstruction = sourceMeasure.FirstInstructionsStaffEntries[staffIndex].Instructions[idx];
  915. if (instruction instanceof KeyInstruction) {
  916. let key: KeyInstruction = KeyInstruction.copy(instruction);
  917. if (this.graphicalMusicSheet.ParentMusicSheet.Transpose !== 0 &&
  918. measure.ParentStaff.ParentInstrument.MidiInstrumentId !== MidiInstrument.Percussion &&
  919. MusicSheetCalculator.transposeCalculator !== undefined) {
  920. MusicSheetCalculator.transposeCalculator.transposeKey(
  921. key, this.graphicalMusicSheet.ParentMusicSheet.Transpose
  922. );
  923. }
  924. accidentalCalculator.ActiveKeyInstruction = key;
  925. }
  926. }
  927. }
  928. for (let idx: number = 0, len: number = sourceMeasure.StaffLinkedExpressions[staffIndex].length; idx < len; ++idx) {
  929. let multiExpression: MultiExpression = sourceMeasure.StaffLinkedExpressions[staffIndex][idx];
  930. if (multiExpression.OctaveShiftStart !== undefined) {
  931. let openOctaveShift: OctaveShift = multiExpression.OctaveShiftStart;
  932. openOctaveShifts[staffIndex] = new OctaveShiftParams(
  933. openOctaveShift, multiExpression.AbsoluteTimestamp,
  934. openOctaveShift.ParentEndMultiExpression.AbsoluteTimestamp
  935. );
  936. }
  937. }
  938. for (let entryIndex: number = 0; entryIndex < sourceMeasure.VerticalSourceStaffEntryContainers.length; entryIndex++) {
  939. let sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[entryIndex].StaffEntries[staffIndex];
  940. if (sourceStaffEntry !== undefined) {
  941. for (let idx: number = 0, len: number = sourceStaffEntry.Instructions.length; idx < len; ++idx) {
  942. let abstractNotationInstruction: AbstractNotationInstruction = sourceStaffEntry.Instructions[idx];
  943. if (abstractNotationInstruction instanceof ClefInstruction) {
  944. activeClefs[staffIndex] = <ClefInstruction>abstractNotationInstruction;
  945. }
  946. }
  947. let graphicalStaffEntry: GraphicalStaffEntry = this.symbolFactory.createStaffEntry(sourceStaffEntry, measure);
  948. if (measure.staffEntries.length > entryIndex) {
  949. measure.addGraphicalStaffEntryAtTimestamp(graphicalStaffEntry);
  950. } else {
  951. measure.addGraphicalStaffEntry(graphicalStaffEntry);
  952. }
  953. let linkedNotes: Note[] = [];
  954. if (sourceStaffEntry.Link !== undefined) {
  955. sourceStaffEntry.findLinkedNotes(linkedNotes);
  956. this.handleStaffEntryLink(graphicalStaffEntry, staffEntryLinks);
  957. }
  958. let octaveShiftValue: OctaveEnum = OctaveEnum.NONE;
  959. if (openOctaveShifts[staffIndex] !== undefined) {
  960. let octaveShiftParams: OctaveShiftParams = openOctaveShifts[staffIndex];
  961. if (sourceStaffEntry.AbsoluteTimestamp >= octaveShiftParams.getAbsoluteStartTimestamp &&
  962. sourceStaffEntry.AbsoluteTimestamp <= octaveShiftParams.getAbsoluteEndTimestamp) {
  963. octaveShiftValue = octaveShiftParams.getOpenOctaveShift.Type;
  964. }
  965. }
  966. for (let idx: number = 0, len: number = sourceStaffEntry.VoiceEntries.length; idx < len; ++idx) {
  967. let voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
  968. this.handleVoiceEntryGraceNotes(
  969. voiceEntry.graceVoiceEntriesBefore, graphicalStaffEntry.graceStaffEntriesBefore, graphicalStaffEntry,
  970. accidentalCalculator, activeClefs[staffIndex], octaveShiftValue, openLyricWords,
  971. tieTimestampListDict, openTuplets, openBeams
  972. );
  973. octaveShiftValue = this.handleVoiceEntry(
  974. voiceEntry, graphicalStaffEntry,
  975. accidentalCalculator, openLyricWords,
  976. tieTimestampListDict,
  977. activeClefs[staffIndex], openTuplets,
  978. openBeams, octaveShiftValue, false, linkedNotes,
  979. sourceStaffEntry
  980. );
  981. this.handleVoiceEntryGraceNotes(
  982. voiceEntry.graceVoiceEntriesAfter, graphicalStaffEntry.graceStaffEntriesAfter, graphicalStaffEntry,
  983. accidentalCalculator, activeClefs[staffIndex], octaveShiftValue, openLyricWords,
  984. tieTimestampListDict, openTuplets, openBeams
  985. );
  986. }
  987. if (sourceStaffEntry.Instructions.length > 0) {
  988. let clefInstruction: ClefInstruction = <ClefInstruction>sourceStaffEntry.Instructions[0];
  989. this.symbolFactory.createInStaffClef(graphicalStaffEntry, clefInstruction);
  990. }
  991. if (sourceStaffEntry.ChordContainer !== undefined) {
  992. sourceStaffEntry.ParentStaff.ParentInstrument.HasChordSymbols = true;
  993. this.symbolFactory.createChordSymbol(sourceStaffEntry, graphicalStaffEntry, this.graphicalMusicSheet.ParentMusicSheet.Transpose);
  994. }
  995. }
  996. }
  997. if (tieTimestampListDict.size() > 0) {
  998. this.handleOpenTies(
  999. measure, openBeams,
  1000. tieTimestampListDict, activeClefs[staffIndex], openOctaveShifts[staffIndex]
  1001. );
  1002. }
  1003. accidentalCalculator.doCalculationsAtEndOfMeasure();
  1004. if (sourceMeasure.LastInstructionsStaffEntries[staffIndex] !== undefined) {
  1005. let lastStaffEntry: SourceStaffEntry = sourceMeasure.LastInstructionsStaffEntries[staffIndex];
  1006. for (let idx: number = 0, len: number = lastStaffEntry.Instructions.length; idx < len; ++idx) {
  1007. let abstractNotationInstruction: AbstractNotationInstruction = lastStaffEntry.Instructions[idx];
  1008. if (abstractNotationInstruction instanceof ClefInstruction) {
  1009. activeClefs[staffIndex] = <ClefInstruction>abstractNotationInstruction;
  1010. }
  1011. }
  1012. }
  1013. for (let idx: number = 0, len: number = sourceMeasure.StaffLinkedExpressions[staffIndex].length; idx < len; ++idx) {
  1014. let multiExpression: MultiExpression = sourceMeasure.StaffLinkedExpressions[staffIndex][idx];
  1015. if (multiExpression.OctaveShiftEnd !== undefined && openOctaveShifts[staffIndex] !== undefined &&
  1016. multiExpression.OctaveShiftEnd === openOctaveShifts[staffIndex].getOpenOctaveShift) {
  1017. openOctaveShifts[staffIndex] = undefined;
  1018. }
  1019. }
  1020. if (measure.staffEntries.length === 0) {
  1021. let sourceStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, staff);
  1022. let note: Note = new Note(undefined, sourceStaffEntry, Fraction.createFromFraction(sourceMeasure.Duration), undefined);
  1023. let graphicalStaffEntry: GraphicalStaffEntry = this.symbolFactory.createStaffEntry(sourceStaffEntry, measure);
  1024. measure.addGraphicalStaffEntry(graphicalStaffEntry);
  1025. graphicalStaffEntry.relInMeasureTimestamp = new Fraction(0, 1);
  1026. let graphicalNotes: GraphicalNote[] = [];
  1027. graphicalStaffEntry.notes.push(graphicalNotes);
  1028. let numberOfDots: number = note.calculateNumberOfNeededDots();
  1029. let graphicalNote: GraphicalNote = this.symbolFactory.createNote( note,
  1030. numberOfDots,
  1031. graphicalStaffEntry,
  1032. new ClefInstruction(ClefEnum.G, 0, 2),
  1033. OctaveEnum.NONE);
  1034. graphicalNotes.push(graphicalNote);
  1035. graphicalStaffEntry.PositionAndShape.ChildElements.push(graphicalNote.PositionAndShape);
  1036. }
  1037. return measure;
  1038. }
  1039. private checkVoiceEntriesForTechnicalInstructions(voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  1040. for (let idx: number = 0, len: number = voiceEntry.TechnicalInstructions.length; idx < len; ++idx) {
  1041. let technicalInstruction: TechnicalInstruction = voiceEntry.TechnicalInstructions[idx];
  1042. this.symbolFactory.createGraphicalTechnicalInstruction(technicalInstruction, graphicalStaffEntry);
  1043. }
  1044. }
  1045. private checkNoteForAccidental(graphicalNote: GraphicalNote, accidentalCalculator: AccidentalCalculator, activeClef: ClefInstruction,
  1046. octaveEnum: OctaveEnum, grace: boolean = false): void {
  1047. let pitch: Pitch = graphicalNote.sourceNote.Pitch;
  1048. let transpose: number = this.graphicalMusicSheet.ParentMusicSheet.Transpose;
  1049. if (transpose !== 0 && graphicalNote.sourceNote.ParentStaffEntry.ParentStaff.ParentInstrument.MidiInstrumentId !== MidiInstrument.Percussion) {
  1050. pitch = graphicalNote.Transpose(
  1051. accidentalCalculator.ActiveKeyInstruction, activeClef, transpose, octaveEnum
  1052. );
  1053. if (graphicalNote.sourceNote.NoteTie !== undefined) {
  1054. graphicalNote.sourceNote.NoteTie.BaseNoteYPosition = graphicalNote.PositionAndShape.RelativePosition.y;
  1055. }
  1056. }
  1057. graphicalNote.sourceNote.halfTone = pitch.getHalfTone();
  1058. let scalingFactor: number = 1.0;
  1059. if (grace) {
  1060. scalingFactor = this.rules.GraceNoteScalingFactor;
  1061. }
  1062. accidentalCalculator.checkAccidental(graphicalNote, pitch, grace, scalingFactor);
  1063. }
  1064. // needed to disable linter, as it doesn't recognize the existing usage of this method.
  1065. // ToDo: check if a newer version doesn't have the problem.
  1066. /* tslint:disable:no-unused-variable */
  1067. private createStaffEntryForTieNote(measure: StaffMeasure, absoluteTimestamp: Fraction, openTie: Tie): GraphicalStaffEntry {
  1068. /* tslint:enable:no-unused-variable */
  1069. let graphicalStaffEntry: GraphicalStaffEntry;
  1070. graphicalStaffEntry = this.symbolFactory.createStaffEntry(openTie.Start.ParentStaffEntry, measure);
  1071. graphicalStaffEntry.relInMeasureTimestamp = Fraction.minus(absoluteTimestamp, measure.parentSourceMeasure.AbsoluteTimestamp);
  1072. this.resetYPositionForLeadSheet(graphicalStaffEntry.PositionAndShape);
  1073. measure.addGraphicalStaffEntry(graphicalStaffEntry);
  1074. return graphicalStaffEntry;
  1075. }
  1076. private updateSkyBottomLines(): void {
  1077. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1078. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1079. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1080. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  1081. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1082. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1083. this.updateSkyBottomLine(staffLine);
  1084. }
  1085. }
  1086. }
  1087. }
  1088. private handleStaffEntries(): void {
  1089. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MeasureList.length; idx < len; ++idx) {
  1090. let measures: StaffMeasure[] = this.graphicalMusicSheet.MeasureList[idx];
  1091. for (let idx2: number = 0, len2: number = measures.length; idx2 < len2; ++idx2) {
  1092. let measure: StaffMeasure = measures[idx2];
  1093. for (let idx3: number = 0, len3: number = measure.staffEntries.length; idx3 < len3; ++idx3) {
  1094. let graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx3];
  1095. if (graphicalStaffEntry.parentMeasure !== undefined && graphicalStaffEntry.notes.length > 0 && graphicalStaffEntry.notes[0].length > 0) {
  1096. this.layoutVoiceEntries(graphicalStaffEntry);
  1097. this.layoutStaffEntry(graphicalStaffEntry);
  1098. }
  1099. }
  1100. }
  1101. }
  1102. }
  1103. private calculateSkyBottomLines(): void {
  1104. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1105. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1106. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1107. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  1108. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1109. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1110. this.calculateSkyBottomLine(staffLine);
  1111. }
  1112. }
  1113. }
  1114. }
  1115. private calculateBeams(): void {
  1116. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1117. let musicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1118. for (let idx2: number = 0, len2: number = musicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1119. let musicSystem: MusicSystem = musicPage.MusicSystems[idx2];
  1120. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1121. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1122. for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
  1123. let measure: StaffMeasure = staffLine.Measures[idx4];
  1124. for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
  1125. let staffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
  1126. this.layoutBeams(staffEntry);
  1127. }
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. private calculateStaffEntryArticulationMarks(): void {
  1134. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1135. let page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1136. for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
  1137. let system: MusicSystem = page.MusicSystems[idx2];
  1138. for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
  1139. let line: StaffLine = system.StaffLines[idx3];
  1140. for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
  1141. let measure: StaffMeasure = line.Measures[idx4];
  1142. for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
  1143. let graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
  1144. for (let idx6: number = 0, len6: number = graphicalStaffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
  1145. let voiceEntry: VoiceEntry = graphicalStaffEntry.sourceStaffEntry.VoiceEntries[idx6];
  1146. if (voiceEntry.Articulations.length > 0) {
  1147. this.layoutArticulationMarks(voiceEntry.Articulations, voiceEntry, graphicalStaffEntry);
  1148. }
  1149. }
  1150. }
  1151. }
  1152. }
  1153. }
  1154. }
  1155. }
  1156. private calculateOrnaments(): void {
  1157. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1158. let page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1159. for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
  1160. let system: MusicSystem = page.MusicSystems[idx2];
  1161. for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
  1162. let line: StaffLine = system.StaffLines[idx3];
  1163. for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
  1164. let measure: StaffMeasure = line.Measures[idx4];
  1165. for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
  1166. let graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
  1167. for (let idx6: number = 0, len6: number = graphicalStaffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
  1168. let voiceEntry: VoiceEntry = graphicalStaffEntry.sourceStaffEntry.VoiceEntries[idx6];
  1169. if (voiceEntry.OrnamentContainer !== undefined) {
  1170. if (voiceEntry.hasTie() && graphicalStaffEntry.relInMeasureTimestamp !== voiceEntry.Timestamp) {
  1171. continue;
  1172. }
  1173. this.layoutOrnament(voiceEntry.OrnamentContainer, voiceEntry, graphicalStaffEntry);
  1174. if (!(this.staffEntriesWithOrnaments.indexOf(graphicalStaffEntry) !== -1)) {
  1175. this.staffEntriesWithOrnaments.push(graphicalStaffEntry);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. private optimizeRestPlacement(): void {
  1186. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1187. let page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1188. for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
  1189. let system: MusicSystem = page.MusicSystems[idx2];
  1190. for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
  1191. let line: StaffLine = system.StaffLines[idx3];
  1192. for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
  1193. let measure: StaffMeasure = line.Measures[idx4];
  1194. for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
  1195. let graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
  1196. this.optimizeRestNotePlacement(graphicalStaffEntry, measure);
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. private calculateTwoRestNotesPlacementWithCollisionDetection(graphicalStaffEntry: GraphicalStaffEntry): void {
  1204. let firstRestNote: GraphicalNote = graphicalStaffEntry.notes[0][0];
  1205. let secondRestNote: GraphicalNote = graphicalStaffEntry.notes[1][0];
  1206. secondRestNote.PositionAndShape.RelativePosition = new PointF2D(0.0, 2.5);
  1207. graphicalStaffEntry.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement();
  1208. firstRestNote.PositionAndShape.computeNonOverlappingPositionWithMargin(
  1209. graphicalStaffEntry.PositionAndShape, ColDirEnum.Up,
  1210. new PointF2D(0.0, secondRestNote.PositionAndShape.RelativePosition.y)
  1211. );
  1212. let relative: PointF2D = firstRestNote.PositionAndShape.RelativePosition;
  1213. relative.y -= 1.0;
  1214. firstRestNote.PositionAndShape.RelativePosition = relative;
  1215. graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
  1216. }
  1217. private calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(graphicalStaffEntry: GraphicalStaffEntry): void {
  1218. let restNote: GraphicalNote;
  1219. let graphicalNotes: GraphicalNote[];
  1220. if (graphicalStaffEntry.notes[0][0].sourceNote.Pitch === undefined) {
  1221. restNote = graphicalStaffEntry.notes[0][0];
  1222. graphicalNotes = graphicalStaffEntry.notes[1];
  1223. } else {
  1224. graphicalNotes = graphicalStaffEntry.notes[0];
  1225. restNote = graphicalStaffEntry.notes[1][0];
  1226. }
  1227. let collision: boolean = false;
  1228. graphicalStaffEntry.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement();
  1229. for (let idx: number = 0, len: number = graphicalNotes.length; idx < len; ++idx) {
  1230. let graphicalNote: GraphicalNote = graphicalNotes[idx];
  1231. if (restNote.PositionAndShape.marginCollisionDetection(graphicalNote.PositionAndShape)) {
  1232. collision = true;
  1233. break;
  1234. }
  1235. }
  1236. if (collision) {
  1237. if (restNote.sourceNote.ParentVoiceEntry.ParentVoice instanceof LinkedVoice) {
  1238. let bottomBorder: number = graphicalNotes[0].PositionAndShape.BorderMarginBottom + graphicalNotes[0].PositionAndShape.RelativePosition.y;
  1239. restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, bottomBorder - restNote.PositionAndShape.BorderMarginTop + 0.5);
  1240. } else {
  1241. let last: GraphicalNote = graphicalNotes[graphicalNotes.length - 1];
  1242. let topBorder: number = last.PositionAndShape.BorderMarginTop + last.PositionAndShape.RelativePosition.y;
  1243. if (graphicalNotes[0].sourceNote.ParentVoiceEntry.ParentVoice instanceof LinkedVoice) {
  1244. restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, topBorder - restNote.PositionAndShape.BorderMarginBottom - 0.5);
  1245. } else {
  1246. let bottomBorder: number = graphicalNotes[0].PositionAndShape.BorderMarginBottom + graphicalNotes[0].PositionAndShape.RelativePosition.y;
  1247. if (bottomBorder < 2.0) {
  1248. restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, bottomBorder - restNote.PositionAndShape.BorderMarginTop + 0.5);
  1249. } else {
  1250. restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, topBorder - restNote.PositionAndShape.BorderMarginBottom - 0.0);
  1251. }
  1252. }
  1253. }
  1254. }
  1255. graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
  1256. }
  1257. private calculateTieCurves(): void {
  1258. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1259. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1260. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1261. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  1262. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1263. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1264. for (let idx4: number = 0, len5: number = staffLine.Measures.length; idx4 < len5; ++idx4) {
  1265. let measure: StaffMeasure = staffLine.Measures[idx4];
  1266. for (let idx6: number = 0, len6: number = measure.staffEntries.length; idx6 < len6; ++idx6) {
  1267. let staffEntry: GraphicalStaffEntry = measure.staffEntries[idx6];
  1268. let graphicalTies: GraphicalTie[] = staffEntry.GraphicalTies;
  1269. for (let idx7: number = 0, len7: number = graphicalTies.length; idx7 < len7; ++idx7) {
  1270. let graphicalTie: GraphicalTie = graphicalTies[idx7];
  1271. if (graphicalTie.StartNote !== undefined && graphicalTie.StartNote.parentStaffEntry === staffEntry) {
  1272. let tieIsAtSystemBreak: boolean = (
  1273. graphicalTie.StartNote.parentStaffEntry.parentMeasure.ParentStaffLine !==
  1274. graphicalTie.EndNote.parentStaffEntry.parentMeasure.ParentStaffLine
  1275. );
  1276. this.layoutGraphicalTie(graphicalTie, tieIsAtSystemBreak);
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }
  1285. // Commented because unused:
  1286. //private calculateFingering(): void {
  1287. // for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1288. // let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1289. // for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1290. // let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  1291. // for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1292. // let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1293. // let skyBottomLineCalculator: SkyBottomLineCalculator = new SkyBottomLineCalculator(this.rules);
  1294. // for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
  1295. // let measure: StaffMeasure = staffLine.Measures[idx4];
  1296. // let measureRelativePosition: PointF2D = measure.PositionAndShape.RelativePosition;
  1297. // for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
  1298. // let staffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
  1299. // let hasTechnicalInstruction: boolean = false;
  1300. // for (let idx6: number = 0, len6: number = staffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
  1301. // let ve: VoiceEntry = staffEntry.sourceStaffEntry.VoiceEntries[idx6];
  1302. // if (ve.TechnicalInstructions.length > 0) {
  1303. // hasTechnicalInstruction = true;
  1304. // break;
  1305. // }
  1306. // }
  1307. // if (hasTechnicalInstruction) {
  1308. // this.layoutFingering(staffLine, skyBottomLineCalculator, staffEntry, measureRelativePosition);
  1309. // }
  1310. // }
  1311. // }
  1312. // }
  1313. // }
  1314. // }
  1315. //}
  1316. private calculateLyricsPosition(): void {
  1317. for (let idx: number = 0, len: number = this.graphicalMusicSheet.ParentMusicSheet.Instruments.length; idx < len; ++idx) {
  1318. let instrument: Instrument = this.graphicalMusicSheet.ParentMusicSheet.Instruments[idx];
  1319. if (instrument.HasLyrics && instrument.LyricVersesNumbers.length > 0) {
  1320. instrument.LyricVersesNumbers.sort();
  1321. }
  1322. }
  1323. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  1324. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  1325. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  1326. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  1327. for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
  1328. let staffLine: StaffLine = musicSystem.StaffLines[idx3];
  1329. this.calculateSingleStaffLineLyricsPosition(staffLine, staffLine.ParentStaff.ParentInstrument.LyricVersesNumbers);
  1330. }
  1331. }
  1332. }
  1333. }
  1334. private calculateDynamicExpressions(): void {
  1335. for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
  1336. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
  1337. for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
  1338. if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
  1339. for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
  1340. if (sourceMeasure.StaffLinkedExpressions[j][k].InstantaniousDynamic !== undefined ||
  1341. (sourceMeasure.StaffLinkedExpressions[j][k].StartingContinuousDynamic !== undefined &&
  1342. sourceMeasure.StaffLinkedExpressions[j][k].StartingContinuousDynamic.StartMultiExpression ===
  1343. sourceMeasure.StaffLinkedExpressions[j][k] && sourceMeasure.StaffLinkedExpressions[j][k].UnknownList.length === 0)
  1344. ) {
  1345. this.calculateDynamicExpressionsForSingleMultiExpression(sourceMeasure.StaffLinkedExpressions[j][k], i, j);
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. private calculateOctaveShifts(): void {
  1353. for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
  1354. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
  1355. for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
  1356. if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
  1357. for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
  1358. if ((sourceMeasure.StaffLinkedExpressions[j][k].OctaveShiftStart !== undefined)) {
  1359. this.calculateSingleOctaveShift(sourceMeasure, sourceMeasure.StaffLinkedExpressions[j][k], i, j);
  1360. }
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. private getFirstLeftNotNullStaffEntryFromContainer(horizontalIndex: number, verticalIndex: number, multiStaffInstrument: boolean): GraphicalStaffEntry {
  1367. if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex] !== undefined) {
  1368. return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex];
  1369. }
  1370. for (let i: number = horizontalIndex - 1; i >= 0; i--) {
  1371. if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex] !== undefined) {
  1372. return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex];
  1373. }
  1374. }
  1375. return undefined;
  1376. }
  1377. private getFirstRightNotNullStaffEntryFromContainer(horizontalIndex: number, verticalIndex: number, multiStaffInstrument: boolean): GraphicalStaffEntry {
  1378. if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex] !== undefined) {
  1379. return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex];
  1380. }
  1381. for (let i: number = horizontalIndex + 1; i < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length; i++) {
  1382. if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex] !== undefined) {
  1383. return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex];
  1384. }
  1385. }
  1386. return undefined;
  1387. }
  1388. private calculateWordRepetitionInstructions(): void {
  1389. for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
  1390. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
  1391. for (let idx: number = 0, len: number = sourceMeasure.FirstRepetitionInstructions.length; idx < len; ++idx) {
  1392. let instruction: RepetitionInstruction = sourceMeasure.FirstRepetitionInstructions[idx];
  1393. this.calculateWordRepetitionInstruction(instruction, i);
  1394. }
  1395. for (let idx: number = 0, len: number = sourceMeasure.LastRepetitionInstructions.length; idx < len; ++idx) {
  1396. let instruction: RepetitionInstruction = sourceMeasure.LastRepetitionInstructions[idx];
  1397. this.calculateWordRepetitionInstruction(instruction, i);
  1398. }
  1399. }
  1400. }
  1401. private calculateRepetitionEndings(): void {
  1402. let musicsheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
  1403. for (let idx: number = 0, len: number = musicsheet.Repetitions.length; idx < len; ++idx) {
  1404. let partListEntry: Repetition = musicsheet.Repetitions[idx];
  1405. this.calcGraphicalRepetitionEndingsRecursively(partListEntry);
  1406. }
  1407. }
  1408. private calculateTempoExpressions(): void {
  1409. for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
  1410. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
  1411. for (let j: number = 0; j < sourceMeasure.TempoExpressions.length; j++) {
  1412. this.calculateTempoExpressionsForSingleMultiTempoExpression(sourceMeasure, sourceMeasure.TempoExpressions[j], i);
  1413. }
  1414. }
  1415. }
  1416. private calculateMoodAndUnknownExpressions(): void {
  1417. for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
  1418. let sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
  1419. for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
  1420. if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
  1421. for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
  1422. if ((sourceMeasure.StaffLinkedExpressions[j][k].MoodList.length > 0) ||
  1423. (sourceMeasure.StaffLinkedExpressions[j][k].UnknownList.length > 0)) {
  1424. this.calculateMoodAndUnknownExpression(sourceMeasure.StaffLinkedExpressions[j][k], i, j);
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }