abcjs 6.1.8 → 6.2.0

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 (132) hide show
  1. package/RELEASE.md +66 -0
  2. package/dist/abcjs-basic-min.js +2 -2
  3. package/dist/abcjs-basic.js +4373 -4424
  4. package/dist/abcjs-basic.js.map +1 -1
  5. package/dist/abcjs-plugin-min.js +2 -2
  6. package/index.js +1 -1
  7. package/package.json +6 -6
  8. package/plugin.js +1 -1
  9. package/src/api/abc_timing_callbacks.js +7 -3
  10. package/src/api/abc_tunebook_svg.js +1 -2
  11. package/src/data/abc_tune.js +2 -2
  12. package/src/midi/abc_midi_create.js +8 -2
  13. package/src/parse/abc_common.js +0 -47
  14. package/src/parse/abc_parse.js +16 -16
  15. package/src/parse/abc_parse_book.js +3 -3
  16. package/src/parse/abc_parse_directive.js +26 -7
  17. package/src/parse/abc_parse_header.js +11 -9
  18. package/src/parse/abc_parse_key_voice.js +17 -17
  19. package/src/parse/abc_parse_music.js +89 -106
  20. package/src/parse/abc_tokenizer.js +60 -60
  21. package/src/parse/abc_transpose.js +14 -3
  22. package/src/parse/tune-builder.js +19 -14
  23. package/src/synth/abc_midi_flattener.js +25 -9
  24. package/src/synth/abc_midi_sequencer.js +1 -1
  25. package/src/synth/create-synth.js +41 -0
  26. package/src/synth/note-to-midi.js +50 -0
  27. package/src/tablatures/instruments/guitar/tab-guitar.js +0 -2
  28. package/src/tablatures/instruments/string-patterns.js +46 -28
  29. package/src/tablatures/instruments/tab-note.js +26 -103
  30. package/src/tablatures/instruments/violin/tab-violin.js +0 -2
  31. package/src/tablatures/tab-absolute-elements.js +9 -31
  32. package/src/tablatures/tab-renderer.js +2 -2
  33. package/src/test/abc_parser_lint.js +8 -5
  34. package/src/write/README.md +31 -0
  35. package/src/write/creation/abstract-engraver.js +1036 -0
  36. package/src/write/creation/add-chord.js +102 -0
  37. package/src/write/{add-text-if.js → creation/add-text-if.js} +6 -6
  38. package/src/write/{calcHeight.js → creation/calc-height.js} +2 -2
  39. package/src/write/creation/create-clef.js +72 -0
  40. package/src/write/creation/create-key-signature.js +31 -0
  41. package/src/write/creation/create-note-head.js +107 -0
  42. package/src/write/creation/create-time-signature.js +55 -0
  43. package/src/write/creation/decoration.js +357 -0
  44. package/src/write/{abc_absolute_element.js → creation/elements/absolute-element.js} +14 -15
  45. package/src/write/creation/elements/beam-element.js +113 -0
  46. package/src/write/{bottom-text.js → creation/elements/bottom-text.js} +14 -15
  47. package/src/write/{abc_brace_element.js → creation/elements/brace-element.js} +5 -5
  48. package/src/write/creation/elements/free-text.js +41 -0
  49. package/src/write/{abc_relative_element.js → creation/elements/relative-element.js} +8 -7
  50. package/src/write/{separator.js → creation/elements/separator.js} +2 -2
  51. package/src/write/{abc_staff_group_element.js → creation/elements/staff-group-element.js} +4 -4
  52. package/src/write/{subtitle.js → creation/elements/subtitle.js} +3 -3
  53. package/src/write/creation/elements/tempo-element.js +63 -0
  54. package/src/write/{abc_tie_element.js → creation/elements/tie-element.js} +15 -11
  55. package/src/write/{top-text.js → creation/elements/top-text.js} +12 -12
  56. package/src/write/creation/elements/triplet-element.js +28 -0
  57. package/src/write/{abc_voice_element.js → creation/elements/voice-element.js} +3 -3
  58. package/src/write/creation/glyphs.js +226 -0
  59. package/src/write/creation/translate-chord.js +37 -0
  60. package/src/write/draw/absolute.js +5 -5
  61. package/src/write/draw/beam.js +8 -8
  62. package/src/write/draw/brace.js +33 -33
  63. package/src/write/draw/crescendo.js +4 -4
  64. package/src/write/draw/debug-box.js +1 -1
  65. package/src/write/draw/draw.js +7 -7
  66. package/src/write/draw/dynamics.js +2 -2
  67. package/src/write/draw/ending.js +6 -6
  68. package/src/write/draw/glissando.js +17 -17
  69. package/src/write/draw/group-elements.js +51 -51
  70. package/src/write/draw/horizontal-line.js +9 -9
  71. package/src/write/draw/non-music.js +1 -1
  72. package/src/write/draw/print-line.js +15 -16
  73. package/src/write/draw/print-stem.js +5 -5
  74. package/src/write/draw/print-symbol.js +12 -12
  75. package/src/write/draw/print-vertical-line.js +8 -8
  76. package/src/write/draw/relative.js +17 -16
  77. package/src/write/draw/selectables.js +5 -5
  78. package/src/write/draw/separator.js +4 -4
  79. package/src/write/draw/set-paper-size.js +2 -2
  80. package/src/write/draw/sprintf.js +31 -31
  81. package/src/write/draw/staff-group.js +36 -30
  82. package/src/write/draw/staff-line.js +2 -2
  83. package/src/write/draw/staff.js +4 -4
  84. package/src/write/draw/tab-line.js +26 -26
  85. package/src/write/draw/tempo.js +30 -30
  86. package/src/write/draw/text.js +5 -5
  87. package/src/write/draw/tie.js +18 -18
  88. package/src/write/draw/triplet.js +6 -6
  89. package/src/write/draw/voice.js +16 -17
  90. package/src/write/{abc_engraver_controller.js → engraver-controller.js} +58 -51
  91. package/src/write/{classes.js → helpers/classes.js} +6 -6
  92. package/src/write/{get-font-and-attr.js → helpers/get-font-and-attr.js} +9 -7
  93. package/src/write/{get-text-size.js → helpers/get-text-size.js} +5 -5
  94. package/src/write/{set-class.js → helpers/set-class.js} +1 -1
  95. package/src/write/{abc_spacing.js → helpers/spacing.js} +1 -1
  96. package/src/write/{highlight.js → interactive/highlight.js} +1 -1
  97. package/src/write/{selection.js → interactive/selection.js} +27 -27
  98. package/src/write/{unhighlight.js → interactive/unhighlight.js} +1 -1
  99. package/src/write/layout/beam.js +13 -13
  100. package/src/write/layout/get-left-edge-of-staff.js +4 -4
  101. package/src/write/layout/layout.js +74 -74
  102. package/src/write/layout/{setUpperAndLowerElements.js → set-upper-and-lower-elements.js} +8 -8
  103. package/src/write/layout/{staffGroup.js → staff-group.js} +32 -32
  104. package/src/write/layout/triplet.js +4 -4
  105. package/src/write/layout/{VoiceElements.js → voice-elements.js} +23 -23
  106. package/src/write/layout/voice.js +6 -6
  107. package/src/write/{abc_renderer.js → renderer.js} +35 -32
  108. package/src/write/svg.js +35 -35
  109. package/test.js +1 -1
  110. package/types/index.d.ts +99 -22
  111. package/version.js +1 -1
  112. package/src/tablatures/instruments/guitar/guitar-fonts.js +0 -19
  113. package/src/tablatures/instruments/violin/violin-fonts.js +0 -19
  114. package/src/tablatures/transposer.js +0 -110
  115. package/src/write/abc_abstract_engraver.js +0 -1026
  116. package/src/write/abc_beam_element.js +0 -113
  117. package/src/write/abc_create_clef.js +0 -72
  118. package/src/write/abc_create_key_signature.js +0 -33
  119. package/src/write/abc_create_note_head.js +0 -107
  120. package/src/write/abc_create_time_signature.js +0 -55
  121. package/src/write/abc_decoration.js +0 -341
  122. package/src/write/abc_glyphs.js +0 -224
  123. package/src/write/abc_tempo_element.js +0 -63
  124. package/src/write/abc_triplet_element.js +0 -28
  125. package/src/write/add-chord.js +0 -103
  126. package/src/write/format-jazz-chord.js +0 -15
  127. package/src/write/free-text.js +0 -41
  128. /package/src/write/{abc_crescendo_element.js → creation/elements/crescendo-element.js} +0 -0
  129. /package/src/write/{abc_dynamic_decoration.js → creation/elements/dynamic-decoration.js} +0 -0
  130. /package/src/write/{abc_ending_element.js → creation/elements/ending-element.js} +0 -0
  131. /package/src/write/{abc_glissando_element.js → creation/elements/glissando-element.js} +0 -0
  132. /package/src/write/layout/{getBarYAt.js → get-bar-y-at.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  var drawTempo = require('./tempo');
2
2
  var drawRelativeElement = require('./relative');
3
- var spacing = require('../abc_spacing');
4
- var setClass = require('../set-class');
3
+ var spacing = require('../helpers/spacing');
4
+ var setClass = require('../helpers/set-class');
5
5
  var elementGroup = require('./group-elements');
6
6
 
7
7
  function drawAbsolute(renderer, params, bartop, selectables, staffPos) {
@@ -9,7 +9,7 @@ function drawAbsolute(renderer, params, bartop, selectables, staffPos) {
9
9
  var isTempo = params.children.length > 0 && params.children[0].type === "TempoElement";
10
10
  params.elemset = [];
11
11
  elementGroup.beginGroup(renderer.paper, renderer.controller);
12
- for (var i=0; i<params.children.length; i++) {
12
+ for (var i = 0; i < params.children.length; i++) {
13
13
  var child = params.children[i];
14
14
  switch (child.type) {
15
15
  case "TempoElement":
@@ -22,7 +22,7 @@ function drawAbsolute(renderer, params, bartop, selectables, staffPos) {
22
22
  var klass = params.type;
23
23
  if (params.type === 'note' || params.type === 'rest') {
24
24
  params.counters = renderer.controller.classes.getCurrent();
25
- klass += ' d' + Math.round(params.durationClass*1000)/1000;
25
+ klass += ' d' + Math.round(params.durationClass * 1000) / 1000;
26
26
  klass = klass.replace(/\./g, '-');
27
27
  if (params.abcelem.pitches) {
28
28
  for (var j = 0; j < params.abcelem.pitches.length; j++) {
@@ -66,7 +66,7 @@ function drawAbsolute(renderer, params, bartop, selectables, staffPos) {
66
66
  params.notePositions = [];
67
67
  for (var jj = 0; jj < params.heads.length; jj++) {
68
68
  params.notePositions.push({
69
- x: params.heads[jj].x + params.heads[jj].w/2,
69
+ x: params.heads[jj].x + params.heads[jj].w / 2,
70
70
  y: staffPos.zero - params.heads[jj].pitch * spacing.STEP
71
71
  });
72
72
  }
@@ -9,9 +9,9 @@ function drawBeam(renderer, params) {
9
9
  var beam = params.beams[i];
10
10
  if (beam.split) {
11
11
  var slope = getSlope(renderer, beam.startX, beam.startY, beam.endX, beam.endY);
12
- var xes = [ ];
13
- for (var j = 0; j < beam.split.length; j+=2) {
14
- xes.push([beam.split[j], beam.split[j+1]]);
12
+ var xes = [];
13
+ for (var j = 0; j < beam.split.length; j += 2) {
14
+ xes.push([beam.split[j], beam.split[j + 1]]);
15
15
  }
16
16
  for (j = 0; j < xes.length; j++) {
17
17
  var y1 = getY(beam.startX, beam.startY, slope, xes[j][0]);
@@ -21,8 +21,8 @@ function drawBeam(renderer, params) {
21
21
  } else
22
22
  pathString += draw(renderer, beam.startX, beam.startY, beam.endX, beam.endY, beam.dy);
23
23
  }
24
- var durationClass = ("abcjs-d"+params.duration).replace(/\./g,"-");
25
- var klasses = renderer.controller.classes.generate('beam-elem '+durationClass);
24
+ var durationClass = ("abcjs-d" + params.duration).replace(/\./g, "-");
25
+ var klasses = renderer.controller.classes.generate('beam-elem ' + durationClass);
26
26
  var el = printPath(renderer, {
27
27
  path: pathString,
28
28
  stroke: "none",
@@ -38,8 +38,8 @@ function draw(renderer, startX, startY, endX, endY, dy) {
38
38
  endY = roundNumber(renderer.calcY(endY));
39
39
  startX = roundNumber(startX);
40
40
  endX = roundNumber(endX);
41
- var startY2 = roundNumber(startY+dy);
42
- var endY2 = roundNumber(endY+dy);
41
+ var startY2 = roundNumber(startY + dy);
42
+ var endY2 = roundNumber(endY + dy);
43
43
  return "M" + startX + " " + startY + " L" + endX + " " + endY +
44
44
  "L" + endX + " " + endY2 + " L" + startX + " " + startY2 + "z";
45
45
  }
@@ -50,7 +50,7 @@ function getSlope(renderer, startX, startY, endX, endY) {
50
50
 
51
51
  function getY(startX, startY, slope, currentX) {
52
52
  var x = currentX - startX;
53
- return startY + x*slope;
53
+ return startY + x * slope;
54
54
  }
55
55
 
56
56
  module.exports = drawBeam;
@@ -1,51 +1,51 @@
1
1
  var sprintf = require('./sprintf');
2
- var spacing = require('../abc_spacing');
2
+ var spacing = require('../helpers/spacing');
3
3
  var renderText = require('./text');
4
4
 
5
5
  function drawBrace(renderer, params, selectables) {
6
6
  // The absoluteY number is the spot where the note on the first ledger line is drawn (i.e. middle C if treble clef)
7
7
  // The STEP offset here moves it to the top and bottom lines
8
- var startY = params.startVoice.staff.absoluteY - spacing.STEP*10;
8
+ var startY = params.startVoice.staff.absoluteY - spacing.STEP * 10;
9
9
  if (params.endVoice && params.endVoice.staff)
10
- params.endY = params.endVoice.staff.absoluteY - spacing.STEP*2;
10
+ params.endY = params.endVoice.staff.absoluteY - spacing.STEP * 2;
11
11
  else if (params.lastContinuedVoice && params.lastContinuedVoice.staff)
12
- params.endY = params.lastContinuedVoice.staff.absoluteY - spacing.STEP*2;
12
+ params.endY = params.lastContinuedVoice.staff.absoluteY - spacing.STEP * 2;
13
13
  else
14
- params.endY = params.startVoice.staff.absoluteY - spacing.STEP*2;
15
- return draw(renderer, params.x,startY, params.endY, params.type, params.header, selectables);
14
+ params.endY = params.startVoice.staff.absoluteY - spacing.STEP * 2;
15
+ return draw(renderer, params.x, startY, params.endY, params.type, params.header, selectables);
16
16
  }
17
17
 
18
18
  function straightPath(renderer, xLeft, yTop, yBottom, type) {
19
19
  xLeft += spacing.STEP;
20
- var xLineWidth = spacing.STEP*0.75;
21
- var yOverlap = spacing.STEP*0.75;
20
+ var xLineWidth = spacing.STEP * 0.75;
21
+ var yOverlap = spacing.STEP * 0.75;
22
22
  var height = yBottom - yTop;
23
23
  // Straight line
24
24
  var pathString = sprintf("M %f %f l %f %f l %f %f l %f %f z",
25
- xLeft, yTop-yOverlap, // top left line
26
- 0, height+yOverlap*2, // bottom left line
25
+ xLeft, yTop - yOverlap, // top left line
26
+ 0, height + yOverlap * 2, // bottom left line
27
27
  xLineWidth, 0, // bottom right line
28
- 0, - (height+yOverlap*2) // top right line
28
+ 0, - (height + yOverlap * 2) // top right line
29
29
  );
30
30
  // Top arm
31
- var wCurve = spacing.STEP*2;
31
+ var wCurve = spacing.STEP * 2;
32
32
  var hCurve = spacing.STEP;
33
33
  pathString += sprintf("M %f %f q %f %f %f %f q %f %f %f %f z",
34
- xLeft+xLineWidth, yTop-yOverlap, // top left arm
35
- wCurve*0.6, hCurve*0.2,
34
+ xLeft + xLineWidth, yTop - yOverlap, // top left arm
35
+ wCurve * 0.6, hCurve * 0.2,
36
36
  wCurve, -hCurve, // right point
37
- -wCurve*0.1, hCurve*0.3,
38
- -wCurve, hCurve+spacing.STEP // left bottom
37
+ -wCurve * 0.1, hCurve * 0.3,
38
+ -wCurve, hCurve + spacing.STEP // left bottom
39
39
  );
40
40
  // Bottom arm
41
41
  pathString += sprintf("M %f %f q %f %f %f %f q %f %f %f %f z",
42
- xLeft+xLineWidth, yTop+yOverlap+height, // bottom left arm
43
- wCurve*0.6, -hCurve*0.2,
42
+ xLeft + xLineWidth, yTop + yOverlap + height, // bottom left arm
43
+ wCurve * 0.6, -hCurve * 0.2,
44
44
  wCurve, hCurve, // right point
45
- -wCurve*0.1, -hCurve*0.3,
46
- -wCurve, -hCurve-spacing.STEP // left bottom
45
+ -wCurve * 0.1, -hCurve * 0.3,
46
+ -wCurve, -hCurve - spacing.STEP // left bottom
47
47
  );
48
- return renderer.paper.path({path:pathString, stroke:renderer.foregroundColor, fill:renderer.foregroundColor, 'class': renderer.controller.classes.generate(type), "data-name": type});
48
+ return renderer.paper.path({ path: pathString, stroke: renderer.foregroundColor, fill: renderer.foregroundColor, 'class': renderer.controller.classes.generate(type), "data-name": type });
49
49
  }
50
50
 
51
51
  function curvyPath(renderer, xLeft, yTop, yBottom, type) {
@@ -54,31 +54,31 @@ function curvyPath(renderer, xLeft, yTop, yBottom, type) {
54
54
  var pathString = curve(xLeft,
55
55
  yTop,
56
56
  [7.5, -8, 21, 0, 18.5, -10.5, 7.5],
57
- [0, yHeight/5.5, yHeight/3.14, yHeight/2, yHeight/2.93, yHeight/4.88, 0]);
57
+ [0, yHeight / 5.5, yHeight / 3.14, yHeight / 2, yHeight / 2.93, yHeight / 4.88, 0]);
58
58
 
59
59
  pathString += curve(xLeft,
60
60
  yTop,
61
61
  [0, 17.5, -7.5, 6.6, -5, 20, 0],
62
- [yHeight/2, yHeight/1.46, yHeight/1.22, yHeight, yHeight/1.19, yHeight/1.42, yHeight/2]);
62
+ [yHeight / 2, yHeight / 1.46, yHeight / 1.22, yHeight, yHeight / 1.19, yHeight / 1.42, yHeight / 2]);
63
63
 
64
- return renderer.paper.path({path:pathString, stroke:renderer.foregroundColor, fill:renderer.foregroundColor, 'class': renderer.controller.classes.generate(type), "data-name": type});
64
+ return renderer.paper.path({ path: pathString, stroke: renderer.foregroundColor, fill: renderer.foregroundColor, 'class': renderer.controller.classes.generate(type), "data-name": type });
65
65
  }
66
66
 
67
67
  function curve(xLeft, yTop, xCurve, yCurve) {
68
68
  return sprintf("M %f %f C %f %f %f %f %f %f C %f %f %f %f %f %f z",
69
- xLeft+xCurve[0], yTop+yCurve[0],
70
- xLeft+xCurve[1], yTop+yCurve[1],
71
- xLeft+xCurve[2], yTop+yCurve[2],
72
- xLeft+xCurve[3], yTop+yCurve[3],
73
- xLeft+xCurve[4], yTop+yCurve[4],
74
- xLeft+xCurve[5], yTop+yCurve[5],
75
- xLeft+xCurve[6], yTop+yCurve[6]);
69
+ xLeft + xCurve[0], yTop + yCurve[0],
70
+ xLeft + xCurve[1], yTop + yCurve[1],
71
+ xLeft + xCurve[2], yTop + yCurve[2],
72
+ xLeft + xCurve[3], yTop + yCurve[3],
73
+ xLeft + xCurve[4], yTop + yCurve[4],
74
+ xLeft + xCurve[5], yTop + yCurve[5],
75
+ xLeft + xCurve[6], yTop + yCurve[6]);
76
76
  }
77
77
 
78
78
  var draw = function (renderer, xLeft, yTop, yBottom, type, header, selectables) {//Tony
79
79
  var ret;
80
80
  if (header) {
81
- renderer.paper.openGroup({klass: renderer.controller.classes.generate("staff-extra voice-name"), "data-name": type});
81
+ renderer.paper.openGroup({ klass: renderer.controller.classes.generate("staff-extra voice-name"), "data-name": type });
82
82
  var position = yTop + (yBottom - yTop) / 2;
83
83
  position = position - renderer.controller.getTextSize.baselineToCenter(header, "voicefont", 'staff-extra voice-name', 0, 1);
84
84
 
@@ -99,7 +99,7 @@ var draw = function (renderer, xLeft, yTop, yBottom, type, header, selectables)
99
99
  if (header) {
100
100
  ret = renderer.paper.closeGroup();
101
101
  }
102
- selectables.wrapSvgEl({el_type: type, startChar: -1, endChar: -1}, ret);
102
+ selectables.wrapSvgEl({ el_type: type, startChar: -1, endChar: -1 }, ret);
103
103
 
104
104
  return ret;
105
105
  };
@@ -14,11 +14,11 @@ function drawCrescendo(renderer, params, selectables) {
14
14
 
15
15
  var el;
16
16
  if (params.dir === "<") {
17
- el = drawLine(renderer, y+height/2, y, y+height/2, y+height, left, right);
17
+ el = drawLine(renderer, y + height / 2, y, y + height / 2, y + height, left, right);
18
18
  } else {
19
- el = drawLine(renderer, y, y+height/2, y+height, y+height/2, left, right);
19
+ el = drawLine(renderer, y, y + height / 2, y + height, y + height / 2, left, right);
20
20
  }
21
- selectables.wrapSvgEl({el_type: "dynamicDecoration", startChar: -1, endChar: -1}, el);
21
+ selectables.wrapSvgEl({ el_type: "dynamicDecoration", startChar: -1, endChar: -1 }, el);
22
22
  return [el];
23
23
  }
24
24
 
@@ -32,7 +32,7 @@ var drawLine = function (renderer, y1, y2, y3, y4, left, right) {
32
32
 
33
33
  var pathString = sprintf("M %f %f L %f %f M %f %f L %f %f",
34
34
  left, y1, right, y2, left, y3, right, y4);
35
- return printPath(renderer, {path:pathString, highlight: "stroke", stroke:renderer.foregroundColor, 'class': renderer.controller.classes.generate('dynamics decoration'), "data-name": "dynamics"});
35
+ return printPath(renderer, { path: pathString, highlight: "stroke", stroke: renderer.foregroundColor, 'class': renderer.controller.classes.generate('dynamics decoration'), "data-name": "dynamics" });
36
36
  };
37
37
 
38
38
  module.exports = drawCrescendo;
@@ -1,7 +1,7 @@
1
1
  function printDebugBox(renderer, attr, comment) {
2
2
  var box = renderer.paper.rectBeneath(attr);
3
3
  if (comment)
4
- renderer.paper.text(comment, {x: 0, y: attr.y+7, "text-anchor": "start", "font-size":"14px", fill: "rgba(0,0,255,.4)", stroke: "rgba(0,0,255,.4)" });
4
+ renderer.paper.text(comment, { x: 0, y: attr.y + 7, "text-anchor": "start", "font-size": "14px", fill: "rgba(0,0,255,.4)", stroke: "rgba(0,0,255,.4)" });
5
5
  return box;
6
6
  }
7
7
 
@@ -1,7 +1,7 @@
1
1
  var drawStaffGroup = require('./staff-group');
2
2
  var setPaperSize = require('./set-paper-size');
3
3
  var nonMusic = require('./non-music');
4
- var spacing = require('../abc_spacing');
4
+ var spacing = require('../helpers/spacing');
5
5
  var Selectables = require('./selectables');
6
6
 
7
7
  function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, selectTypes, tuneNumber, lineOffset) {
@@ -22,8 +22,8 @@ function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, se
22
22
  }
23
23
  if (staffgroups.length >= 1)
24
24
  addStaffPadding(renderer, renderer.spacing.staffSeparation, staffgroups[staffgroups.length - 1], abcLine.staffGroup);
25
- var staffgroup = engraveStaffLine(renderer, abcLine.staffGroup, selectables,line);
26
- staffgroup.line = lineOffset+line; // If there are non-music lines then the staffgroup array won't line up with the line array, so this keeps track.
25
+ var staffgroup = engraveStaffLine(renderer, abcLine.staffGroup, selectables, line);
26
+ staffgroup.line = lineOffset + line; // If there are non-music lines then the staffgroup array won't line up with the line array, so this keeps track.
27
27
  staffgroups.push(staffgroup);
28
28
  renderer.paper.closeGroup()
29
29
  } else if (abcLine.nonMusic) {
@@ -44,21 +44,21 @@ function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, se
44
44
  return { staffgroups: staffgroups, selectables: selectables.getElements() };
45
45
  }
46
46
 
47
- function engraveStaffLine(renderer, staffGroup, selectables,lineNumber) {
48
- drawStaffGroup(renderer, staffGroup, selectables,lineNumber);
47
+ function engraveStaffLine(renderer, staffGroup, selectables, lineNumber) {
48
+ drawStaffGroup(renderer, staffGroup, selectables, lineNumber);
49
49
  var height = staffGroup.height * spacing.STEP;
50
50
  renderer.y += height;
51
51
  return staffGroup;
52
52
  }
53
53
 
54
54
  function addStaffPadding(renderer, staffSeparation, lastStaffGroup, thisStaffGroup) {
55
- var lastStaff = lastStaffGroup.staffs[lastStaffGroup.staffs.length-1];
55
+ var lastStaff = lastStaffGroup.staffs[lastStaffGroup.staffs.length - 1];
56
56
  var lastBottomLine = -(lastStaff.bottom - 2); // The 2 is because the scale goes to 2 below the last line.
57
57
  var nextTopLine = thisStaffGroup.staffs[0].top - 10; // Because 10 represents the top line.
58
58
  var naturalSeparation = nextTopLine + lastBottomLine; // This is how far apart they'd be without extra spacing
59
59
  var separationInPixels = naturalSeparation * spacing.STEP;
60
60
  if (separationInPixels < staffSeparation)
61
- renderer.moveY(staffSeparation-separationInPixels);
61
+ renderer.moveY(staffSeparation - separationInPixels);
62
62
  }
63
63
 
64
64
  module.exports = draw;
@@ -9,11 +9,11 @@ function drawDynamics(renderer, params, selectables) {
9
9
  scalex: scalex,
10
10
  scaley: scaley,
11
11
  klass: renderer.controller.classes.generate('decoration dynamics'),
12
- fill:renderer.foregroundColor,
12
+ fill: renderer.foregroundColor,
13
13
  stroke: "none",
14
14
  name: "dynamics"
15
15
  });
16
- selectables.wrapSvgEl({el_type: "dynamicDecoration", startChar: -1, endChar: -1, decoration: params.dec}, el);
16
+ selectables.wrapSvgEl({ el_type: "dynamicDecoration", startChar: -1, endChar: -1, decoration: params.dec }, el);
17
17
  return [el];
18
18
  }
19
19
 
@@ -11,22 +11,22 @@ function drawEnding(renderer, params, linestartx, lineendx, selectables) {
11
11
  var pathString = '';
12
12
 
13
13
  if (params.anchor1) {
14
- linestartx = roundNumber(params.anchor1.x+params.anchor1.w);
14
+ linestartx = roundNumber(params.anchor1.x + params.anchor1.w);
15
15
  pathString += sprintf("M %f %f L %f %f ",
16
- linestartx, y, linestartx, roundNumber(y+height));
16
+ linestartx, y, linestartx, roundNumber(y + height));
17
17
  }
18
18
 
19
19
  if (params.anchor2) {
20
20
  lineendx = roundNumber(params.anchor2.x);
21
21
  pathString += sprintf("M %f %f L %f %f ",
22
- lineendx, y, lineendx, roundNumber(y+height));
22
+ lineendx, y, lineendx, roundNumber(y + height));
23
23
  }
24
24
 
25
25
  pathString += sprintf("M %f %f L %f %f ",
26
26
  linestartx, y, lineendx, y);
27
27
 
28
- renderer.paper.openGroup({klass: renderer.controller.classes.generate("ending"), "data-name": "ending"});
29
- printPath(renderer, {path: pathString, stroke: renderer.foregroundColor, fill: renderer.foregroundColor, "data-name": "line"});
28
+ renderer.paper.openGroup({ klass: renderer.controller.classes.generate("ending"), "data-name": "ending" });
29
+ printPath(renderer, { path: pathString, stroke: renderer.foregroundColor, fill: renderer.foregroundColor, "data-name": "line" });
30
30
  if (params.anchor1)
31
31
  renderText(renderer, {
32
32
  x: roundNumber(linestartx + 5),
@@ -39,7 +39,7 @@ function drawEnding(renderer, params, linestartx, lineendx, selectables) {
39
39
  name: params.text
40
40
  });
41
41
  var g = renderer.paper.closeGroup();
42
- selectables.wrapSvgEl({el_type: "ending", startChar: -1, endChar: -1}, g);
42
+ selectables.wrapSvgEl({ el_type: "ending", startChar: -1, endChar: -1 }, g);
43
43
  return [g];
44
44
  }
45
45
 
@@ -9,18 +9,18 @@ function drawGlissando(renderer, params, selectables) {
9
9
  var margin = 4;
10
10
  var leftY = renderer.calcY(params.anchor1.heads[0].pitch)
11
11
  var rightY = renderer.calcY(params.anchor2.heads[0].pitch)
12
- var leftX = params.anchor1.x + params.anchor1.w/2
13
- var rightX = params.anchor2.x + params.anchor2.w/2
12
+ var leftX = params.anchor1.x + params.anchor1.w / 2
13
+ var rightX = params.anchor2.x + params.anchor2.w / 2
14
14
  var len = lineLength(leftX, leftY, rightX, rightY)
15
- var marginLeft = params.anchor1.w/2 + margin
16
- var marginRight = params.anchor2.w/2 + margin
15
+ var marginLeft = params.anchor1.w / 2 + margin
16
+ var marginRight = params.anchor2.w / 2 + margin
17
17
  var s = slope(leftX, leftY, rightX, rightY)
18
18
  var leftYAdj = getY(leftY, s, marginLeft)
19
19
  var rightYAdj = getY(rightY, s, -marginRight)
20
- var num = numSquigglies(len-marginLeft-marginRight)
20
+ var num = numSquigglies(len - marginLeft - marginRight)
21
21
 
22
- var el = drawSquiggly(renderer, leftX+marginLeft, leftYAdj, num, s)
23
- selectables.wrapSvgEl({el_type: "glissando", startChar: -1, endChar: -1}, el);
22
+ var el = drawSquiggly(renderer, leftX + marginLeft, leftYAdj, num, s)
23
+ selectables.wrapSvgEl({ el_type: "glissando", startChar: -1, endChar: -1 }, el);
24
24
  return [el];
25
25
  }
26
26
 
@@ -28,20 +28,20 @@ function lineLength(leftX, leftY, rightX, rightY) {
28
28
  // The length from notehead center to notehead center.
29
29
  var w = rightX - leftX
30
30
  var h = rightY - leftY
31
- return Math.sqrt(w*w + h*h)
31
+ return Math.sqrt(w * w + h * h)
32
32
  }
33
33
 
34
34
  function slope(leftX, leftY, rightX, rightY) {
35
- return (rightY-leftY) / (rightX - leftX)
35
+ return (rightY - leftY) / (rightX - leftX)
36
36
  }
37
37
 
38
38
  function getY(y, slope, xOfs) {
39
- return roundNumber(y + (xOfs)*slope);
39
+ return roundNumber(y + (xOfs) * slope);
40
40
  }
41
41
 
42
42
  function numSquigglies(length) {
43
43
  var endLen = 5; // The width of the end - that is, the non repeating part
44
- return Math.max(2, Math.floor((length - endLen*2) / 6));
44
+ return Math.max(2, Math.floor((length - endLen * 2) / 6));
45
45
  }
46
46
 
47
47
  var leftStart = [[3.5, -4.8]]
@@ -58,18 +58,18 @@ function segment(arr, slope) {
58
58
  return ret
59
59
  }
60
60
 
61
- var drawSquiggly = function(renderer, x, y, num, slope) {
61
+ var drawSquiggly = function (renderer, x, y, num, slope) {
62
62
  var p = sprintf("M %f %f", x, y);
63
63
  p += segment(leftStart, slope)
64
64
  var i
65
65
  for (i = 0; i < num; i++) {
66
- p+=segment(top, slope)
66
+ p += segment(top, slope)
67
67
  }
68
68
  p += segment(right, slope)
69
- for ( i = 0; i < num; i++)
70
- p+=segment(bottom, slope)
71
- p+=segment(leftEnd, slope) + 'z'
72
- return printPath(renderer, {path:p, highlight: "stroke", stroke:renderer.foregroundColor, 'class': renderer.controller.classes.generate('decoration'), "data-name": "glissando"});
69
+ for (i = 0; i < num; i++)
70
+ p += segment(bottom, slope)
71
+ p += segment(leftEnd, slope) + 'z'
72
+ return printPath(renderer, { path: p, highlight: "stroke", stroke: renderer.foregroundColor, 'class': renderer.controller.classes.generate('decoration'), "data-name": "glissando" });
73
73
  }
74
74
 
75
75
  module.exports = drawGlissando;
@@ -4,63 +4,63 @@
4
4
 
5
5
  var roundNumber = require("./round-number");
6
6
 
7
- function Group() {
8
- this.ingroup = false;
9
- }
7
+ function Group() {
8
+ this.ingroup = false;
9
+ }
10
10
 
11
- Group.prototype.beginGroup = function (paper, controller) {
12
- this.paper = paper;
13
- this.controller = controller;
14
- this.path = [];
15
- this.lastM = [0, 0];
16
- this.ingroup = true;
17
- this.paper.openGroup();
18
- };
11
+ Group.prototype.beginGroup = function (paper, controller) {
12
+ this.paper = paper;
13
+ this.controller = controller;
14
+ this.path = [];
15
+ this.lastM = [0, 0];
16
+ this.ingroup = true;
17
+ this.paper.openGroup();
18
+ };
19
19
 
20
- Group.prototype.isInGroup = function() {
21
- return this.ingroup;
22
- }
20
+ Group.prototype.isInGroup = function () {
21
+ return this.ingroup;
22
+ }
23
23
 
24
- Group.prototype.addPath = function (path) {
25
- path = path || [];
26
- if (path.length === 0) return;
27
- path[0][0] = "m";
28
- path[0][1] = roundNumber(path[0][1] - this.lastM[0]);
29
- path[0][2] = roundNumber(path[0][2] - this.lastM[1]);
30
- this.lastM[0] += path[0][1];
31
- this.lastM[1] += path[0][2];
32
- this.path.push(path[0]);
33
- for (var i = 1, ii = path.length; i < ii; i++) {
34
- if (path[i][0] === "m") {
35
- this.lastM[0] += path[i][1];
36
- this.lastM[1] += path[i][2];
37
- }
38
- this.path.push(path[i]);
24
+ Group.prototype.addPath = function (path) {
25
+ path = path || [];
26
+ if (path.length === 0) return;
27
+ path[0][0] = "m";
28
+ path[0][1] = roundNumber(path[0][1] - this.lastM[0]);
29
+ path[0][2] = roundNumber(path[0][2] - this.lastM[1]);
30
+ this.lastM[0] += path[0][1];
31
+ this.lastM[1] += path[0][2];
32
+ this.path.push(path[0]);
33
+ for (var i = 1, ii = path.length; i < ii; i++) {
34
+ if (path[i][0] === "m") {
35
+ this.lastM[0] += path[i][1];
36
+ this.lastM[1] += path[i][2];
39
37
  }
40
- };
38
+ this.path.push(path[i]);
39
+ }
40
+ };
41
41
 
42
- /**
43
- * End a group of glyphs that will always be moved, scaled and highlighted together
44
- */
45
- Group.prototype.endGroup = function (klass, name) {
46
- this.ingroup = false;
47
- //if (this.path.length === 0) return null;
48
- var path = "";
49
- for (var i = 0; i < this.path.length; i++)
50
- path += this.path[i].join(" ");
51
- this.path = [];
42
+ /**
43
+ * End a group of glyphs that will always be moved, scaled and highlighted together
44
+ */
45
+ Group.prototype.endGroup = function (klass, name) {
46
+ this.ingroup = false;
47
+ //if (this.path.length === 0) return null;
48
+ var path = "";
49
+ for (var i = 0; i < this.path.length; i++)
50
+ path += this.path[i].join(" ");
51
+ this.path = [];
52
52
 
53
- var ret = this.paper.closeGroup();
54
- if (ret) {
55
- ret.setAttribute("class", this.controller.classes.generate(klass))
56
- ret.setAttribute("fill", this.controller.renderer.foregroundColor)
57
- ret.setAttribute("stroke", "none")
58
- ret.setAttribute("data-name", name)
59
- }
60
- return ret;
61
- };
53
+ var ret = this.paper.closeGroup();
54
+ if (ret) {
55
+ ret.setAttribute("class", this.controller.classes.generate(klass))
56
+ ret.setAttribute("fill", this.controller.renderer.foregroundColor)
57
+ ret.setAttribute("stroke", "none")
58
+ ret.setAttribute("data-name", name)
59
+ }
60
+ return ret;
61
+ };
62
62
 
63
- // There is just a singleton of this object.
64
- var elementGroup = new Group();
63
+ // There is just a singleton of this object.
64
+ var elementGroup = new Group();
65
65
 
66
66
  module.exports = elementGroup;
@@ -7,19 +7,19 @@ function printHorizontalLine(renderer, width, vertical, comment) {
7
7
  var y = renderer.y;
8
8
  if (vertical) y = vertical;
9
9
  y = Math.round(y);
10
- renderer.paper.text(""+Math.round(y), {x: 10, y: y, "text-anchor": "start", "font-size":"18px", fill: fill, stroke: fill });
10
+ renderer.paper.text("" + Math.round(y), { x: 10, y: y, "text-anchor": "start", "font-size": "18px", fill: fill, stroke: fill });
11
11
  var x1 = 50;
12
12
  var x2 = width;
13
- var pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y-dy, x1+x2, y-dy,
14
- x2, y+dy, x1, y+dy);
15
- renderer.paper.pathToBack({path:pathString, stroke:"none", fill:fill, 'class': renderer.controller.classes.generate('staff')});
16
- for (var i = 1; i < width/100; i++) {
17
- pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", i*100-dy, y-5, i*100-dy, y+5,
18
- i*100+dy, y-5, i*100+dy, y+5);
19
- renderer.paper.pathToBack({path:pathString, stroke:"none", fill:fill, 'class': renderer.controller.classes.generate('staff')});
13
+ var pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y - dy, x1 + x2, y - dy,
14
+ x2, y + dy, x1, y + dy);
15
+ renderer.paper.pathToBack({ path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff') });
16
+ for (var i = 1; i < width / 100; i++) {
17
+ pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", i * 100 - dy, y - 5, i * 100 - dy, y + 5,
18
+ i * 100 + dy, y - 5, i * 100 + dy, y + 5);
19
+ renderer.paper.pathToBack({ path: pathString, stroke: "none", fill: fill, 'class': renderer.controller.classes.generate('staff') });
20
20
  }
21
21
  if (comment)
22
- renderer.paper.text(comment, {x: width+70, y: y, "text-anchor": "start", "font-size":"18px", fill: fill, stroke: fill });
22
+ renderer.paper.text(comment, { x: width + 70, y: y, "text-anchor": "start", "font-size": "18px", fill: fill, stroke: fill });
23
23
  }
24
24
 
25
25
  module.exports = printHorizontalLine;
@@ -31,7 +31,7 @@ function nonMusic(renderer, obj, selectables) {
31
31
  } else if (row.separator) {
32
32
  drawSeparator(renderer, row.separator)
33
33
  } else if (row.startGroup) {
34
- renderer.paper.openGroup({klass: row.klass, "data-name": row.name});
34
+ renderer.paper.openGroup({ klass: row.klass, "data-name": row.name });
35
35
  } else if (row.endGroup) {
36
36
  // TODO-PER: also create a history element with the title "row.endGroup"
37
37
  var g = renderer.paper.closeGroup();
@@ -1,23 +1,22 @@
1
1
  var sprintf = require('./sprintf');
2
2
  var roundNumber = require("./round-number");
3
3
 
4
- function printLine(renderer, x1, x2, y , klass, name ,dy ) {
5
- if (!dy ) dy = 0.35;
6
- var fill = renderer.foregroundColor;
7
- x1 = roundNumber(x1);
8
- x2 = roundNumber(x2);
9
- var y1 = roundNumber(y - dy);
10
- var y2 = roundNumber(y + dy);
11
- var pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y1, x2, y1,
12
- x2, y2, x1, y2);
13
- var options = { path: pathString, stroke: "none", fill: fill };
14
- if (name)
15
- options['data-name'] = name;
16
- if (klass)
17
- options['class'] = klass;
18
- var ret = renderer.paper.pathToBack(options);
4
+ function printLine(renderer, x1, x2, y, klass, name, dy) {
5
+ var fill = renderer.foregroundColor;
6
+ x1 = roundNumber(x1);
7
+ x2 = roundNumber(x2);
8
+ var y1 = roundNumber(y - dy);
9
+ var y2 = roundNumber(y + dy);
10
+ var pathString = sprintf("M %f %f L %f %f L %f %f L %f %f z", x1, y1, x2, y1,
11
+ x2, y2, x1, y2);
12
+ var options = { path: pathString, stroke: "none", fill: fill };
13
+ if (name)
14
+ options['data-name'] = name;
15
+ if (klass)
16
+ options['class'] = klass;
17
+ var ret = renderer.paper.pathToBack(options);
19
18
 
20
- return ret;
19
+ return ret;
21
20
  }
22
21
 
23
22
  module.exports = printLine;
@@ -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,9 @@ 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
+ var pathArray = [["M", x, y1], ["L", x, y2], ["L", x2, y2], ["L", x2, y1], ["z"]];
16
+ var attr = { path: "" };
17
17
  for (var i = 0; i < pathArray.length; i++)
18
18
  attr.path += pathArray[i].join(" ");
19
19
  if (klass)
@@ -21,7 +21,7 @@ function printStem(renderer, x, dx, y1, y2, klass, name) {
21
21
  if (name)
22
22
  attr['data-name'] = name;
23
23
  if (!elementGroup.isInGroup()) {
24
- attr.stroke ="none";
24
+ attr.stroke = "none";
25
25
  attr.fill = renderer.foregroundColor;
26
26
  }
27
27
  return renderer.paper.pathToBack(attr);