abcjs 6.1.9 → 6.2.1

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 (135) hide show
  1. package/LICENSE.md +1 -1
  2. package/RELEASE.md +58 -0
  3. package/dist/abcjs-basic-min.js +2 -2
  4. package/dist/abcjs-basic-min.js.LICENSE +1 -1
  5. package/dist/abcjs-basic.js +4505 -4556
  6. package/dist/abcjs-basic.js.map +1 -1
  7. package/dist/abcjs-plugin-min.js +2 -2
  8. package/dist/abcjs-plugin-min.js.LICENSE +1 -1
  9. package/index.js +2 -2
  10. package/license.js +1 -1
  11. package/package.json +1 -1
  12. package/plugin.js +2 -2
  13. package/src/api/abc_timing_callbacks.js +8 -4
  14. package/src/api/abc_tunebook_svg.js +1 -2
  15. package/src/data/abc_tune.js +3 -3
  16. package/src/parse/abc_common.js +0 -47
  17. package/src/parse/abc_parse.js +16 -16
  18. package/src/parse/abc_parse_book.js +3 -3
  19. package/src/parse/abc_parse_directive.js +26 -7
  20. package/src/parse/abc_parse_header.js +11 -9
  21. package/src/parse/abc_parse_key_voice.js +17 -17
  22. package/src/parse/abc_parse_music.js +88 -105
  23. package/src/parse/abc_tokenizer.js +60 -60
  24. package/src/parse/tune-builder.js +19 -14
  25. package/src/synth/abc_midi_flattener.js +25 -9
  26. package/src/synth/create-synth.js +71 -4
  27. package/src/synth/load-note.js +1 -1
  28. package/src/synth/note-to-midi.js +50 -0
  29. package/src/synth/place-note.js +10 -2
  30. package/src/tablatures/instruments/guitar/tab-guitar.js +0 -2
  31. package/src/tablatures/instruments/string-patterns.js +47 -29
  32. package/src/tablatures/instruments/tab-note.js +26 -103
  33. package/src/tablatures/instruments/violin/tab-violin.js +0 -2
  34. package/src/tablatures/tab-absolute-elements.js +9 -31
  35. package/src/tablatures/tab-renderer.js +2 -2
  36. package/src/test/abc_parser_lint.js +7 -4
  37. package/src/write/README.md +31 -0
  38. package/src/write/creation/abstract-engraver.js +1036 -0
  39. package/src/write/creation/add-chord.js +102 -0
  40. package/src/write/{add-text-if.js → creation/add-text-if.js} +6 -6
  41. package/src/write/{calcHeight.js → creation/calc-height.js} +2 -2
  42. package/src/write/creation/create-clef.js +72 -0
  43. package/src/write/creation/create-key-signature.js +31 -0
  44. package/src/write/creation/create-note-head.js +107 -0
  45. package/src/write/creation/create-time-signature.js +55 -0
  46. package/src/write/creation/decoration.js +357 -0
  47. package/src/write/{abc_absolute_element.js → creation/elements/absolute-element.js} +14 -15
  48. package/src/write/creation/elements/beam-element.js +113 -0
  49. package/src/write/{bottom-text.js → creation/elements/bottom-text.js} +14 -15
  50. package/src/write/{abc_brace_element.js → creation/elements/brace-element.js} +5 -5
  51. package/src/write/creation/elements/free-text.js +41 -0
  52. package/src/write/{abc_relative_element.js → creation/elements/relative-element.js} +7 -7
  53. package/src/write/{separator.js → creation/elements/separator.js} +2 -2
  54. package/src/write/{abc_staff_group_element.js → creation/elements/staff-group-element.js} +4 -4
  55. package/src/write/{subtitle.js → creation/elements/subtitle.js} +3 -3
  56. package/src/write/creation/elements/tempo-element.js +63 -0
  57. package/src/write/{abc_tie_element.js → creation/elements/tie-element.js} +15 -11
  58. package/src/write/{top-text.js → creation/elements/top-text.js} +12 -12
  59. package/src/write/creation/elements/triplet-element.js +28 -0
  60. package/src/write/{abc_voice_element.js → creation/elements/voice-element.js} +3 -3
  61. package/src/write/creation/glyphs.js +226 -0
  62. package/src/write/creation/translate-chord.js +37 -0
  63. package/src/write/draw/absolute.js +5 -5
  64. package/src/write/draw/beam.js +8 -8
  65. package/src/write/draw/brace.js +33 -33
  66. package/src/write/draw/crescendo.js +4 -4
  67. package/src/write/draw/debug-box.js +1 -1
  68. package/src/write/draw/draw.js +7 -7
  69. package/src/write/draw/dynamics.js +2 -2
  70. package/src/write/draw/ending.js +6 -6
  71. package/src/write/draw/glissando.js +17 -17
  72. package/src/write/draw/group-elements.js +51 -51
  73. package/src/write/draw/horizontal-line.js +9 -9
  74. package/src/write/draw/non-music.js +1 -1
  75. package/src/write/draw/print-line.js +25 -16
  76. package/src/write/draw/print-stem.js +15 -5
  77. package/src/write/draw/print-symbol.js +12 -12
  78. package/src/write/draw/print-vertical-line.js +8 -8
  79. package/src/write/draw/relative.js +17 -16
  80. package/src/write/draw/selectables.js +5 -5
  81. package/src/write/draw/separator.js +4 -4
  82. package/src/write/draw/set-paper-size.js +2 -2
  83. package/src/write/draw/sprintf.js +31 -31
  84. package/src/write/draw/staff-group.js +36 -30
  85. package/src/write/draw/staff-line.js +2 -2
  86. package/src/write/draw/staff.js +4 -4
  87. package/src/write/draw/tab-line.js +26 -26
  88. package/src/write/draw/tempo.js +30 -30
  89. package/src/write/draw/text.js +5 -5
  90. package/src/write/draw/tie.js +18 -18
  91. package/src/write/draw/triplet.js +6 -6
  92. package/src/write/draw/voice.js +16 -17
  93. package/src/write/{abc_engraver_controller.js → engraver-controller.js} +58 -51
  94. package/src/write/{classes.js → helpers/classes.js} +6 -6
  95. package/src/write/{get-font-and-attr.js → helpers/get-font-and-attr.js} +9 -7
  96. package/src/write/{get-text-size.js → helpers/get-text-size.js} +5 -5
  97. package/src/write/{set-class.js → helpers/set-class.js} +1 -1
  98. package/src/write/{abc_spacing.js → helpers/spacing.js} +1 -1
  99. package/src/write/{highlight.js → interactive/highlight.js} +1 -1
  100. package/src/write/{selection.js → interactive/selection.js} +34 -31
  101. package/src/write/{unhighlight.js → interactive/unhighlight.js} +1 -1
  102. package/src/write/layout/beam.js +13 -13
  103. package/src/write/layout/get-left-edge-of-staff.js +4 -4
  104. package/src/write/layout/layout.js +74 -74
  105. package/src/write/layout/{setUpperAndLowerElements.js → set-upper-and-lower-elements.js} +8 -8
  106. package/src/write/layout/{staffGroup.js → staff-group.js} +32 -32
  107. package/src/write/layout/triplet.js +4 -4
  108. package/src/write/layout/{VoiceElements.js → voice-elements.js} +23 -23
  109. package/src/write/layout/voice.js +6 -6
  110. package/src/write/{abc_renderer.js → renderer.js} +36 -32
  111. package/src/write/svg.js +35 -35
  112. package/test.js +2 -2
  113. package/types/index.d.ts +37 -8
  114. package/version.js +1 -1
  115. package/src/tablatures/instruments/guitar/guitar-fonts.js +0 -19
  116. package/src/tablatures/instruments/violin/violin-fonts.js +0 -19
  117. package/src/tablatures/transposer.js +0 -110
  118. package/src/write/abc_abstract_engraver.js +0 -1026
  119. package/src/write/abc_beam_element.js +0 -113
  120. package/src/write/abc_create_clef.js +0 -72
  121. package/src/write/abc_create_key_signature.js +0 -33
  122. package/src/write/abc_create_note_head.js +0 -107
  123. package/src/write/abc_create_time_signature.js +0 -55
  124. package/src/write/abc_decoration.js +0 -357
  125. package/src/write/abc_glyphs.js +0 -224
  126. package/src/write/abc_tempo_element.js +0 -63
  127. package/src/write/abc_triplet_element.js +0 -28
  128. package/src/write/add-chord.js +0 -103
  129. package/src/write/format-jazz-chord.js +0 -15
  130. package/src/write/free-text.js +0 -41
  131. /package/src/write/{abc_crescendo_element.js → creation/elements/crescendo-element.js} +0 -0
  132. /package/src/write/{abc_dynamic_decoration.js → creation/elements/dynamic-decoration.js} +0 -0
  133. /package/src/write/{abc_ending_element.js → creation/elements/ending-element.js} +0 -0
  134. /package/src/write/{abc_glissando_element.js → creation/elements/glissando-element.js} +0 -0
  135. /package/src/write/layout/{getBarYAt.js → get-bar-y-at.js} +0 -0
@@ -2,7 +2,7 @@ var elementGroup = require('./group-elements');
2
2
  var roundNumber = require("./round-number");
3
3
 
4
4
  function printStem(renderer, x, dx, y1, y2, klass, name) {
5
- if (dx<0 || y1<y2) { // correct path "handedness" for intersection with other elements
5
+ if (dx < 0 || y1 < y2) { // correct path "handedness" for intersection with other elements
6
6
  var tmp = roundNumber(y2);
7
7
  y2 = roundNumber(y1);
8
8
  y1 = tmp;
@@ -11,9 +11,19 @@ function printStem(renderer, x, dx, y1, y2, klass, name) {
11
11
  y2 = roundNumber(y2);
12
12
  }
13
13
  x = roundNumber(x);
14
- var x2 = roundNumber(x+dx);
15
- var pathArray = [["M",x,y1],["L", x, y2],["L", x2, y2],["L",x2,y1],["z"]];
16
- var attr = { path: ""};
14
+ var x2 = roundNumber(x + dx);
15
+ // TODO-PER: This fixes a firefox bug where a path needs to go over the 0.5 mark or it isn't displayed
16
+ if (renderer.firefox112 && Math.abs(dx) < 1) {
17
+ var higher = Math.max(x,x2)
18
+ var int = Math.floor(higher)
19
+ var distToHalf = 0.52 - (higher - int)
20
+ if (distToHalf > 0) {
21
+ x += distToHalf
22
+ x2 += distToHalf
23
+ }
24
+ }
25
+ var pathArray = [["M", x, y1], ["L", x, y2], ["L", x2, y2], ["L", x2, y1], ["z"]];
26
+ var attr = { path: "" };
17
27
  for (var i = 0; i < pathArray.length; i++)
18
28
  attr.path += pathArray[i].join(" ");
19
29
  if (klass)
@@ -21,7 +31,7 @@ function printStem(renderer, x, dx, y1, y2, klass, name) {
21
31
  if (name)
22
32
  attr['data-name'] = name;
23
33
  if (!elementGroup.isInGroup()) {
24
- attr.stroke ="none";
34
+ attr.stroke = "none";
25
35
  attr.fill = renderer.foregroundColor;
26
36
  }
27
37
  return renderer.paper.pathToBack(attr);
@@ -1,5 +1,5 @@
1
1
  var renderText = require('./text');
2
- var glyphs = require('../abc_glyphs');
2
+ var glyphs = require('../creation/glyphs');
3
3
  var elementGroup = require('./group-elements');
4
4
 
5
5
  /**
@@ -14,17 +14,17 @@ function printSymbol(renderer, x, offset, symbol, options) {
14
14
  if (!symbol) return null;
15
15
  if (symbol.length > 1 && symbol.indexOf(".") < 0) {
16
16
  var groupClass = elementGroup.isInGroup() ? '' : options.klass // If this is already in a group then don't repeat the classes for the sub-group)
17
- renderer.paper.openGroup({"data-name": options.name, klass: groupClass});
17
+ renderer.paper.openGroup({ "data-name": options.name, klass: groupClass });
18
18
  var dx = 0;
19
19
  for (var i = 0; i < symbol.length; i++) {
20
- var s = symbol.charAt(i);
20
+ var s = symbol[i];
21
21
  ycorr = glyphs.getYCorr(s);
22
- el = glyphs.printSymbol(x + dx, renderer.calcY(offset + ycorr), s, renderer.paper, {stroke: options.stroke, fill: options.fill});
22
+ el = glyphs.printSymbol(x + dx, renderer.calcY(offset + ycorr), s, renderer.paper, { stroke: options.stroke, fill: options.fill });
23
23
  if (el) {
24
24
  if (i < symbol.length - 1)
25
- dx += kernSymbols(s, symbol.charAt(i + 1), glyphs.getSymbolWidth(s));
25
+ dx += kernSymbols(s, symbol[i + 1], glyphs.getSymbolWidth(s));
26
26
  } else {
27
- renderText(renderer, { x: x, y: renderer.y, text: "no symbol:" + symbol, type: "debugfont", klass: 'debug-msg', anchor: 'start'}, false);
27
+ renderText(renderer, { x: x, y: renderer.y, text: "no symbol:" + symbol, type: "debugfont", klass: 'debug-msg', anchor: 'start' }, false);
28
28
  }
29
29
  }
30
30
  var g = renderer.paper.closeGroup();
@@ -32,14 +32,14 @@ function printSymbol(renderer, x, offset, symbol, options) {
32
32
  } else {
33
33
  ycorr = glyphs.getYCorr(symbol);
34
34
  if (elementGroup.isInGroup()) {
35
- el = glyphs.printSymbol(x, renderer.calcY(offset + ycorr), symbol, renderer.paper, {"data-name": options.name});
35
+ el = glyphs.printSymbol(x, renderer.calcY(offset + ycorr), symbol, renderer.paper, { "data-name": options.name });
36
36
  } else {
37
- el = glyphs.printSymbol(x, renderer.calcY(offset + ycorr), symbol, renderer.paper, {klass: options.klass, stroke: options.stroke, fill: options.fill, "data-name": options.name});
37
+ el = glyphs.printSymbol(x, renderer.calcY(offset + ycorr), symbol, renderer.paper, { klass: options.klass, stroke: options.stroke, fill: options.fill, "data-name": options.name });
38
38
  }
39
39
  if (el) {
40
40
  return el;
41
41
  }
42
- renderText(renderer, { x: x, y: renderer.y, text: "no symbol:" + symbol, type: "debugfont", klass: 'debug-msg', anchor: 'start'}, false);
42
+ renderText(renderer, { x: x, y: renderer.y, text: "no symbol:" + symbol, type: "debugfont", klass: 'debug-msg', anchor: 'start' }, false);
43
43
  return null;
44
44
  }
45
45
  }
@@ -48,11 +48,11 @@ function kernSymbols(lastSymbol, thisSymbol, lastSymbolWidth) {
48
48
  // This is just some adjustments to make it look better.
49
49
  var width = lastSymbolWidth;
50
50
  if (lastSymbol === 'f' && thisSymbol === 'f')
51
- width = width*2/3;
51
+ width = width * 2 / 3;
52
52
  if (lastSymbol === 'p' && thisSymbol === 'p')
53
- width = width*5/6;
53
+ width = width * 5 / 6;
54
54
  if (lastSymbol === 'f' && thisSymbol === 'z')
55
- width = width*5/8;
55
+ width = width * 5 / 8;
56
56
  return width;
57
57
  }
58
58
 
@@ -1,17 +1,17 @@
1
1
  var sprintf = require("./sprintf");
2
2
 
3
- function printVerticalLine (renderer, x, y1, y2) {
3
+ function printVerticalLine(renderer, x, y1, y2) {
4
4
  var dy = 0.35;
5
5
  var fill = "#00aaaa";
6
6
  var pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x - dy, y1, x - dy, y2,
7
7
  x + dy, y1, x + dy, y2);
8
- renderer.paper.pathToBack({path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff')});
9
- pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x - 20, y1, x - 20, y1+3,
10
- x, y1, x, y1+3);
11
- renderer.paper.pathToBack({path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff')});
12
- pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x + 20, y2, x + 20, y2+3,
13
- x, y2, x, y2+3);
14
- renderer.paper.pathToBack({path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff')});
8
+ renderer.paper.pathToBack({ path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff') });
9
+ pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x - 20, y1, x - 20, y1 + 3,
10
+ x, y1, x, y1 + 3);
11
+ renderer.paper.pathToBack({ path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff') });
12
+ pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x + 20, y2, x + 20, y2 + 3,
13
+ x, y2, x, y2 + 3);
14
+ renderer.paper.pathToBack({ path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff') });
15
15
 
16
16
  }
17
17
 
@@ -7,7 +7,7 @@ function drawRelativeElement(renderer, params, bartop) {
7
7
  if (params.pitch === undefined)
8
8
  window.console.error(params.type + " Relative Element y-coordinate not set.");
9
9
  var y = renderer.calcY(params.pitch);
10
- switch(params.type) {
10
+ switch (params.type) {
11
11
  case "symbol":
12
12
  if (params.c === null) return null;
13
13
  var klass = "symbol";
@@ -16,8 +16,8 @@ function drawRelativeElement(renderer, params, bartop) {
16
16
  scalex: params.scalex,
17
17
  scaley: params.scaley,
18
18
  klass: renderer.controller.classes.generate(klass),
19
- // fill:"none",
20
- // stroke: renderer.foregroundColor,
19
+ // fill:"none",
20
+ // stroke: renderer.foregroundColor,
21
21
  name: params.name
22
22
  });
23
23
  break;
@@ -33,45 +33,46 @@ function drawRelativeElement(renderer, params, bartop) {
33
33
  y += 2.5;
34
34
  tabClass = 'tab-grace'
35
35
  }
36
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: "" + params.c, type: tabFont, klass: renderer.controller.classes.generate(tabClass), anchor: hAnchor, centerVertically: false, dim: params.dim , cursor: 'default'}, false);
36
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: "" + params.c, type: tabFont, klass: renderer.controller.classes.generate(tabClass), anchor: hAnchor, centerVertically: false, dim: params.dim, cursor: 'default' }, false);
37
37
  break;
38
38
  case "barNumber":
39
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: ""+params.c, type: "measurefont", klass: renderer.controller.classes.generate('bar-number'), anchor: "middle", dim: params.dim, name: "bar-number"}, true);
39
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: "" + params.c, type: "measurefont", klass: renderer.controller.classes.generate('bar-number'), anchor: "middle", dim: params.dim, name: "bar-number" }, true);
40
40
  break;
41
41
  case "lyric":
42
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: "vocalfont", klass: renderer.controller.classes.generate('lyric'), anchor: "middle", dim: params.dim, name: "lyric"}, false);
42
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: "vocalfont", klass: renderer.controller.classes.generate('lyric'), anchor: "middle", dim: params.dim, name: "lyric" }, false);
43
43
  break;
44
44
  case "chord":
45
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'gchordfont', klass: renderer.controller.classes.generate("chord"), anchor: "middle", dim: params.dim, lane: params.getLane(), name: "chord"}, false);
45
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'gchordfont', klass: renderer.controller.classes.generate("chord"), anchor: "middle", dim: params.dim, lane: params.getLane(), name: "chord" }, false);
46
46
  break;
47
47
  case "decoration":
48
48
  // The +6 is to compensate for the placement of text in svg: to be on the same row as symbols, the y-coord needs to compensate for the center line.
49
- params.graphelem = renderText(renderer, { x: params.x, y: y+6, text: params.c, type: 'annotationfont', klass: renderer.controller.classes.generate("annotation"), anchor: params.anchor, centerVertically: true, dim: params.dim}, false);
49
+ params.graphelem = renderText(renderer, { x: params.x, y: y + 6, text: params.c, type: 'annotationfont', klass: renderer.controller.classes.generate("annotation"), anchor: params.anchor, centerVertically: true, dim: params.dim }, false);
50
50
  break;
51
51
  case "text":
52
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'annotationfont', klass: renderer.controller.classes.generate("annotation"), anchor: "start", centerVertically: params.centerVertically, dim: params.dim, lane: params.getLane(), name: "annotation"}, false);
52
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'annotationfont', klass: renderer.controller.classes.generate("annotation"), anchor: "start", centerVertically: params.centerVertically, dim: params.dim, lane: params.getLane(), name: "annotation" }, false);
53
53
  break;
54
54
  case "multimeasure-text":
55
- params.graphelem = renderText(renderer, { x: params.x+params.w/2, y: y, text: params.c, type: 'tempofont', klass: renderer.controller.classes.generate("rest"), anchor: "middle", centerVertically: false, dim: params.dim}, false);
55
+ params.graphelem = renderText(renderer, { x: params.x + params.w / 2, y: y, text: params.c, type: 'tempofont', klass: renderer.controller.classes.generate("rest"), anchor: "middle", centerVertically: false, dim: params.dim }, false);
56
56
  break;
57
57
  case "part":
58
- params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'partsfont', klass: renderer.controller.classes.generate("part"), anchor: "start", dim: params.dim, name: params.c}, true);
58
+ params.graphelem = renderText(renderer, { x: params.x, y: y, text: params.c, type: 'partsfont', klass: renderer.controller.classes.generate("part"), anchor: "start", dim: params.dim, name: params.c }, true);
59
59
  break;
60
60
  case "bar":
61
- params.graphelem = printStem(renderer, params.x, params.linewidth, y, (bartop)?bartop:renderer.calcY(params.pitch2), null, "bar"); break; // bartop can't be 0
61
+ params.graphelem = printStem(renderer, params.x, params.linewidth + renderer.lineThickness, y, (bartop) ? bartop : renderer.calcY(params.pitch2), null, "bar"); break; // bartop can't be 0
62
62
  case "stem":
63
- params.graphelem = printStem(renderer, params.x, params.linewidth, y, renderer.calcY(params.pitch2), 'abcjs-stem', 'stem'); break;
63
+ var stemWidth = params.linewidth > 0 ? params.linewidth + renderer.lineThickness : params.linewidth - renderer.lineThickness
64
+ params.graphelem = printStem(renderer, params.x, stemWidth, y, renderer.calcY(params.pitch2), 'abcjs-stem', 'stem'); break;
64
65
  case "ledger":
65
- params.graphelem = printStaffLine(renderer, params.x, params.x+params.w, params.pitch, "abcjs-ledger", "ledger"); break;
66
+ params.graphelem = printStaffLine(renderer, params.x, params.x + params.w, params.pitch, "abcjs-ledger", "ledger", 0.35 + renderer.lineThickness); break;
66
67
  }
67
- if (params.scalex!==1 && params.graphelem) {
68
+ if (params.scalex !== 1 && params.graphelem) {
68
69
  scaleExistingElem(renderer.paper, params.graphelem, params.scalex, params.scaley, params.x, y);
69
70
  }
70
71
  return params.graphelem;
71
72
  }
72
73
 
73
74
  function scaleExistingElem(paper, elem, scaleX, scaleY, x, y) {
74
- paper.setAttributeOnElement(elem, { style: "transform:scale("+scaleX+","+scaleY + ");transform-origin:" + x + "px " + y + "px;"});
75
+ paper.setAttributeOnElement(elem, { style: "transform:scale(" + scaleX + "," + scaleY + ");transform-origin:" + x + "px " + y + "px;" });
75
76
  }
76
77
 
77
78
  module.exports = drawRelativeElement;
@@ -1,5 +1,5 @@
1
- var highlight = require('../highlight');
2
- var unhighlight = require('../unhighlight');
1
+ var highlight = require('../interactive/highlight');
2
+ var unhighlight = require('../interactive/unhighlight');
3
3
 
4
4
  function Selectables(paper, selectTypes, tuneNumber) {
5
5
  this.elements = [];
@@ -17,9 +17,9 @@ Selectables.prototype.add = function (absEl, svgEl, isNoteOrTabNumber, staffPos)
17
17
  return;
18
18
  var params;
19
19
  if (this.selectTypes === undefined)
20
- params = { selectable: false, "data-index": this.elements.length}; // This is the old behavior.
20
+ params = { selectable: false, "data-index": this.elements.length }; // This is the old behavior.
21
21
  else
22
- params = { selectable: true, tabindex: 0, "data-index": this.elements.length};
22
+ params = { selectable: true, tabindex: 0, "data-index": this.elements.length };
23
23
  this.paper.setAttributeOnElement(svgEl, params);
24
24
  var sel = { absEl: absEl, svgEl: svgEl, isDraggable: isNoteOrTabNumber };
25
25
  if (staffPos !== undefined)
@@ -45,7 +45,7 @@ Selectables.prototype.canSelect = function (absEl) {
45
45
  return this.selectTypes.indexOf(absEl.abcelem.el_type) >= 0;
46
46
  };
47
47
 
48
- Selectables.prototype.wrapSvgEl = function(abcelem, el) {
48
+ Selectables.prototype.wrapSvgEl = function (abcelem, el) {
49
49
  var absEl = {
50
50
  tuneNumber: this.tuneNumber,
51
51
  abcelem: abcelem,
@@ -3,14 +3,14 @@ function drawSeparator(renderer, width) {
3
3
  var stroke = "rgba(0,0,0,0)";
4
4
  var y = Math.round(renderer.y);
5
5
  var staffWidth = renderer.controller.width;
6
- var x1 = (staffWidth - width)/2;
6
+ var x1 = (staffWidth - width) / 2;
7
7
  var x2 = x1 + width;
8
8
  var pathString = 'M ' + x1 + ' ' + y +
9
9
  ' L ' + x2 + ' ' + y +
10
- ' L ' + x2 + ' ' + (y+1) +
11
- ' L ' + x1 + ' ' + (y+1) +
10
+ ' L ' + x2 + ' ' + (y + 1) +
11
+ ' L ' + x1 + ' ' + (y + 1) +
12
12
  ' L ' + x1 + ' ' + y + ' z';
13
- renderer.paper.pathToBack({path:pathString, stroke:stroke, fill:fill, 'class': renderer.controller.classes.generate('defined-text')});
13
+ renderer.paper.pathToBack({ path: pathString, stroke: stroke, fill: fill, 'class': renderer.controller.classes.generate('defined-text') });
14
14
  }
15
15
 
16
16
  module.exports = drawSeparator;
@@ -1,6 +1,6 @@
1
1
  function setPaperSize(renderer, maxwidth, scale, responsive) {
2
- var w = (maxwidth+renderer.padding.right)*scale;
3
- var h = (renderer.y+renderer.padding.bottom)*scale;
2
+ var w = (maxwidth + renderer.padding.right) * scale;
3
+ var h = (renderer.y + renderer.padding.bottom) * scale;
4
4
  if (renderer.isPrint)
5
5
  h = Math.max(h, 1056); // 11in x 72pt/in x 1.33px/pt
6
6
  // TODO-PER: We are letting the page get as long as it needs now, but eventually that should go to a second page.
@@ -29,37 +29,37 @@
29
29
 
30
30
  //function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }
31
31
 
32
- var sprintf = function() {
33
- var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
34
- while (f) {
35
- if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
36
- else if (m = /^\x25{2}/.exec(f)) o.push('%');
37
- else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
38
- if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
39
- if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
40
- throw("Expecting number but found " + typeof(a));
41
- switch (m[7]) {
42
- case 'b': a = a.toString(2); break;
43
- case 'c': a = String.fromCharCode(a); break;
44
- case 'd': a = parseInt(a); break;
45
- case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
46
- case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
47
- case 'o': a = a.toString(8); break;
48
- case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
49
- case 'u': a = Math.abs(a); break;
50
- case 'x': a = a.toString(16); break;
51
- case 'X': a = a.toString(16).toUpperCase(); break;
52
- }
53
- a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
54
- c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
55
- x = m[5] - String(a).length;
56
- p = m[5] ? str_repeat(c, x) : '';
57
- o.push(m[4] ? a + p : p + a);
58
- }
59
- else throw ("Huh ?!");
60
- f = f.substring(m[0].length);
61
- }
62
- return o.join('');
32
+ var sprintf = function () {
33
+ var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
34
+ while (f) {
35
+ if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
36
+ else if (m = /^\x25{2}/.exec(f)) o.push('%');
37
+ else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
38
+ if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw ("Too few arguments.");
39
+ if (/[^s]/.test(m[7]) && (typeof (a) != 'number'))
40
+ throw ("Expecting number but found " + typeof (a));
41
+ switch (m[7]) {
42
+ case 'b': a = a.toString(2); break;
43
+ case 'c': a = String.fromCharCode(a); break;
44
+ case 'd': a = parseInt(a); break;
45
+ case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
46
+ case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
47
+ case 'o': a = a.toString(8); break;
48
+ case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
49
+ case 'u': a = Math.abs(a); break;
50
+ case 'x': a = a.toString(16); break;
51
+ case 'X': a = a.toString(16).toUpperCase(); break;
52
+ }
53
+ a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
54
+ c = m[3] ? m[3] == '0' ? '0' : m[3][1] : ' ';
55
+ x = m[5] - String(a).length;
56
+ p = m[5] ? str_repeat(c, x) : '';
57
+ o.push(m[4] ? a + p : p + a);
58
+ }
59
+ else throw ("Huh ?!");
60
+ f = f.substring(m[0].length);
61
+ }
62
+ return o.join('');
63
63
  };
64
64
 
65
65
  module.exports = sprintf;
@@ -1,4 +1,4 @@
1
- var spacing = require('../abc_spacing');
1
+ var spacing = require('../helpers/spacing');
2
2
  var drawBrace = require('./brace');
3
3
  var drawVoice = require('./voice');
4
4
  var printStaff = require('./staff');
@@ -6,7 +6,7 @@ var printDebugBox = require('./debug-box');
6
6
  var printStem = require('./print-stem');
7
7
  var nonMusic = require('./non-music');
8
8
 
9
- function drawStaffGroup(renderer, params, selectables,lineNumber) {
9
+ function drawStaffGroup(renderer, params, selectables, lineNumber) {
10
10
  // We enter this method with renderer.y pointing to the topmost coordinate that we're allowed to draw.
11
11
  // All of the children that will be drawn have a relative "pitch" set, where zero is the first ledger line below the staff.
12
12
  // renderer.y will be offset at the beginning of each staff by the amount required to make the relative pitch work.
@@ -25,20 +25,22 @@ function drawStaffGroup(renderer, params, selectables,lineNumber) {
25
25
  renderer.moveY(spacing.STEP, staff1.top);
26
26
  staff1.absoluteY = renderer.y;
27
27
  if (renderer.showDebug) {
28
- if (renderer.showDebug.indexOf("box") >= 0) {
28
+ if (renderer.showDebug.indexOf("box") >= 0 && staff1.voices) {
29
29
  boxAllElements(renderer, params.voices, staff1.voices);
30
30
  }
31
31
  if (renderer.showDebug.indexOf("grid") >= 0) {
32
- renderer.paper.dottedLine({x1: renderer.padding.left, x2: renderer.padding.left+renderer.controller.width, y1: startY, y2: startY, stroke: "#0000ff"});
32
+ renderer.paper.dottedLine({ x1: renderer.padding.left, x2: renderer.padding.left + renderer.controller.width, y1: startY, y2: startY, stroke: "#0000ff" });
33
33
  printDebugBox(renderer,
34
- { x: renderer.padding.left,
34
+ {
35
+ x: renderer.padding.left,
35
36
  y: renderer.calcY(staff1.originalTop),
36
37
  width: renderer.controller.width,
37
38
  height: renderer.calcY(staff1.originalBottom) - renderer.calcY(staff1.originalTop),
38
39
  fill: renderer.foregroundColor,
39
40
  stroke: renderer.foregroundColor,
40
41
  "fill-opacity": 0.1,
41
- "stroke-opacity": 0.1 });
42
+ "stroke-opacity": 0.1
43
+ });
42
44
  colorIndex = 0;
43
45
  debugPrintGridItem(staff1, 'chordHeightAbove');
44
46
  debugPrintGridItem(staff1, 'chordHeightBelow');
@@ -71,23 +73,23 @@ function drawStaffGroup(renderer, params, selectables,lineNumber) {
71
73
 
72
74
  var linePitch = 2;
73
75
  var bartop = 0;
74
- for (var i=0;i<params.voices.length;i++) {
76
+ for (var i = 0; i < params.voices.length; i++) {
75
77
  var staff = params.voices[i].staff;
76
78
  var tabName = params.voices[i].tabNameInfos;
77
- renderer.y = staff.absoluteY ;
79
+ renderer.y = staff.absoluteY;
78
80
  renderer.controller.classes.incrVoice();
79
81
  //renderer.y = staff.y;
80
82
  // offset for starting the counting at middle C
81
83
  if (!params.voices[i].duplicate) {
82
- // renderer.moveY(spacing.STEP, staff.top);
83
- if (!topLine) topLine = renderer.calcY(10);
84
- bottomLine = renderer.calcY(linePitch);
84
+ // renderer.moveY(spacing.STEP, staff.top);
85
+ if (!topLine) topLine = renderer.calcY(10);
86
+ bottomLine = renderer.calcY(linePitch);
85
87
  if (staff.lines !== 0) {
86
88
  if (staff.linePitch) {
87
- linePitch = staff.linePitch;
89
+ linePitch = staff.linePitch;
88
90
  }
89
91
  renderer.controller.classes.newMeasure();
90
- var lines = printStaff(renderer, params.startx, params.w, staff.lines, staff.linePitch, staff.dy);
92
+ var lines = printStaff(renderer, params.startx, params.w, staff.lines, staff.linePitch, 0.35);
91
93
  bottomLine = lines[1];
92
94
  staff.bottomLine = bottomLine;
93
95
  staff.topLine = lines[0];
@@ -110,15 +112,15 @@ function drawStaffGroup(renderer, params, selectables,lineNumber) {
110
112
  drawVoice(renderer, params.voices[i], bartop, selectables, {
111
113
  top: startY,
112
114
  zero: renderer.y,
113
- height: params.height*spacing.STEP
115
+ height: params.height * spacing.STEP
114
116
  });
115
- var tabNameHeight = 0;
117
+ var tabNameHeight = 0;
116
118
  if (tabName) {
117
119
  // print tab infos on staffBottom
118
120
  var r = { rows: [] };
119
121
  r.rows.push({ absmove: bottomLine + 2 });
120
122
  var leftMargin = 8;
121
- r.rows.push({ left: params.startx+leftMargin, text: tabName.name, font: 'tablabelfont', klass: 'text instrument-name', anchor: 'start' });
123
+ r.rows.push({ left: params.startx + leftMargin, text: tabName.name, font: 'tablabelfont', klass: 'text instrument-name', anchor: 'start' });
122
124
  r.rows.push({ move: tabName.textSize.height });
123
125
  nonMusic(renderer, r);
124
126
  tabNameHeight = tabName.textSize.height;
@@ -126,9 +128,9 @@ function drawStaffGroup(renderer, params, selectables,lineNumber) {
126
128
 
127
129
  renderer.controller.classes.newMeasure();
128
130
  if (!params.voices[i].duplicate) {
129
- bartop = renderer.calcY(2 + tabNameHeight); // This connects the bar lines between two different staves.
130
- // if (staff.bottom < 0)
131
- // renderer.moveY(spacing.STEP, -staff.bottom);
131
+ bartop = renderer.calcY(2 + tabNameHeight); // This connects the bar lines between two different staves.
132
+ // if (staff.bottom < 0)
133
+ // renderer.moveY(spacing.STEP, -staff.bottom);
132
134
  }
133
135
  }
134
136
  renderer.controller.classes.newMeasure();
@@ -143,23 +145,25 @@ function drawStaffGroup(renderer, params, selectables,lineNumber) {
143
145
  renderer.y = startY;
144
146
 
145
147
  function debugPrintGridItem(staff, key) {
146
- var colors = [ "rgb(207,27,36)", "rgb(168,214,80)", "rgb(110,161,224)", "rgb(191,119,218)", "rgb(195,30,151)",
147
- "rgb(31,170,177)", "rgb(220,166,142)" ];
148
- if (staff.positionY[key]) {
148
+ var colors = ["rgb(207,27,36)", "rgb(168,214,80)", "rgb(110,161,224)", "rgb(191,119,218)", "rgb(195,30,151)",
149
+ "rgb(31,170,177)", "rgb(220,166,142)"];
150
+ if (staff.positionY && staff.positionY[key]) {
149
151
  var height = staff.specialY[key] * spacing.STEP;
150
152
  if (key === "chordHeightAbove" && staff.specialY.chordLines && staff.specialY.chordLines.above)
151
153
  height *= staff.specialY.chordLines.above;
152
154
  if (key === "chordHeightBelow" && staff.specialY.chordLines && staff.specialY.chordLines.below)
153
155
  height *= staff.specialY.chordLines.below;
154
156
  printDebugBox(renderer,
155
- { x: renderer.padding.left,
157
+ {
158
+ x: renderer.padding.left,
156
159
  y: renderer.calcY(staff.positionY[key]),
157
160
  width: renderer.controller.width,
158
161
  height: height,
159
162
  fill: colors[colorIndex],
160
163
  stroke: colors[colorIndex],
161
164
  "fill-opacity": 0.4,
162
- "stroke-opacity": 0.4 },
165
+ "stroke-opacity": 0.4
166
+ },
163
167
  key.substr(0, 4));
164
168
  colorIndex += 1; if (colorIndex > 6) colorIndex = 0;
165
169
  }
@@ -190,9 +194,10 @@ function boxAllElements(renderer, voices, which) {
190
194
  var coords = elem.getFixedCoords();
191
195
  if (elem.invisible || coords.t === undefined || coords.b === undefined)
192
196
  continue;
193
- var height = (coords.t - coords.b)*spacing.STEP;
197
+ var height = (coords.t - coords.b) * spacing.STEP;
194
198
  printDebugBox(renderer,
195
- { x: coords.x,
199
+ {
200
+ x: coords.x,
196
201
  y: renderer.calcY(coords.t),
197
202
  width: coords.w,
198
203
  height: height,
@@ -200,18 +205,19 @@ function boxAllElements(renderer, voices, which) {
200
205
  "fill-opacity": 0.4,
201
206
  stroke: "#4aa93d",
202
207
  "stroke-opacity": 0.8
203
- });
208
+ });
204
209
 
205
210
  for (var k = 0; k < elem.children.length; k++) {
206
211
  var relElem = elem.children[k];
207
212
  var chord = relElem.getChordDim();
208
213
  if (chord) {
209
214
  var y = renderer.calcY(relElem.pitch);
210
- y += relElem.dim.font.size*relElem.getLane();
215
+ y += relElem.dim.font.size * relElem.getLane();
211
216
  printDebugBox(renderer,
212
- { x: chord.left,
217
+ {
218
+ x: chord.left,
213
219
  y: y,
214
- width: chord.right-chord.left,
220
+ width: chord.right - chord.left,
215
221
  height: relElem.dim.font.size,
216
222
  fill: "none",
217
223
  stroke: "#4aa93d",
@@ -1,8 +1,8 @@
1
1
  var printLine = require('./print-line');
2
2
 
3
- function printStaffLine(renderer, x1,x2, pitch, klass, name , dy) {
3
+ function printStaffLine(renderer, x1, x2, pitch, klass, name, dy) {
4
4
  var y = renderer.calcY(pitch);
5
- return printLine(renderer,x1,x2,y,klass,name,dy);
5
+ return printLine(renderer, x1, x2, y, klass, name, dy);
6
6
  }
7
7
 
8
8
  module.exports = printStaffLine;
@@ -1,6 +1,6 @@
1
1
  var printStaffLine = require('./staff-line');
2
2
 
3
- function printStaff(renderer, startx, endx, numLines , linePitch , dy) {
3
+ function printStaff(renderer, startx, endx, numLines, linePitch, dy) {
4
4
  var klass = "abcjs-top-line";
5
5
  var pitch = 2;
6
6
  if (linePitch) {
@@ -11,7 +11,7 @@ function printStaff(renderer, startx, endx, numLines , linePitch , dy) {
11
11
  var firstYLine = 0;
12
12
  var lastYLine = 0;
13
13
  if (numLines === 1) {
14
- printStaffLine(renderer, startx,endx,6, klass);
14
+ printStaffLine(renderer, startx, endx, 6, klass, null, dy + renderer.lineThickness);
15
15
  firstYLine = renderer.calcY(10);
16
16
  lastYLine = renderer.calcY(2);
17
17
  } else {
@@ -22,12 +22,12 @@ function printStaff(renderer, startx, endx, numLines , linePitch , dy) {
22
22
  if (firstYLine === 0) {
23
23
  firstYLine = lastYLine;
24
24
  }
25
- printStaffLine(renderer, startx, endx, curpitch, klass , null , dy) ;
25
+ printStaffLine(renderer, startx, endx, curpitch, klass, null, dy + renderer.lineThickness);
26
26
  klass = undefined;
27
27
  }
28
28
  }
29
29
  renderer.paper.closeGroup();
30
- return [firstYLine,lastYLine];
30
+ return [firstYLine, lastYLine];
31
31
  }
32
32
 
33
33
  module.exports = printStaff;
@@ -2,38 +2,38 @@ var sprintf = require('./sprintf');
2
2
  var roundNumber = require('./round-number');
3
3
  var printStem = require('./print-stem');
4
4
 
5
- function TabLine(renderer , klass , dx , name) {
6
- this.renderer = renderer;
7
- if (!dx) dx = 0.35; // default
8
- this.dx = dx;
9
- this.klass = klass;
10
- this.name = name;
11
- var fill = renderer.foregroundColor;
12
- this.options = { stroke: "none", fill: fill };
13
- if (name)
14
- this.options['data-name'] = name;
15
- if (klass)
16
- this.options['class'] = klass;
5
+ function TabLine(renderer, klass, dx, name) {
6
+ this.renderer = renderer;
7
+ if (!dx) dx = 0.35; // default
8
+ this.dx = dx;
9
+ this.klass = klass;
10
+ this.name = name;
11
+ var fill = renderer.foregroundColor;
12
+ this.options = { stroke: "none", fill: fill };
13
+ if (name)
14
+ this.options['data-name'] = name;
15
+ if (klass)
16
+ this.options['class'] = klass;
17
17
  }
18
18
 
19
19
  TabLine.prototype.printVertical = function (y1, y2, x) {
20
- return printStem(this.renderer,
21
- x,
22
- this.dx,
23
- y1,
24
- y2,
25
- this.options.klass,
26
- this.options.name);
20
+ return printStem(this.renderer,
21
+ x,
22
+ this.dx,
23
+ y1,
24
+ y2,
25
+ this.options.klass,
26
+ this.options.name);
27
27
  }
28
28
 
29
29
  TabLine.prototype.printHorizontal = function (x1, x2, y) {
30
- x1 = roundNumber(x1);
31
- x2 = roundNumber(x2);
32
- var y1 = roundNumber(y - this.dx);
33
- var y2 = roundNumber(y + this.dx);
34
- this.options.path = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y1, x2, y1,
35
- x2, y2, x1, y2);
36
- return this.renderer.paper.pathToBack(this.options);
30
+ x1 = roundNumber(x1);
31
+ x2 = roundNumber(x2);
32
+ var y1 = roundNumber(y - this.dx);
33
+ var y2 = roundNumber(y + this.dx);
34
+ this.options.path = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y1, x2, y1,
35
+ x2, y2, x1, y2);
36
+ return this.renderer.paper.pathToBack(this.options);
37
37
  }
38
38
 
39
39
  module.exports = TabLine;