abcjs 6.0.0-beta.9 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/.github/workflows/tests.yml +29 -0
  2. package/CODE_OF_CONDUCT.md +76 -0
  3. package/CONTRIBUTING.md +1 -0
  4. package/LICENSE.md +1 -1
  5. package/README.md +88 -7
  6. package/RELEASE.md +961 -1
  7. package/abcjs-audio.css +14 -5
  8. package/dist/.gitignore +1 -2
  9. package/dist/abcjs-basic-min.js +3 -0
  10. package/dist/abcjs-basic-min.js.LICENSE +23 -0
  11. package/dist/abcjs-basic.js +28232 -0
  12. package/dist/abcjs-basic.js.map +1 -0
  13. package/dist/abcjs-plugin-min.js +3 -0
  14. package/dist/abcjs-plugin-min.js.LICENSE +23 -0
  15. package/index.js +27 -2
  16. package/{static-wrappers/license.js → license.js} +1 -1
  17. package/package.json +26 -29
  18. package/{src/plugin/abc_plugin.js → plugin.js} +31 -19
  19. package/src/api/abc_animation.js +1 -17
  20. package/src/api/abc_tablatures.js +144 -0
  21. package/src/api/abc_timing_callbacks.js +216 -117
  22. package/src/api/abc_tunebook.js +18 -67
  23. package/src/api/abc_tunebook_svg.js +40 -48
  24. package/src/data/abc_tune.js +232 -972
  25. package/src/data/deline-tune.js +199 -0
  26. package/src/edit/abc_editarea.js +112 -0
  27. package/src/edit/abc_editor.js +95 -221
  28. package/src/midi/abc_midi_create.js +48 -50
  29. package/src/parse/abc_common.js +0 -14
  30. package/src/parse/abc_parse.js +167 -1321
  31. package/src/parse/abc_parse_book.js +62 -0
  32. package/src/parse/abc_parse_directive.js +164 -41
  33. package/src/parse/abc_parse_header.js +116 -145
  34. package/src/parse/abc_parse_key_voice.js +26 -20
  35. package/src/parse/abc_parse_music.js +1337 -0
  36. package/src/parse/abc_tokenizer.js +21 -15
  37. package/src/parse/abc_transpose.js +3 -15
  38. package/src/parse/tune-builder.js +896 -0
  39. package/src/parse/wrap_lines.js +205 -453
  40. package/src/synth/abc_midi_flattener.js +1292 -0
  41. package/src/{midi → synth}/abc_midi_renderer.js +44 -17
  42. package/src/synth/abc_midi_sequencer.js +648 -0
  43. package/src/synth/active-audio-context.js +3 -14
  44. package/src/synth/cents-to-factor.js +10 -0
  45. package/src/synth/create-note-map.js +21 -32
  46. package/src/synth/create-synth-control.js +20 -103
  47. package/src/synth/create-synth.js +185 -77
  48. package/src/synth/download-buffer.js +7 -21
  49. package/src/synth/get-midi-file.js +13 -20
  50. package/src/synth/images/{loading.svg → loading.svg.js} +4 -0
  51. package/src/synth/images/loop.svg.js +65 -0
  52. package/src/synth/images/pause.svg.js +10 -0
  53. package/src/synth/images/play.svg.js +9 -0
  54. package/src/synth/images/{reset.svg → reset.svg.js} +5 -1
  55. package/src/synth/instrument-index-to-name.js +1 -16
  56. package/src/synth/load-note.js +37 -76
  57. package/src/synth/pitch-to-note-name.js +0 -15
  58. package/src/synth/pitches-to-perc.js +64 -0
  59. package/src/synth/place-note.js +78 -68
  60. package/src/synth/play-event.js +17 -18
  61. package/src/synth/register-audio-context.js +11 -23
  62. package/src/synth/sounds-cache.js +0 -15
  63. package/src/synth/supports-audio.js +9 -23
  64. package/src/synth/synth-controller.js +80 -49
  65. package/src/synth/synth-sequence.js +20 -34
  66. package/src/tablatures/instruments/guitar/guitar-fonts.js +19 -0
  67. package/src/tablatures/instruments/guitar/guitar-patterns.js +23 -0
  68. package/src/tablatures/instruments/guitar/tab-guitar.js +50 -0
  69. package/src/tablatures/instruments/string-patterns.js +277 -0
  70. package/src/tablatures/instruments/string-tablature.js +56 -0
  71. package/src/tablatures/instruments/tab-note.js +282 -0
  72. package/src/tablatures/instruments/tab-notes.js +41 -0
  73. package/src/tablatures/instruments/violin/tab-violin.js +47 -0
  74. package/src/tablatures/instruments/violin/violin-fonts.js +19 -0
  75. package/src/tablatures/instruments/violin/violin-patterns.js +23 -0
  76. package/src/tablatures/tab-absolute-elements.js +310 -0
  77. package/src/tablatures/tab-common.js +29 -0
  78. package/src/tablatures/tab-renderer.js +243 -0
  79. package/src/tablatures/transposer.js +110 -0
  80. package/src/test/abc_midi_lint.js +5 -22
  81. package/src/test/abc_midi_sequencer_lint.js +11 -14
  82. package/src/test/abc_parser_lint.js +136 -32
  83. package/src/test/abc_vertical_lint.js +94 -32
  84. package/src/test/rendering-lint.js +38 -5
  85. package/src/write/abc_absolute_element.js +112 -120
  86. package/src/write/abc_abstract_engraver.js +102 -253
  87. package/src/write/abc_beam_element.js +30 -290
  88. package/src/write/abc_brace_element.js +12 -121
  89. package/src/write/abc_create_clef.js +21 -32
  90. package/src/write/abc_create_key_signature.js +8 -26
  91. package/src/write/abc_create_note_head.js +107 -0
  92. package/src/write/abc_create_time_signature.js +2 -21
  93. package/src/write/abc_crescendo_element.js +3 -50
  94. package/src/write/abc_decoration.js +7 -30
  95. package/src/write/abc_dynamic_decoration.js +3 -37
  96. package/src/write/abc_ending_element.js +1 -57
  97. package/src/write/abc_engraver_controller.js +111 -234
  98. package/src/write/abc_glyphs.js +8 -18
  99. package/src/write/abc_relative_element.js +57 -97
  100. package/src/write/abc_renderer.js +10 -832
  101. package/src/write/abc_spacing.js +0 -15
  102. package/src/write/abc_staff_group_element.js +14 -349
  103. package/src/write/abc_tempo_element.js +9 -117
  104. package/src/write/abc_tie_element.js +5 -68
  105. package/src/write/abc_triplet_element.js +6 -124
  106. package/src/write/abc_voice_element.js +7 -222
  107. package/src/write/add-chord.js +103 -0
  108. package/src/write/add-text-if.js +33 -0
  109. package/src/write/bottom-text.js +79 -0
  110. package/src/write/calcHeight.js +17 -0
  111. package/src/write/classes.js +100 -0
  112. package/src/write/draw/absolute.js +68 -0
  113. package/src/write/draw/beam.js +56 -0
  114. package/src/write/draw/brace.js +106 -0
  115. package/src/write/draw/crescendo.js +38 -0
  116. package/src/write/draw/debug-box.js +8 -0
  117. package/src/write/draw/draw.js +56 -0
  118. package/src/write/draw/dynamics.js +20 -0
  119. package/src/write/draw/ending.js +46 -0
  120. package/src/write/draw/group-elements.js +66 -0
  121. package/src/write/draw/horizontal-line.js +25 -0
  122. package/src/write/draw/non-music.js +50 -0
  123. package/src/write/draw/print-line.js +24 -0
  124. package/src/write/draw/print-path.js +7 -0
  125. package/src/write/draw/print-stem.js +30 -0
  126. package/src/write/draw/print-symbol.js +59 -0
  127. package/src/write/draw/print-vertical-line.js +18 -0
  128. package/src/write/draw/relative.js +77 -0
  129. package/src/write/draw/round-number.js +5 -0
  130. package/src/write/draw/selectables.js +59 -0
  131. package/src/write/draw/separator.js +16 -0
  132. package/src/write/draw/set-paper-size.js +45 -0
  133. package/src/write/{sprintf.js → draw/sprintf.js} +0 -0
  134. package/src/write/draw/staff-group.js +226 -0
  135. package/src/write/draw/staff-line.js +9 -0
  136. package/src/write/draw/staff.js +33 -0
  137. package/src/write/draw/tab-line.js +40 -0
  138. package/src/write/draw/tempo.js +45 -0
  139. package/src/write/draw/text.js +71 -0
  140. package/src/write/draw/tie.js +97 -0
  141. package/src/write/draw/triplet.js +46 -0
  142. package/src/write/draw/voice.js +102 -0
  143. package/src/write/format-jazz-chord.js +15 -0
  144. package/src/write/free-text.js +41 -0
  145. package/src/write/get-font-and-attr.js +37 -0
  146. package/src/write/get-text-size.js +56 -0
  147. package/src/write/highlight.js +11 -0
  148. package/src/write/layout/VoiceElements.js +121 -0
  149. package/src/write/layout/beam.js +213 -0
  150. package/src/write/layout/get-left-edge-of-staff.js +56 -0
  151. package/src/write/layout/getBarYAt.js +6 -0
  152. package/src/write/layout/layout.js +94 -0
  153. package/src/write/layout/setUpperAndLowerElements.js +232 -0
  154. package/src/write/layout/staffGroup.js +146 -0
  155. package/src/write/layout/triplet.js +75 -0
  156. package/src/write/layout/voice.js +137 -0
  157. package/src/write/selection.js +188 -70
  158. package/src/write/separator.js +10 -0
  159. package/src/write/set-class.js +21 -0
  160. package/src/write/subtitle.js +12 -0
  161. package/src/write/svg.js +95 -43
  162. package/src/write/top-text.js +54 -0
  163. package/src/write/unhighlight.js +11 -0
  164. package/test.js +27 -64
  165. package/types/index.d.ts +1095 -0
  166. package/version.js +1 -1
  167. package/.babelrc +0 -5
  168. package/.eslintrc +0 -3
  169. package/.gitmodules +0 -3
  170. package/Dockerfile +0 -8
  171. package/abcjs-midi.css +0 -166
  172. package/build-utils/loadPresets.js +0 -14
  173. package/build-utils/presets/webpack.analyze.js +0 -6
  174. package/build-utils/presets/webpack.optimize.js +0 -30
  175. package/build-utils/webpack.development.js +0 -14
  176. package/build-utils/webpack.production.js +0 -35
  177. package/deploy-docs.sh +0 -25
  178. package/docker-compose.yml +0 -13
  179. package/docs/README.md +0 -33
  180. package/fix-versions.sh +0 -23
  181. package/midi.js +0 -62
  182. package/src/api/abc_tunebook_midi.js +0 -116
  183. package/src/midi/abc_midi_controls.js +0 -701
  184. package/src/midi/abc_midi_flattener.js +0 -1119
  185. package/src/midi/abc_midi_js_preparer.js +0 -243
  186. package/src/midi/abc_midi_sequencer.js +0 -401
  187. package/src/midi/abc_midi_ui_generator.js +0 -86
  188. package/src/plugin/abc_plugin_midi.js +0 -220
  189. package/src/synth/images/loop.svg +0 -61
  190. package/src/synth/images/pause.svg +0 -6
  191. package/src/synth/images/play.svg +0 -5
  192. package/src/transform/abc2abc_write.js +0 -395
  193. package/static-wrappers/basic.js +0 -2
  194. package/static-wrappers/midi.js +0 -2
  195. package/static-wrappers/plugin-midi.js +0 -6
  196. package/static-wrappers/plugin.js +0 -6
  197. package/webpack.config.js +0 -29
@@ -13,10 +13,7 @@ function lintOne(history, abcString) {
13
13
  var originalText = "``";
14
14
  if (history.absEl && history.absEl.abcelem && history.absEl.abcelem.startChar >= 0)
15
15
  originalText = '`' + abcString.substring(history.absEl.abcelem.startChar, history.absEl.abcelem.endChar) + '`';
16
- if (history.selectable)
17
- originalText += " selectable";
18
- else
19
- originalText += " not-selectable";
16
+ originalText += " selectable";
20
17
  if (history.isDraggable)
21
18
  originalText += " draggable";
22
19
  else
@@ -105,6 +102,8 @@ function listAbsElement(absEl, indent) {
105
102
  var item = absEl[keys[i]];
106
103
  switch(keys[i]) {
107
104
  case "abcelem":
105
+ case "highlight":
106
+ case "unhighlight":
108
107
  break;
109
108
  case "elemset":
110
109
  // List this at the bottom
@@ -134,6 +133,24 @@ function listAbsElement(absEl, indent) {
134
133
  }
135
134
  }
136
135
  break;
136
+ case "tuneNumber":
137
+ case "bottom":
138
+ case "duration":
139
+ case "durationClass":
140
+ case "extraw":
141
+ case "minspacing":
142
+ case "top":
143
+ case "type":
144
+ case "w":
145
+ case "x":
146
+ output.push(keys[i] + ": " + item);
147
+ break;
148
+ case "invisible":
149
+ case "isClef":
150
+ // Don't clutter with false items
151
+ if (item)
152
+ output.push(keys[i] + ": " + item);
153
+ break;
137
154
  default:
138
155
  if (item !== undefined)
139
156
  output.push(keys[i] + ": " + item);
@@ -150,7 +167,6 @@ function listAbsElement(absEl, indent) {
150
167
  }
151
168
 
152
169
  function listRelativeElement(relativeElement, indent) {
153
- var tab = createIndent(indent);
154
170
  var tab2 = createIndent(indent+1);
155
171
  var output = [];
156
172
  output.push("relative element: " + relativeElement.type);
@@ -161,6 +177,9 @@ function listRelativeElement(relativeElement, indent) {
161
177
  case "parent":
162
178
  case "part":
163
179
  break;
180
+ case "dim":
181
+ output.push(keys[i] +": "+JSON.stringify(item.attr));
182
+ break;
164
183
  case "graphelem":
165
184
  if (item) {
166
185
  output.push(keys[i] +": ");
@@ -169,6 +188,20 @@ function listRelativeElement(relativeElement, indent) {
169
188
  output.push(svg);
170
189
  }
171
190
  break;
191
+ case "note":
192
+ break;
193
+ case "tempo":
194
+ var tempoDetails = [];
195
+ if (item.preString)
196
+ tempoDetails.push("preString: " + item.preString);
197
+ if (item.duration && item.duration.length)
198
+ tempoDetails.push("duration: " + item.duration.join(","));
199
+ if (item.bpm)
200
+ tempoDetails.push("bpm: " + item.bpm);
201
+ if (item.postString)
202
+ tempoDetails.push("postString: " + item.postString);
203
+ output.push(keys[i] + ": " + tempoDetails.join(", "));
204
+ break;
172
205
  default:
173
206
  if (item !== undefined)
174
207
  output.push(keys[i] + ": " + (''+item).replace(/\n/g, "\\n"));
@@ -1,26 +1,38 @@
1
1
  // abc_absolute_element.js: Definition of the AbsoluteElement class.
2
- // Copyright (C) 2010-2020 Gregory Dyke (gregdyke at gmail dot com) and Paul Rosen
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
- // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6
- // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
7
- // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2
+
3
+ var setClass = require('./set-class');
4
+ var highlight = require("./highlight");
5
+ var unhighlight = require("./unhighlight");
6
+
7
+ // Everything that is placed in the SVG is first created as an absolute element. This is one unit of graphic information.
8
+ // That is, it embodies a concept: a clef, a time signature, a bar line,etc. or most complexly:
9
+ // a note with its accidental, grace note, chord symbol, trill, stem, eighth flags, etc.
10
+ // In the largest sense, these are placed on the page at a particular place that is determined during the layout phase.
11
+ // This object doesn't contain any of the drawing information, though. That information is contained in an array of
12
+ // RelativeElements as the "children" of this class.
13
+ // During the layout phase, the width of all the children is calculated and the X coordinate of the absolute element is set.
8
14
  //
9
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15
+ // So, after the AbsoluteElement is placed, then its children can be placed relative to that. There are different types of
16
+ // relative elements that are placed with different rules:
17
+ // 1) Fixed - these elements don't move relative to the absolute element's coordinates. These are things like the notehead,
18
+ // any ledger lines, accidentals, etc.
19
+ // 2) Slotted - these elements can move vertically and don't get Y coordinates until after the absolute element is placed.
20
+ // These are things like the chord symbol, many decorations, the lyrics, etc.
10
21
  //
11
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
12
- // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
14
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
-
17
- var spacing = require('./abc_spacing');
22
+ // Relative elements are also classified by how they are related. This could be:
23
+ // 1) Increases the absolute element's width to the left. This doesn't change the center point of
24
+ // the absolute element, so adding a sharp to the note won't move it to the right. However, if the elements
25
+ // are close together then this enforces a minimum distance.
26
+ // 2) Has no effect on the width. Annotations and the tempo act like this. No matter how long they are the width doesn't change.
27
+ // 3) Increases the absolute element's width to the right. This doesn't change the center point,
28
+ // but it will increase the minimum distance.
29
+ // 4) Sets the width on both sides. This is the note heads. They are centered on both sides of the absolute element's X coordinate.
18
30
 
19
31
  // duration - actual musical duration - different from notehead duration in triplets. refer to abcelem to get the notehead duration
20
32
  // minspacing - spacing which must be taken on top of the width defined by the duration
21
33
  // type is a meta-type for the element. It is not necessary for drawing, but it is useful to make semantic sense of the element. For instance, it can be used in the element's class name.
22
34
  var AbsoluteElement = function AbsoluteElement(abcelem, duration, minspacing, type, tuneNumber, options) {
23
- //console.log("Absolute:",abcelem, type);
35
+ // console.log("Absolute:",abcelem, duration, minspacing, type, tuneNumber, options);
24
36
  if (!options)
25
37
  options = {};
26
38
  this.tuneNumber = tuneNumber;
@@ -33,13 +45,17 @@ var AbsoluteElement = function AbsoluteElement(abcelem, duration, minspacing, ty
33
45
  this.heads = [];
34
46
  this.extra = [];
35
47
  this.extraw = 0;
36
- //this.decs = [];
37
48
  this.w = 0;
38
49
  this.right = [];
39
50
  this.invisible = false;
40
51
  this.bottom = undefined;
41
52
  this.top = undefined;
42
53
  this.type = type;
54
+
55
+ // The following are the dimensions of the fixed part of the element.
56
+ // That is, the chord text will be a different height depending on lot of factors, but the 8th flag will always be in the same place.
57
+ this.fixed = { w: 0, t: undefined, b: undefined }; // there is no x-coord here, because that is set later.
58
+
43
59
  // these are the heights of all of the vertical elements that can't be placed until the end of the line.
44
60
  // the vertical order of elements that are above is: tempo, part, volume/dynamic, ending/chord, lyric
45
61
  // the vertical order of elements that are below is: lyric, chord, volume/dynamic
@@ -59,41 +75,29 @@ var AbsoluteElement = function AbsoluteElement(abcelem, duration, minspacing, ty
59
75
  };
60
76
  };
61
77
 
62
- // For each of the relative elements that can't be placed in advance (because their vertical placement depends on everything
63
- // else on the line), this iterates through them and sets their pitch. By the time this is called, specialYResolved contains a
64
- // hash with the vertical placement (in pitch units) for each type.
65
- // TODO-PER: I think this needs to be separated by "above" and "below". How do we know that for dynamics at the point where they are being defined, though? We need a pass through all the relative elements to set "above" and "below".
66
- AbsoluteElement.prototype.setUpperAndLowerElements = function(specialYResolved) {
67
- // specialYResolved contains the actual pitch for each of the classes of elements.
68
- for (var i = 0; i < this.children.length; i++) {
69
- var child = this.children[i];
70
- for (var key in this.specialY) { // for each class of element that needs to be placed vertically
71
- if (this.specialY.hasOwnProperty(key)) {
72
- if (child[key]) { // If this relative element has defined a height for this class of element
73
- child.pitch = specialYResolved[key];
74
- if (child.top === undefined) { // TODO-PER: HACK! Not sure this is the right place to do this.
75
- child.setUpperAndLowerElements(specialYResolved);
76
- this.pushTop(child.top);
77
- this.pushBottom(child.bottom);
78
- }
79
- }
80
- }
81
- }
82
- }
83
- };
84
-
85
- AbsoluteElement.prototype.getMinWidth = function () { // absolute space taken to the right of the note
86
- return this.w;
87
- };
88
-
89
- AbsoluteElement.prototype.getExtraWidth = function () { // space needed to the left of the note
90
- return -this.extraw;
78
+ AbsoluteElement.prototype.getFixedCoords = function () {
79
+ return { x: this.x, w: this.fixed.w, t: this.fixed.t, b: this.fixed.b };
91
80
  };
92
81
 
93
82
  AbsoluteElement.prototype.addExtra = function (extra) {
83
+ // used for accidentals, multi-measure rest text,
84
+ // left-side decorations, gracenote heads,
85
+ // left annotations, gracenote stems.
86
+ // if (!(extra.c && extra.c.indexOf("accidentals") >= 0) &&
87
+ // !(extra.c && extra.c.indexOf("arpeggio") >= 0) &&
88
+ // extra.type !== "multimeasure-text" &&
89
+ // !(extra.c === "noteheads.quarter" && (extra.scalex === 0.6 || extra.scalex === 0.36)) &&
90
+ // !(extra.type === "stem" && extra.linewidth === -0.6) &&
91
+ // extra.position !== "left"
92
+ // )
93
+ // console.log("extra", extra);
94
+
95
+ this.fixed.w = Math.max(this.fixed.w, extra.dx+extra.w);
96
+ if (this.fixed.t === undefined) this.fixed.t = extra.top; else this.fixed.t = Math.max(this.fixed.t, extra.top);
97
+ if (this.fixed.b === undefined) this.fixed.b = extra.bottom; else this.fixed.b = Math.min(this.fixed.b, extra.bottom);
94
98
  if (extra.dx<this.extraw) this.extraw = extra.dx;
95
99
  this.extra[this.extra.length] = extra;
96
- this.addChild(extra);
100
+ this._addChild(extra);
97
101
  };
98
102
 
99
103
  AbsoluteElement.prototype.addHead = function (head) {
@@ -103,18 +107,66 @@ AbsoluteElement.prototype.addHead = function (head) {
103
107
  };
104
108
 
105
109
  AbsoluteElement.prototype.addRight = function (right) {
110
+ // // used for clefs, note heads, bar lines, stems, key-signature accidentals, non-beamed flags, dots
111
+ // if (!(right.c && right.c.indexOf("clefs") >= 0) &&
112
+ // !(right.c && right.c.indexOf("noteheads") >= 0) &&
113
+ // !(right.c && right.c.indexOf("flags") >= 0) &&
114
+ // !(right.c && right.c.indexOf("rests") >= 0) &&
115
+ // !(right.c && right.c.indexOf("dots.dot") >= 0) &&
116
+ // right.type !== "stem" &&
117
+ // right.type !== "bar" &&
118
+ // right.type !== "none" && // used when an invisible anchor is needed.
119
+ // !(this.type.indexOf("clef") >= -1 && right.c === "8") &&
120
+ // this.type.indexOf("key-signature") === -1 &&
121
+ // this.type.indexOf("time-signature") === -1 &&
122
+ // !(this.abcelem && this.abcelem.rest && this.abcelem.rest.type === "spacer") &&
123
+ // !(this.abcelem && this.abcelem.rest && this.abcelem.rest.type === "invisible") &&
124
+ // !(right.type === "text" && right.position === "relative") &&
125
+ // !(right.type === "text" && right.position === "right") &&
126
+ // !(right.type === "text" && right.position === "above") &&
127
+ // !(right.type === "text" && right.position === "below")
128
+ // )
129
+ // console.log("right", right);
130
+ // These are the elements that are the fixed part.
131
+ this.fixed.w = Math.max(this.fixed.w, right.dx+right.w);
132
+ if (right.top !== undefined) {
133
+ if (this.fixed.t === undefined) this.fixed.t = right.top; else this.fixed.t = Math.max(this.fixed.t, right.top);
134
+ }
135
+ if (right.bottom !== undefined) {
136
+ if (this.fixed.b === undefined) this.fixed.b = right.bottom; else this.fixed.b = Math.min(this.fixed.b, right.bottom);
137
+ }
138
+ // if (isNaN(this.fixed.t) || isNaN(this.fixed.b))
139
+ // debugger;
106
140
  if (right.dx+right.w>this.w) this.w = right.dx+right.w;
107
141
  this.right[this.right.length] = right;
108
- this.addChild(right);
142
+ this._addChild(right);
143
+ };
144
+
145
+ AbsoluteElement.prototype.addFixed = function (elem) {
146
+ // used for elements that can't move relative to other elements after they have been placed.
147
+ // used for ledger lines, bar numbers, debug msgs, clef, key sigs, time sigs
148
+ this._addChild(elem);
149
+ };
150
+
151
+ AbsoluteElement.prototype.addFixedX = function (elem) {
152
+ // used for elements that can't move horizontally relative to other elements after they have been placed.
153
+ // used for parts, tempo, decorations
154
+ this._addChild(elem);
109
155
  };
110
156
 
111
157
  AbsoluteElement.prototype.addCentered = function (elem) {
158
+ // // used for chord labels, lyrics
159
+ // if (!(elem.type === "chord" && elem.position === "above") &&
160
+ // !(elem.type === "chord" && elem.position === "below") &&
161
+ // elem.type !== 'lyric'
162
+ // )
163
+ // console.log("centered", elem);
112
164
  var half = elem.w/2;
113
165
  if (-half<this.extraw) this.extraw = -half;
114
166
  this.extra[this.extra.length] = elem;
115
167
  if (elem.dx+half>this.w) this.w = elem.dx+half;
116
168
  this.right[this.right.length] = elem;
117
- this.addChild(elem);
169
+ this._addChild(elem);
118
170
  };
119
171
 
120
172
  AbsoluteElement.prototype.setLimit = function(member, child) {
@@ -125,8 +177,8 @@ AbsoluteElement.prototype.setLimit = function(member, child) {
125
177
  this.specialY[member] = Math.max(this.specialY[member], child[member]);
126
178
  };
127
179
 
128
- AbsoluteElement.prototype.addChild = function (child) {
129
- //console.log("Relative:",child);
180
+ AbsoluteElement.prototype._addChild = function (child) {
181
+ // console.log("Relative:",child);
130
182
  child.parent = this;
131
183
  this.children[this.children.length] = child;
132
184
  this.pushTop(child.top);
@@ -168,84 +220,24 @@ AbsoluteElement.prototype.setX = function (x) {
168
220
  this.children[i].setX(x);
169
221
  };
170
222
 
171
- AbsoluteElement.prototype.setHint = function () {
172
- this.hint = true;
223
+ AbsoluteElement.prototype.center = function (before, after) {
224
+ // Used to center whole rests
225
+ var midpoint = (after.x - before.x) / 2 + before.x;
226
+ this.x = midpoint - this.w / 2;
227
+ for (var k = 0; k < this.children.length; k++)
228
+ this.children[k].setX(this.x);
173
229
  };
174
230
 
175
- AbsoluteElement.prototype.draw = function (renderer, bartop) {
176
- if (this.invisible) return;
177
- this.elemset = [];
178
- renderer.beginGroup();
179
- for (var i=0; i<this.children.length; i++) {
180
- if (/*ABCJS.write.debugPlacement*/false) {
181
- if (this.children[i].klass === 'ornament')
182
- renderer.printShadedBox(this.x, renderer.calcY(this.children[i].top), this.w, renderer.calcY(this.children[i].bottom)-renderer.calcY(this.children[i].top), "rgb(0,0,200)", 0.3);
183
- }
184
- var el = this.children[i].draw(renderer,bartop);
185
- if (el)
186
- this.elemset.push(el);
187
- }
188
- var klass = this.type;
189
- if (this.type === 'note' || this.type === 'rest') {
190
- klass += ' d' + Math.round(this.durationClass*1000)/1000;
191
- klass = klass.replace(/\./g, '-');
192
- if (this.abcelem.pitches) {
193
- for (var j = 0; j < this.abcelem.pitches.length; j++) {
194
- klass += ' p' + this.abcelem.pitches[j].pitch;
195
- }
196
- }
197
- }
198
- var g = renderer.endGroup(klass);
199
- if (g)
200
- this.elemset.push(g);
201
- if (klass === "tempo" && this.children.length > 0) {
202
- renderer.controller.currentAbsEl.elemset[0] = this.elemset[0];
203
- // Combine any tempo elements that are in a row. TODO-PER: this is a hack because the tempo note is an AbsoluteElement so there are nested AbsoluteElements here.
204
- this.children[0].adjustElements(renderer);
205
- }
206
- if (this.klass)
207
- this.setClass("mark", "", "#00ff00");
208
- if (this.hint)
209
- this.setClass("abcjs-hint", "", null);
210
- this.abcelem.abselem = this;
211
-
212
- var step = spacing.STEP;
213
- };
214
-
215
- AbsoluteElement.prototype.isIE=/*@cc_on!@*/false;//IE detector
216
-
217
- AbsoluteElement.prototype.setClass = function (addClass, removeClass, color) {
218
- if (!this.elemset)
219
- return;
220
- for (var i = 0; i < this.elemset.length; i++) {
221
- var el = this.elemset[i];
222
- el.setAttribute("fill", color);
223
- var kls = el.getAttribute("class");
224
- if (!kls) kls = "";
225
- kls = kls.replace(removeClass, "");
226
- kls = kls.replace(addClass, "");
227
- if (addClass.length > 0) {
228
- if (kls.length > 0 && kls.charAt(kls.length - 1) !== ' ') kls += " ";
229
- kls += addClass;
230
- }
231
- el.setAttribute("class", kls);
232
- }
231
+ AbsoluteElement.prototype.setHint = function () {
232
+ this.hint = true;
233
233
  };
234
234
 
235
235
  AbsoluteElement.prototype.highlight = function (klass, color) {
236
- if (klass === undefined)
237
- klass = "abcjs-note_selected";
238
- if (color === undefined)
239
- color = "#ff0000";
240
- this.setClass(klass, "", color);
236
+ highlight.bind(this)(klass, color);
241
237
  };
242
238
 
243
239
  AbsoluteElement.prototype.unhighlight = function (klass, color) {
244
- if (klass === undefined)
245
- klass = "abcjs-note_selected";
246
- if (color === undefined)
247
- color = "#000000";
248
- this.setClass("", klass, color);
240
+ unhighlight.bind(this)(klass, color);
249
241
  };
250
242
 
251
243
  module.exports = AbsoluteElement;