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.
- package/RELEASE.md +66 -0
- package/dist/abcjs-basic-min.js +2 -2
- package/dist/abcjs-basic.js +4373 -4424
- package/dist/abcjs-basic.js.map +1 -1
- package/dist/abcjs-plugin-min.js +2 -2
- package/index.js +1 -1
- package/package.json +6 -6
- package/plugin.js +1 -1
- package/src/api/abc_timing_callbacks.js +7 -3
- package/src/api/abc_tunebook_svg.js +1 -2
- package/src/data/abc_tune.js +2 -2
- package/src/midi/abc_midi_create.js +8 -2
- package/src/parse/abc_common.js +0 -47
- package/src/parse/abc_parse.js +16 -16
- package/src/parse/abc_parse_book.js +3 -3
- package/src/parse/abc_parse_directive.js +26 -7
- package/src/parse/abc_parse_header.js +11 -9
- package/src/parse/abc_parse_key_voice.js +17 -17
- package/src/parse/abc_parse_music.js +89 -106
- package/src/parse/abc_tokenizer.js +60 -60
- package/src/parse/abc_transpose.js +14 -3
- package/src/parse/tune-builder.js +19 -14
- package/src/synth/abc_midi_flattener.js +25 -9
- package/src/synth/abc_midi_sequencer.js +1 -1
- package/src/synth/create-synth.js +41 -0
- package/src/synth/note-to-midi.js +50 -0
- package/src/tablatures/instruments/guitar/tab-guitar.js +0 -2
- package/src/tablatures/instruments/string-patterns.js +46 -28
- package/src/tablatures/instruments/tab-note.js +26 -103
- package/src/tablatures/instruments/violin/tab-violin.js +0 -2
- package/src/tablatures/tab-absolute-elements.js +9 -31
- package/src/tablatures/tab-renderer.js +2 -2
- package/src/test/abc_parser_lint.js +8 -5
- package/src/write/README.md +31 -0
- package/src/write/creation/abstract-engraver.js +1036 -0
- package/src/write/creation/add-chord.js +102 -0
- package/src/write/{add-text-if.js → creation/add-text-if.js} +6 -6
- package/src/write/{calcHeight.js → creation/calc-height.js} +2 -2
- package/src/write/creation/create-clef.js +72 -0
- package/src/write/creation/create-key-signature.js +31 -0
- package/src/write/creation/create-note-head.js +107 -0
- package/src/write/creation/create-time-signature.js +55 -0
- package/src/write/creation/decoration.js +357 -0
- package/src/write/{abc_absolute_element.js → creation/elements/absolute-element.js} +14 -15
- package/src/write/creation/elements/beam-element.js +113 -0
- package/src/write/{bottom-text.js → creation/elements/bottom-text.js} +14 -15
- package/src/write/{abc_brace_element.js → creation/elements/brace-element.js} +5 -5
- package/src/write/creation/elements/free-text.js +41 -0
- package/src/write/{abc_relative_element.js → creation/elements/relative-element.js} +8 -7
- package/src/write/{separator.js → creation/elements/separator.js} +2 -2
- package/src/write/{abc_staff_group_element.js → creation/elements/staff-group-element.js} +4 -4
- package/src/write/{subtitle.js → creation/elements/subtitle.js} +3 -3
- package/src/write/creation/elements/tempo-element.js +63 -0
- package/src/write/{abc_tie_element.js → creation/elements/tie-element.js} +15 -11
- package/src/write/{top-text.js → creation/elements/top-text.js} +12 -12
- package/src/write/creation/elements/triplet-element.js +28 -0
- package/src/write/{abc_voice_element.js → creation/elements/voice-element.js} +3 -3
- package/src/write/creation/glyphs.js +226 -0
- package/src/write/creation/translate-chord.js +37 -0
- package/src/write/draw/absolute.js +5 -5
- package/src/write/draw/beam.js +8 -8
- package/src/write/draw/brace.js +33 -33
- package/src/write/draw/crescendo.js +4 -4
- package/src/write/draw/debug-box.js +1 -1
- package/src/write/draw/draw.js +7 -7
- package/src/write/draw/dynamics.js +2 -2
- package/src/write/draw/ending.js +6 -6
- package/src/write/draw/glissando.js +17 -17
- package/src/write/draw/group-elements.js +51 -51
- package/src/write/draw/horizontal-line.js +9 -9
- package/src/write/draw/non-music.js +1 -1
- package/src/write/draw/print-line.js +15 -16
- package/src/write/draw/print-stem.js +5 -5
- package/src/write/draw/print-symbol.js +12 -12
- package/src/write/draw/print-vertical-line.js +8 -8
- package/src/write/draw/relative.js +17 -16
- package/src/write/draw/selectables.js +5 -5
- package/src/write/draw/separator.js +4 -4
- package/src/write/draw/set-paper-size.js +2 -2
- package/src/write/draw/sprintf.js +31 -31
- package/src/write/draw/staff-group.js +36 -30
- package/src/write/draw/staff-line.js +2 -2
- package/src/write/draw/staff.js +4 -4
- package/src/write/draw/tab-line.js +26 -26
- package/src/write/draw/tempo.js +30 -30
- package/src/write/draw/text.js +5 -5
- package/src/write/draw/tie.js +18 -18
- package/src/write/draw/triplet.js +6 -6
- package/src/write/draw/voice.js +16 -17
- package/src/write/{abc_engraver_controller.js → engraver-controller.js} +58 -51
- package/src/write/{classes.js → helpers/classes.js} +6 -6
- package/src/write/{get-font-and-attr.js → helpers/get-font-and-attr.js} +9 -7
- package/src/write/{get-text-size.js → helpers/get-text-size.js} +5 -5
- package/src/write/{set-class.js → helpers/set-class.js} +1 -1
- package/src/write/{abc_spacing.js → helpers/spacing.js} +1 -1
- package/src/write/{highlight.js → interactive/highlight.js} +1 -1
- package/src/write/{selection.js → interactive/selection.js} +27 -27
- package/src/write/{unhighlight.js → interactive/unhighlight.js} +1 -1
- package/src/write/layout/beam.js +13 -13
- package/src/write/layout/get-left-edge-of-staff.js +4 -4
- package/src/write/layout/layout.js +74 -74
- package/src/write/layout/{setUpperAndLowerElements.js → set-upper-and-lower-elements.js} +8 -8
- package/src/write/layout/{staffGroup.js → staff-group.js} +32 -32
- package/src/write/layout/triplet.js +4 -4
- package/src/write/layout/{VoiceElements.js → voice-elements.js} +23 -23
- package/src/write/layout/voice.js +6 -6
- package/src/write/{abc_renderer.js → renderer.js} +35 -32
- package/src/write/svg.js +35 -35
- package/test.js +1 -1
- package/types/index.d.ts +99 -22
- package/version.js +1 -1
- package/src/tablatures/instruments/guitar/guitar-fonts.js +0 -19
- package/src/tablatures/instruments/violin/violin-fonts.js +0 -19
- package/src/tablatures/transposer.js +0 -110
- package/src/write/abc_abstract_engraver.js +0 -1026
- package/src/write/abc_beam_element.js +0 -113
- package/src/write/abc_create_clef.js +0 -72
- package/src/write/abc_create_key_signature.js +0 -33
- package/src/write/abc_create_note_head.js +0 -107
- package/src/write/abc_create_time_signature.js +0 -55
- package/src/write/abc_decoration.js +0 -341
- package/src/write/abc_glyphs.js +0 -224
- package/src/write/abc_tempo_element.js +0 -63
- package/src/write/abc_triplet_element.js +0 -28
- package/src/write/add-chord.js +0 -103
- package/src/write/format-jazz-chord.js +0 -15
- package/src/write/free-text.js +0 -41
- /package/src/write/{abc_crescendo_element.js → creation/elements/crescendo-element.js} +0 -0
- /package/src/write/{abc_dynamic_decoration.js → creation/elements/dynamic-decoration.js} +0 -0
- /package/src/write/{abc_ending_element.js → creation/elements/ending-element.js} +0 -0
- /package/src/write/{abc_glissando_element.js → creation/elements/glissando-element.js} +0 -0
- /package/src/write/layout/{getBarYAt.js → get-bar-y-at.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var getBarYAt = require('./
|
|
1
|
+
var getBarYAt = require('./get-bar-y-at');
|
|
2
2
|
|
|
3
3
|
function layoutTriplet(element) {
|
|
4
4
|
// TODO end and beginning of line (PER: P.S. I'm not sure this can happen: I think the parser will always specify both the start and end points.)
|
|
@@ -7,13 +7,13 @@ function layoutTriplet(element) {
|
|
|
7
7
|
var beam = element.anchor1.parent.beam;
|
|
8
8
|
// if hasBeam is true, then the first and last element in the triplet have the same beam.
|
|
9
9
|
// We also need to check if the beam doesn't contain other notes so that `(3 dcdcc` will do a bracket.
|
|
10
|
-
if (element.hasBeam && (beam.elems[0] !== element.anchor1.parent || beam.elems[beam.elems.length-1] !== element.anchor2.parent))
|
|
10
|
+
if (element.hasBeam && (beam.elems[0] !== element.anchor1.parent || beam.elems[beam.elems.length - 1] !== element.anchor2.parent))
|
|
11
11
|
element.hasBeam = false;
|
|
12
12
|
|
|
13
13
|
if (element.hasBeam) {
|
|
14
14
|
// If there is a beam then we don't need to draw anything except the text. The beam could either be above or below.
|
|
15
15
|
var left = isAbove(beam) ? element.anchor1.x + element.anchor1.w : element.anchor1.x;
|
|
16
|
-
element.yTextPos = heightAtMidpoint(left,
|
|
16
|
+
element.yTextPos = heightAtMidpoint(left, element.anchor2.x, beam);
|
|
17
17
|
element.yTextPos += isAbove(beam) ? 3 : -2; // This creates some space between the beam and the number.
|
|
18
18
|
element.xTextPos = xAtMidpoint(left, element.anchor2.x);
|
|
19
19
|
element.top = element.yTextPos + 1;
|
|
@@ -69,7 +69,7 @@ function heightAtMidpoint(startX, endX, beam) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function xAtMidpoint(startX, endX) {
|
|
72
|
-
return startX + (endX - startX)/2;
|
|
72
|
+
return startX + (endX - startX) / 2;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
module.exports = layoutTriplet;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var VoiceElement = function VoiceElements() {}
|
|
1
|
+
var VoiceElement = function VoiceElements() { }
|
|
2
2
|
|
|
3
3
|
VoiceElement.beginLayout = function (startx, voice) {
|
|
4
|
-
voice.i=0;
|
|
5
|
-
voice.durationindex=0;
|
|
4
|
+
voice.i = 0;
|
|
5
|
+
voice.durationindex = 0;
|
|
6
6
|
//this.ii=this.children.length;
|
|
7
|
-
voice.startx=startx;
|
|
8
|
-
voice.minx=startx; // furthest left to where negatively positioned elements are allowed to go
|
|
9
|
-
voice.nextx=startx; // x position where the next element of this voice should be placed assuming no other voices and no fixed width constraints
|
|
10
|
-
voice.spacingduration=0; // duration left to be laid out in current iteration (omitting additional spacing due to other aspects, such as bars, dots, sharps and flats)
|
|
7
|
+
voice.startx = startx;
|
|
8
|
+
voice.minx = startx; // furthest left to where negatively positioned elements are allowed to go
|
|
9
|
+
voice.nextx = startx; // x position where the next element of this voice should be placed assuming no other voices and no fixed width constraints
|
|
10
|
+
voice.spacingduration = 0; // duration left to be laid out in current iteration (omitting additional spacing due to other aspects, such as bars, dots, sharps and flats)
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
VoiceElement.layoutEnded = function (voice) {
|
|
14
|
-
return (voice.i>=voice.children.length);
|
|
14
|
+
return (voice.i >= voice.children.length);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
VoiceElement.getNextX = function (voice) {
|
|
@@ -20,7 +20,7 @@ VoiceElement.getNextX = function (voice) {
|
|
|
20
20
|
|
|
21
21
|
// number of spacing units expected for next positioning
|
|
22
22
|
VoiceElement.getSpacingUnits = function (voice) {
|
|
23
|
-
return Math.sqrt(voice.spacingduration*8);
|
|
23
|
+
return Math.sqrt(voice.spacingduration * 8);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// Try to layout the element at index this.i
|
|
@@ -38,12 +38,12 @@ VoiceElement.layoutOneItem = function (x, spacing, voice, minPadding, firstVoice
|
|
|
38
38
|
// It overlaps if the either the child's top or bottom is inside the firstChild's or at least within 1
|
|
39
39
|
// A special case is if the element is on the same line then it can share a note head, if the notehead is the same
|
|
40
40
|
var overlaps = firstChild &&
|
|
41
|
-
((child.abcelem.maxpitch <= firstChild.abcelem.maxpitch+1 && child.abcelem.maxpitch >= firstChild.abcelem.minpitch-1) ||
|
|
42
|
-
|
|
41
|
+
((child.abcelem.maxpitch <= firstChild.abcelem.maxpitch + 1 && child.abcelem.maxpitch >= firstChild.abcelem.minpitch - 1) ||
|
|
42
|
+
(child.abcelem.minpitch <= firstChild.abcelem.maxpitch + 1 && child.abcelem.minpitch >= firstChild.abcelem.minpitch - 1))
|
|
43
43
|
// See if they can share a note head
|
|
44
44
|
if (overlaps && child.abcelem.minpitch === firstChild.abcelem.minpitch && child.abcelem.maxpitch === firstChild.abcelem.maxpitch &&
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
firstChild.heads && firstChild.heads.length > 0 && child.heads && child.heads.length > 0 &&
|
|
46
|
+
firstChild.heads[0].c === child.heads[0].c)
|
|
47
47
|
overlaps = false;
|
|
48
48
|
// If this note overlaps the note in the first voice and we haven't moved the note yet (this can be called multiple times)
|
|
49
49
|
if (overlaps) {
|
|
@@ -65,17 +65,17 @@ VoiceElement.layoutOneItem = function (x, spacing, voice, minPadding, firstVoice
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
var extraWidth = getExtraWidth(child, pad);
|
|
68
|
-
if (er<extraWidth) { // shift right by needed amount
|
|
68
|
+
if (er < extraWidth) { // shift right by needed amount
|
|
69
69
|
// There's an exception if a bar element is after a Part element, there is no shift.
|
|
70
|
-
if (voice.i === 0 || child.type !== 'bar' || (voice.children[voice.i-1].type !== 'part' && voice.children[voice.i-1].type !== 'tempo')
|
|
71
|
-
x+=extraWidth-er;
|
|
70
|
+
if (voice.i === 0 || child.type !== 'bar' || (voice.children[voice.i - 1].type !== 'part' && voice.children[voice.i - 1].type !== 'tempo'))
|
|
71
|
+
x += extraWidth - er;
|
|
72
72
|
}
|
|
73
73
|
child.setX(x);
|
|
74
74
|
|
|
75
75
|
voice.spacingduration = child.duration;
|
|
76
76
|
//update minx
|
|
77
|
-
voice.minx = x+getMinWidth(child); // add necessary layout space
|
|
78
|
-
if (voice.i!==voice.children.length-1) voice.minx+=child.minspacing; // add minimumspacing except on last elem
|
|
77
|
+
voice.minx = x + getMinWidth(child); // add necessary layout space
|
|
78
|
+
if (voice.i !== voice.children.length - 1) voice.minx += child.minspacing; // add minimumspacing except on last elem
|
|
79
79
|
|
|
80
80
|
this.updateNextX(x, spacing, voice);
|
|
81
81
|
|
|
@@ -89,20 +89,20 @@ VoiceElement.layoutOneItem = function (x, spacing, voice, minPadding, firstVoice
|
|
|
89
89
|
VoiceElement.shiftRight = function (dx, voice) {
|
|
90
90
|
var child = voice.children[voice.i];
|
|
91
91
|
if (!child) return;
|
|
92
|
-
child.setX(child.x+dx);
|
|
93
|
-
voice.minx+=dx;
|
|
94
|
-
voice.nextx+=dx;
|
|
92
|
+
child.setX(child.x + dx);
|
|
93
|
+
voice.minx += dx;
|
|
94
|
+
voice.nextx += dx;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
// call when spacingduration has been updated
|
|
98
98
|
VoiceElement.updateNextX = function (x, spacing, voice) {
|
|
99
|
-
voice.nextx= x + (spacing*Math.sqrt(voice.spacingduration*8));
|
|
99
|
+
voice.nextx = x + (spacing * Math.sqrt(voice.spacingduration * 8));
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
VoiceElement.updateIndices = function (voice) {
|
|
103
103
|
if (!this.layoutEnded(voice)) {
|
|
104
104
|
voice.durationindex += voice.children[voice.i].duration;
|
|
105
|
-
if (voice.children[voice.i].type === 'bar') voice.durationindex = Math.round(voice.durationindex*64)/64; // everytime we meet a barline, do rounding to nearest 64th
|
|
105
|
+
if (voice.children[voice.i].type === 'bar') voice.durationindex = Math.round(voice.durationindex * 64) / 64; // everytime we meet a barline, do rounding to nearest 64th
|
|
106
106
|
voice.i++;
|
|
107
107
|
}
|
|
108
108
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var layoutBeam = require('./beam');
|
|
2
|
-
var getBarYAt = require('./
|
|
2
|
+
var getBarYAt = require('./get-bar-y-at');
|
|
3
3
|
var layoutTriplet = require('./triplet');
|
|
4
4
|
|
|
5
|
-
var layoutVoice = function(voice) {
|
|
5
|
+
var layoutVoice = function (voice) {
|
|
6
6
|
for (var i = 0; i < voice.beams.length; i++) {
|
|
7
7
|
if (voice.beams[i].type === 'BeamElem') {
|
|
8
8
|
layoutBeam(voice.beams[i]);
|
|
@@ -66,7 +66,7 @@ function placeInLane(rightMost, relElem) {
|
|
|
66
66
|
}
|
|
67
67
|
// If we didn't return early, then we need a new row
|
|
68
68
|
rightMost.push(xCoords.right);
|
|
69
|
-
relElem.putChordInLane(rightMost.length-1);
|
|
69
|
+
relElem.putChordInLane(rightMost.length - 1);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -90,7 +90,7 @@ function setLaneForChord(absElems) {
|
|
|
90
90
|
placeInLane(rightMostAbove, relElem);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
for (j = absElems[i].children.length-1; j >=0; j--) {
|
|
93
|
+
for (j = absElems[i].children.length - 1; j >= 0; j--) {
|
|
94
94
|
relElem = absElems[i].children[j];
|
|
95
95
|
if (relElem.chordHeightBelow) {
|
|
96
96
|
placeInLane(rightMostBelow, relElem);
|
|
@@ -121,8 +121,8 @@ function setLane(absElems, numLanesAbove, numLanesBelow) {
|
|
|
121
121
|
var relElem = absElems[i].children[j];
|
|
122
122
|
if (relElem.chordHeightAbove) {
|
|
123
123
|
relElem.invertLane(numLanesAbove);
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
// } else if (relElem.chordHeightBelow) {
|
|
125
|
+
// relElem.invertLane(below);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -2,33 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
/*global Math */
|
|
4
4
|
|
|
5
|
-
var spacing = require('./
|
|
5
|
+
var spacing = require('./helpers/spacing');
|
|
6
6
|
var Svg = require('./svg');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Implements the API for rendering ABCJS Abstract Rendering Structure to a canvas/paper (e.g. SVG, Raphael, etc)
|
|
10
10
|
* @param {Object} paper
|
|
11
11
|
*/
|
|
12
|
-
var Renderer = function(paper) {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var Renderer = function (paper) {
|
|
13
|
+
this.paper = new Svg(paper);
|
|
14
|
+
this.controller = null;
|
|
15
15
|
|
|
16
|
-
this.space = 3*spacing.SPACE;
|
|
17
|
-
|
|
16
|
+
this.space = 3 * spacing.SPACE;
|
|
17
|
+
this.padding = {}; // renderer's padding is managed by the controller
|
|
18
18
|
this.reset();
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
Renderer.prototype.reset = function() {
|
|
21
|
+
Renderer.prototype.reset = function () {
|
|
22
22
|
|
|
23
23
|
this.paper.clear();
|
|
24
24
|
this.y = 0;
|
|
25
25
|
this.abctune = null;
|
|
26
26
|
this.path = null;
|
|
27
27
|
this.isPrint = false;
|
|
28
|
+
this.lineThickness = 0;
|
|
28
29
|
this.initVerticalSpace();
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
Renderer.prototype.newTune = function(abcTune) {
|
|
32
|
+
Renderer.prototype.newTune = function (abcTune) {
|
|
32
33
|
this.abctune = abcTune; // TODO-PER: this is just to get the font info.
|
|
33
34
|
this.setVerticalSpace(abcTune.formatting);
|
|
34
35
|
//this.measureNumber = null;
|
|
@@ -37,12 +38,18 @@ Renderer.prototype.newTune = function(abcTune) {
|
|
|
37
38
|
this.setPadding(abcTune);
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
Renderer.prototype.
|
|
41
|
-
this.
|
|
42
|
-
right: params.paddingright, left: params.paddingleft };
|
|
41
|
+
Renderer.prototype.setLineThickness = function (lineThickness) {
|
|
42
|
+
this.lineThickness = lineThickness
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
Renderer.prototype.
|
|
45
|
+
Renderer.prototype.setPaddingOverride = function (params) {
|
|
46
|
+
this.paddingOverride = {
|
|
47
|
+
top: params.paddingtop, bottom: params.paddingbottom,
|
|
48
|
+
right: params.paddingright, left: params.paddingleft
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
Renderer.prototype.setPadding = function (abctune) {
|
|
46
53
|
// If the padding is set in the tune, then use that.
|
|
47
54
|
// Otherwise, if the padding is set in the override, use that.
|
|
48
55
|
// Otherwise, use the defaults (there are a different set of defaults for screen and print.)
|
|
@@ -80,7 +87,7 @@ Renderer.prototype.adjustNonScaledItems = function (scale) {
|
|
|
80
87
|
/**
|
|
81
88
|
* Set the the values for all the configurable vertical space options.
|
|
82
89
|
*/
|
|
83
|
-
Renderer.prototype.initVerticalSpace = function() {
|
|
90
|
+
Renderer.prototype.initVerticalSpace = function () {
|
|
84
91
|
// conversion: 37.7953 = conversion factor for cm to px.
|
|
85
92
|
// All of the following values are in px.
|
|
86
93
|
this.spacing = {
|
|
@@ -95,7 +102,7 @@ Renderer.prototype.initVerticalSpace = function() {
|
|
|
95
102
|
parts: 11.33, // Set the vertical space above a new part.
|
|
96
103
|
slurHeight: 1.0, // Set the slur height factor.
|
|
97
104
|
staffSeparation: 61.33, // Do not put a staff system closer than <unit> from the previous system.
|
|
98
|
-
stemHeight: 26.67+10, // Set the stem height.
|
|
105
|
+
stemHeight: 26.67 + 10, // Set the stem height.
|
|
99
106
|
subtitle: 3.78, // Set the vertical space above the subtitle.
|
|
100
107
|
systemStaffSeparation: 48, // Do not place the staves closer than <unit> inside a system. * This values applies to all staves when in the tune header. Otherwise, it applies to the next staff
|
|
101
108
|
text: 18.9, // Set the vertical space above the history.
|
|
@@ -133,43 +140,39 @@ the <float> fraction of the page width.
|
|
|
133
140
|
*/
|
|
134
141
|
};
|
|
135
142
|
|
|
136
|
-
Renderer.prototype.setVerticalSpace = function(formatting) {
|
|
143
|
+
Renderer.prototype.setVerticalSpace = function (formatting) {
|
|
137
144
|
// conversion from pts to px 4/3
|
|
138
145
|
if (formatting.staffsep !== undefined)
|
|
139
|
-
this.spacing.staffSeparation = formatting.staffsep *4/3;
|
|
146
|
+
this.spacing.staffSeparation = formatting.staffsep * 4 / 3;
|
|
140
147
|
if (formatting.composerspace !== undefined)
|
|
141
|
-
this.spacing.composer = formatting.composerspace *4/3;
|
|
148
|
+
this.spacing.composer = formatting.composerspace * 4 / 3;
|
|
142
149
|
if (formatting.partsspace !== undefined)
|
|
143
|
-
this.spacing.parts = formatting.partsspace *4/3;
|
|
150
|
+
this.spacing.parts = formatting.partsspace * 4 / 3;
|
|
144
151
|
if (formatting.textspace !== undefined)
|
|
145
|
-
this.spacing.text = formatting.textspace *4/3;
|
|
152
|
+
this.spacing.text = formatting.textspace * 4 / 3;
|
|
146
153
|
if (formatting.musicspace !== undefined)
|
|
147
|
-
this.spacing.music = formatting.musicspace *4/3;
|
|
154
|
+
this.spacing.music = formatting.musicspace * 4 / 3;
|
|
148
155
|
if (formatting.titlespace !== undefined)
|
|
149
|
-
this.spacing.title = formatting.titlespace *4/3;
|
|
156
|
+
this.spacing.title = formatting.titlespace * 4 / 3;
|
|
150
157
|
if (formatting.sysstaffsep !== undefined)
|
|
151
|
-
this.spacing.systemStaffSeparation = formatting.sysstaffsep *4/3;
|
|
158
|
+
this.spacing.systemStaffSeparation = formatting.sysstaffsep * 4 / 3;
|
|
152
159
|
if (formatting.subtitlespace !== undefined)
|
|
153
|
-
this.spacing.subtitle = formatting.subtitlespace *4/3;
|
|
160
|
+
this.spacing.subtitle = formatting.subtitlespace * 4 / 3;
|
|
154
161
|
if (formatting.topspace !== undefined)
|
|
155
|
-
this.spacing.top = formatting.topspace *4/3;
|
|
162
|
+
this.spacing.top = formatting.topspace * 4 / 3;
|
|
156
163
|
if (formatting.vocalspace !== undefined)
|
|
157
|
-
this.spacing.vocal = formatting.vocalspace *4/3;
|
|
164
|
+
this.spacing.vocal = formatting.vocalspace * 4 / 3;
|
|
158
165
|
if (formatting.wordsspace !== undefined)
|
|
159
|
-
this.spacing.words = formatting.wordsspace *4/3;
|
|
166
|
+
this.spacing.words = formatting.wordsspace * 4 / 3;
|
|
160
167
|
};
|
|
161
168
|
|
|
162
169
|
|
|
163
|
-
/**
|
|
164
|
-
* Leave space before printing a staff system
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
170
|
/**
|
|
168
171
|
* Calculates the y for a given pitch value (relative to the stave the renderer is currently printing)
|
|
169
172
|
* @param {number} ofs pitch value (bottom C on a G clef = 0, D=1, etc.)
|
|
170
173
|
*/
|
|
171
|
-
Renderer.prototype.calcY = function(ofs) {
|
|
172
|
-
|
|
174
|
+
Renderer.prototype.calcY = function (ofs) {
|
|
175
|
+
return this.y - ofs * spacing.STEP;
|
|
173
176
|
};
|
|
174
177
|
|
|
175
178
|
Renderer.prototype.moveY = function (em, numLines) {
|
package/src/write/svg.js
CHANGED
|
@@ -10,7 +10,7 @@ function Svg(wrapper) {
|
|
|
10
10
|
wrapper.appendChild(this.svg);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
Svg.prototype.clear = function() {
|
|
13
|
+
Svg.prototype.clear = function () {
|
|
14
14
|
if (this.svg) {
|
|
15
15
|
var wrapper = this.svg.parentNode;
|
|
16
16
|
this.svg = createSvg();
|
|
@@ -23,14 +23,14 @@ Svg.prototype.clear = function() {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
Svg.prototype.setTitle = function(title) {
|
|
26
|
+
Svg.prototype.setTitle = function (title) {
|
|
27
27
|
var titleEl = document.createElement("title");
|
|
28
28
|
var titleNode = document.createTextNode(title);
|
|
29
29
|
titleEl.appendChild(titleNode);
|
|
30
30
|
this.svg.insertBefore(titleEl, this.svg.firstChild);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
Svg.prototype.setResponsiveWidth = function(w, h) {
|
|
33
|
+
Svg.prototype.setResponsiveWidth = function (w, h) {
|
|
34
34
|
// this technique is from: http://thenewcode.com/744/Make-SVG-Responsive, thx to https://github.com/iantresman
|
|
35
35
|
this.svg.setAttribute("viewBox", "0 0 " + w + " " + h);
|
|
36
36
|
this.svg.setAttribute("preserveAspectRatio", "xMinYMin meet");
|
|
@@ -59,20 +59,20 @@ Svg.prototype.setResponsiveWidth = function(w, h) {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
Svg.prototype.setSize = function(w, h) {
|
|
62
|
+
Svg.prototype.setSize = function (w, h) {
|
|
63
63
|
this.svg.setAttribute('width', w);
|
|
64
64
|
this.svg.setAttribute('height', h);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
Svg.prototype.setAttribute = function(attr, value) {
|
|
67
|
+
Svg.prototype.setAttribute = function (attr, value) {
|
|
68
68
|
this.svg.setAttribute(attr, value);
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
Svg.prototype.setScale = function(scale) {
|
|
71
|
+
Svg.prototype.setScale = function (scale) {
|
|
72
72
|
if (scale !== 1) {
|
|
73
|
-
this.svg.style.transform = "scale("+scale+","+scale+")";
|
|
74
|
-
this.svg.style['-ms-transform'] = "scale("+scale+","+scale+")";
|
|
75
|
-
this.svg.style['-webkit-transform'] = "scale("+scale+","+scale+")";
|
|
73
|
+
this.svg.style.transform = "scale(" + scale + "," + scale + ")";
|
|
74
|
+
this.svg.style['-ms-transform'] = "scale(" + scale + "," + scale + ")";
|
|
75
|
+
this.svg.style['-webkit-transform'] = "scale(" + scale + "," + scale + ")";
|
|
76
76
|
this.svg.style['transform-origin'] = "0 0";
|
|
77
77
|
this.svg.style['-ms-transform-origin-x'] = "0";
|
|
78
78
|
this.svg.style['-ms-transform-origin-y'] = "0";
|
|
@@ -85,14 +85,14 @@ Svg.prototype.setScale = function(scale) {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
Svg.prototype.insertStyles = function(styles) {
|
|
88
|
+
Svg.prototype.insertStyles = function (styles) {
|
|
89
89
|
var el = document.createElementNS(svgNS, "style");
|
|
90
90
|
el.textContent = styles;
|
|
91
91
|
this.svg.insertBefore(el, this.svg.firstChild); // prepend is not available on older browsers.
|
|
92
|
-
// this.svg.prepend(el);
|
|
92
|
+
// this.svg.prepend(el);
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
Svg.prototype.setParentStyles = function(attr) {
|
|
95
|
+
Svg.prototype.setParentStyles = function (attr) {
|
|
96
96
|
// This is needed to get the size right when there is scaling involved.
|
|
97
97
|
for (var key in attr) {
|
|
98
98
|
if (attr.hasOwnProperty(key)) {
|
|
@@ -125,7 +125,7 @@ function constructVLine(x1, y1, y2) {
|
|
|
125
125
|
" l " + 0 + " " + (-len) + " " + " z ";
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
Svg.prototype.rect = function(attr) {
|
|
128
|
+
Svg.prototype.rect = function (attr) {
|
|
129
129
|
// This uses path instead of rect so that it can be hollow and the color changes with "fill" instead of "stroke".
|
|
130
130
|
var lines = [];
|
|
131
131
|
var x1 = attr.x;
|
|
@@ -140,7 +140,7 @@ Svg.prototype.rect = function(attr) {
|
|
|
140
140
|
return this.path({ path: lines.join(" "), stroke: "none", "data-name": attr["data-name"] });
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
Svg.prototype.dottedLine = function(attr) {
|
|
143
|
+
Svg.prototype.dottedLine = function (attr) {
|
|
144
144
|
var el = document.createElementNS(svgNS, 'line');
|
|
145
145
|
el.setAttribute("x1", attr.x1);
|
|
146
146
|
el.setAttribute("x2", attr.x2);
|
|
@@ -151,7 +151,7 @@ Svg.prototype.dottedLine = function(attr) {
|
|
|
151
151
|
this.svg.insertBefore(el, this.svg.firstChild);
|
|
152
152
|
};
|
|
153
153
|
|
|
154
|
-
Svg.prototype.rectBeneath = function(attr) {
|
|
154
|
+
Svg.prototype.rectBeneath = function (attr) {
|
|
155
155
|
var el = document.createElementNS(svgNS, 'rect');
|
|
156
156
|
el.setAttribute("x", attr.x);
|
|
157
157
|
el.setAttribute("width", attr.width);
|
|
@@ -168,7 +168,7 @@ Svg.prototype.rectBeneath = function(attr) {
|
|
|
168
168
|
this.svg.insertBefore(el, this.svg.firstChild);
|
|
169
169
|
};
|
|
170
170
|
|
|
171
|
-
Svg.prototype.text = function(text, attr, target) {
|
|
171
|
+
Svg.prototype.text = function (text, attr, target) {
|
|
172
172
|
var el = document.createElementNS(svgNS, 'text');
|
|
173
173
|
el.setAttribute("stroke", "none");
|
|
174
174
|
for (var key in attr) {
|
|
@@ -176,7 +176,7 @@ Svg.prototype.text = function(text, attr, target) {
|
|
|
176
176
|
el.setAttribute(key, attr[key]);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
var lines = (""+text).split("\n");
|
|
179
|
+
var lines = ("" + text).split("\n");
|
|
180
180
|
for (var i = 0; i < lines.length; i++) {
|
|
181
181
|
var line = document.createElementNS(svgNS, 'tspan');
|
|
182
182
|
line.setAttribute("x", attr.x ? attr.x : 0);
|
|
@@ -211,24 +211,24 @@ Svg.prototype.text = function(text, attr, target) {
|
|
|
211
211
|
return el;
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
Svg.prototype.guessWidth = function(text, attr) {
|
|
214
|
+
Svg.prototype.guessWidth = function (text, attr) {
|
|
215
215
|
var svg = this.createDummySvg();
|
|
216
216
|
var el = this.text(text, attr, svg);
|
|
217
217
|
var size;
|
|
218
218
|
try {
|
|
219
|
-
size
|
|
219
|
+
size = el.getBBox();
|
|
220
220
|
if (isNaN(size.height) || !size.height) // TODO-PER: I don't think this can happen unless there isn't a browser at all.
|
|
221
|
-
size = { width: attr['font-size']/2, height: attr['font-size'] + 2 }; // Just a wild guess.
|
|
221
|
+
size = { width: attr['font-size'] / 2, height: attr['font-size'] + 2 }; // Just a wild guess.
|
|
222
222
|
else
|
|
223
|
-
size = {width: size.width, height: size.height};
|
|
223
|
+
size = { width: size.width, height: size.height };
|
|
224
224
|
} catch (ex) {
|
|
225
|
-
size = { width: attr['font-size']/2, height: attr['font-size'] + 2 }; // Just a wild guess.
|
|
225
|
+
size = { width: attr['font-size'] / 2, height: attr['font-size'] + 2 }; // Just a wild guess.
|
|
226
226
|
}
|
|
227
227
|
svg.removeChild(el);
|
|
228
228
|
return size;
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
-
Svg.prototype.createDummySvg = function() {
|
|
231
|
+
Svg.prototype.createDummySvg = function () {
|
|
232
232
|
if (!this.dummySvg) {
|
|
233
233
|
this.dummySvg = createSvg();
|
|
234
234
|
var styles = [
|
|
@@ -247,9 +247,9 @@ Svg.prototype.createDummySvg = function() {
|
|
|
247
247
|
|
|
248
248
|
var sizeCache = {};
|
|
249
249
|
|
|
250
|
-
Svg.prototype.getTextSize = function(text, attr, el) {
|
|
250
|
+
Svg.prototype.getTextSize = function (text, attr, el) {
|
|
251
251
|
if (typeof text === 'number')
|
|
252
|
-
text = ''+text;
|
|
252
|
+
text = '' + text;
|
|
253
253
|
if (!text || text.match(/^\s+$/))
|
|
254
254
|
return { width: 0, height: 0 };
|
|
255
255
|
var key;
|
|
@@ -264,11 +264,11 @@ Svg.prototype.getTextSize = function(text, attr, el) {
|
|
|
264
264
|
el = this.text(text, attr);
|
|
265
265
|
var size;
|
|
266
266
|
try {
|
|
267
|
-
size
|
|
267
|
+
size = el.getBBox();
|
|
268
268
|
if (isNaN(size.height) || !size.height)
|
|
269
269
|
size = this.guessWidth(text, attr);
|
|
270
270
|
else
|
|
271
|
-
size = {width: size.width, height: size.height};
|
|
271
|
+
size = { width: size.width, height: size.height };
|
|
272
272
|
} catch (ex) {
|
|
273
273
|
size = this.guessWidth(text, attr);
|
|
274
274
|
}
|
|
@@ -283,7 +283,7 @@ Svg.prototype.getTextSize = function(text, attr, el) {
|
|
|
283
283
|
return size;
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
-
Svg.prototype.openGroup = function(options) {
|
|
286
|
+
Svg.prototype.openGroup = function (options) {
|
|
287
287
|
options = options ? options : {};
|
|
288
288
|
var el = document.createElementNS(svgNS, "g");
|
|
289
289
|
if (options.klass)
|
|
@@ -303,7 +303,7 @@ Svg.prototype.openGroup = function(options) {
|
|
|
303
303
|
return el;
|
|
304
304
|
};
|
|
305
305
|
|
|
306
|
-
Svg.prototype.closeGroup = function() {
|
|
306
|
+
Svg.prototype.closeGroup = function () {
|
|
307
307
|
var g = this.currentGroup.shift();
|
|
308
308
|
if (g && g.children.length === 0) {
|
|
309
309
|
// If nothing was added to the group it is because all the elements were invisible. We don't need the group, then.
|
|
@@ -313,7 +313,7 @@ Svg.prototype.closeGroup = function() {
|
|
|
313
313
|
return g;
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
-
Svg.prototype.path = function(attr) {
|
|
316
|
+
Svg.prototype.path = function (attr) {
|
|
317
317
|
var el = document.createElementNS(svgNS, "path");
|
|
318
318
|
for (var key in attr) {
|
|
319
319
|
if (attr.hasOwnProperty(key)) {
|
|
@@ -329,7 +329,7 @@ Svg.prototype.path = function(attr) {
|
|
|
329
329
|
return el;
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
-
Svg.prototype.pathToBack = function(attr) {
|
|
332
|
+
Svg.prototype.pathToBack = function (attr) {
|
|
333
333
|
var el = document.createElementNS(svgNS, "path");
|
|
334
334
|
for (var key in attr) {
|
|
335
335
|
if (attr.hasOwnProperty(key)) {
|
|
@@ -345,14 +345,14 @@ Svg.prototype.pathToBack = function(attr) {
|
|
|
345
345
|
return el;
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
-
Svg.prototype.append = function(el) {
|
|
348
|
+
Svg.prototype.append = function (el) {
|
|
349
349
|
if (this.currentGroup.length > 0)
|
|
350
350
|
this.currentGroup[0].appendChild(el);
|
|
351
351
|
else
|
|
352
352
|
this.svg.appendChild(el);
|
|
353
353
|
};
|
|
354
354
|
|
|
355
|
-
Svg.prototype.prepend = function(el) {
|
|
355
|
+
Svg.prototype.prepend = function (el) {
|
|
356
356
|
// The entire group is prepended, so don't prepend the individual elements.
|
|
357
357
|
if (this.currentGroup.length > 0)
|
|
358
358
|
this.currentGroup[0].appendChild(el);
|
|
@@ -360,7 +360,7 @@ Svg.prototype.prepend = function(el) {
|
|
|
360
360
|
this.svg.insertBefore(el, this.svg.firstChild);
|
|
361
361
|
};
|
|
362
362
|
|
|
363
|
-
Svg.prototype.setAttributeOnElement = function(el, attr) {
|
|
363
|
+
Svg.prototype.setAttributeOnElement = function (el, attr) {
|
|
364
364
|
for (var key in attr) {
|
|
365
365
|
if (attr.hasOwnProperty(key)) {
|
|
366
366
|
el.setAttributeNS(null, key, attr[key]);
|
|
@@ -368,7 +368,7 @@ Svg.prototype.setAttributeOnElement = function(el, attr) {
|
|
|
368
368
|
}
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
-
Svg.prototype.moveElementToChild = function(parent, child) {
|
|
371
|
+
Svg.prototype.moveElementToChild = function (parent, child) {
|
|
372
372
|
parent.appendChild(child);
|
|
373
373
|
};
|
|
374
374
|
|
package/test.js
CHANGED
|
@@ -24,7 +24,7 @@ THE SOFTWARE.
|
|
|
24
24
|
var abcjs = require('./index');
|
|
25
25
|
var version = require('./version');
|
|
26
26
|
var Parse = require('./src/parse/abc_parse');
|
|
27
|
-
var EngraverController = require('./src/write/
|
|
27
|
+
var EngraverController = require('./src/write/engraver-controller')
|
|
28
28
|
|
|
29
29
|
abcjs.signature = "abcjs-test v" + version;
|
|
30
30
|
|