MusicSheetCalculator.ts 88 KB

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