abcjs 6.0.0-beta.9 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/.github/workflows/tests.yml +29 -0
  2. package/CODE_OF_CONDUCT.md +76 -0
  3. package/CONTRIBUTING.md +1 -0
  4. package/LICENSE.md +1 -1
  5. package/README.md +88 -7
  6. package/RELEASE.md +961 -1
  7. package/abcjs-audio.css +14 -5
  8. package/dist/.gitignore +1 -2
  9. package/dist/abcjs-basic-min.js +3 -0
  10. package/dist/abcjs-basic-min.js.LICENSE +23 -0
  11. package/dist/abcjs-basic.js +28232 -0
  12. package/dist/abcjs-basic.js.map +1 -0
  13. package/dist/abcjs-plugin-min.js +3 -0
  14. package/dist/abcjs-plugin-min.js.LICENSE +23 -0
  15. package/index.js +27 -2
  16. package/{static-wrappers/license.js → license.js} +1 -1
  17. package/package.json +26 -29
  18. package/{src/plugin/abc_plugin.js → plugin.js} +31 -19
  19. package/src/api/abc_animation.js +1 -17
  20. package/src/api/abc_tablatures.js +144 -0
  21. package/src/api/abc_timing_callbacks.js +216 -117
  22. package/src/api/abc_tunebook.js +18 -67
  23. package/src/api/abc_tunebook_svg.js +40 -48
  24. package/src/data/abc_tune.js +232 -972
  25. package/src/data/deline-tune.js +199 -0
  26. package/src/edit/abc_editarea.js +112 -0
  27. package/src/edit/abc_editor.js +95 -221
  28. package/src/midi/abc_midi_create.js +48 -50
  29. package/src/parse/abc_common.js +0 -14
  30. package/src/parse/abc_parse.js +167 -1321
  31. package/src/parse/abc_parse_book.js +62 -0
  32. package/src/parse/abc_parse_directive.js +164 -41
  33. package/src/parse/abc_parse_header.js +116 -145
  34. package/src/parse/abc_parse_key_voice.js +26 -20
  35. package/src/parse/abc_parse_music.js +1337 -0
  36. package/src/parse/abc_tokenizer.js +21 -15
  37. package/src/parse/abc_transpose.js +3 -15
  38. package/src/parse/tune-builder.js +896 -0
  39. package/src/parse/wrap_lines.js +205 -453
  40. package/src/synth/abc_midi_flattener.js +1292 -0
  41. package/src/{midi → synth}/abc_midi_renderer.js +44 -17
  42. package/src/synth/abc_midi_sequencer.js +648 -0
  43. package/src/synth/active-audio-context.js +3 -14
  44. package/src/synth/cents-to-factor.js +10 -0
  45. package/src/synth/create-note-map.js +21 -32
  46. package/src/synth/create-synth-control.js +20 -103
  47. package/src/synth/create-synth.js +185 -77
  48. package/src/synth/download-buffer.js +7 -21
  49. package/src/synth/get-midi-file.js +13 -20
  50. package/src/synth/images/{loading.svg → loading.svg.js} +4 -0
  51. package/src/synth/images/loop.svg.js +65 -0
  52. package/src/synth/images/pause.svg.js +10 -0
  53. package/src/synth/images/play.svg.js +9 -0
  54. package/src/synth/images/{reset.svg → reset.svg.js} +5 -1
  55. package/src/synth/instrument-index-to-name.js +1 -16
  56. package/src/synth/load-note.js +37 -76
  57. package/src/synth/pitch-to-note-name.js +0 -15
  58. package/src/synth/pitches-to-perc.js +64 -0
  59. package/src/synth/place-note.js +78 -68
  60. package/src/synth/play-event.js +17 -18
  61. package/src/synth/register-audio-context.js +11 -23
  62. package/src/synth/sounds-cache.js +0 -15
  63. package/src/synth/supports-audio.js +9 -23
  64. package/src/synth/synth-controller.js +80 -49
  65. package/src/synth/synth-sequence.js +20 -34
  66. package/src/tablatures/instruments/guitar/guitar-fonts.js +19 -0
  67. package/src/tablatures/instruments/guitar/guitar-patterns.js +23 -0
  68. package/src/tablatures/instruments/guitar/tab-guitar.js +50 -0
  69. package/src/tablatures/instruments/string-patterns.js +277 -0
  70. package/src/tablatures/instruments/string-tablature.js +56 -0
  71. package/src/tablatures/instruments/tab-note.js +282 -0
  72. package/src/tablatures/instruments/tab-notes.js +41 -0
  73. package/src/tablatures/instruments/violin/tab-violin.js +47 -0
  74. package/src/tablatures/instruments/violin/violin-fonts.js +19 -0
  75. package/src/tablatures/instruments/violin/violin-patterns.js +23 -0
  76. package/src/tablatures/tab-absolute-elements.js +310 -0
  77. package/src/tablatures/tab-common.js +29 -0
  78. package/src/tablatures/tab-renderer.js +243 -0
  79. package/src/tablatures/transposer.js +110 -0
  80. package/src/test/abc_midi_lint.js +5 -22
  81. package/src/test/abc_midi_sequencer_lint.js +11 -14
  82. package/src/test/abc_parser_lint.js +136 -32
  83. package/src/test/abc_vertical_lint.js +94 -32
  84. package/src/test/rendering-lint.js +38 -5
  85. package/src/write/abc_absolute_element.js +112 -120
  86. package/src/write/abc_abstract_engraver.js +102 -253
  87. package/src/write/abc_beam_element.js +30 -290
  88. package/src/write/abc_brace_element.js +12 -121
  89. package/src/write/abc_create_clef.js +21 -32
  90. package/src/write/abc_create_key_signature.js +8 -26
  91. package/src/write/abc_create_note_head.js +107 -0
  92. package/src/write/abc_create_time_signature.js +2 -21
  93. package/src/write/abc_crescendo_element.js +3 -50
  94. package/src/write/abc_decoration.js +7 -30
  95. package/src/write/abc_dynamic_decoration.js +3 -37
  96. package/src/write/abc_ending_element.js +1 -57
  97. package/src/write/abc_engraver_controller.js +111 -234
  98. package/src/write/abc_glyphs.js +8 -18
  99. package/src/write/abc_relative_element.js +57 -97
  100. package/src/write/abc_renderer.js +10 -832
  101. package/src/write/abc_spacing.js +0 -15
  102. package/src/write/abc_staff_group_element.js +14 -349
  103. package/src/write/abc_tempo_element.js +9 -117
  104. package/src/write/abc_tie_element.js +5 -68
  105. package/src/write/abc_triplet_element.js +6 -124
  106. package/src/write/abc_voice_element.js +7 -222
  107. package/src/write/add-chord.js +103 -0
  108. package/src/write/add-text-if.js +33 -0
  109. package/src/write/bottom-text.js +79 -0
  110. package/src/write/calcHeight.js +17 -0
  111. package/src/write/classes.js +100 -0
  112. package/src/write/draw/absolute.js +68 -0
  113. package/src/write/draw/beam.js +56 -0
  114. package/src/write/draw/brace.js +106 -0
  115. package/src/write/draw/crescendo.js +38 -0
  116. package/src/write/draw/debug-box.js +8 -0
  117. package/src/write/draw/draw.js +56 -0
  118. package/src/write/draw/dynamics.js +20 -0
  119. package/src/write/draw/ending.js +46 -0
  120. package/src/write/draw/group-elements.js +66 -0
  121. package/src/write/draw/horizontal-line.js +25 -0
  122. package/src/write/draw/non-music.js +50 -0
  123. package/src/write/draw/print-line.js +24 -0
  124. package/src/write/draw/print-path.js +7 -0
  125. package/src/write/draw/print-stem.js +30 -0
  126. package/src/write/draw/print-symbol.js +59 -0
  127. package/src/write/draw/print-vertical-line.js +18 -0
  128. package/src/write/draw/relative.js +77 -0
  129. package/src/write/draw/round-number.js +5 -0
  130. package/src/write/draw/selectables.js +59 -0
  131. package/src/write/draw/separator.js +16 -0
  132. package/src/write/draw/set-paper-size.js +45 -0
  133. package/src/write/{sprintf.js → draw/sprintf.js} +0 -0
  134. package/src/write/draw/staff-group.js +226 -0
  135. package/src/write/draw/staff-line.js +9 -0
  136. package/src/write/draw/staff.js +33 -0
  137. package/src/write/draw/tab-line.js +40 -0
  138. package/src/write/draw/tempo.js +45 -0
  139. package/src/write/draw/text.js +71 -0
  140. package/src/write/draw/tie.js +97 -0
  141. package/src/write/draw/triplet.js +46 -0
  142. package/src/write/draw/voice.js +102 -0
  143. package/src/write/format-jazz-chord.js +15 -0
  144. package/src/write/free-text.js +41 -0
  145. package/src/write/get-font-and-attr.js +37 -0
  146. package/src/write/get-text-size.js +56 -0
  147. package/src/write/highlight.js +11 -0
  148. package/src/write/layout/VoiceElements.js +121 -0
  149. package/src/write/layout/beam.js +213 -0
  150. package/src/write/layout/get-left-edge-of-staff.js +56 -0
  151. package/src/write/layout/getBarYAt.js +6 -0
  152. package/src/write/layout/layout.js +94 -0
  153. package/src/write/layout/setUpperAndLowerElements.js +232 -0
  154. package/src/write/layout/staffGroup.js +146 -0
  155. package/src/write/layout/triplet.js +75 -0
  156. package/src/write/layout/voice.js +137 -0
  157. package/src/write/selection.js +188 -70
  158. package/src/write/separator.js +10 -0
  159. package/src/write/set-class.js +21 -0
  160. package/src/write/subtitle.js +12 -0
  161. package/src/write/svg.js +95 -43
  162. package/src/write/top-text.js +54 -0
  163. package/src/write/unhighlight.js +11 -0
  164. package/test.js +27 -64
  165. package/types/index.d.ts +1095 -0
  166. package/version.js +1 -1
  167. package/.babelrc +0 -5
  168. package/.eslintrc +0 -3
  169. package/.gitmodules +0 -3
  170. package/Dockerfile +0 -8
  171. package/abcjs-midi.css +0 -166
  172. package/build-utils/loadPresets.js +0 -14
  173. package/build-utils/presets/webpack.analyze.js +0 -6
  174. package/build-utils/presets/webpack.optimize.js +0 -30
  175. package/build-utils/webpack.development.js +0 -14
  176. package/build-utils/webpack.production.js +0 -35
  177. package/deploy-docs.sh +0 -25
  178. package/docker-compose.yml +0 -13
  179. package/docs/README.md +0 -33
  180. package/fix-versions.sh +0 -23
  181. package/midi.js +0 -62
  182. package/src/api/abc_tunebook_midi.js +0 -116
  183. package/src/midi/abc_midi_controls.js +0 -701
  184. package/src/midi/abc_midi_flattener.js +0 -1119
  185. package/src/midi/abc_midi_js_preparer.js +0 -243
  186. package/src/midi/abc_midi_sequencer.js +0 -401
  187. package/src/midi/abc_midi_ui_generator.js +0 -86
  188. package/src/plugin/abc_plugin_midi.js +0 -220
  189. package/src/synth/images/loop.svg +0 -61
  190. package/src/synth/images/pause.svg +0 -6
  191. package/src/synth/images/play.svg +0 -5
  192. package/src/transform/abc2abc_write.js +0 -395
  193. package/static-wrappers/basic.js +0 -2
  194. package/static-wrappers/midi.js +0 -2
  195. package/static-wrappers/plugin-midi.js +0 -6
  196. package/static-wrappers/plugin.js +0 -6
  197. package/webpack.config.js +0 -29
@@ -0,0 +1,199 @@
1
+ function delineTune(inputLines, options) {
2
+ if (!options) options = {};
3
+ var lineBreaks = !!options.lineBreaks;
4
+ var outputLines = [];
5
+ var inMusicLine = false;
6
+ var currentMeter = [];
7
+ var currentKey = [];
8
+ var currentClef = [];
9
+ var currentVocalFont = [];
10
+ var currentGChordFont = [];
11
+ var currentTripletFont = [];
12
+ var currentAnnotationFont = [];
13
+ for (var i = 0; i < inputLines.length; i++) {
14
+ var inputLine = inputLines[i];
15
+ if (inputLine.staff) {
16
+ if (inMusicLine && !inputLine.vskip) {
17
+ var outputLine = outputLines[outputLines.length-1];
18
+ //findMismatchKeys(inputLine, outputLine, ["staff", "staffGroup"], "line", i)
19
+ for (var s = 0; s < outputLine.staff.length; s++) {
20
+ var inputStaff = inputLine.staff[s];
21
+ var outputStaff = outputLine.staff[s];
22
+ if (inputStaff) {
23
+ if (!objEqual(inputStaff.meter, currentMeter[s])) {
24
+ // The meter changed for this line, otherwise it wouldn't have been set
25
+ addMeterToVoices(inputStaff.meter, inputStaff.voices)
26
+ currentMeter[s] = inputStaff.meter;
27
+ delete inputStaff.meter;
28
+ }
29
+ if (!objEqual(inputStaff.key, currentKey[s])) {
30
+ addKeyToVoices(inputStaff.key, inputStaff.voices);
31
+ currentKey[s] = inputStaff.key;
32
+ delete inputStaff.key;
33
+ }
34
+ if (inputStaff.title)
35
+ outputStaff.abbrevTitle = inputStaff.title;
36
+ if (!objEqual(inputStaff.clef, currentClef[s])) {
37
+ addClefToVoices(inputStaff.clef, inputStaff.voices);
38
+ currentClef[s] = inputStaff.clef;
39
+ delete inputStaff.clef;
40
+ }
41
+ if (!objEqual(inputStaff.vocalfont, currentVocalFont[s])) {
42
+ addFontToVoices(inputStaff.vocalfont, inputStaff.voices, 'vocalfont')
43
+ currentVocalFont[s] = inputStaff.vocalfont;
44
+ delete inputStaff.vocalfont;
45
+ }
46
+ if (!objEqual(inputStaff.gchordfont, currentGChordFont[s])) {
47
+ addFontToVoices(inputStaff.gchordfont, inputStaff.voices, 'gchordfont')
48
+ currentGChordFont[s] = inputStaff.gchordfont;
49
+ delete inputStaff.gchordfont;
50
+ }
51
+ if (!objEqual(inputStaff.tripletfont, currentTripletFont[s])) {
52
+ addFontToVoices(inputStaff.tripletfont, inputStaff.voices, 'tripletfont')
53
+ currentTripletFont[s] = inputStaff.tripletfont;
54
+ delete inputStaff.tripletfont;
55
+ }
56
+ if (!objEqual(inputStaff.annotationfont, currentAnnotationFont[s])) {
57
+ addFontToVoices(inputStaff.annotationfont, inputStaff.voices, 'annotationfont')
58
+ currentAnnotationFont[s] = inputStaff.annotationfont;
59
+ delete inputStaff.annotationfont;
60
+ }
61
+ }
62
+ //findMismatchKeys(inputStaff, outputStaff, ["voices", "title", "abbrevTitle", "barNumber", "meter", "key", "clef", "vocalfont", "gchordfont", "tripletfont", "annotationfont"], "staff", i + ' ' + s)
63
+ if (inputStaff) {
64
+ for (var v = 0; v < outputStaff.voices.length; v++) {
65
+ var outputVoice = outputStaff.voices[v];
66
+ var inputVoice = inputStaff.voices[v];
67
+ if (lineBreaks)
68
+ outputVoice.push({el_type: "break"});
69
+ if (inputVoice)
70
+ outputStaff.voices[v] = outputVoice.concat(inputVoice)
71
+ }
72
+ }
73
+ }
74
+ } else {
75
+ for (var ii = 0; ii < inputLine.staff.length; ii++) {
76
+ currentKey[ii] = inputLine.staff[ii].key;
77
+ currentMeter[ii] = inputLine.staff[ii].meter;
78
+ currentClef[ii] = inputLine.staff[ii].clef;
79
+ }
80
+ // copy this because we are going to change it and we don't want to change the original.
81
+ outputLines.push(cloneLine(inputLine));
82
+ }
83
+ inMusicLine = true;
84
+ } else {
85
+ inMusicLine = false;
86
+ outputLines.push(inputLine);
87
+ }
88
+ }
89
+ return outputLines;
90
+ }
91
+ // function findMismatchKeys(input, output, ignore, context, context2) {
92
+ // if (!input) {
93
+ // return;
94
+ // }
95
+ // var outputKeys = Object.keys(output);
96
+ // var inputKeys = Object.keys(input);
97
+ // for (var ii = 0; ii < ignore.length; ii++) {
98
+ // if (outputKeys.indexOf(ignore[ii]) >= 0) {
99
+ // outputKeys.splice(outputKeys.indexOf(ignore[ii]), 1);
100
+ // }
101
+ // if (inputKeys.indexOf(ignore[ii]) >= 0) {
102
+ // inputKeys.splice(inputKeys.indexOf(ignore[ii]), 1);
103
+ // }
104
+ // }
105
+ // if (inputKeys.join(",") !== outputKeys.join(",")) {
106
+ // console.log("keys mismatch "+context + ' ' + context2, input, output);
107
+ // }
108
+ // for (var k = 0; k < inputKeys.length; k++) {
109
+ // var key = inputKeys[k];
110
+ // if (ignore.indexOf(key) < 0) {
111
+ // var inputValue = JSON.stringify(input[key], replacer);
112
+ // var outputValue = JSON.stringify(output[key], replacer);
113
+ // if (inputValue !== outputValue)
114
+ // console.log("value mismatch "+context + ' ' + context2 + ' ' + key, inputValue, outputValue)
115
+ // }
116
+ // }
117
+ // }
118
+ function replacer(key, value) {
119
+ // Filtering out properties
120
+ if (key === 'abselem') {
121
+ return 'abselem';
122
+ }
123
+ return value;
124
+ }
125
+
126
+ function addMeterToVoices(meter, voices) {
127
+ meter.el_type = "meter";
128
+ meter.startChar = -1;
129
+ meter.endChar = -1;
130
+ for (var i = 0; i < voices.length; i++) {
131
+ voices[i].unshift(meter);
132
+ }
133
+ }
134
+
135
+ function addKeyToVoices(key, voices) {
136
+ key.el_type = "key";
137
+ key.startChar = -1;
138
+ key.endChar = -1;
139
+ for (var i = 0; i < voices.length; i++) {
140
+ voices[i].unshift(key);
141
+ }
142
+ }
143
+
144
+ function addClefToVoices(clef, voices) {
145
+ clef.el_type = "clef";
146
+ clef.startChar = -1;
147
+ clef.endChar = -1;
148
+ for (var i = 0; i < voices.length; i++) {
149
+ voices[i].unshift(clef);
150
+ }
151
+ }
152
+
153
+ function addFontToVoices(font, voices, type) {
154
+ font.el_type = "font";
155
+ font.type = type;
156
+ font.startChar = -1;
157
+ font.endChar = -1;
158
+ for (var i = 0; i < voices.length; i++) {
159
+ voices[i].unshift(font);
160
+ }
161
+ }
162
+
163
+ function objEqual(input, output) {
164
+ if (!input)
165
+ return true; // the default is whatever the old output is.
166
+ var inputValue = JSON.stringify(input, replacer);
167
+ var outputValue = JSON.stringify(output, replacer);
168
+ return inputValue === outputValue;
169
+ }
170
+
171
+ function cloneLine(line) {
172
+ var output = {};
173
+ var keys = Object.keys(line);
174
+ for (var i = 0; i < keys.length; i++) {
175
+ if (keys[i] !== "staff")
176
+ output[keys[i]] = line[keys[i]];
177
+ else {
178
+ output.staff = [];
179
+ for (var j = 0; j < line.staff.length; j++) {
180
+ var staff = {};
181
+ var keys2 = Object.keys(line.staff[j]);
182
+ for (var k = 0; k < keys2.length; k++) {
183
+ if (keys2[k] !== "voices")
184
+ staff[keys2[k]] = line.staff[j][keys2[k]];
185
+ else {
186
+ staff.voices = [];
187
+ for (var v = 0; v < line.staff[j].voices.length; v++) {
188
+ staff.voices.push([].concat(line.staff[j].voices[v]));
189
+ }
190
+ }
191
+ }
192
+ output.staff.push(staff)
193
+ }
194
+ }
195
+ }
196
+ return output;
197
+ }
198
+
199
+ module.exports = delineTune;
@@ -0,0 +1,112 @@
1
+ // abc_editor.js
2
+
3
+ // window.ABCJS.Editor is the interface class for the area that contains the ABC text. It is responsible for
4
+ // holding the text of the tune and calling the parser and the rendering engines.
5
+ //
6
+ // EditArea is an example of using a textarea as the control that is shown to the user. As long as
7
+ // the same interface is used, window.ABCJS.Editor can use a different type of object.
8
+ //
9
+ // EditArea:
10
+ // - constructor(textareaid)
11
+ // This contains the id of a textarea control that will be used.
12
+ // - addSelectionListener(listener)
13
+ // A callback class that contains the entry point fireSelectionChanged()
14
+ // - addChangeListener(listener)
15
+ // A callback class that contains the entry point fireChanged()
16
+ // - getSelection()
17
+ // returns the object { start: , end: } with the current selection in characters
18
+ // - setSelection(start, end)
19
+ // start and end are the character positions that should be selected.
20
+ // - getString()
21
+ // returns the ABC text that is currently displayed.
22
+ // - setString(str)
23
+ // sets the ABC text that is currently displayed, and resets the initialText variable
24
+ // - getElem()
25
+ // returns the textarea element
26
+ // - string initialText
27
+ // Contains the starting text. This can be compared against the current text to see if anything changed.
28
+ //
29
+
30
+ // Polyfill for CustomEvent for old IE versions
31
+ try {
32
+ if (typeof window.CustomEvent !== "function") {
33
+ var CustomEvent = function (event, params) {
34
+ params = params || {bubbles: false, cancelable: false, detail: undefined};
35
+ var evt = document.createEvent('CustomEvent');
36
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
37
+ return evt;
38
+ };
39
+ CustomEvent.prototype = window.Event.prototype;
40
+ window.CustomEvent = CustomEvent;
41
+ }
42
+ } catch (e) {
43
+ // if we aren't in a browser, this code will crash, but it is not needed then either.
44
+ }
45
+
46
+ var EditArea = function(textareaid) {
47
+ this.textarea = document.getElementById(textareaid);
48
+ this.initialText = this.textarea.value;
49
+ this.isDragging = false;
50
+ }
51
+
52
+ EditArea.prototype.addSelectionListener = function(listener) {
53
+ this.textarea.onmousemove = function(ev) {
54
+ if (this.isDragging)
55
+ listener.fireSelectionChanged();
56
+ };
57
+ };
58
+
59
+ EditArea.prototype.addChangeListener = function(listener) {
60
+ this.changelistener = listener;
61
+ this.textarea.onkeyup = function() {
62
+ listener.fireChanged();
63
+ };
64
+ this.textarea.onmousedown = function() {
65
+ this.isDragging = true;
66
+ listener.fireSelectionChanged();
67
+ };
68
+ this.textarea.onmouseup = function() {
69
+ this.isDragging = false;
70
+ listener.fireChanged();
71
+ };
72
+ this.textarea.onchange = function() {
73
+ listener.fireChanged();
74
+ };
75
+ };
76
+
77
+ //TODO won't work under IE?
78
+ EditArea.prototype.getSelection = function() {
79
+ return {start: this.textarea.selectionStart, end: this.textarea.selectionEnd};
80
+ };
81
+
82
+ EditArea.prototype.setSelection = function(start, end) {
83
+ if(this.textarea.setSelectionRange)
84
+ this.textarea.setSelectionRange(start, end);
85
+ else if(this.textarea.createTextRange) {
86
+ // For IE8
87
+ var e = this.textarea.createTextRange();
88
+ e.collapse(true);
89
+ e.moveEnd('character', end);
90
+ e.moveStart('character', start);
91
+ e.select();
92
+ }
93
+ this.textarea.focus();
94
+ };
95
+
96
+ EditArea.prototype.getString = function() {
97
+ return this.textarea.value;
98
+ };
99
+
100
+ EditArea.prototype.setString = function(str) {
101
+ this.textarea.value = str;
102
+ this.initialText = this.getString();
103
+ if (this.changelistener) {
104
+ this.changelistener.fireChanged();
105
+ }
106
+ };
107
+
108
+ EditArea.prototype.getElem = function() {
109
+ return this.textarea;
110
+ };
111
+
112
+ module.exports = EditArea;