VexFlowMusicSheetCalculator.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var MusicSheetCalculator_1 = require("../MusicSheetCalculator");
  8. var VexFlowGraphicalSymbolFactory_1 = require("./VexFlowGraphicalSymbolFactory");
  9. var VexFlowTextMeasurer_1 = require("./VexFlowTextMeasurer");
  10. var Vex = require("vexflow");
  11. var Logging_1 = require("../../../Common/Logging");
  12. var VexFlowMusicSheetCalculator = (function (_super) {
  13. __extends(VexFlowMusicSheetCalculator, _super);
  14. function VexFlowMusicSheetCalculator() {
  15. _super.call(this, new VexFlowGraphicalSymbolFactory_1.VexFlowGraphicalSymbolFactory());
  16. MusicSheetCalculator_1.MusicSheetCalculator.TextMeasurer = new VexFlowTextMeasurer_1.VexFlowTextMeasurer();
  17. }
  18. VexFlowMusicSheetCalculator.prototype.clearRecreatedObjects = function () {
  19. _super.prototype.clearRecreatedObjects.call(this);
  20. for (var _i = 0, _a = this.graphicalMusicSheet.MeasureList; _i < _a.length; _i++) {
  21. var staffMeasures = _a[_i];
  22. for (var _b = 0, staffMeasures_1 = staffMeasures; _b < staffMeasures_1.length; _b++) {
  23. var staffMeasure = staffMeasures_1[_b];
  24. staffMeasure.clean();
  25. }
  26. }
  27. };
  28. //protected clearSystemsAndMeasures(): void {
  29. // for (let measure of measures) {
  30. //
  31. // }
  32. //}
  33. /**
  34. * Calculates the x layout of the staff entries within the staff measures belonging to one source measure.
  35. * All staff entries are x-aligned throughout all vertically aligned staff measures.
  36. * This method is called within calculateXLayout.
  37. * The staff entries are aligned with minimum needed x distances.
  38. * The MinimumStaffEntriesWidth of every measure will be set - needed for system building.
  39. * @param measures
  40. * @returns the minimum required x width of the source measure (=list of staff measures)
  41. */
  42. VexFlowMusicSheetCalculator.prototype.calculateMeasureXLayout = function (measures) {
  43. // Finalize beams
  44. for (var _i = 0, measures_1 = measures; _i < measures_1.length; _i++) {
  45. var measure = measures_1[_i];
  46. measure.finalizeBeams();
  47. }
  48. // Format the voices
  49. var allVoices = [];
  50. var formatter = new Vex.Flow.Formatter({
  51. align_rests: true,
  52. });
  53. for (var _a = 0, measures_2 = measures; _a < measures_2.length; _a++) {
  54. var measure = measures_2[_a];
  55. var mvoices = measure.vfVoices;
  56. var voices = [];
  57. for (var voiceID in mvoices) {
  58. if (mvoices.hasOwnProperty(voiceID)) {
  59. voices.push(mvoices[voiceID]);
  60. allVoices.push(mvoices[voiceID]);
  61. }
  62. }
  63. if (voices.length === 0) {
  64. Logging_1.Logging.warn("Found a measure with no voices... Continuing anyway.", mvoices);
  65. continue;
  66. }
  67. formatter.joinVoices(voices);
  68. }
  69. var firstMeasure = measures[0];
  70. // FIXME: The following ``+ 5.0'' is temporary: it was added as a workaround for
  71. // FIXME: a more relaxed formatting of voices
  72. var width = formatter.preCalculateMinTotalWidth(allVoices) / 10.0 + 5.0;
  73. for (var _b = 0, measures_3 = measures; _b < measures_3.length; _b++) {
  74. var measure = measures_3[_b];
  75. measure.minimumStaffEntriesWidth = width;
  76. measure.formatVoices = undefined;
  77. }
  78. firstMeasure.formatVoices = function (w) {
  79. formatter.format(allVoices, w);
  80. };
  81. return width;
  82. };
  83. VexFlowMusicSheetCalculator.prototype.updateStaffLineBorders = function (staffLine) {
  84. return;
  85. };
  86. VexFlowMusicSheetCalculator.prototype.calculateMeasureNumberPlacement = function (musicSystem) {
  87. return;
  88. };
  89. /**
  90. * Can be used to calculate stem directions, helper(ledger) lines, and overlapping note x-displacement.
  91. * Is Excecuted per voice entry of a staff entry.
  92. * After that layoutStaffEntry is called.
  93. * @param voiceEntry
  94. * @param graphicalNotes
  95. * @param graphicalStaffEntry
  96. * @param hasPitchedNote
  97. * @param isGraceStaffEntry
  98. */
  99. VexFlowMusicSheetCalculator.prototype.layoutVoiceEntry = function (voiceEntry, graphicalNotes, graphicalStaffEntry, hasPitchedNote, isGraceStaffEntry) {
  100. return;
  101. };
  102. /**
  103. * Do all layout calculations that have to be done per staff entry, like dots, ornaments, arpeggios....
  104. * This method is called after the voice entries are handled by layoutVoiceEntry().
  105. * @param graphicalStaffEntry
  106. */
  107. VexFlowMusicSheetCalculator.prototype.layoutStaffEntry = function (graphicalStaffEntry) {
  108. graphicalStaffEntry.parentMeasure.layoutStaffEntry(graphicalStaffEntry);
  109. };
  110. /**
  111. * calculates the y positions of the staff lines within a system and
  112. * furthermore the y positions of the systems themselves.
  113. */
  114. VexFlowMusicSheetCalculator.prototype.calculateSystemYLayout = function () {
  115. for (var idx = 0, len = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  116. var graphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  117. if (!this.leadSheet) {
  118. var globalY = 0;
  119. for (var idx2 = 0, len2 = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  120. var musicSystem = graphicalMusicPage.MusicSystems[idx2];
  121. // calculate y positions of stafflines within system
  122. var y = 10;
  123. for (var _i = 0, _a = musicSystem.StaffLines; _i < _a.length; _i++) {
  124. var line = _a[_i];
  125. line.PositionAndShape.RelativePosition.y = y;
  126. y += 10;
  127. }
  128. // set y positions of systems using the previous system and a fixed distance.
  129. musicSystem.PositionAndShape.BorderBottom = y + 0;
  130. musicSystem.PositionAndShape.RelativePosition.y = globalY;
  131. globalY += y + 0;
  132. }
  133. }
  134. }
  135. };
  136. /**
  137. * Is called at the begin of the method for creating the vertically aligned staff measures belonging to one source measure.
  138. */
  139. VexFlowMusicSheetCalculator.prototype.initStaffMeasuresCreation = function () {
  140. return;
  141. };
  142. VexFlowMusicSheetCalculator.prototype.handleTie = function (tie, startGraphicalStaffEntry, staffIndex, measureIndex) {
  143. return;
  144. };
  145. VexFlowMusicSheetCalculator.prototype.layoutGraphicalTie = function (tie, tieIsAtSystemBreak) {
  146. return;
  147. };
  148. VexFlowMusicSheetCalculator.prototype.calculateSingleStaffLineLyricsPosition = function (staffLine, lyricVersesNumber) {
  149. return;
  150. };
  151. VexFlowMusicSheetCalculator.prototype.calculateSingleOctaveShift = function (sourceMeasure, multiExpression, measureIndex, staffIndex) {
  152. return;
  153. };
  154. VexFlowMusicSheetCalculator.prototype.calculateWordRepetitionInstruction = function (repetitionInstruction, measureIndex) {
  155. return;
  156. };
  157. VexFlowMusicSheetCalculator.prototype.calculateMoodAndUnknownExpression = function (multiExpression, measureIndex, staffIndex) {
  158. return;
  159. };
  160. VexFlowMusicSheetCalculator.prototype.createGraphicalTieNote = function (beams, activeClef, octaveShiftValue, graphicalStaffEntry, duration, numberOfDots, openTie, isLastTieNote) {
  161. return;
  162. };
  163. /**
  164. * Is called if a note is part of a beam.
  165. * @param graphicalNote
  166. * @param beam
  167. * @param openBeams a list of all currently open beams
  168. */
  169. VexFlowMusicSheetCalculator.prototype.handleBeam = function (graphicalNote, beam, openBeams) {
  170. graphicalNote.parentStaffEntry.parentMeasure.handleBeam(graphicalNote, beam);
  171. };
  172. VexFlowMusicSheetCalculator.prototype.handleVoiceEntryLyrics = function (lyricsEntries, voiceEntry, graphicalStaffEntry, openLyricWords) {
  173. return;
  174. };
  175. VexFlowMusicSheetCalculator.prototype.handleVoiceEntryOrnaments = function (ornamentContainer, voiceEntry, graphicalStaffEntry) {
  176. return;
  177. };
  178. VexFlowMusicSheetCalculator.prototype.handleVoiceEntryArticulations = function (articulations, voiceEntry, graphicalStaffEntry) {
  179. return;
  180. };
  181. /**
  182. * Is called if a note is part of a tuplet.
  183. * @param graphicalNote
  184. * @param tuplet
  185. * @param openTuplets a list of all currently open tuplets
  186. */
  187. VexFlowMusicSheetCalculator.prototype.handleTuplet = function (graphicalNote, tuplet, openTuplets) {
  188. return;
  189. };
  190. return VexFlowMusicSheetCalculator;
  191. }(MusicSheetCalculator_1.MusicSheetCalculator));
  192. exports.VexFlowMusicSheetCalculator = VexFlowMusicSheetCalculator;