MusicSheetCalculator.js 79 KB

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