abc2svg
Check-in Differences
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From af5bcae7ac2b432e To bb366150962b55e3

2021-01-27
09:43
util: abcweb: fix: accept class abc with other classes - ticket [f632b51e4d] ... (check-in: 16278b1c38 user: jef tags: trunk)
2021-01-24
18:23
New release v1.20.17 ... (check-in: bb36615096 user: jef tags: trunk, v1.20.17)
18:21
core: play: separate %%soundfont from the other fonts definitions ... (check-in: ec8cb878ad user: jef tags: trunk)
2020-01-01
16:36
core: fix: bad transposition with score=<note1> (without <note2>) ... (check-in: dc98412a6d user: jef tags: trunk)
14:18
New release v1.20.7 ... (check-in: af5bcae7ac user: jef tags: trunk, v1.20.7)
14:06
core: fix: bad display when m: and '%%writefields m 0' ... (check-in: 2bcf730e67 user: jef tags: trunk)

Changes to README.md.





1
2
3

4
5
6
7
8


9
10
11
12
13

14
15
16

17
18

19





20

21

22
23

24
25
26
27
28
29
30
31



32
33
34

35
36
37
38
39
40
41
42
43
44
45
46




47
48


49
50
51

52
53
54
55









56
57
58
59



60
61
62
63

64
65
66
67
68














69
70





71

72

73
74




75
76
77






78
79
80
81


82
83
84

85
86
87
88
89

90
91

92
93
94
95
96

97
98
99
100
101
102
103
104
105
106
107


108
109
110
111
112







113
114






115
116
117
118
119
120





121
122
123

124
125
126
127




128
129


130

131
132





133


134



135

136
137






138


139


140



141
142













143

144
145
146











147
148


149
150
151
152
153
154












155

156
157
158



159

160
161
162








163
164
165









166







167




168
169

170


171
172

173





174
175
176















177
178

179


180

181

182
183

184
185
186
187



188


189
190


191
192
193
194

195
196




197











198

199
200

201
202
203


204
205
206
207
208
209





210
211
212
213
214
215




216
217
218


219
220
221
222
223



224
225
226
227
228
229
230
231
232
233








234
235
236

237
238
239

240
241



242
243
244
245













246
247
















































































































































248

249
250
251



252
253
254


255
256


257
258

259


















1
2
3
4
5
6
7

8





9
10





11

12

13


14

15
16
17
18
19
20
21

22
23

24




25



26
27
28



29





30






31
32
33
34


35
36



37
38



39
40
41
42
43
44
45
46
47




48
49
50




51





52
53
54
55
56
57
58
59
60
61
62
63
64
65


66
67
68
69
70
71
72

73


74
75
76
77



78
79
80
81
82
83




84
85



86
87




88


89



90

91






92




93
94





95
96
97
98
99
100
101
102

103
104
105
106
107
108
109





110
111
112
113
114
115


116
117



118
119
120
121
122

123
124
125
126


127
128
129
130
131
132
133
134

135
136
137
138
139


140
141
142
143
144
145
146
147
148

149
150
151
152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169



170
171
172
173
174
175
176
177
178
179
180
181

182
183
184





185
186
187
188
189
190
191
192
193
194
195
196

197
198


199
200
201
202
203



204
205
206
207
208
209
210
211
212


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234

235

236
237
238

239
240
241
242
243
244
245



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263
264
265

266

267
268

269
270



271
272
273
274
275
276


277
278
279
280
281
282
283


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

300
301

302
303


304
305
306





307
308
309
310
311
312
313




314
315
316
317
318


319
320
321
322



323
324
325
326
327








328
329
330
331
332
333
334
335
336
337

338
339
340

341
342
343
344
345
346




347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508

509
510
511
512


513
514


515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
+
+
+
+
+


-
+
-
-
-
-
-
+
+
-
-
-
-
-
+
-

-
+
-
-
+
-
+
+
+
+
+

+
-
+

-
+
-
-
-
-

-
-
-
+
+
+
-
-
-
+
-
-
-
-
-

-
-
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
+

-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+

+
-
+
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
-
-
-
+

-
-
-
-
+
-
-
+
-
-
-

-
+
-
-
-
-
-
-

-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+

-
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+

-
-
-
+
+
+
+

-
+
+

+
-
-
+
+
+
+
+

+
+
-
+
+
+

+
-
-
+
+
+
+
+
+

+
+
-
+
+

+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
-
+
+
+

+
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
-
+
+
+
+

-
+
-
+
+

-
+

+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

+
+
-
+
-
+

-
+

-
-
-
+
+
+

+
+
-
-
+
+




+
-
-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
-
+

-
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+


-
-
-
-
+
+
+
+

-
-
+
+


-
-
-
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
+


-
+


+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+


-
+
+
+

-
-
+
+
-
-
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<style>
p{margin-left:.5cm;max-width:21cm}
li{margin-left:.5cm;max-width:20cm}
li p{margin-left:0}
</style>
## abc2svg

**abc2svg** is a set of tools written in Javascript and based on
**abc2svg** is a set of Javascript files for handling the
[abcm2ps](https://github.com/leesavide/abcm2ps).

It permits to edit, display, print and play music from files written in
[ABC](http://abcnotation.com/).

 [ABC music notation](http://abcnotation.com/). This includes
editing, displaying, printing, playing the music files and
Its specific features are described (with abc2svg!) in the document
[abcm2ps/abc2svg features](http://moinejf.free.fr/abcm2ps-doc/features.xhtml)
and the parameters in
[abcm2ps/abc2svg parameters](http://moinejf.free.fr/abcm2ps-doc/index.html).

converting them to other formats such as ABC and MEI notations.
### Web usage

**abc2svg** may be used in any web browser.
The **abc2svg** core is based on the
The needed files are available in my site
[http://moinejf.free.fr/js/](http://moinejf.free.fr/js).  
[abcm2ps](https://github.com/leesavide/abcm2ps) C code
They are updated on release change.
which requires compilation on every operating system. 
The **abc2svg** scripts can run in any system with no compilation on
any platform that contains an internet browser. This includes Windows,
Apple, and Unix-like systems (Linux, BSD...) as well as portable devices
such as cell phones and iPads.

A description of the ABC parameters that relate to both abcm2ps
These files are:
and abc2svg can be found [here][1].

- `abc2svg-1.js`   
[1]: http://moinejf.free.fr/abcm2ps-doc/index.html "abc2svg documentation"
  This script is the **abc2svg** core.  
  It contains the ABC parser and the SVG generation engine.  
  It must be included in the (X)HTML header of the pages
  where ABC rendering is needed (in `<script src=` tags).

- `abcemb-1.js`   
  This script replaces the ABC or MEI sequences by SVG images of the music
  (the ABC sequences start on `X:` or `%abc` at start of line,
Note: The ABC music notation is now discussed in the mailing list
[abcusers at groups.io](https://groups.io/g/abcusers).
Some work in progress about the ABC draft may be found in these
  and stop on any ML tag - see below for MEI).  
  See the
  [%%beginml documentation](http://moinejf.free.fr/abcm2ps-doc/beginml.xhtml)
[temporary pages](http://moinejf.free.fr/abcstd/).
  for an example.   
  When the URL of the (X)HTML file ends with '#' followed by a string,
  only the first tune containing this string is displayed.   
  Note that, if the ABC sequence contains the characters '<', '>' or '&',
  it must be enclosed in a XML comment (starting after the first `X:` or `%abc`).

- `abcemb1-1.js`   
  This script is to be used with the core in (X)HTML files.  
  It works quite the same as the previous script, but replaces the whole
  page by the selected tune.
  When there is no selection ('#' + string at the end of the URL),
  a list of the tunes is displayed.   
### 1. Web browser usage

#### 1.1 Rendering ABC files from a local or remote source

  When a tune is displayed, a menu offers the edition of the ABC source and
  the automatic scroll of the music (this is done according to the tempo -
After accessing ABC files with a web browser either from a local or web
source, you can render or play the music without much preparation.
  repeats and parts are not handled).   
  See [this tune](http://moinejf.free.fr/abc/boyvin-2-2.html)
  for an example.   
One approach uses [bookmarklets](https://en.wikipedia.org/wiki/Bookmarklet).

- `abcemb2-1.js`   
  This script is also to be used with the core in (X)HTML files.  
  The differences with the script `abcemb-1.js` are:
A bookmarklet is the same as a normal bookmark in a web browser.
Its title (or name) is anything you want to use to identify it and its URL
(or location or address) is javascript code starting by `javascript:`.
First, create a bookmark from this page adding it to your library of
bookmarks. Next, edit this mark changing the title and the URL. (Details
for editing a bookmark are specific for each browser. To get instructions,
search on the internet the name of the browser and keywords such as
'bookmarklet' and 'javascript in url'). To edit the URL, extract
the javascript code
  - the ABC sequences are replaced in HTML elements with the class `abc`,
  - the string after '#' in the URL does a real %%select (i.e. this may
    select many tunes),
  - there is no menu nor list of tunes
by right clicking on one of the bookmarklets below and selecting
copy url. Then, paste this code into the URL of your new bookmark
in your library.
  - if the ABC sequences contain the characters '<', '>' or '&',
    either these sequences must be enclosed in a XML comment, or the characters
    must be replaced by their XML counterparts ('&amp;lt;', '&amp;gt;' or '&amp;amp;').
  

- `abcdoc-1.js`   
  This script is also to be used in (X)HTML pages with the core.  
  Mainly used for ABC documentation, it lets the ABC source sequences
  in the page before the SVG images.  
  See the source of
To use a abc2svg bookmarklet, first load an ABC file into your
browser either from a web site of from a file on your system.
Once you see the textual abc code, click on the bookmarklet
that you created. After a slight delay depending upon the
complexity of the abc code, it should be replaced by a music
representation or a list of the contents of the ABC file. Here
are two bookmarklets that you can try.

This
<a href="javascript:(function(){var%20s,n=3,d=document,b=d.body;d.head.innerHTML='&lt;style&gt;\nsvg{display:block};@media print{body{margin:0;padding:0;border:0}.nop{display:none}}\n&lt;/style&gt;';b.innerHTML='\n%25abc-2.2%25%3c!--\n'+b.textContent+'%25--%3e\n';function%20f(u){s=d.createElement('script');s.src='http://moinejf.free.fr/js/'+u;s.onload=function(){if(--n==0)dom_loaded()};d.head.appendChild(s)};f('abcweb-1.js');f('snd-1.js')})()"
title="Copy me">first abc2svg bookmarklet</a>
renders all the music it finds in the page currently displayed.  
Once the music is displayed, clicking inside a tune starts playing it
from the beginning.
  [abcm2ps/abc2svg features](http://moinejf.free.fr/abcm2ps-doc/features.xhtml)
  for an example.
Clicking on a particular note or rest starts playing from that point.  
To print or convert the music to a PDF file,
simply click on the 'Print' button of the web browser.
(If the 'Print' button does not appear on your browser menu,
try right clicking on the web page.)

Alternatively, if your source contains many tunes, you can
- `play-1.js`   
use this
  This script may be used with `abcemb{,1,2}-1.js` for playing the
  rendered ABC music.  
<a href="javascript:(function(){var%20s,n=3,d=document,b=d.body;d.head.innerHTML='&lt;style&gt;\nsvg{display:block};@media print{body{margin:0;padding:0;border:0}.nop{display:none}}\n&lt;/style&gt;';b.innerHTML='\n%25abc-2.2%25%3c!--\n'+b.textContent+'%25--%3e\n';function%20f(u){s=d.createElement('script');s.src='http://moinejf.free.fr/js/'+u;s.onload=function(){if(--n==0)dom_loaded()};d.head.appendChild(s)};f('abcweb1-1.js');f('snd-1.js')})()"
title="Copy me">second bookmarklet</a>.
The browser will list the titles of the tunes. Click on one of the titles
to view the music representation.
  See [this page](http://moinejf.free.fr/abcm2ps-doc/au_clair.xhtml)
  for an example.

Playing and printing work in the same manner as above.  
The generated pages contain a yellow menu in the top right corner which permits
you to return to the tune list or to modify the music. With this last option,
you can adjust the page size before printing, correct the ABC syntax or
do some transposition.
Note that these changes stay only with the browser and are not saved
- `abcweb2-1.js`   
  This script works the same as `abcemb2-1.js` but it must use `snd-1.js`
  for playing.
  
to your system.

- `snd-1.js`   
  This script contains a other way for playing. It is used in the editor
  and it may be used with `abcweb2-1.js`.
If you want to experiment with these bookmarklets, here are some raw ABC files:

- `follow-1.js`   
  This script may be used after `play-1.js` or `snd-1.js` for highlighting
  the notes while playing.   
  See [this page](http://moinejf.free.fr/abcm2ps-doc/tabac.xhtml)
- [from my site](http://moinejf.free.fr/abc/agora.abc "agora.abc")
  for an example.

- [from Cranford Publications][2]
- `edit-1.xhtml`   
  This is a simple web
  [ABC editor/player](http://moinejf.free.fr/js/edit-1.xhtml).

When looking at a ABC file in a web browser, you may also use a
[2]: http://www.cranfordpub.com/tunes/abcs/NatalieBlueprint.txt "Blueprint"
<a href="https://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a>
as
<a href="javascript:(function(){var%20s,n=3,d=document,b=d.body;b.innerHTML='\n%25abc-2.2\n%25%3c!--\n'+b.textContent+'%25--%3e\n';function%20f(u){s=d.createElement('script');s.src='http://moinejf.free.fr/js/'+u;s.onload=function(){if(--n==0)dom_loaded()};d.head.appendChild(s)};f('play-1.js');f('follow-1.js');f('abcemb-1.js')})();void(0)">this one</a>
for rendering all tunes, or
<a href="javascript:(function(){var%20s,n=3,d=document,b=d.body;b.innerHTML='\n%25abc-2.2\n%25%3c!--\n'+b.textContent+'%25--%3e\n';function%20f(u){s=d.createElement('script');s.src='http://moinejf.free.fr/js/'+u;s.onload=function(){if(--n==0)dom_loaded()};d.head.appendChild(s)};f('play-1.js');f('follow-1.js');f('abcemb1-1.js')})();void(0)">this one</a>
for rendering the tunes one by one.

##### Notes:
- The music is rendered as SVG images. There is one image per
  music line / text block.  
  If you want to move these images to some other files,
#### 1.2 Writing, playing and printing music with the abc2svg editor

  each one must contain the full CSS and defs. For that, insert   
  `        %%fullsvg x`   
  in the ABC file before rendering (see the
  [fullsvg documentation](http://moinejf.free.fr/abcm2ps-doc/fullsvg.xhtml)
  for more information).
The [abc2svg editor][3]
is another example of what can be done with **abc2svg**.

[3]: http://moinejf.free.fr/js/edit-1.xhtml "ABC editor based on abc2svg"

If you are unfamiliar with ABC music notation, just copy this ABC sequence below
and paste it into the text area of the editor.

- Playing uses the HTML5 audio and/or midi APIs.
	X:1
	T:C scale
	M:C
	L:1/4
	K:C
	CDEF|GABc|

- With the editor, if you want to render ABC files
  which contain `%%abc-include`, you must:
  - load the ABC file from the browse button
  - click in the include file name
  - load the include file by the same browse button  
If your ABC files contain `%%abc-include`, then you must:

  - load the ABC file using the browse button,
  - click the include file name button,
  - and load the include file using the same previous browse button.  

  Then, you may edit and save both files.  
  There may be only one included file.
Only one included file is allowed.

- The editor comes with different ways to enter the music from the keyboard.  
  If you have a US keyboard, you may try these bookmarklets:
<a href="javascript:(function(){if(typeof%20loadjs=='function'){loadjs('abckbd-1.js')}else{alert('use%20with%20abc2svg%20editor')}})();void(0)">keyboard 1</a>
If you have a US keyboard, its behaviour can be changed for easier music
entering by one of these bookmarklets:
<a href="javascript:(function(){if(typeof%20abc2svg.loadjs=='function'){abc2svg.loadjs('abckbd-1.js')}else{alert('use%20with%20abc2svg%20editor')}})()"
title="Copy me">keyboard 1</a>
and
<a href="javascript:(function(){if(typeof%20loadjs=='function'){loadjs('abckbd2-1.js')}else{alert('use%20with%20abc2svg%20editor')}})();void(0)">keyboard 2</a>
<a href="javascript:(function(){if(typeof%20abc2svg.loadjs=='function'){abc2svg.loadjs('abckbd2-1.js')}else{alert('use%20with%20abc2svg%20editor')}})()"
title="Copy me">keyboard 2</a>.

#### 1.3 Publishing music on your web pages
- The .js and .xhtml file names have a suffix which is the version of
  the core interface (actually '`-1`').

To insert music in your web pages, you just have to insert the lines

	<script src="http://moinejf.free.fr/js/abcweb-1.js"></script>
	<script src="http://moinejf.free.fr/js/snd-1.js"></script>

in the HTML &lt;head&gt; and put the music as
ABC sequences in the &lt;body&gt;.
### nodeJS usage

[This example][4] demonstrates how to do it.
(Note that, in the example, the paths are relative - see why below.)

[4]: http://moinejf.free.fr/abcm2ps-doc/tabac.xhtml "J'ai du bon tabac"
Installed via **npm**, the **abc2svg** package comes with the
command line (batch) programs `abc2svg` and `abc2odt`.

As it is apparent, HTML and ABC can be mixed in the same html file.
Both are rendered in the order you defined them.

You may also have noticed this CSS about SVG elements:  
`        svg { display: block }`

This permits to have the music on separate vertical areas.  
Without this CSS, the music is in-lined as in [this other example][5].
These ones may be used as **abcm2ps** to generate XHTML or ODT files.   

[5]: http://moinejf.free.fr/abcm2ps-doc/dansou-i.html "Tune index example"

Global ABC parameters may be added as `parameter=value` in the query string
of the URL of the page. The [following example][16] calls the same
"J'ai du bon tabac" with `pagescale=1.2` (giving `%%pagescale 1.2`).
`abc2svg` writes to standard output:   
`        abc2svg mytunes.abc > Out.xhtml`

[16]: http://moinejf.free.fr/abcm2ps-doc/tabac.xhtml?pagescale=1.2 "J'ai du bon tabac"

In the above examples, all the ABC music is generated (displayed
and ready to be played) by means of the script **abcweb-1.js**.  
If there is a large collection of tunes, it may be preferable to
link to the other script, **abcweb1-1.js**, which permits you
to select particular tune(s). Without an explicit
selection (see below), a list of the tunes is displayed, and,
after a tune has been selected, the whole page is replaced by the music.
(The HTML code, if any, is not displayed.)
A menu on the top right corner of the screen
permits to get the tune list again. Here is [a real example][6].

[6]: http://moinejf.free.fr/abc/boyvin-2-2.html "J. Boyvin organ tunes"
`abc2odt` output is `abc.odt` or the file specified
by the command line argument `-o`:   
`        abc2odt my_file.abc -o my_file.odt`

As you may note in the menu, the edition of the ABC content is proposed.
This permits, for example, to transpose the tunes.
This edition is done inside the browser, so, your changes will be lost
after leaving the page.

When accessing such pages, an external selection of the tunes
can be accomplished by ending the URL with the character '`#`'
followed by a [regular expression][7]
to be applied to the tune headers.
For instance, here is the ['Duo' de J. Boyvin][8].

### Build
[7]: https://en.wikibooks.org/wiki/Regular_Expressions "Regular expressions"
[8]: http://moinejf.free.fr/abc/boyvin-2-2.html#T:Duo "Duo"

If you want to build the **abc2svg** scripts in your machine,
you must first get the files from
[chisel](https://chiselapp.com/user/moinejf/repository/abc2svg),
either as a tarball or a Zip archive
(click `Timeline` and then in the top commit),
In the first example ("J'ai du bon tabac"), you saw that care
should be taken with regard to the special XML characters
'&lt;', '&gt;' and '&amp;' by enclosing
the ABC sequences inside XML comments.

With any of the above scripts the music may be printed using
the 'Print' button of the browser. You should add a style as:  
`       @media print{body{margin:0;padding:0;border:0}.nop{display:none}}`  

to remove the margins, the error messages and the menus from the
printed pages.

or by cloning the repository in some directory:
#### 1.4 Installing abc2svg on your system or on your server

> `fossil clone https://chiselapp.com/user/moinejf/repository/abc2svg abc2svg.fossil`   
> `fossil open abc2svg.fossil`
The **abc2svg** package on my server is still being tuned
which could change its behaviour at any unknown time; so you may
prefer to install and run it from your own system. 

There are many ways to install abc2svg:
Then, building is done using the tool [ninja](https://ninja-build.org/)
or [samurai](https://github.com/michaelforney/samurai).  
You may do it:

- [Guido Gonzato's page](http://abcplus.sourceforge.net/#abc2svg)  
  Guido maintains a ZIP archive of the abc2vg scripts after
  each release of a new version (many thanks, Guido!).  
  You can just download and unzip this archive. **abc2svg** should
  run immediately in your machine without connecting to my site.  
  In the same page, you can also find some binaries for the fastest
  javascript interpreter (QuickJS - see below).

- without minification  
  This is interesting for debug purpose, the scripts being more human friendly.
- tarball  
  From the timeline in the [chisel repository][13], you can get a tarball
  any version of the abc2svg source and install it in your system.  
  The abc2svg scripts must then be built from the raw source files
  described in the section 'Build' below.  
  The disadvantage of this approach is that if you want
  to use an other or newer version you need to download a new tarball.

[13]: https://chiselapp.com/user/moinejf/repository/abc2svg/timeline)

- fossil clone  
  If you can get the fossil program (one binary) for your system,
  you may clone the chisel repository by  
  `        fossil clone https://chiselapp.com/user/moinejf/repository/abc2svg abc2svg.fossil`  
  `        fossil open abc2svg.fossil`  
  and get the abc2svg source files containing the last changes
  between the official versions. Updating your files is done by  
  `        NOMIN=1 samu -v`
  `        fossil pull`  
  `        fossil update`  
  Building the scripts is done in the same way as with a tarball.  
  The repository is presently over 23Mb.

- in a standard way with minification  
  For those unfamiliar with [fossil][14], it is an integrated
  In this case, you need the tool `uglifyjs` which comes with nodeJS.
  software management system similar to [git](https://git-scm.com/).  
  Chisel acts like a repository similar to [github](https://github.com/).

  `        samu -v`
[14]: https://fossil-scm.org/home/doc/trunk/www/index.wiki

- npm  
  The scripts may be installed from the `npm` repository by:  
  `        npm install abc2svg`  
  They are ready to run (web and shell with nodejs).
  I upload a new npm version about once a month.
If you also want to change or add music glyphs, you may edit the source
file `font/abc2svg.sfd`. In this case, you will need both `base64` and `fontforge`,
and run

Using bookmarklets with a local installation does not work directly
because of a cross-domain security hole, but this is possible by running
a local HTTP server (you will also have to change the location
of the scripts in the bookmarklet code).

If you have write access on a remote server, you may put there
the abc2svg scripts. There is no automatic process to do that.
You will have to
[look at my site](http://moinejf.free.fr/js/ "all abc2svg scripts")
to determine the files that need to be copied.

In addition, you have to set the correct location of the abc2svg scripts
in your pages. As a trick, I put the abc2svg scripts in a folder
at the same level as the HTML files:

`        samu -v font.js`
`        <script src="../js/abcweb-1.js"></script>`

This allows the generation of the music to run either locally
or remotely.
If you cannot or don't want to install `ninja` or `samurai`, you may build

the abc2svg files by `./build` which is a shell script.
### 2. Automatic creation of music sheets

### Batch
#### 2.1 abc2svg shell scripts

After building the **abc2svg** scripts, you will be able to generate music
sheets from the command line as you did with `abcm2ps`, thanks to the
following shell scripts (the result goes to stdout):  
As you have seen, printing the music can be done easily with any web browser.
You can automate the process of creating music sheets
with **abc2svg** using shell scripts running a Javascript interpreter.

The interfaces to the various scripts are different. Below you will
find various scripts that I had to built.
- `abcqjs` with `qjs` 
   ([QuickJS by Fabrice Bellard and Charlie Gordon](https://bellard.org/quickjs/))

- `abcqjs` with `qjs` [QuickJS by Fabrice Bellard and Charlie Gordon][10]
- `abcjs24` with `js24` (Mozilla JavaScript shell - Spidermonkey)
- `abcjs52` with `js52` (Mozilla JavaScript shell - Spidermonkey)
- `abcjs60` with `js60` (Mozilla JavaScript shell - Spidermonkey)
- `abcjsc` with `jsc-1` (webkitgtk2)
- `abcv8` with `d8` (Google libv8)
- `abcnode` with `node` (nodeJS)
- `abcv8` with `d8` (Google libv8)
- `abcnode` with `node` (nodeJS without module)
- `abc2svg` with `node` (nodeJS with modules)

[10]: https://bellard.org/quickjs/

Each script gets the abc2svg options and ABC files from the command line
and sends the generated file to `stdout` and possible errors to `stderr`.  
The general syntax of the command line is:  
`        script [script.js] [options] ABC_file [[options] ABC_file]* [options]`
with:

- `script.js` is an optional backend script.  
  It defaults to `tohtml.js` (HTML+SVG)
- `options` are the ABC options.  
  For compatibility, the last options are moved before the last ABC file.

#### backend scripts
#### 2.2 Backend scripts

By default, the batch scripts generate (XHTML+SVG) files.   
By default, the shell scripts generate (HTML+SVG) files.  
This output may be modified by backend scripts. These ones must appear
just after the command.   
There are:
immediately following the name of the shell script.  
They are:

- `toabc.js`   
  This script outputs back the (selected) ABC tunes of the ABC source file.   
  Transposition is applied.   
  The resulting file does not contain the formatting parameters.   
  Example:   
- `toabc.js`  
  This script returns the (selected) ABC tunes from the ABC source file  
  applying transposition.  
  The resulting file does not contain the formatting parameters.  
  Example:  
  `        abcqjs toabc.js my_file.abc --select X:2 > tune_2.abc`

- `toabw.js`   
  This script outputs a Abiword file (ABW+SVG) which may be read by some
  word processors (abiword, libreoffice...) and converted to many other
  formats by the batch function of abiword.   
- `toabw.js`  
  This script outputs an Abiword file (ABW+SVG) that can be read by some
  word processors (abiword, libreoffice...). The word processor allows
  you to convert the file to many other formats from a command line.  
  The abc2svg music font (`abc2svf.woff` or `abc2svg.ttf`) must be installed
  in the local system for displaying and/or converting the .abw file.   
  Example:   
  in the local system for displaying and/or converting the .abw file.  
  Example:  
  `        abcv8 toabw.js my_file.abc > my_file.abw`

- `tomei.js`   
  This script outputs the music as a [MEI](https://music-encoding.org/) file.   
  Indeed, only one tune may be translated from ABC to MEI (multi-tunes ABC
- `tomei.js`  
  This script outputs the music as a [MEI](https://music-encoding.org/) file.  
  Note, only one tune may be translated from ABC to MEI (multi-tunes ABC
  generates bad MEI).

- `toodt.js`   
  This script creates an Open Document (ODT+SVG) which may be read by most
  word processors (abiword, libreoffice...).   
  It runs only with the npm script `abc2svg` and asks for the npm module
  `jszip` to be installed.   
  The output ODT document may be specified by the command line argument `-o`
  (default `abc.odt`).   
  Example:   
- `toodt.js`  
  This script creates an Open Document (ODT+SVG) which can be read by most
  word processors (abiword, libreoffice...).  
  It runs only with the shell script `abc2svg` and asks for the npm module
  `jszip` to be installed.  
  The output ODT document may be specified in the command line argument
  after `-o` (default `abc.odt`).  
  Example:  
  `        abc2svg toodt.js my_file.abc -o my_file.odt`

- `toparam.js`   
- `toparam.js`  
  This script just outputs the abc2svg parameters.

#### PDF generation
#### 2.3 PDF generation

`abctopdf` is a shell script which converts ABC to PDF using one of the
previous shell scripts and, either a chrome/chromium compatible web browser
(settable by the environment variable 'BROWSER'),
or the program [weasyprint](https://weasyprint.org/) or
previous shell scripts and the program `rsvg-convert`.   
As a constraint, the used music font must be installed and defined by
`%%musicfont <fontname>`.   
Example:   
the program `rsvg-convert`.

With `rsvg-convert`, the used music font must be installed and defined by
`%%musicfont <fontname>`.

Note also that, with `weasyprint` or `rsvg-convert`, the paper size is
forced to A4. Instructions for changing this size may be found in the
script source.

The output PDF document may be specified by the command line argument `-o`
(default `abc.pdf`).

Example:  
`        abctopdf my_file.abc -o my_file.pdf`

### 3. Build

The abc2svg scripts which are used to render the music
either by a web browser or by a shell script must be built from
the source files you got by tarball or fossil clone.

Quoting [Douglas Crockford](https://www.crockford.com/jsmin.html),
minification is a process that removes comments and unnecessary whitespace from
JavaScript files. It typically reduces file size by half, resulting in
faster downloads.

If you can run one of the tools [ninja](https://ninja-build.org/)
or [samurai](https://github.com/michaelforney/samurai), you can build
the scripts

- without minification  
  This is useful for debugging purposes and the scripts are more human friendly.

  `        NOMIN=1 samu -v`

   or

  `        NOMIN=1`  
  `        export NOMIN`  
  `        ninja -v`

- in a standard way with minification  
  In this case, you need one of the tools
  [JSMin](https://www.crockford.com/jsmin.html) or
 `uglifyjs` which comes with nodeJS.

  `        samu -v`

If you also want to change or add music glyphs, you may edit the source
file `font/abc2svg.sfd`.
In this case, you will need both `base64` and `fontforge`, and run

`        samu -v font.js`

If you cannot or don't want to install `ninja` or `samurai`, you may build
the abc2svg files by the shell script `./build`.
(This script must be run by a Posix compatible shell.)

### 4. Inside the code of abc2svg

#### 4.1 Core and modules

`abc2svg-1.js` is the **abc2svg** core.  
It contains the ABC parser and the SVG generation engine.
It is needed for all music rendering. It is automatically loaded
by the web scripts and the shell scripts.  
If you want to use the core with your own scripts,
its API is described in the [wiki][11].

[11]: https://chiselapp.com/user/moinejf/repository/abc2svg/wiki?name=interface-1

The core does not handle all the abc2svg commands/parameters.
Some of them are treated by modules.
A module is a script which is loaded in the browser or in the JS interpreter
when the command it treats is seen in the ABC flow.  
Detailed information about the modules may be found in the [wiki][12].

[12]: https://chiselapp.com/user/moinejf/repository/abc2svg/wiki?name=modules

#### 4.2 Internal information

- The music is displayed as SVG images. There is one image per
  music line / text block.  
  If you want to move these images to some other files,
  each one must contain the full CSS and defs. For that, insert  
  `        %%fullsvg x`  
  in the ABC file before rendering (see the
  [fullsvg documentation](http://moinejf.free.fr/abcm2ps-doc/fullsvg.xhtml)
  for more information).

- Playing uses the HTML5 audio and/or the midi APIs.  
  For audio, by default, abc2svg uses a sound font (format SF2)
  which is split into one file
  per instrument. This sound font is stored in the subdirectory `Scc1t2/`.
  Each instrument file is a base64 encoded javascript array.

  Other sound fonts may be used. Some of them are stored in the subdirectory
  `sf2/` (`AWE_ROM_gm` and `2MBGMGS`). Two formats are supported: raw SF2 and
  SF2 wrapped into javascript (the raw SF2 files can be loaded
  only when they are in the same HTTP domain).
  The shell script `sf.sh` (in `sf2/`) may be used to create the javacript files
  from raw SF2 files.  
  The sound font to be used for playing may be defined in the ABC code
  by the command `%%soundfont`. E.g.:  
  `        %%soundfont http://moinejf.free.fr/js/sf2/AWE_ROM_gm.js`

- The names of the abc2svg scripts have a suffix which is the version of
  the core interface (actually '`-1`').

#### 4.3 More about the web scripts

Here are the scripts which are used in a web context:

- `abcweb-1.js`  
  This script replaces the ABC or MEI sequences found in the (X)HTML file
  by SVG images of the music. The ABC sequences may start on `X:` or `%abc-`
  at start of line, and stop on any XML tag also at start of line
  (see below for MEI).
  They may also appear after a (X)HTML element of the class "abc"
  (lower case letters) or inside a &lt;script&gt; with a type
  ["text/vnd.abc"](https://www.iana.org/assignments/media-types/text/vnd.abc)
  (the script element is removed from the page).  
  When a ABC sequence is not included in a &lt;script&gt; and when it contains
  the characters '<', '>' or '&',
  it must be enclosed in a XML comment or in a CDATA
  (%&lt;![CDATA[ .. %]]&gt; - the comment or CDATA must be in a ABC comment).  
  See the
  [%%beginml documentation](http://moinejf.free.fr/abcm2ps-doc/beginml.xhtml)
  for an example, and here is [how to put inline music in HTML][15].   
  Playing and highlighting the played notes may be offered loading
  the script `snd-1.js` (see below).

[15]: http://moinejf.free.fr/abcm2ps-doc/inline.html "abc2svg - inline music"

- `abcweb1-1.js`  
  This script replaces all the page body by music as SVG images.  
  As with abcweb-1.js, the music sequences start on `X:` or `%abc`
  at start of line, stop on any ML tag, a XML comment must be used
  when there are special XML characters, and playing is possible.  
  When there are many tunes in the file, the script displays a list
  of the tunes. The list step may be bypassed when the URL of the file
  contains a regular expression in the 'hash' value ('#' followed by
  a string at the end of the URL).
  This string does a
  [%%select](http://moinejf.free.fr/abcm2ps-doc/select.xhtml).  
  When one or many tunes are displayed, a menu in the top/right corner
  offers to go back to the tune list or to modify the ABC source.
  
- `snd-1.js`  
  This script may be used with `abcweb{,1}-1.js` to play the rendered
  ABC music.  

- `abcdoc-1.js`  
  This script is mainly used for ABC documentation.
  It lets the ABC source sequences in the page before the SVG images.  
  See the source of
  [abcm2ps/abc2svg features](http://moinejf.free.fr/abcm2ps-doc/features.xhtml)
  for an example.

### MEI support
### 5. MEI support

As an experimental feature, an extented core `mei2svg-1.js` may be generated.
This one may handle both the ABC and [MEI](https://music-encoding.org/) notations.
This one may handle both the ABC and
[MEI](https://music-encoding.org/ "Music Encoding Initiative")
notations.

In browser mode, the script `abcemb-1.js` loads either abc2svg-1.js or
mei2svg-1.js after checking the music notation type (`%abc` or `X:` is ABC,
In browser mode, the script `abcweb-1.js` loads either `abc2svg-1.js` or
`mei2svg-1.js` after checking if `<mei` exists in the page (see
`<mei` is MEI - see
[this tune](http://moinejf.free.fr/abc/Czerny_op603_6.html) for an example).
[this tune](http://moinejf.free.fr/abc/Czerny_op603_6.html)
for an example).

In batch mode, the script `abcqjs` also loads the right abc2svg core
In shell mode, the script `abcqjs` also loads the right abc2svg core
according to the source file extension (`.abc` or `.mei`).

### 6. Credit

**abc2svg** includes the following packages:

- wps by Tomas Hlavaty  
  <http://logand.com/sw/wps/log.html>

- JavaScript SoundFont 2 Parser by imaya/GREE Inc and Colin Clark  
  <https://github.com/colinbdclark/sf2-parser>

- Scc1t2  
  <http://www.ibiblio.org/thammer/HammerSound/localfiles/soundfonts/>

- strftime by T. H. Doan  
  <https://thdoan.github.io/strftime/>

[Jean-François Moine](http://moinejf.free.fr)
Changes to abc2odt.
1
2
3
4
5
6
7
8
9
10
11
12

13
14

15
16
17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11

12
13

14
15

16
17
18
19
20
21
22











-
+

-
+

-







#! /usr/bin/env node

// abc2odt

// define the system functions
    var	sep = require('path').sep

function usage() {
	abc2svg.printErr('ABC to ODT translator with\
 abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abc2odt [g_options] ABC_file [f_options] [ABC_file [f_options]]* [-o output_file]\n\
  abc2odt [options] ABC_file [[options] ABC_file]* [options] [-o output_file]\n\
Arguments:\n\
  g_options   global ABC options\n\
  options     ABC options (the last options are moved before the last file)\n\
  ABC_file    ABC file\n\
  f_options   file options\n\
  output_file output file - default is "./abc.odt"')
	abc2svg.quit()
}

// load the abc2svg core
var m = require("abc2svg/abc2svg-1");
global.abc2svg = m.abc2svg;
︙
Changes to abc2svg.
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

1
2
3
4
5
6
7













8
9
10
11
12
13
14
-
+






-
-
-
-
-
-
-
-
-
-
-
-
-







#! /usr/bin/env node
#!/usr/bin/env node

// abc2svg with native nodeJS

// define the system functions
    var	sep = require('path').sep

function usage() {
	abc2svg.printErr('ABC translator with Node.js\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abc2svg [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
	abc2svg.quit()
}

// load the abc2svg core
var m = require("abc2svg/abc2svg-1");
global.abc2svg = m.abc2svg;
global.Abc = m.Abc;

// interpreter specific functions
abc2svg.print = function(str) {
︙
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55


56
57
58













59







-
+










-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
+
		geval(abc2svg.readFile(__dirname + sep + fn))
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
			abc2svg.printErr('Cannot read file ' + fn)
	}
}

// load the command line
m = require("abc2svg/cmdline");
global.user = m.user;
global.abc_cmd = m.abc_cmd

// main
var args = process.argv
if (!args[2])
	usage();
args.shift();
args.shift()

// if the first argument is a script, load it
if (/\.js$/.test(args[0])) {
    var fn = args[0][0] == '/' ? args[0] : (__dirname + '/' + args[0]),
	f = abc2svg.readFile(fn);
	eval(f);
	args.shift()
}

// if no rendering engine, load xhtml
if (typeof(abc2svg.abc_init) != 'function')
	require("abc2svg/toxhtml");

abc_cmd("nodeJS", args)
abc_cmd("nodeJS", args, "Node.js")
Changes to abc2svg.ttf.

cannot compute difference between binary files

Changes to abcjs24.
1
2
3
4
5
6
7

8

9
10
11


12
13

14
15

16
17
18


19
20
21


22
23
24
25
26
27
28
29
30
31
32


33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

1
2
3
4


5
6

7
8


9
10
11

12


13
14


15
16
17


18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36

37



















38




-
-

+
-
+

-
-
+
+

-
+
-
-
+

-
-
+
+

-
-
+
+










-
+
+

+



-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
#!/usr/bin/env js24
// abc2svg with js24 (Mozilla JavaScript shell - Spidermonkey
//		packages: debian: libmozjs-24-bin, voidlinux: mozjs24)

loadRelativeToScript("abc2svg-1.js")

// interpreter specific functions
var abc2svg = {
abc2svg.print = function(str) {
    print: function(str) {
	print(str)
}
abc2svg.printErr = function(str) {
    },
    printErr: function(str) {
	printErr(str)
}
    },

abc2svg.quit = function() {
    quit: function() {
	quit(1)
}
abc2svg.readFile = function(fname) {
    },
    readFile: function(fname) {
	return read(fname)
}
abc2svg.loadjs = function(fn, relay, onerror) {
    },
    loadjs: function(fn, relay, onerror) {
	try {
		loadRelativeToScript(fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
	}
} // loadjs()
    } // loadjs()
} // abc2svg

loadRelativeToScript("abc2svg-1.js")
loadRelativeToScript("cmdline.js")

// main
	var	args = scriptArgs

	if (/\.js$/.test(args[0])) {
		load(args[0])
		args.shift()
	}
	if (typeof abc2svg.abc_init != 'function')
		loadRelativeToScript("toxhtml.js")
	if (!args[0]) {
		printErr('ABC translator with js24 (SpiderMonkey)\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcjs24 [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		quit()
	}
	abc_cmd("abcjs24", args)
	abc_cmd("abcjs24", scriptArgs, "js24 (SpiderMonkey)")
Changes to abcjs52.
1
2
3
4
5
6
7

8

9
10
11


12
13

14
15

16
17
18


19
20
21


22
23
24
25
26
27
28
29
30
31
32


33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

1
2
3
4


5
6

7
8


9
10
11

12


13
14


15
16
17


18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36

37



















38




-
-

+
-
+

-
-
+
+

-
+
-
-
+

-
-
+
+

-
-
+
+










-
+
+

+



-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
#!/usr/bin/env js52
// abc2svg with js52 (Mozilla JavaScript shell - Spidermonkey
//		packages: debian: libmozjs-52-dev, voidlinux: mozjs52)

loadRelativeToScript("abc2svg-1.js")

// interpreter specific functions
var abc2svg = {
abc2svg.print = function(str) {
    print: function(str) {
	print(str)
}
abc2svg.printErr = function(str) {
    },
    printErr: function(str) {
	printErr(str)
}
    },

abc2svg.quit = function() {
    quit: function() {
	quit(1)
}
abc2svg.readFile = function(fname) {
    },
    readFile: function(fname) {
	return read(fname)
}
abc2svg.loadjs = function(fn, relay, onerror) {
    },
    loadjs: function(fn, relay, onerror) {
	try {
		loadRelativeToScript(fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
	}
} // loadjs()
    } // loadjs()
} // abc2svg

loadRelativeToScript("abc2svg-1.js")
loadRelativeToScript("cmdline.js")

// main
	var	args = scriptArgs

	if (/\.js$/.test(args[0])) {
		load(args[0])
		args.shift()
	}
	if (typeof abc2svg.abc_init != 'function')
		loadRelativeToScript("toxhtml.js")
	if (!args[0]) {
		printErr('ABC translator with js52 (SpiderMonkey)\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcjs52 [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		quit()
	}
	abc_cmd("abcjs52", args)
	abc_cmd("abcjs52", scriptArgs, "js52 (SpiderMonkey)")
Changes to abcjs60.
1
2
3
4
5
6
7

8

9
10
11


12
13

14
15

16
17
18


19
20
21


22
23
24
25
26
27
28
29
30
31
32


33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

1
2
3
4


5
6

7
8


9
10
11

12


13
14


15
16
17


18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36

37



















38




-
-

+
-
+

-
-
+
+

-
+
-
-
+

-
-
+
+

-
-
+
+










-
+
+

+



-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
#!/usr/bin/env js60
// abc2svg with js60 (Mozilla JavaScript shell - Spidermonkey
//		packages: debian: libmozjs-60-dev, voidlinux: mozjs60)

loadRelativeToScript("abc2svg-1.js")

// interpreter specific functions
var abc2svg = {
abc2svg.print = function(str) {
    print: function(str) {
	print(str)
}
abc2svg.printErr = function(str) {
    },
    printErr: function(str) {
	printErr(str)
}
    },

abc2svg.quit = function() {
    quit: function() {
	quit(1)
}
abc2svg.readFile = function(fname) {
    },
    readFile: function(fname) {
	return read(fname)
}
abc2svg.loadjs = function(fn, relay, onerror) {
    },
    loadjs: function(fn, relay, onerror) {
	try {
		loadRelativeToScript(fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
	}
} // loadjs()
    } // loadjs()
} // abc2svg

loadRelativeToScript("abc2svg-1.js")
loadRelativeToScript("cmdline.js")

// main
	var	args = scriptArgs

	if (/\.js$/.test(args[0])) {
		load(args[0])
		args.shift()
	}
	if (typeof abc2svg.abc_init != 'function')
		loadRelativeToScript("toxhtml.js")
	if (!args[0]) {
		printErr('ABC translator with js60 (SpiderMonkey)\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcjs60 [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		quit()
	}
	abc_cmd("abcjs60", args)
	abc_cmd("abcjs60", scriptArgs, "js60 (SpiderMonkey)")
Changes to abcjsc.
︙
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43

44

45
46
47


48
49
50


51
52
53


54
55
56


57
58
59
60
61
62
63
64
65

66


67
68


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
28
29
30
31
32
33
34

35
36
37
38
39
40


41
42

43
44


45
46
47


48
49
50


51
52
53


54
55
56
57
58
59
60
61
62
63

64
65
66
67


68
69
70
71
72



















73
74
75
76
77
78
79
80







-
+





-
-

+
-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+








-
+

+
+
-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







//								(b3 & 0x3f))
//				}
//			} else {
//				fout += String.fromCharCode(((b1 & 0x1f) << 6) +
//							(b2 & 0x3f))
//			}
//		} else {
//			fout += fin[i]
//			fout += String.fromCharCode(b1)
//		}
//	}
//	return fout
//}

load(progdir + 'abc2svg-1.js')

// interpreter specific functions
var abc2svg = {
abc2svg.print = function(str) {
    print: function(str) {
	print(str)
}
abc2svg.printErr = function(str) {
    },
    printErr: function(str) {
	printErr(str)
}
abc2svg.quit = function() {
    },
    quit: function() {
	quit(1)
}
abc2svg.readFile = function(fname) {
    },
    readFile: function(fname) {
	return read(fname)
}
abc2svg.loadjs = function(fn, relay, onerror) {
    },
    loadjs: function(fn, relay, onerror) {
	try {
		load(progdir + fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			print('Cannot read file ' + fn)
			printErr('Cannot read file ' + fn)
	}
    } // loadjs()
} // abc2svg
}


load(progdir + 'abc2svg-1.js')
load(progdir + 'cmdline.js')

function main(args) {
	if (/\.js$/.test(args[0])) {
		load(args[0])
		args.shift()
	}
	if (!args[0]) {
		print('ABC translator with jsc (webkit2gtk)\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcjsc [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  script to load - default: toxhtml.js (XHTML+SVG generation)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		quit()
	}
	if (typeof(abc2svg.abc_init) != 'function')
		load(progdir + 'toxhtml.js')
	abc_cmd('abcjsc', args)
	abc_cmd('abcjsc', args, 'jsc (webkit2gtk)')
}

if (typeof arguments == 'undefined')
	var arguments = ''

main(arguments)
" -- "$@"
Changes to abcnode.
1
2

3
4
5

6
7
8



9
10
11
12
13


14
15
16
17
18
19
20


1
2
3

4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
-
-
+


-
+



+
+
+



-
-
+
+







#!/bin/sh
# abc2svg with raw nodeJS
:;# abc2svg with raw nodeJS
progdir=`dirname $0`

cat ${progdir}/abc2svg-1.js > /tmp/toto.js
cat ${progdir}/abc2svg-1.js ${progdir}/cmdline.js > /tmp/toto.js
case $1 in
	*.js)
		cat $1 >> /tmp/toto.js
		if grep 'abc2svg.abc_init =' "$1" > /dev/null; then
			x="no"
		fi
		shift
		;;
esac
if ! grep 'abc2svg.abc_init =' "$1" > /dev/null; then
	cat ${progdir}/toxhtml.js >> /tmp/toto.js
if [ "x$x" != 'xno' ]; then
	cat ${progdir}/tohtml.js >> /tmp/toto.js
fi

cat <<EOF >> /tmp/toto.js
    var	progdir='${progdir}/'

// interpreter specific functions
abc2svg.print = function(str) {
︙
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
53
54
55
56
57
58
59

60



61

62












63
64
65

66
67
68
69







-

-
-
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-



-
+



			abc2svg.printErr('Cannot read file ' + fn)
	}
}

// (this file is wrapped)
global.Abc = Abc
global.abc2svg = abc2svg
EOF

cat ${progdir}/cmdline.js >> /tmp/toto.js

cat <<EOF >> /tmp/toto.js
// main
	var args = process.argv
    var	args = process.argv
	if (!args[2]) {
		abc2svg.print('ABC translator with nodeJS\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcnode [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options');
		abc2svg.quit(1)
	}
	args.shift()
	args.shift()
	global.user = user;		// (for modules/page.js)
	abc_cmd("abcnode", args)
	abc_cmd("abcnode", process.argv, "nodeJS")
EOF

node /tmp/toto.js "$@"
Changes to abcqjs.
1
2
3
4

5
6
7
8
9
10

11
12

13
14

15














































16

17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112

113
114
115
116
1
2
3

4
5



6

7


8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67

68




























































69
70























71


72
73
74
75
76



-
+

-
-
-

-
+
-
-
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+









-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+




:;# shell script to convert ABC or MEI music notation to other format
# using abc2svg and quickjs (https://bellard.org/quickjs/)

test -f /tmp/abcqjs.js && exec qjs --std /tmp/abcqjs.js $0 "$@"
exec qjs --std -e '

cat > /tmp/abcqjs.js << EOF
//javascript

    var	i,
	args = scriptArgs
	args = scriptArgs,
	args.shift()		// remove '/tmp/abcqjs.js'
    var	core = "abc2svg-1.js",
	core = "abc2svg-1.js",
	path = args.shift().	// the 1st argument is the script name
			match(/(.*\/).*/)
			match(/.*\//)

// interpreter specific functions
function load(fn) {
	return std.loadScript(fn)
}
var abc2svg = {
	print: function(str) {
		print(str)
	},
	printErr: function(str) {
		std.err.printf("%s\n", str)
	},
	quit: function() {
		std.exit(1)
	},
	readFile: function(fname) {
	    var	f, b

		f = std.open(fname, "r")
		if (!f)
			return ""

		b = f.readAsString()
		f.close()
		return b
	}, // readfile()
	get_mtime: function(fn) {
		return new Date(os.stat(fn)[0].mtime)
	},
	loadjs: function(fn, relay, onerror) {
		try {
			load(fn[0] == "/" ? fn : (path + fn))
		} catch(e) {
			if (onerror)
				onerror()
			else
				abc2svg.printErr("Cannot read file " + fn +
					"\n  " + e.name + ": " + e.message)
			return
		}
		if (relay)
			relay()
	} // loadjs()
} // abc2svg

// --- main ---

	path = path ? path[1] : ""
	path = path ? path[0] : ""

	i = args.length
	while (--i >= 0) {
		if (/\.mei$/.test(args[i])) {
			core = "mei2svg-1.js"
			break
		}
	}

std.loadScript(path + core)
	load(path + core)

// interpreter specific functions
function load(fn) {
	return std.loadScript(fn)
}
abc2svg.print = function(str) {
	print(str)
}
abc2svg.printErr = function(str) {
	std.err.printf("%s\n", str)
}

abc2svg.quit = function() {
	std.exit(1)
}
abc2svg.readFile = function(fname) {
    var	l, f,
	b = "",
	bt = "",
	cnt = 30

	try {
		f = std.open(fname, "r")
	} catch(e) {
		return ""
	}

	while (1) {
		if (--cnt < 0) {
			cnt = 30
			bt += b
			b = ""
		}
		l = f.getline()
		if (l == null)
			break
		b += l + "\n"
	}
	f.close()
	return bt + b
} // readfile()

abc2svg.get_mtime = function(fn) {
	return new Date(os.stat(fn)[0].mtime)
}

abc2svg.loadjs = function(fn, relay, onerror) {
	try {
		std.loadScript(path + fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
	}
} // loadjs()

std.loadScript(path + "cmdline.js")
	load(path + "cmdline.js")

// main
	if (/\.js$/.test(args[0])) {
		if (args[0][0] == "/")
			std.loadScript(args[0])
		else
			std.loadScript(path + args[0])
		args.shift()
	}
	if (typeof abc2svg.abc_init != 'function')
		std.loadScript(path + "toxhtml.js")
	if (!args[0]) {
		abc2svg.printErr('ABC translator with quickjs\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcqjs [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		abc2svg.quit()
	}
	abc_cmd("abcqjs", args)
	abc_cmd("abcqjs", args, "QuickJS")
EOF
exec qjs --std /tmp/abcqjs.js $0 "$@"
' $0 "$@"

The previous solution with the shebang line as
#!/usr/bin/env -S qjs --std
did not work with non-GNU versions of env
Changes to abctopdf.
1






2




3

4
5






6
7
8
9
10
11

12
13

14
15
16
17
18
19
20
21
22

1
2
3
4
5
6
7
8
9
10
11

12
13

14
15
16
17
18
19
20
21
22
23
24

25
26

27
28

29
30
31
32
33
34
35
-
+
+
+
+
+
+

+
+
+
+
-
+

-
+
+
+
+
+
+





-
+

-
+

-







#!/bin/sh
:;# abctopdf
# convert ABC to PDF using abc2svg and one of
#	- a chrome/chromium compatible web browser
#	  (if not found, set its name in the environment variable 'BROWSER')
#	- weasyprint (https://weasyprint.org/)
#	- rsvg-convert (https://wiki.gnome.org/Projects/LibRsvg)
#
# Note: when weasyprint or rsvg-convert are used,
#	this script forces A4 as the paper size.
#	For an other size, change
#		'size: A4' and '--pageheight 29.7cm' with weasyprint
# abctopdf - converts ABC to PDF using abc2svg
#		'%%pageheight 29.7cm' with rsvg-convert
#
# Copyright (C) 2019 Jean-François Moine - License GPL3+
# Copyright (C) 2019-2020 Jean-François Moine - License GPL3+

# set a browser
if [ x$BROWSER = x ]; then
	BROWSER=chromium
fi

if [ $# -eq 0 ]; then
	cat << EOF
ABC to PDF translator using abc2svg
Usage:
  abctopdf [g_options] ABC_file [f_options] [ABC_file [f_options]]* [-o output_file]
  abctopdf [options] ABC_file [[options] ABC_file] [options] [-o output_file]
Arguments:
  g_options   global ABC options
  options     ABC options (the last options are moved before the last file)
  ABC_file    ABC file
  f_options   file options
  output_file output file - default is "./abc.pdf"
EOF
	exit 1
fi

# choose a abc2svg batch script with an available JS interpreter
if [ ${0#./} != $0 ]; then
︙
71
72
73
74
75
76
77
78
79

80
81
82
83
84



85
86
87
88




















































89
90
91
92
93
94
95
84
85
86
87
88
89
90


91
92
93



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159







-
-
+


-
-
-
+
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	else
		set -- "$@" "$a"
	fi
	shift
done

# check if some chromium-based browser is available
# test rsvg-convert
for c in chromium-browser vivaldi opera brave-browser epic google-chrome; do
for c in $BROWSER chromium-browser vivaldi opera brave-browser epic google-chrome; do
	if command -v $c >/dev/null 2>&1; then
		echo "and $c"
		command $abcscr "$@" > /tmp/o.xhtml
		$c --headless --disable-gpu --print-to-pdf=$out /tmp/o.xhtml
		rm /tmp/o.xhtml
		command $abcscr "$@" > /tmp/o.html
		$c --headless --disable-gpu --print-to-pdf=$out /tmp/o.html
		rm /tmp/o.html
		exit 0
	fi
done

# try weasyprint
if command -v weasyprint >/dev/null 2>&1; then
	echo "and weasyprint"

	rm -f /tmp/abc*.svg

# generate a (HTML+SVG) file
# then, extract the SVG images (pages) to /tmp/ and build a file.html
	cat > /tmp/abc.html <<EOF
<!DOCTYPE html>
<meta charset="utf-8"/>
<style>
@page {
 size: A4;
 margin: 0;
}
</style>
<body>
EOF
n=0
command $abcscr --pageheight 29.7cm --fullsvg 1 --musicfont abc2svg "$@" | while read v; do
	case "$v" in
	"<svg"*)
		n=$(($n+1))
		fn="/tmp/abc$n.svg"
		echo $v > $fn
		echo "<img src=\"/tmp/abc${n}.svg\"/>" >> /tmp/abc.html
		;;
	"</svg"*)
		echo $v >> $fn
		fn=
		;;
	"</body"*)
		break;;
	*)
		if [ "X$fn" != "X" ]; then
			echo $v >> $fn
		else
			echo $v >> /tmp/abc.html
		fi
		;;
	esac
done
	echo '</body>' >> /tmp/abc.html

echo weasyprint -f pdf /tmp/abc.html $out
	weasyprint -f pdf /tmp/abc.html $out
	rm -f /tmp/abc*.svg /tmp/abc.html
	exit 0
fi

# last chance with rsvg-convert
# check the required programs
if ! command -v rsvg-convert >/dev/null 2>&1; then
	echo "$0: program 'rsvg-convert' not found - abort"
	exit 1
fi
echo "and rsvg-convert"

︙
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167





168
169
170
171
172
173
174
175
176
177


178
179
180
181

182
183
184
185
186
187
188
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260







+











-
+




















+
+
+
+
+










+
+



-
+







// - front-end
	fix_out = abc2svg.page.img_out
	abc2svg.page.img_out = function(page, p) {
		fix_out(page, font_bug(p))
	}
// - back-end
    var	page_h, page_out,
	page_cl = "",
	page_sty = ""

	// get the style from the image and remove it from the block
	function get_style(p) {
	    var	i,
		sty = p.match(/<style.*?>((.|\n)*?)<\/style>/)

		if (!sty)
			return p
		sty = sty[1].split('\n')
		if (!page_sty)
			page_sty = '<style type="text/css">\n</style>\n'
			page_sty = '<style>\n</style>\n'
		for (i = 0; i < sty.length; i++) {
			if (page_sty.indexOf(sty[i]) < 0)
				page_sty = page_sty.replace('</style>\n',
						sty[i] + '\n</style>\n')
		}
		return p.replace(/<style(.|\n)*?\/style>\n/, '')
	} // get_style()

	// low level output
	abc.page.user_out = function(p) {
	    var	h, w,
		cfmt = abc.cfmt()

		switch (p.slice(0, 4)) {
		case "<div":			// new page
			page_h = 0
			page_out = ""
			break
		case "<svg":			// SVG image
			p = get_style(p)
			if (!page_cl) {
				h = p.match(/<svg(.|\n)*?class="([^"]*)"[^>]*>/) // "
				if (h)
					page_cl = h[2]
			}
			page_out += p
			    .replace(/<svg(.|\n)*?>/,
				'<g transform="translate(0, ' +
					page_h.toFixed(1) + ')">')
			    .replace('</svg>', '</g>\n')
			page_h += Number(p.match(/height="(\d+)px"/)[1])
			break
		case "</di":			// end of page
			w = cfmt.pagewidth
			h = cfmt.pageheight
			if (!page_cl)
				page_cl = "music"	// old version
			abc2svg.print('\
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
 xmlns:xlink="http://www.w3.org/1999/xlink"\n\
 color="black" class="music" stroke-width=".7"\n\
 color="black" class="' + page_cl + '" stroke-width=".7"\n\
 width="' +
				(w * .75).toFixed(0) + 'px" height="' +
				(h * .75).toFixed(0) + 'px" viewBox="0 0 ' +
					w.toFixed(0) + ' ' +
					h.toFixed(0) + '"' +
				(cfmt.bgcolor ?
					(' style="background-color: ' +
︙
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286







-
+







}
%%endjs
EOF

# purge /tmp
rm -f /tmp/abc*.svg

# generate a (XHTML+SVG) file with a abc2svg batch script
# generate a (HTML+SVG) file with a abc2svg batch script
# then, extract the SVG images (pages) to /tmp
n=0
command $abcscr /tmp/fix.abc "$@" | while read v; do
	case "$v" in
	"<svg"*)
		n=$(($n+1))
		fn="/tmp/abc$n.svg"
︙
Changes to abcv8.
1
2
3
4
5

6
7
8
9

10
11
12
13
14
15
16
17
18


























19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
1
2
3
4

5
6


7
8









9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50





















51
52




-
+

-
-

+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

#!/bin/sh
# abc2svg with d8 (libv8 Google)
progdir=`dirname $0`

exec d8 -e "var args='$*', progdir='${progdir}/'
exec d8 -e "var args='$*', path='${progdir}/'

load(progdir + 'abc2svg-1.js');

// interpreter specific functions
var abc2svg = {
abc2svg.print = function(str) {
	print(str)
}
abc2svg.quit = function() {
	quit(1)
}
abc2svg.readFile = function(fname) {
	return read(fname)
}
	print: function(str) {
		print(str)
	},
	quit: function() {
		quit(1)
	},
	readFile: function(fname) {
		return read(fname)
	}, // readfile()
	loadjs: function(fn, relay, onerror) {
		try {
			load(fn[0] == '/' ? fn : (path + fn))
			if (relay)
				relay()
		} catch(e) {
			if (onerror)
				onerror()
			else
				printErr('Cannot read file ' + fn)
		}
	} // loadjs()
} // abc2svg

load(path + 'abc2svg-1.js');

// interpreter specific functions
abc2svg.loadjs = function(fn, relay, onerror) {
	try {
		load(progdir + script)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			print('Cannot read file ' + fn)
	}
}

load(progdir + 'cmdline.js')
load(path + 'cmdline.js')

// main
	args = args.split(/\s+/)
	if (/\.js$/.test(args[0])) {
		load(args[0])
		args.shift()
	}
	if (typeof(abc2svg.abc_init) != 'function')
		load(progdir + 'toxhtml.js')

	if (!args[0]) {
		print('ABC translator with d8 (Google v8 shell)\
 and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
  abcv8 [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
  script.js  generation script to load - default: toxhtml.js (XHTML+SVG)\n\
  g_options  global ABC options\n\
  ABC_file   ABC file\n\
  f_options  file options')
		quit()
	}
	abc_cmd('abcv8', args)
	abc_cmd('abcv8', args.split(/\s+/), 'd8 (Google v8 shell)')
"
Changes to build.
1
2

3
4





















5
6
7
8

9
10

11
12
13
14
15








16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

























33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48














49
50
51
52
53




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43

















44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71













72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-
-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+

-
+





+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+





+
+
#!/bin/sh
# simple build of abc2svg as a shell script
:;# simple build of abc2svg as a shell script

MAJOR=1

# use jsmin if available
if command -v jsmin >/dev/null 2>&1; then
# binary program
gen() {
 cat "$@" | jsmin
}
elif command -v qjs >/dev/null 2>&1; then
# script using QuickJS
if [ ! -f jsmin-min.js ] || [ jsmin-min.js -ot jsmin.js ]; then
	qjs --std jsmin.js < jsmin.js > jsmin-min.js
fi
gen() {
 cat "$@" | qjs --std jsmin-min.js
}
else
# no minify
gen() {
 cat "$@"
}
fi

out=abc2svg-$MAJOR.js
VERSION=`grep '"version"' package.json|cut -d'"' -f4`
DATE=`date '+%Y-%m-%d' -r package.json`
DATE=`date -r package.json '+%Y-%m-%d'`
cp core/license $out
cat core/abc2svg.js core/deco.js core/draw.js\
gen core/abc2svg.js core/deco.js core/draw.js\
 font.js core/format.js core/front.js core/music.js core/parse.js core/subs.js\
 core/svg.js core/tune.js core/lyrics.js core/gchord.js core/tail.js\
 core/modules.js >> $out
 echo "abc2svg.version=\"$VERSION\";abc2svg.vdate=\"$DATE\"" >> $out

out=mei2svg-$MAJOR.js
cp core/license $out
gen core/abc2svg.js core/deco.js core/draw.js\
 font.js core/format.js core/front.js core/music.js core/parse.js core/subs.js\
 core/svg.js core/tune.js core/lyrics.js core/gchord.js core/mei.js core/tail.js\
 core/modules.js >> $out
 echo "abc2svg.version=\"$VERSION\";abc2svg.vdate=\"$DATE\"" >> $out

cp modules/ambitus.js ambitus-$MAJOR.js
cp modules/break.js break-$MAJOR.js
cp modules/capo.js capo-$MAJOR.js
cat util/midi.js modules/clair.js >> clair-$MAJOR.js
cp modules/clip.js clip-$MAJOR.js
cp modules/combine.js combine-$MAJOR.js
cp modules/diag.js diag-$MAJOR.js
cp modules/equalbars.js equalbars-$MAJOR.js
cp modules/grid.js grid-$MAJOR.js
cp modules/grid2.js grid2-$MAJOR.js
cp modules/MIDI.js MIDI-$MAJOR.js
cat modules/page.js modules/strftime.js > page-$MAJOR.js
cp modules/perc.js perc-$MAJOR.js
cat modules/wps.js modules/psvg.js > psvg-$MAJOR.js
cp modules/soloffs.js soloffs-$MAJOR.js
cp modules/sth.js sth-$MAJOR.js
cp modules/temper.js temper-$MAJOR.js
gen modules/ambitus.js > ambitus-$MAJOR.js
gen modules/break.js > break-$MAJOR.js
gen modules/capo.js > capo-$MAJOR.js
gen modules/chordnames.js > chordnames-$MAJOR.js
gen modules/clair.js > clair-$MAJOR.js
gen modules/clip.js > clip-$MAJOR.js
gen modules/combine.js > combine-$MAJOR.js
gen modules/diag.js > diag-$MAJOR.js
gen modules/equalbars.js > equalbars-$MAJOR.js
gen modules/gamelan.js > gamelan-$MAJOR.js
gen modules/grid.js > grid-$MAJOR.js
gen modules/grid2.js > grid2-$MAJOR.js
gen modules/grid3.js > grid3-$MAJOR.js
gen modules/jazzchord.js > jazzchord-$MAJOR.js
gen modules/jianpu.js > jianpu-$MAJOR.js
gen modules/mdnn.js > mdnn-$MAJOR.js
gen modules/MIDI.js > MIDI-$MAJOR.js
gen modules/page.js modules/strftime.js > page-$MAJOR.js
gen modules/pedline.js > pedline-$MAJOR.js
gen modules/perc.js > perc-$MAJOR.js
gen modules/wps.js modules/psvg.js > psvg-$MAJOR.js
gen modules/soloffs.js > soloffs-$MAJOR.js
gen modules/sth.js > sth-$MAJOR.js
gen modules/strtab.js > strtab-$MAJOR.js
gen modules/temper.js > temper-$MAJOR.js

cp editor/edit.css edit-$MAJOR.css

cp util/abcdoc.js abcdoc-$MAJOR.js
cp util/abcemb.js abcemb-$MAJOR.js
cp util/abcemb1.js abcemb1-$MAJOR.js
cp util/abcemb2.js abcemb2-$MAJOR.js
cp util/abcweb2.js abcweb2-$MAJOR.js
cp util/follow.js follow-$MAJOR.js
cp util/json.js json-$MAJOR.js
cp util/midi.js setmidi-$MAJOR.js
cp util/toaudio.js toaudio-$MAJOR.js
cat util/play.js util/toaudio.js util/toaudio5.js util/midi.js\
 util/sf2-parser.js util/tomidi5.js > play-$MAJOR.js
cat util/play.js util/sndgen.js util/sndaud.js util/midi.js\
 util/sf2-parser.js util/sndmid.js > snd-$MAJOR.js
gen util/abcdoc.js > abcdoc-$MAJOR.js
gen util/abcemb.js > abcemb-$MAJOR.js
gen util/abcemb1.js > abcemb1-$MAJOR.js
gen util/abcemb2.js > abcemb2-$MAJOR.js
gen util/abcweb.js > abcweb-$MAJOR.js
gen util/abcweb1.js > abcweb1-$MAJOR.js
gen util/abcweb.js > abcweb2-$MAJOR.js
gen util/chord.js > chord-$MAJOR.js
gen util/json.js > json-$MAJOR.js
gen util/toaudio.js > toaudio-$MAJOR.js
gen util/play.js util/toaudio.js util/toaudio5.js\
 util/sf2-parser.js util/tomidi5.js util/follow.js > play-$MAJOR.js
gen util/play.js util/sndgen.js util/sndaud.js\
 util/sf2-parser.js util/sndmid.js util/follow.js > snd-$MAJOR.js

sed "s+@MAJOR@+$MAJOR+" editor/edit.xhtml > edit-$MAJOR.xhtml
sed "s+@MAJOR@+$MAJOR+" editor/abckbd.js > abckbd-$MAJOR.js
sed "s+@MAJOR@+$MAJOR+" editor/abckbd2.js > abckbd2-$MAJOR.js
sed "s+@MAJOR@+$MAJOR+" editor/edit.js > edit-$MAJOR.js

touch follow-$MAJOR.js
Changes to build.ninja.
1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







# rules for ninja (ninja-build)
# rules for ninja (ninja-build) or samurai

# minifying with 'jsmin' or 'uglifyjs' may be disabled by running
#	NOMIN=1 ninja -v

MAJOR=1

# ninja tool
︙
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-
+







-
+







   echo '// abc2svg music font' > font.js;$
   echo "var musicfont = 'url(\"data:application/octet-stream;base64,\\" >> font.js;$
   base64 abc2svg.ttf | sed 's/$$/\\/' >> font.js;$
   echo "\") format(\"truetype\")'" >> font.js

rule jsc
  command = VERSION=`grep '"version"' package.json|cut -d'"' -f4`;$
   if command -v fossil >/dev/null 2>&1; then $
   if [ -e .fslckout ] && command -v fossil >/dev/null 2>&1; then $
	c=`fossil info | grep checkout:`;$
	t=`fossil info | grep tags: | awk '{print $$NF}'`;$
	if [ "$${t#v}" != "$$VERSION" ]; then $
		VERSION="$${VERSION}-$$(echo $$c | cut -d' ' -f2 | cut -c1-10)";$
	fi;$
	DATE=`echo $$c | cut -d' ' -f3`;$
   else $
	DATE=`date '+%Y-%m-%d' -r package.json`;$
	DATE=`date -r package.json '+%Y-%m-%d'`;$
   fi;$
   cp core/license $out;$
   if [ "x$$NOMIN" = "x" ]; then $
      if command -v jsmin >/dev/null 2>&1; then $
	cat $in | jsmin >> $out;$
      else $
	cat $in | uglifyjs >> $out;$
︙
94
95
96
97
98
99
100

101

102
103
104
105

106
107




108
109

110
111
112
113

114
115
116
117
118
119
120
121


122
123


124
125
126
127
128

129
130

131
132
133
134
135
136
137
138
139

140
141
142
143
144








145
146
147
148
149
150
151
152
153
154

155
156
157
158
159





94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131


132
133
134

135
136

137
138

139
140
141
142
143
144
145
146
147

148





149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176







+
-
+




+


+
+
+
+


+




+








+
+
-
-
+
+

-


-
+

-
+








-
+
-
-
-
-
-
+
+
+
+
+
+
+
+









-
+





+
+
+
+
+
 font.js core/format.js core/front.js core/music.js core/parse.js core/subs.js $
 core/svg.js core/tune.js core/lyrics.js core/gchord.js core/mei.js core/tail.js $
 core/modules.js | package.json

build ambitus-$MAJOR.js: jscu modules/ambitus.js
build break-$MAJOR.js: jscu modules/break.js
build capo-$MAJOR.js: jscu modules/capo.js
build chordnames-$MAJOR.js: jscu modules/chordnames.js
build clair-$MAJOR.js: jscu util/midi.js modules/clair.js
build clair-$MAJOR.js: jscu modules/clair.js
build clip-$MAJOR.js: jscu modules/clip.js
build combine-$MAJOR.js: jscu modules/combine.js
build diag-$MAJOR.js: jscu modules/diag.js
build equalbars-$MAJOR.js: jscu modules/equalbars.js
build gamelan-$MAJOR.js: jscu modules/gamelan.js
build grid-$MAJOR.js: jscu modules/grid.js
build grid2-$MAJOR.js: jscu modules/grid2.js
build grid3-$MAJOR.js: jscu modules/grid3.js
build jazzchord-$MAJOR.js: jscu modules/jazzchord.js
build jianpu-$MAJOR.js: jscu modules/jianpu.js
build mdnn-$MAJOR.js: jscu modules/mdnn.js
build MIDI-$MAJOR.js: jscu modules/MIDI.js
build page-$MAJOR.js: jscu modules/page.js modules/strftime.js
build pedline-$MAJOR.js: jscu modules/pedline.js
build perc-$MAJOR.js: jscu modules/perc.js
build psvg-$MAJOR.js: jscu modules/wps.js modules/psvg.js
build soloffs-$MAJOR.js: jscu modules/soloffs.js
build sth-$MAJOR.js: jscu modules/sth.js
build strtab-$MAJOR.js: jscu modules/strtab.js
build temper-$MAJOR.js: jscu modules/temper.js

build edit-$MAJOR.css: cp editor/edit.css

build abcdoc-$MAJOR.js: jscu util/abcdoc.js
build abcemb-$MAJOR.js: jscu util/abcemb.js
build abcemb1-$MAJOR.js: jscu util/abcemb1.js
build abcemb2-$MAJOR.js: jscu util/abcemb2.js
build abcweb-$MAJOR.js: jscu util/abcweb.js
build abcweb1-$MAJOR.js: jscu util/abcweb1.js
build abcweb2-$MAJOR.js: jscu util/abcweb2.js
build follow-$MAJOR.js: jscu util/follow.js
build abcweb2-$MAJOR.js: jscu util/abcweb.js
build chord-$MAJOR.js: jscu util/chord.js
build json-$MAJOR.js: jscu util/json.js
build setmidi-$MAJOR.js: jscu util/midi.js
build toaudio-$MAJOR.js: jscu util/toaudio.js
build play-$MAJOR.js: jscu util/play.js util/toaudio.js $
 util/toaudio5.js util/midi.js util/sf2-parser.js util/tomidi5.js
 util/toaudio5.js util/sf2-parser.js util/tomidi5.js util/follow.js
build snd-$MAJOR.js: jscu util/play.js util/sndgen.js $
 util/sndaud.js util/midi.js util/sf2-parser.js util/sndmid.js
 util/sndaud.js util/sf2-parser.js util/sndmid.js util/follow.js

build edit-$MAJOR.xhtml: cpm editor/edit.xhtml
build abckbd-$MAJOR.js: edit editor/abckbd.js
build abckbd2-$MAJOR.js: edit editor/abckbd2.js
build edit-$MAJOR.js: edit editor/edit.js

build all: phony abc2svg-$MAJOR.js abcdoc-$MAJOR.js $
 abcemb-$MAJOR.js abcemb1-$MAJOR.js abcemb2-$MAJOR.js $
 abcweb2-$MAJOR.js $
 abcweb-$MAJOR.js abcweb1-$MAJOR.js abcweb2-$MAJOR.js chord-$MAJOR.js $
 json-$MAJOR.js $
 setmidi-$MAJOR.js toaudio-$MAJOR.js snd-$MAJOR.js play-$MAJOR.js psvg-$MAJOR.js $
 ambitus-$MAJOR.js break-$MAJOR.js capo-$MAJOR.js clair-$MAJOR.js clip-$MAJOR.js $
 combine-$MAJOR.js diag-$MAJOR.js equalbars-$MAJOR.js grid-$MAJOR.js grid2-$MAJOR.js $
 MIDI-$MAJOR.js page-$MAJOR.js perc-$MAJOR.js soloffs-$MAJOR.js sth-$MAJOR.js $
 json-$MAJOR.js toaudio-$MAJOR.js snd-$MAJOR.js play-$MAJOR.js psvg-$MAJOR.js $
 ambitus-$MAJOR.js break-$MAJOR.js capo-$MAJOR.js $
 chordnames-$MAJOR.js clair-$MAJOR.js clip-$MAJOR.js $
 combine-$MAJOR.js diag-$MAJOR.js equalbars-$MAJOR.js gamelan-$MAJOR.js $
 grid-$MAJOR.js grid2-$MAJOR.js grid3-$MAJOR.js jianpu-$MAJOR.js $
 jazzchord-$MAJOR.js  mdnn-$MAJOR.js $
 MIDI-$MAJOR.js page-$MAJOR.js pedline-$MAJOR.js perc-$MAJOR.js $
 soloffs-$MAJOR.js sth-$MAJOR.js strtab-$MAJOR.js $
 temper-$MAJOR.js edit-$MAJOR.css edit-$MAJOR.js edit-$MAJOR.xhtml $
 abckbd-$MAJOR.js abckbd2-$MAJOR.js follow-$MAJOR.js
# not mei2svg-$MAJOR.js

default all

# npm/fossil new release
rule version
  command = npm version $out;$
	tag=`ag '"version"' package.json|cut -d'"' -f4`;$
	tag=`ag -Q '"version"' package.json|cut -d'"' -f4`;$
	fossil commit -m "New release v$$tag" -tag v$$tag;$
	$tool -v;$
	npm publish
build minor: version
build patch: version

# temporary
rule nul
  command = touch $out
build follow-$MAJOR.js: nul
Changes to cmdline.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23



24
25
26
27
28
29
30














31
32
33
34
35
36
37
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24

25





26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


-
+


















-
-
+
+
+
-

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







// abc2svg - cmdline.js - command line
//
// Copyright (C) 2014-2018 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

// user definitions
var user = {
	read_file: function(fn) {	// include a file (%%abc-include)
	    var	file = abc2svg.readFile(fn),
	read_file: function(fn) {	// read a file (main or included)
	    var	i,
		file = abc2svg.readFile(fn)
		i = file.indexOf('\r')

		if (i < 0)
			return file	// standard
		if (file[i + 1] == '\n')
			return file.replace(/\r\n/g, '\n')	// M$
		return file.replace(/\r/g, '\n')		// Mac
		if (!file)
			return file
		i = file.indexOf('\r')
		if (i >= 0) {
			if (file[i + 1] == '\n')
				file =  file.replace(/\r\n/g, '\n')	// M$
			else
				fike =  file.replace(/\r/g, '\n')	// Mac
		}

		// load the required modules (synchronous)
		abc2svg.modules.load(file)

		return file
	},
	errtxt: ''
}

	// print or store the error messages
	if (typeof abc2svg.printErr == 'function')
		user.errmsg = function(msg, l, c) { abc2svg.printErr(msg) }
︙
54
55
56
57
58
59
60

61

62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88









































89
90
91
92
93
94
95
96
97
98
99
100
101




102
103
104
105
106

107
108
109
110
111




112
113
114
115
116
117



118
119

120
121
122
123
124
125
126
127
128
129
130
131
63
64
65
66
67
68
69
70

71


72
73
74
75
76
77
78
79
80
81
82
83
84



85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157





158
159
160
161

162




163
164
165


166




167
168
169
170
171
172
173
174







+
-
+
-
-
+












-
-
-








-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













+
+
+
+




-
+
-
-
-
-
-
+
+
+
+
-

-
-
-
-
+
+
+
-
-
+
-
-
-
-








			fn += ".abc"
			try {
				file = user.read_file(fn)
			} catch (e) {
			}
		}
	}
	if (!file) {
	if (!file && fn != "default.abc") {
		if (fn != "default.abc")
//		abc2svg.abort(new Error("Cannot read file '" + fn + "'"))
		user.errmsg("Cannot read file '" + fn + "'")
			user.errmsg("Cannot read file '" + fn + "'")
		return
	}
//	if (typeof(utf_convert) == "function")
//		file = utf_convert(file)

	if (fn.slice(-4) == ".mei") {
		if (!abc.mei2mus)
			abc2svg.abort(new Error("No MEI support"));
		abc.mei2mus(file)
		return
	}

	// load the required modules (synchronous)
	abc2svg.modules.load(file)

	// generate
	try {
		abc.tosvg(fn, file)
	} catch (e) {
		abc2svg.abort(e)
	}
} // do_file()

function abc_cmd(cmd, args) {
function abc_cmd(cmd, args, interp_name) {
	var	arg, parm, fn;

	abc2svg.abort = function(e) {
		abc2svg.printErr('javascript error: ' + e.message +
			'\nStack:\n'  + e.stack)
		abc2svg.quit()
	} // abort()

	// put the last options before the last file
	function arg_reorder(a) {
	    var	f,
		i = a.length - 2

		while (i > 2 && a[i].slice(0, 2) == '--')
			i -= 2
		f = a[--i]
		a.splice(i, 1)
		a.push(f)
	} // arg_reorder()

	// if the first argument is a javascript file, load it
	if (/\.js$/.test(args[0])) {
		abc2svg.loadjs(args[0])
		args.shift()
	}

	if (!args[0]) {
		abc2svg.printErr('ABC translator with ' + interp_name +
			' and abc2svg-' + abc2svg.version + ' ' +
					abc2svg.vdate +
			'\nUsage:\n  ' + cmd +
		    ' [script.js] [options] ABC_file [[options] ABC_file]* [options]\n\
Arguments:\n\
  script.js  generation script to load - default: tohtml.js (HTML+SVG)\n\
  options    ABC options (the last options are moved before the last file)\n\
  ABC_file   ABC file')
		abc2svg.quit()
	}

	// the default output is HTML+SVG
	if (typeof abc2svg.abc_init != 'function')
		abc2svg.loadjs("tohtml.js")

	// initialize the backend
	abc = new abc2svg.Abc(user)
	if (typeof global == "object" && !global.abc)
		global.abc = abc
	abc2svg.abc_init(args)

	// load 'default.abc'
	try {
		do_file("default.abc")
	} catch (e) {
	}

	// put the last options before the last ABC file
	if (args.length > 2 && args[args.length - 2].slice(0, 2) == '--')
		arg_reorder(args)

	while (1) {
		arg = args.shift()
		if (!arg)
			break
		if (arg[0] == "-") {
		if (arg[0] == "-" && arg[1] == "-") {
			if (arg[1] == "-") {
				parm = args.shift();
				parm = arg.replace('--', 'I:') + " " + parm + "\n"
				abc2svg.modules.load(parm);
				abc.tosvg(cmd, parm)
			parm = arg.replace('--', 'I:') + " " +
				args.shift() + "\n"
			abc2svg.modules.load(parm)
			abc.tosvg(cmd, parm)
			}
		} else {
			if (fn) {
				do_file(fn);
				abc.tosvg('cmd', '%%select\n')
			}
			do_file(arg)
			abc.tosvg('cmd', '%%select\n')
		}
			fn = arg
		}
	}
	}
	if (fn)
		do_file(fn);

	abc2svg.abc_end()
}

// nodejs
if (typeof module == 'object' && typeof exports == 'object') {
	exports.user = user;
	exports.abc_cmd = abc_cmd
}
Changes to core/abc2svg.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - abc2svg.js
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
53
54
55
56
57
58
59






60
61
62
63
64
65
66
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72







+
+
+
+
+
+







	// slur/tie types (3 + 1 bits)
	SL_ABOVE: 0x01,
	SL_BELOW: 0x02,
	SL_AUTO: 0x03,
	SL_HIDDEN: 0x04,
	SL_DOTTED: 0x08		// (modifier bit)
    };

// !! tied to the symbol types in abc2svg.js !!
abc2svg.sym_name = ['bar', 'clef', 'custos', '', 'grace',
		'key', 'meter', 'Zrest', 'note', 'part',
		'rest', 'yspace', 'staves', 'Break', 'tempo',
		'', 'block', 'remark']

	// key table - index = number of accidentals + 7
abc2svg.keys = [
	new Int8Array([-1,-1,-1,-1,-1,-1,-1 ]),	// 7 flat signs
	new Int8Array([-1,-1,-1, 0,-1,-1,-1 ]),	// 6 flat signs
	new Int8Array([ 0,-1,-1, 0,-1,-1,-1 ]),	// 5 flat signs
	new Int8Array([ 0,-1,-1, 0, 0,-1,-1 ]),	// 4 flat signs
︙
137
138
139
140
141
142
143


















































144
145
146
147
148
149
150
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







} // b40p()
abc2svg.b40a = function(b) {
	return abc2svg.b40_a[b % 40]
} // b40a()
abc2svg.b40m = function(b) {
	return ((b / 40) | 0) * 12 + abc2svg.b40_m[b % 40]
} // b40m()

// chord table
// This table is used in various modules
// to convert the types of chord symbols to a minimum set.
// More chord types may be added by the command %%chordalias.
abc2svg.ch_alias = {
	"maj": "",
	"min": "m",
	"-": "m",
	"°": "dim",
	"+": "aug",
	"+5": "aug",
	"maj7": "M7",
	"Δ7": "M7",
	"Δ": "M7",
	"min7": "m7",
	"-7": "m7",
	"ø7": "m7b5",
	"°7": "dim7",
	"min+7": "m+7",
	"aug7": "+7",
	"7+5": "+7",
	"7#5": "+7",
	"sus": "sus4",
	"7sus": "7sus4"
} // ch_alias

// simplify a rational number n/d
abc2svg.rat = function(n, d) {
    var	a, t,
	n0 = 0,
	d1 = 0,
	n1 = 1,
	d0 = 1
	while (1) {
		if (d == 0)
			break
		t = d
		a = (n / d) | 0
		d = n % d
		n = t
		t = n0 + a * n1
		n0 = n1
		n1 = t
		t = d0 + a * d1
		d0 = d1
		d1 = t
	}
	return [n1, d1]
} // rat()

// compare pitches
// This function is used to sort the note pitches
abc2svg.pitcmp = function(n1, n2) { return n1.pit - n2.pit }

// start of the Abc object
abc2svg.Abc = function(user) {
︙
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198


199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292







+











-
+
+








-
+



















-
+







	CM = 37.8,		// 1 inch = 2.54 centimeter
	YSTEP = 256		/* number of steps for y offsets */

// error texts
var errs = {
	bad_char: "Bad character '$1'",
	bad_grace: "Bad character in grace note sequence",
	bad_transp: "Bad transpose value",
	bad_val: "Bad value in $1",
	bar_grace: "Cannot have a bar in grace notes",
	ignored: "$1: inside tune - ignored",
	misplaced: "Misplaced '$1' in %%score",
	must_note: "!$1! must be on a note",
	must_note_rest: "!$1! must be on a note or a rest",
	nonote_vo: "No note in voice overlay",
	not_ascii: "Not an ASCII character",
	not_enough_n: 'Not enough notes/rests for %%repeat',
	not_enough_m: 'Not enough measures for %%repeat',
	not_enough_p: "Not enough parameters in %%map",
	not_in_tune: "Cannot have '$1' inside a tune"
	not_in_tune: "Cannot have '$1' inside a tune",
	notransp: "Cannot transpose with a temperament"
}

    var	self = this,				// needed for modules
	glovar = {
		meter: {
			type: C.METER,		// meter in tune header
			wmeasure: 1,		// no M:
			a_meter: []		// default: none
		}
		},
	},
	info = {},			// information fields
	parse = {
		ctx: {},
		prefix: '%',
		state: 0,
		ottava: [],
		line: new scanBuf
	},
	tunes = [],		// first time symbol and voice array per tune for playing
	psvg			// PostScript

// utilities
function clone(obj, lvl) {
	if (!obj)
		return obj
	var tmp = new obj.constructor
	for (var k in obj)
	    if (obj.hasOwnProperty(k)) {
		if (lvl && typeof obj[k] == 'object')
		if (lvl && typeof obj[k] != "number")
			tmp[k] = clone(obj[k], lvl - 1)
		else
			tmp[k] = obj[k]
	    }
	return tmp
}

︙
271
272
273
274
275
276
277





278
279
280
281
282
283
284
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347







+
+
+
+
+







}

function error(sev, s, msg, a1, a2, a3, a4) {
	var i, j, regex, tmp

	if (!sev && cfmt.quiet)
		return
	if (s) {
		if (s.err)		// only one error message per symbol
			return
		s.err = true
	}
	if (user.textrans) {
		tmp = user.textrans[msg]
		if (tmp)
			msg = tmp
	}
	if (arguments.length > 3)
		msg = msg.replace(/\$./g, function(a) {
︙
325
326
327
328
329
330
331
332

333
334
335
388
389
390
391
392
393
394

395
396
397
398







-
+




	error(sev, s, msg, a1, a2, a3, a4)
}

// inject javascript code
function js_inject(js) {
	if (!/eval *\(|Function|setTimeout|setInterval/.test(js))
		eval('"use strict"\n' + js)
		eval('"use strict";\n' + js)
	else
		syntax(1, "Unsecure code")
}
Changes to core/deco.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


































19
20
21
22
23
24
25
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







// abc2svg - deco.js - decorations
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// Decoration objects
// dd {			// decoration definition (static)
//	dd_en,			// definition of the ending decoration
//	dd_st,			// definition of the starting decoration
//	func,			// function
//	glyph,			// glyph
//	h,			// height / ascent
//	hd,			// descent
//	inv,			// inverted glyph
//	name,			// name
//	str,			// string
//	wl,			// left width
//	wr,			// right width
// }
// de {			// decoration elements (in an array - one list per music line)
//	dd,			// definition of the decoration
//	defl {			// flags
//		noen,			// no end of this decoration
//		nost,			// no start of this decoration
//	},
//	has_val,		// defined value
//	ix,			// index of the decoration in the 'de' list
//	lden,			// end of a long decoration
//	ldst,			// start of a long decoration if true
//	m,			// note index when note decoration
//	prev,			// previous decoration (hack for 'tr~~~~~')
//	s,			// symbol
//	start,			// start of the decoration (in the ending element)
//	up,			// above the symbol
//	val,			// value
//	x,			// x offset
//	y,			// y offset
// }

var	dd_tb = {},		// definition of the decorations
	a_de			// array of the decoration elements

// decorations - populate with standard decorations
var decos = {
	dot: "0 stc 5 1 1",
︙
68
69
70
71
72
73
74
75
76


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92


93
94
95
96
97
98
99
102
103
104
105
106
107
108


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124


125
126
127
128
129
130
131
132
133







-
-
+
+














-
-
+
+







	"D.S.": "3 dsgn 16 10 10",
	"D.C.alcoda": "3 dacs 16 38 38 D.C. al Coda",
	"D.S.alcoda": "3 dacs 16 38 38 D.S. al Coda",
	"D.C.alfine": "3 dacs 16 38 38 D.C. al Fine",
	"D.S.alfine": "3 dacs 16 38 38 D.S. al Fine",
	fine: "3 dacs 16 10 10 Fine",
	turn: "3 turn 10 0 5",
	"trill(": "3 ltr 8 0 0",
	"trill)": "3 ltr 8 0 0",
	"trill(": "3 ltr 8 4 0",
	"trill)": "3 ltr 8 4 0",
	f: "6 f 18 1 7",
	ff: "6 ff 18 2 10",
	fff: "6 fff 18 4 13",
	ffff: "6 ffff 18 6 16",
	mf: "6 mf 18 6 13",
	mp: "6 mp 18 6 16",
	p: "6 p 18 2 8",
	pp: "6 pp 18 5 14",
	ppp: "6 ppp 18 8 20",
	pppp: "6 pppp 18 10 25",
	pralltriller: "3 umrd 10 5 5",
	sfz: "6 sfz 18 4 10",
	ped: "4 ped 18 6 10",
	"ped-up": "4 pedoff 12 4 4",
	"ped(": "4 lped 20 1 1",
	"ped)": "4 lped 20 1 1",
	"ped(": "4 lped 20 5 5",
	"ped)": "4 lped 20 5 5",
	"crescendo(": "6 cresc 18 0 0",
	"crescendo)": "6 cresc 18 0 0",
	"<(": "6 cresc 18 0 0",
	"<)": "6 cresc 18 0 0",
	"diminuendo(": "6 dim 18 0 0",
	"diminuendo)": "6 dim 18 0 0",
	">(": "6 dim 18 0 0",
︙
124
125
126
127
128
129
130
131









132
133
134
135
136
137
138
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180







-
+
+
+
+
+
+
+
+
+







	rbstop: "37 0 0 0 0",
	"/": "38 0 0 6 6",
	"//": "38 0 0 6 6",
	"///": "38 0 0 6 6",
	"beam-accel": "39 0 0 0 0",
	"beam-rall": "39 0 0 0 0",
	stemless: "40 0 0 0 0",
	rbend: "41 0 0 0 0"},
	rbend: "41 0 0 0 0",
	editorial: "42 0 0 0 0",
	"sacc-1": "3 sacc-1 6,4 4 4",
	sacc3: "3 sacc3 6,5 4 4",
	sacc1: "3 sacc1 6,4 4 4",
	courtesy: "43 0 0 0 0",
	"cacc-1": "3 cacc-1 0 0 0",
	cacc3: "3 cacc3 0 0 0",
	cacc1: "3 cacc1 0 0 0"},

	// types of decoration per function
	f_near = [true, true, true],
	f_note = [false, false, false, true, true, true, false, false, true],
	f_staff = [false, false, false, false, false, false, true, true]

/* -- get the max/min vertical offset -- */
︙
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405







-
+







	if (y > -6 && y < 24) {
		if (up)
			y += 3;
		y = (((y + 6) / 6) | 0) * 6 - 6		/* between lines */
	}
	if (up)
		s.ymx = y + dd.h
	else if (dd.name[0] == 'w')
	else if (dd.name[0] == 'w')		// wedge
		s.ymn = y - dd.h
	else
		s.ymn = y
	de.y = y
	if (s.type == C.NOTE)
		de.x += s.notes[s.stem >= 0 ? 0 : s.nhd].shhd
	if (dd.name[0] == 'd'			/* if dot decoration */
︙
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459





460
461
462
463
464
465
466
487
488
489
490
491
492
493
494
495
496
497
498
499



500
501
502
503
504
505
506
507
508
509
510
511







+





-
-
-
+
+
+
+
+








// special case for long decoration
function d_trill(de) {
	if (de.ldst)
		return
    var	up, y, w, tmp,
	dd = de.dd,
	de2 = de.prev,
		s2 = de.s,
		st = s2.st,
		s = de.start.s,
		x = s.x

	if (de.prev) {			// hack 'tr~~~~~'
		x = de.prev.x + 10;
		y = de.prev.y
	if (de2) {			// same height
		x = de2.s.x + de.dd.wl + 2
		de2.val -= de2.dd.wr
		if (de2.val < 8)
			de2.val = 8
	}
	de.st = st

	if (dd.func != 4) {		// if not below
		switch (dd.glyph) {
		case "8va":
		case "15ma":
︙
477
478
479
480
481
482
483
484
485
486



487
488
489
490
491

492
493
494
495
496
497
498
499
500

501
















502
503
504
505
506
507
508
522
523
524
525
526
527
528



529
530
531
532
533
534


535
536
537
538
539
540

541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568







-
-
-
+
+
+



-
-
+





-



+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			x = de.x - 20 - 3;
			w = 20
		}
	} else {
		w = s2.x - x - 6
		if (s2.type == C.NOTE)
			w -= 6
		if (w < 20) {
			x -= (20 - w) * .5;
			w = 20
		if (w < 10) {
			x -= 10 - w
			w = 10
		}
	}
	dd = de.dd;
	if (!y)
		y = y_get(st, up, x, w)
	y = y_get(st, up, x - dd.wl - 5, w)
	if (up) {
		tmp = staff_tb[s.st].topbar + 2
		if (y < tmp)
			y = tmp
	} else {
		y -= dd.h;
		tmp = staff_tb[s.st].botbar - 2
		if (y > tmp)
			y = tmp
		y -= dd.h
	}
	if (de2) {			// if same height
		if (up) {
			if (y < de2.y)
				y = de2.y	// (only on one note)
		} else {
			if (y >= de2.y) {
				y = de2.y
			} else {
				do {
					de2.y = y
					de2 = de2.prev	// go backwards
				} while (de2)
			}
		}
	}

	de.lden = false;
	de.has_val = true;
	de.val = w;
	de.x = x;
	de.y = y
	if (up)
		y += dd.h;
︙
522
523
524
525
526
527
528
529


530
531
532
533
534
535
536
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597







-
+
+







	if (de.start) {			// if long decoration
		d_trill(de)
		return
	}
	var	yc, up, inv,
		s = de.s,
		dd = de.dd,
		x = s.x,
//		x = s.x,
	x = de.x,
		w = dd.wl + dd.wr,
		stafft = staff_tb[s.st].topbar + 2,
		staffb = staff_tb[s.st].botbar - 2

	if (s.nhd)
		x += s.notes[s.stem >= 0 ? 0 : s.nhd].shhd;
	up = -1
︙
583
584
585
586
587
588
589
590

591
592
593
594
595
596

597
598
599
600

601
602
603
604
605
606
607
644
645
646
647
648
649
650

651
652
653
654
655
656

657
658
659
660

661
662
663
664
665
666
667
668







-
+





-
+



-
+







		break
	default:
		if (dd.name.indexOf("invert") == 0)
			inv = true
		if (dd.name != "invertedfermata"
		 && (up > 0
		  || (up < 0 && s.multi >= 0))) {
			yc = y_get(s.st, true, s.x - dd.wl, w) + 2
			yc = y_get(s.st, true, s.x - dd.wl, w) + 2 + dd.hd
			if (yc < stafft)
				yc = stafft;
			y_set(s.st, true, s.x - dd.wl, w, yc + dd.h);
			s.ymx = yc + dd.h
		} else {
			yc = y_get(s.st, false, s.x - dd.wl, w) - 2
			yc = y_get(s.st, false, s.x - dd.wl, w) - 3 + dd.hd
			if (yc > staffb)
				yc = staffb;
			yc -= dd.h;
			y_set(s.st, false, s.x - dd.wl, w, yc)
			y_set(s.st, false, s.x - dd.wl, w, yc - dd.hd)
			if (dd.name == "fermata")
				inv = true;
			s.ymn = yc
		}
		break
	}
	if (inv) {
︙
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655

656
657
658
659
660
661
662
663
664


665
666
667
668
669
670
671
672
673
674
675






676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694


695
696
697
698
699
700
701
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707
708
709

710
711
712
713
714
715
716

717
718
719
720
721
722
723
724


725
726
727
728
729
730
731
732
733
734



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767







+








-
+









-
+






-
+







-
-
+
+








-
-
-
+
+
+
+
+
+


















-
+
+







	d_pf,		/* 6 - tied to staff (dynamic marks) */
	d_cresc		/* 7 */
]

// add a decoration
/* syntax:
 *	%%deco <name> <c_func> <glyph> <h> <wl> <wr> [<str>]
 * "<h>" may be followed by ",<hd>" (descent)
 */
function deco_add(param) {
	var dv = param.match(/(\S*)\s+(.*)/);
	decos[dv[1]] = dv[2]
}

// define a decoration
function deco_def(nm) {
    var a, dd, dd2, name2, c, i, elts, str,
    var a, dd, dd2, name2, c, i, elts, str, hd,
	text = decos[nm]

	if (!text) {
		if (cfmt.decoerr)
			error(1, null, "Unknown decoration '$1'", nm)
		return //undefined
	}

	// extract the values
	a = text.match(/(\d+)\s+(.+?)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)/)
	a = text.match(/(\d+)\s+(.+?)\s+([0-9.,]+)\s+([0-9.]+)\s+([0-9.]+)/)
	if (!a) {
		error(1, null, "Invalid decoration '$1'", nm)
		return //undefined
	}
	var	c_func = Number(a[1]),
//		glyph = a[2],
		h = parseFloat(a[3]),
		h = a[3],
		wl = parseFloat(a[4]),
		wr = parseFloat(a[5])

	if (isNaN(c_func)) {
		error(1, null, "%%deco: bad C function value '$1'", a[1])
		return //undefined
	}
	if ((c_func < 0 || c_func > 10)
	 && (c_func < 32 || c_func > 41)) {
	if (c_func > 10
	 && (c_func < 32 || c_func > 43)) {
		error(1, null, "%%deco: bad C function index '$1'", c_func)
		return //undefined
	}
	if (c_func == 5)			// old !trill(!
		c_func = 3
	if (c_func == 7)			// old !cresc(!
		c_func = 6

	if (h < 0 || wl < 0 || wr < 0) {
		error(1, null, "%%deco: cannot have a negative value '$1'", text)
		return //undefined
	if (h.indexOf(',') > 0) {
		h = h.split(',')
		hd = h[1]
		h = h[0]
	} else {
		hd = 0
	}
	if (h > 50 || wl > 80 || wr > 80) {
		error(1, null, "%%deco: abnormal h/wl/wr value '$1'", text)
		return //undefined
	}

	// create/redefine the decoration
	dd = dd_tb[nm]
	if (!dd) {
		dd = {
			name: nm
		}
		dd_tb[nm] = dd
	}

	/* set the values */
	dd.func = dd.name.indexOf("head-") == 0 ? 9 : c_func;
	dd.glyph = a[2];
	dd.h = h;
	dd.h = Number(h)
	dd.hd = Number(hd)
	dd.wl = wl;
	dd.wr = wr;
	str = text.replace(a[0], '').trim()
	if (str) {				// optional string
		if (str[0] == '"')
			str = str.slice(1, -1);
		dd.str = str
︙
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
891
892
893
894
895
896
897

898
899
900
901
902
903
904
905







-
+







			for (j = 0; j <= s.nhd; j++)
				s.notes[j].dur *= 2;
			for (j = 0; j <= prev.nhd; j++)
				prev.notes[j].dur *= 2
			continue
		case 35:		/* xstem */
			if (s.type != C.NOTE) {
				error(1, s, "!xstem! must be on a note")
				error(1, s, errs.must_note, dd.name)
				continue
			}
			s.xstem = true;
			continue
		case 36:		/* beambr1 / beambr2 */
			if (s.type != C.NOTE) {
				error(1, s, errs.must_note, dd.name)
︙
864
865
866
867
868
869
870























871
872
873
874
875
876
877
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			continue
		case 40:		/* stemless */
			s.stemless = true
			continue
		case 41:		/* rbend */
			s.rbstop = 2	// with end
			continue
		case 42:		// editorial
			if (!s.notes[0].acc)
				continue
			dcn = "sacc" + s.notes[0].acc.toString() // small accidental
			dd = dd_tb[dcn]
			if (!dd) {
				dd = deco_def(dcn)
				if (!dd) {
					error(1, s, errs.bad_val, "!editorial!")
					continue
				}
			}
			delete s.notes[0].acc
			curvoice.acc[s.notes[0].pit + 19] = 0	// ignore the accidental
			break
		case 43:		// courtesy
			j = curvoice.acc[s.notes[0].pit + 19]
			if (s.notes[0].acc || !j)
				continue
			if (!s.notes[0].a_dcn)
				s.notes[0].a_dcn = []
			s.notes[0].a_dcn.push("cacc" + j)
			continue
		}

		// add the decoration in the symbol
		if (!s.a_dd)
			s.a_dd = []
		s.a_dd.push(dd)
	}
︙
924
925
926
927
928
929
930
931
932


933
934
935
936
937
938
939
1013
1014
1015
1016
1017
1018
1019


1020
1021
1022
1023
1024
1025
1026
1027
1028







-
-
+
+







	if (wl != 0 && s.prev && s.prev.type == C.BAR)
		wl -= 3
	return wl
}

/* -- draw the decorations -- */
/* (the staves are defined) */
function draw_all_deco() {
	if (a_de.length == 0)
Abc.prototype.draw_all_deco = function() {
	if (!a_de.length)
		return
	var	de, de2, dd, s, note, f, st, x, y, y2, ym, uf, i, str, a,
		new_de = [],
		ymid = []

	if (!cfmt.dynalign) {
		st = nstaff;
︙
973
974
975
976
977
978
979
980
981
982
983
984
985

986

987
988
989
990
991
992
993
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082







-





+
-
+







		else
			set_scale(s);

		st = de.st;
		if (!staff_tb[st].topbar)
			continue		// invisible staff
		x = de.x;
//		y = de.y + staff_tb[st].y / staff_tb[st].staffscale
		y = de.y + staff_tb[st].y

		// update the coordinates if head decoration
		if (de.m != undefined) {
			note = s.notes[de.m];
			if (note.shhd)
			x += note.shhd * stv_g.scale;
				x += note.shhd * stv_g.scale;

		/* center the dynamic marks between two staves */
/*fixme: KO when deco on other voice and same direction*/
		} else if (f_staff[dd.func] && !cfmt.dynalign
			&& ((de.up && st > 0)
			 || (!de.up && st < nstaff))) {
			if (de.up)
︙
1129
1130
1131
1132
1133
1134
1135


1136
1137
1138
1139
1140
1141
1142
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233







+
+







				st: s.st,
				ix: a_de.length,
				defl: {},
				x: s.x,
				y: s.y,
//				dy: 0
			}
			if (s.type == C.BAR)
				de.x -= s.wl / 2 - 2
			a_de.push(de)
			if (dd.dd_en) {
				de.ldst = true
			} else if (dd.dd_st) {
//fixme: pb with "()"
				de.lden = true;
				de.defl.nost = true
︙
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1301
1302
1303
1304
1305
1306
1307


1308
1309
1310

1311
1312
1313
1314
1315
1316
1317
1318







-
-



-
+







				de.defl.nost = true
			}
		}
	} // create_dh()

	// create all decorations of a note (chord and heads)
	function create_all(s) {
		var m

		if (s.a_dd)
			create_deco(s)
		if (s.notes) {
			for (m = 0; m < s.notes.length; m++) {
			for (var m = 0; m < s.notes.length; m++) {
				if (s.notes[m].a_dcn)
					create_dh(s, m)
			}
		}
	} // create_all()

	// link the long decorations
︙
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282





1283
1284
1285
1286
1287
1288
1289
1342
1343
1344
1345
1346
1347
1348

1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368



1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380







-
+




-
+














-
-
-
+
+
+
+
+







					if (!de2.start
					 && de2.dd == dd2 && de2.s.st == st)
						break
				}
			}
			if (j == n_de) {	// no end, insert one
				de2 = {
					s: de.s,
					s: s,
					st: de.st,
					dd: dd2,
					ix: a_de.length - 1,
					x: realwidth - 6,
					y: de.s.y,
					y: s.y,
					lden: true,
					defl: {
						noen: true
					}
				}
				if (de2.x < s.x + 10)
					de2.x = s.x + 10
				if (de.m != undefined)
					de2.m = de.m;
				a_de.push(de2)
			}
			de2.start = de;
			de2.defl.nost = de.defl.nost

			// handle 'tr~~~~~'
			if (dd.name == "trill("
			 && i > 0 && a_de[i - 1].dd.name == "trill")
			// handle same decoration type at a same time
			if (i > 0
			 && a_de[i - 1].s.time == de.s.time
			 && a_de[i - 1].dd.name.slice(0, dd.name.length - 1) ==
					dd.name.slice(0, dd.name.length - 1))
				de2.prev = a_de[i - 1]
		}

		// add starting decorations
		for (i = 0; i < n_de; i++) {
			de2 = a_de[i]
			if (!de2.lden	// not the end of long decoration
︙
1313
1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432







-
+













+







		case C.CLEF:
		case C.KEY:
		case C.METER:
			continue
		}
		break
	}
	if (a_de.length != 0)
	if (a_de.length)
		ldeco_update(s)

	for ( ; s; s = s.ts_next) {
		switch (s.type) {
		case C.BAR:
		case C.MREST:
		case C.NOTE:
		case C.REST:
		case C.SPACE:
			break
		case C.GRACE:
			for (g = s.extra; g; g = g.next)
				create_all(g)
			break
		default:
			continue
		}
		create_all(s)
	}
	ll_deco()			// link the long decorations
}
︙
1359
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369


1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1451
1452
1453
1454
1455
1456
1457

1458



1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1471







-
+
-
-
-
+
+



-
+







// -- define the music elements tied to the staff --
//	- decoration tied to the staves
//	- chord symbols
//	- repeat brackets
/* (the staves are not yet defined) */
/* (unscaled delayed output) */
function draw_deco_staff() {
	var	s, first_gchord, p_voice, x, y, w, i, v, de, dd,
    var	s, p_voice, y, i, v, de, dd,
		gch, gch2, ix, top, bot,
		minmax = new Array(nstaff + 1),
		nd = a_de.length
	minmax = new Array(nstaff + 1),
	nd = a_de.length

	/* draw the repeat brackets */
	function draw_repbra(p_voice) {
		var s, s1, y, y2, i, p, w, wh, first_repeat;
		var s, s1, x, y, y2, i, p, w, wh, first_repeat;

		/* search the max y offset */
		y = staff_tb[p_voice.st].topbar + 25	// 20 (vert bar) + 5 (room)
		for (s = p_voice.sym; s; s = s.next) {
			if (s.type != C.BAR)
				continue
			if (!s.rbstart || s.norepbra)
︙
1397
1398
1399
1400
1401
1402
1403
1404
1405


1406
1407
1408
1409
1410
1411
1412
1488
1489
1490
1491
1492
1493
1494


1495
1496
1497
1498
1499
1500
1501
1502
1503







-
-
+
+







			y2 = y_get(p_voice.st, true, s1.x, s.x - s1.x)
			if (y < y2)
				y = y2

			/* have room for the repeat numbers */
			if (s1.text) {
				wh = strwh(s1.text);
				y2 = y_get(p_voice.st, true, s1.x + 4, wh[0]);
				y2 += wh[1]
				y2 = y_get(p_voice.st, true, s1.x + 4, wh[0]) +
						wh[1]
				if (y < y2)
					y = y2
			}
			if (s.rbstart)
				s = s.prev
		}

︙
1426
1427
1428
1429
1430
1431
1432

1433
1434


1435
1436
1437
1438
1439
1440
1441
1517
1518
1519
1520
1521
1522
1523
1524


1525
1526
1527
1528
1529
1530
1531
1532
1533







+
-
-
+
+







				s = s.next
				if (s.rbstop)
					break
			}
			if (s1 == s)
				break
			x = s1.x
			if (cfmt.measurenb > 0 & s.bar_num
//			if (s1.bar_type[0] == ":")
//				x -= 4;
			 && s.bar_num % cfmt.measurenb)
				x += 6
			if (s.type != C.BAR) {
				w = s.rbstop ? 0 : s.x - realwidth + 4
			} else if ((s.bar_type.length > 1	// if complex bar
				 && s.bar_type != "[]")
				|| s.bar_type == "]") {
//				if (s.bar_type == "]")
//					s.invis = true
︙
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569

1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1621
1622
1623
1624
1625
1626
1627


































1628

















1629
1630
1631
1632
1633
1634
1635







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







			y = de.y
		}
		if (de.up)
			y += dd.h;
		y_set(de.st, de.up, de.x, de.val, y)
	}

	// search the vertical offset for the chord symbols
	for (i = 0; i <= nstaff; i++)
		minmax[i] = {
			ymin: 0,
			ymax: 24
		}
	for (s = tsfirst; s; s = s.ts_next) {
		if (!s.a_gch)
			continue
		if (!first_gchord)
			first_gchord = s;
		gch2 = null
		for (ix = 0; ix < s.a_gch.length; ix++) {
			gch = s.a_gch[ix]
			if (gch.type != 'g')
				continue
			gch2 = gch	// chord closest to the staff
			if (gch.y < 0)
				break
		}
		if (gch2) {
			w = gch2.wh[0]
			if (gch2.y >= 0) {
				y = y_get(s.st, true, s.x, w)
				if (y > minmax[s.st].ymax)
					minmax[s.st].ymax = y
			} else {
				y = y_get(s.st, false, s.x, w)
				if (y < minmax[s.st].ymin)
					minmax[s.st].ymin = y
			}
		}
	}

	draw_all_chsy()		// draw all chord symbols
	// draw the chord symbols if any
	if (first_gchord) {
		for (i = 0; i <= nstaff; i++) {
			bot = staff_tb[i].botbar;
			if (minmax[i].ymin > bot - 4)
				minmax[i].ymin = bot - 4
			top = staff_tb[i].topbar;
			if (minmax[i].ymax < top + 4)
				minmax[i].ymax = top + 4
		}
		set_dscale(-1)		/* restore the scale parameters */
		for (s = first_gchord; s; s = s.ts_next) {
			if (!s.a_gch)
				continue
			self.draw_gchord(s, minmax[s.st].ymin, minmax[s.st].ymax)
		}
	}

	/* draw the repeat brackets */
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (p_voice.second || !p_voice.sym)
			continue
		draw_repbra(p_voice)
︙
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637


1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654



1655
1656
1657
1658

1659
1660
1661
1662
1663
1664

1665
1666

1667
1668
1669
1670
1671
1672
1673
1669
1670
1671
1672
1673
1674
1675

1676


1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688

1689
1690
1691
1692


1693
1694
1695
1696
1697
1698

1699
1700





1701
1702

1703
1704
1705
1706
1707
1708
1709
1710







-

-
-
+
+










-




-
-
+
+
+



-
+

-
-
-
-
-
+

-
+







			if (y < staff_tb[st].topbar + 14)
				y = staff_tb[st].topbar + 14;
			xy_str(0, y, bar_num.toString());
			y_set(st, true, 0, 20, y + gene.curfont.size + 2)
		} else if (bar_num % cfmt.measurenb == 0) {
			for ( ; ; s = s.ts_next) {
				switch (s.type) {
				case C.TIMESIG:
				case C.CLEF:
				case C.KEYSIG:
				case C.FMTCHG:
				case C.KEY:
				case C.METER:
				case C.STBRK:
					continue
				}
				break
			}

			// don't display the number twice
		     if (s.type != C.BAR || !s.bar_num) {
			if (s.prev)
				s = s.prev;
			x = s.x + s.wr;
			any_nb = true;
			w = w0
			if (bar_num >= 10)
				w *= bar_num >= 100 ? 3 : 2
			if (gene.curfont.box)
				w += 4;
			if (gene.curfont.pad)
				w += gene.curfont.pad * 2
			x = s.x + s.wr + 1	// if clef, shift a bit
			y = y_get(st, true, x, w)
			if (y < staff_tb[st].topbar + 6)
				y = staff_tb[st].topbar + 6;
			y += 2;
			y += 2 + gene.curfont.pad
			xy_str(x, y, bar_num.toString())
			if (gene.curfont.box) {
				y += 2;
				w += 3
			}
			y += gene.curfont.size;
			y += gene.curfont.size + gene.curfont.pad
			y_set(st, true, x, w, y);
			s.ymx = y
//			s.ymx = y
		     }
		}
	}

	for ( ; s; s = s.ts_next) {
		switch (s.type) {
		case C.STAVES:
︙
1693
1694
1695
1696
1697
1698
1699


1700

1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713

1714
1715
1716
1717
1718
1719

1720
1721
1722
1723

1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736



1737
1738
1739
1740
1741
1742
1743
1744
1745

1746
1747
1748
1749
1750
1751
1752
1730
1731
1732
1733
1734
1735
1736
1737
1738

1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751

1752




1753

1754


1755

1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766



1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777

1778
1779
1780
1781
1782
1783
1784
1785







+
+
-
+












-
+
-
-
-
-

-
+
-
-

-
+










-
-
-
+
+
+








-
+







		 || s.bar_mrep)
			continue
		if (!any_nb)
			any_nb = true;
		w = w0
		if (bar_num >= 10)
			w *= bar_num >= 100 ? 3 : 2
		if (gene.curfont.pad)
			w += gene.curfont.pad * 2
		x = s.x - w * .4;
		x = s.x - w * (s.text ? .6 : .4)
		y = y_get(st, true, x, w)
		if (y < staff_tb[st].topbar + 3)
			y = staff_tb[st].topbar + 3
		if (s.next.type == C.NOTE) {
			if (s.next.stem > 0) {
				if (y < s.next.ys - gene.curfont.size)
					y = s.next.ys - gene.curfont.size
			} else {
				if (y < s.next.y)
					y = s.next.y
			}
		}
		y += 2;
		y += 2 + gene.curfont.pad
		if (gene.curfont.box) {
			y += 2;
			w += 3
		}
		xy_str(x, y, bar_num.toString())
		y += gene.curfont.size;
		y += gene.curfont.size + gene.curfont.pad
		if (gene.curfont.box)
			y += 2;
		y_set(st, true, x, w, y);
		s.ymx = y
//		s.ymx = y
	}
	gene.nbar = bar_num

	if (font_size)
		param_set_font("measurefont", "* " + font_size.toString());
}

/* -- draw the parts and the tempo information -- */
/* (the staves are being defined) */
function draw_partempo(st, top) {
	var	s, some_part, some_tempo, h, w, y,
		dy = 0,		/* put the tempo indication at top */
		ht = 0
    var	s, some_part, some_tempo, h, w, y,
	dy = 0,		/* put the tempo indication at top */
	ht = 0

	/* get the minimal y offset */
	var	ymin = staff_tb[st].topbar + 8,
		dosh = 0,
		shift = 1,
		x = -100	// (must be negative for %%soloffs)

	for (s = tsfirst; s; s = s.ts_next) {
		if (s.type != C.TEMPO || s.del)
		if (s.type != C.TEMPO || s.invis)
			continue
		if (!some_tempo)
			some_tempo = s;
		w = s.tempo_wh[0]
		if (s.time == 0 && s.x > 40)	// at start of tune and no %%soloffs,
			s.x = 40;	// shift the tempo over the key signature
		y = y_get(st, true, s.x - 16, w)
︙
1767
1768
1769
1770
1771
1772
1773
1774

1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785


1786
1787
1788
1789
1790
1791
1792
1793

1794
1795
1796
1797
1798
1799


1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810

1811
1812
1813
1814

1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826


1827
1828
1829
1830
1800
1801
1802
1803
1804
1805
1806

1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827

1828
1829
1830
1831
1832


1833
1834
1835
1836
1837
1838
1839
1840
1841
1842



1843
1844
1845
1846

1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865







-
+











+
+







-
+




-
-
+
+








-
-
-
+



-
+












+
+




			ht *= 2
		if (top < ymin + ht)
			dy = ymin + ht - top

		/* draw the tempo indications */
		for (s = some_tempo; s; s = s.ts_next) {
			if (s.type != C.TEMPO
			 || s.del)		// (displayed by %%titleformat)
			 || s.invis)		// (displayed by %%titleformat)
				continue
			if (user.anno_start || user.anno_stop) {
				s.wl = 16;
				s.wr = 30;
				s.ymn = (dosh & 1) ? h : y;
				s.ymx = s.ymn + 14;
				anno_start(s)
			}
			writempo(s, s.x - 16, (dosh & 1) ? h : y);
			anno_stop(s);
			dosh >>= 1
			while (s.ts_next && s.ts_next.type == C.TEMPO)
				s = s.ts_next
		}
	}

	/* then, put the parts */
/*fixme: should reduce vertical space if parts don't overlap tempo...*/
	ymin = staff_tb[st].topbar + 6
	for (s = tsfirst; s; s = s.ts_next) {
		if (s.type != C.PART)
		if (s.type != C.PART || s.invis)
			continue
		if (!some_part) {
			some_part = s;
			set_font("parts");
			h = gene.curfont.size + 2
						/* + cfmt.partsspace ?? */
			h = gene.curfont.size + 2 +
				gene.curfont.pad * 2
		}
		w = strwh(s.text)[0];
		y = y_get(st, true, s.x - 10, w + 3)
		if (ymin < y)
			ymin = y
	}
	if (some_part) {
		set_sscale(-1)
		if (gene.curfont.box)
			h += 2
		if (top < ymin + h + ht)
		if (top + dy < ymin + h + ht)
			dy = ymin + h + ht - top

		for (s = some_part; s; s = s.ts_next) {
			if (s.type != C.PART)
			if (s.type != C.PART || s.invis)
				continue
			s.x -= 10;
			if (user.anno_start || user.anno_stop) {
				w = strwh(s.text)[0];
				s.wl = 0;
				s.wr = w;
				s.ymn = -ht - h;
				s.ymx = s.ymn + h;
				anno_start(s)
			}
			xy_str(s.x, 2 - ht - h, s.text);
			anno_stop(s)
			while (s.ts_next && s.ts_next.type == C.PART)
				s = s.ts_next
		}
	}
	return dy
}
Changes to core/draw.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - draw.js - draw functions
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
30
31
32
33
34
35
36
37


38
39
40
41
42
43
44
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45







-
+
+







	BEAM_OFFSET	= .25,	/* pos of flat beam relative to staff line */
	BEAM_SHIFT	= 5,	/* shift of second and third beams */
	BEAM_STUB	= 8,	/* length of stub for flag under beam */ 
	SLUR_SLOPE	= .5,	/* max slope of a slur */
	GSTEM		= 15,	/* grace note stem length */
	GSTEM_XOFF	= 2.3	/* x offset for grace note stem */

    var cache
    var cache,
	anno_a = []		// symbols with annotations

/* -- compute the best vertical offset for the beams -- */
function b_pos(grace, stem, nflags, b) {
	var	top, bot, d1, d2,
		shift = !grace ? BEAM_SHIFT : 3.5,
		depth = !grace ? BEAM_DEPTH : 1.8

︙
72
73
74
75
76
77
78

79
80
81
82
83
84
85
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87







+







	s = clone(s)
	s.invis = true
	delete s.extra;
	delete s.text
	delete s.a_gch
	delete s.a_ly
	delete s.a_dd;
	delete s.tp
	s.notes = clone(s.notes)
	for (m = 0; m <= s.nhd; m++) {
		note = s.notes[m] = clone(s.notes[m])
		delete note.a_dcn
	}
	return s
}
︙
473
474
475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
475
476
477
478
479
480
481

482

483
484
485
486
487
488
489
490







-

-
+







				x1 += 5;
				x2 -= 6
			}
		}

		y1 = bm.a * x1 + bm.b - dy;
		x2 -= x1;
	//--fixme: scale (bm.a already scaled!)
		x2 /= stv_g.scale;
		dy2 = bm.a * x2 * stv_g.scale;
		dy2 = bm.a * x2
		xypath(x1, y1, true);
		output += 'l' + x2.toFixed(1) + ' ' + (-dy2).toFixed(1) +
			'v' + h.toFixed(1) +
			'l' + (-x2).toFixed(1) + ' ' + dy2.toFixed(1) +
			'z"/>\n'
	} // draw_beam()

︙
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638







-
+







	anno_stop(s1, 'beam')
}

/* -- draw the left side of the staves -- */
function draw_lstaff(x) {
//	if (cfmt.alignbars)
//		return
	var	i, j, yb, h,
    var	i, j, yb, h, fl,
		nst = cur_sy.nstaff,
		l = 0

	/* -- draw a system brace or bracket -- */
	function draw_sysbra(x, st, flag) {
		var i, st_end, yt, yb

︙
655
656
657
658
659
660
661

662

663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682


683
684

685
686

687
688

689
690
691
692
693
694

695
696
697

698
699
700
701
702
703
704
656
657
658
659
660
661
662
663

664
665
666
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683

684
685
686

687
688

689
690

691
692
693
694
695
696

697
698
699

700
701
702
703
704
705
706
707







+
-
+



-
+















-
+
+

-
+

-
+

-
+





-
+


-
+







		if (flag & (CLOSE_BRACE | CLOSE_BRACE2))
			out_brace(x, yb, yt - yb)
		else
			out_bracket(x, yt, yt - yb)
	}

	for (i = 0; ; i++) {
		fl = cur_sy.staves[i].flags
		if (cur_sy.staves[i].flags & (OPEN_BRACE | OPEN_BRACKET))
		if (fl & (OPEN_BRACE | OPEN_BRACKET))
			l++
		if (cur_sy.st_print[i])
			break
		if (cur_sy.staves[i].flags & (CLOSE_BRACE | CLOSE_BRACKET))
		if (fl & (CLOSE_BRACE | CLOSE_BRACKET))
			l--
		if (i == nst)
			break
	}
	for (j = nst; j > i; j--) {
		if (cur_sy.st_print[j])
			break
	}
	if (i == j && l == 0)
		return
	yb = staff_tb[j].y + staff_tb[j].botbar * staff_tb[j].staffscale;
	h = staff_tb[i].y + staff_tb[i].topbar * staff_tb[i].staffscale - yb;
	xypath(x, yb);
	output += "v" + (-h).toFixed(1) + '"/>\n'
	for (i = 0; i <= nst; i++) {
		if (cur_sy.staves[i].flags & OPEN_BRACE)
		fl = cur_sy.staves[i].flags
		if (fl & OPEN_BRACE)
			draw_sysbra(x, i, CLOSE_BRACE)
		if (cur_sy.staves[i].flags & OPEN_BRACKET)
		if (fl & OPEN_BRACKET)
			draw_sysbra(x, i, CLOSE_BRACKET)
		if (cur_sy.staves[i].flags & OPEN_BRACE2)
		if (fl & OPEN_BRACE2)
			draw_sysbra(x - 6, i, CLOSE_BRACE2)
		if (cur_sy.staves[i].flags & OPEN_BRACKET2)
		if (fl & OPEN_BRACKET2)
			draw_sysbra(x - 6, i, CLOSE_BRACKET2)
	}
}

/* -- draw the time signature -- */
function draw_meter(x, s) {
function draw_meter(s) {
	if (!s.a_meter)
		return
    var	dx, i, j, meter,
    var	dx, i, j, meter, x,
		st = s.st,
		p_staff = staff_tb[st],
		y = p_staff.y;

	// adjust the vertical offset according to the staff definition
	if (p_staff.stafflines != '|||||')
		y += (p_staff.topbar + p_staff.botbar) / 2 - 12	// bottom
︙
717
718
719
720
721
722
723


724
725
726
727
728
729
730











731
732
733
734
735





















736
737
738
739

















740
741
742
743
744


745
746
747
748
749
750
751
752

753
754



755
756
757
758
759
760
761

762
763
764



765

766




767
768
769
770






771
772
773


774
775

776



777
778
779
780






781
782
783
784
785
786
787
788
789
790
791
792
793







794
795
796
797
798
799
800
720
721
722
723
724
725
726
727
728
729






730
731
732
733
734
735
736
737
738
739
740





741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

781


782
783
784
785
786
787
788
789
790
791
792


793
794
795
796
797
798
799
800
801

802
803


804
805
806
807
808

809
810
811
812
813
814


815
816
817
818
819
820
821


822
823
824
825
826
827
828
829
830




831
832
833
834
835
836
837
838
839
840
841
842







843
844
845
846
847
848
849
850
851
852
853
854
855
856







+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-

-
-
+
+








+
-
-
+
+
+






-
+

-
-
+
+
+

+
-
+
+
+
+


-
-
+
+
+
+
+
+

-
-
+
+


+

+
+
+
-
-
-
-
+
+
+
+
+
+






-
-
-
-
-
-
-
+
+
+
+
+
+
+







			out_XYAB('\
<text x="X" y="Y" text-anchor="middle">A</text>\n',
				x, y + 12, m_gl(meter.top))
		}
	}
}

    var	acc_nd = {}		// cache of the microtonal accidentals

/* -- draw an accidental -- */
function draw_acc(x, y, acc,
			micro_n,
			micro_d) {
	if (micro_n) {
		if (micro_n == micro_d) {
			acc = acc == -1 ?	// flat
function draw_acc(x, y, a) {
	if (typeof a != "number") {		// if microtone
	    var	c,
		n = a[0],
		d = a[1]

		c = n + '_' + d
		a = acc_nd[c]
		if (!a) {
			a = abc2svg.rat(Math.abs(n), d)
			d = a[1]
				-2 : 2		// double flat : sharp
		} else if (micro_n * 2 != micro_d) {
			xygl(x, y, "acc" + acc + '_' + micro_n + '_' + micro_d)
			return
		}
			a = (n < 0 ? -a[0] : a[0]).toString()
			if (d != 1)
				a += '_' + d
			acc_nd[c] = a
		}
	}
	xygl(x, y, "acc" + a)
}

// memorize the helper/ledger lines
function set_hl(p_st, n, x, dx1, dx2) {
    var	i, hl

	if (n >= 0) {
		hl = p_st.hlu[n]
		if (!hl)
			hl = p_st.hlu[n] = []
	} else {
		hl = p_st.hld[-n]
		if (!hl)
			hl = p_st.hld[-n] = []
	}
	xygl(x, y, "acc" + acc)
}


	for (i = 0; i < hl.length; i++) {
		if (x >= hl[i][0])
			break
	}
	if (i == hl.length) {
		hl.push([x, dx1, dx2])
	} else if (x > hl[i][0]) {
		hl.splice(++i, 0, [x, dx1, dx2])
	} else {
		if (dx1 < hl[i][1])
			hl[i][1] = dx1
		if (dx2 > hl[i][2])
			hl[i][2] = dx2
	}
} // set_hl()

// draw helper lines
//fixme: double lines when needed for different voices
// (possible hook)
Abc.prototype.draw_hl = function(x, s, hltype) {
    var	i, j, n,
Abc.prototype.draw_hl = function(s) {
    var	i, j, n, note,
	hla = [],
	st = s.st,
	p_staff = staff_tb[st]

	// check if any helper line
	if (!p_staff.hll)
		return			// no helper line (no line)
	for (i = 0; i <= s.nhd; i++) {
		note = s.notes[i]
		if (!p_staff.hlmap[s.notes[i].pit - p_staff.hll])
			hla.push((s.notes[i].pit - 18) * 3)
		if (!p_staff.hlmap[note.pit - p_staff.hll])
			hla.push([note.pit - 18,
				  note.shhd * stv_g.scale])
	}
	n = hla.length
	if (!n)
		return			// no

	// handle the helper lines out of the staff
    var	staffb = p_staff.y,
    var	dx1, dx2, hl, shhd,hlp,
	stafflines = p_staff.stafflines,
	top = (stafflines.length - 1) * 6,
	bot = p_staff.botline,
	top = stafflines.length - 1,
	yu =  top,
	bot = p_staff.botline / 6,
	yl = bot,
	dx = s.grace ? 4 : hw_tb[s.head] * 1.3
	yu = top

	// get the x start and x stop of the intermediate helper lines
	note = s.notes[s.stem < 0 ? s.nhd : 0]
	shhd = note.shhd

	for (i = 0; i < hla.length; i++) {
		if (hla[i] < yl) {
			yl = (((hla[i] + 51) / 6) | 0) * 6 - 48;
		hlp = hla[i][0]
		dx1 = (hla[i][1] < shhd ? hla[i][1] : shhd) - dx
		dx2 = (hla[i][1] > shhd ? hla[i][1] : shhd) + dx
		if (hlp < bot * 2) {
			if (hlp < yl * 2)
				yl = ++hlp >> 1
			n--
		} else if (hla[i] > yu) {
			yu = ((hla[i] / 6) | 0) * 6;
		} else if (hlp > top * 2) {
			yu = hlp >> 1
			n--
		}
		set_hl(p_staff, hlp >> 1, s.x, dx1, dx2)
	}

	dx1 = shhd - dx
	dx2 = shhd + dx
	for (; yl < bot; yl += 6)
		xygl(x, staffb + yl, hltype)
	for (; yu > top; yu -= 6)
		xygl(x, staffb + yu, hltype)
	while (++yl < bot)
		set_hl(p_staff, yl,
			s.x, dx1, dx2)
	while (--yu > top)
		set_hl(p_staff, yu,
			s.x, dx1, dx2)
	if (!n)
		return			// no more helper lines

	// draw the helper lines inside the staff
	i = yl;
	j = yu
	while (i > bot && stafflines[i / 6] == '-')
		i -= 6
	while (j < top && stafflines[j / 6] == '-')
		j += 6
	for ( ; i < j; i += 6) {
		if (stafflines[i / 6] == '-')
			xygl(x, staffb + i, hltype)	// hole
	while (i > bot && stafflines[i] == '-')
		i--
	while (j < top && stafflines[j] == '-')
		j++
	for ( ; i < j; i++) {
		if (stafflines[i] == '-')
			set_hl(p_staff, i, s.x, dx1, dx2)
	}
}

/* -- draw a key signature -- */
// (possible hook)
var	sharp_cl = new Int8Array([24, 9, 15, 21, 6, 12, 18]),
	flat_cl = new Int8Array([12, 18, 24, 9, 15, 21, 6]),
︙
907
908
909
910
911
912
913

914
915

916
917

918
919
920
921
922
923
924
925
963
964
965
966
967
968
969
970
971

972
973

974

975
976
977
978
979
980
981







+

-
+

-
+
-







			if (i != 0
			 && (shift > last_shift + 18
			  || shift < last_shift - 18))
				x -= 5.5		// no clash
			else if (acc.acc != last_acc)
				x += 3;
			last_acc = acc.acc;
			s2.x = x
			s2.notes[0].pit = shift / 3 + 18;
			self.draw_hl(x, s2, "hl");
			self.draw_hl(s2)
			last_shift = shift;
			draw_acc(x, staffb + shift,
			draw_acc(x, staffb + shift, acc.acc)
				 acc.acc, acc.micro_n, acc.micro_d);
			x += 5.5
		}
	}
}

/* -- convert the standard measure bars -- */
function bar_cnv(bar_type) {
︙
936
937
938
939
940
941
942











943
944
945
946
947
948
949
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016







+
+
+
+
+
+
+
+
+
+
+







	case ":::|":
		return bar_type + "]"		/* :..| -> :..|] */
	case "::":
		return cfmt.dblrepbar		/* :: -> double repeat bar */
	}
	return bar_type
}

// output the measure repeat number
function nrep_out(x, y, n) {
	y -= 3
	if (n < 10) {
		xygl(x - 4, y, "mtr" + n)
	} else {
		xygl(x - 10, y, "mtr" + ((n / 10) | 0))
		xygl(x - 2, y, "mtr" + (n % 10))
	}
} // nrep_out()

/* -- draw a rest -- */
/* (the staves are defined) */
var rest_tb = [
	"r128", "r64", "r32", "r16", "r8",
	"r4",
	"r2", "r1", "r0", "r00"]
︙
962
963
964
965
966
967
968
969
970
971




972
973
974
975
976

977
978
979
980
981
982
983
1029
1030
1031
1032
1033
1034
1035



1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051







-
-
-
+
+
+
+




-
+







			s.nflags = -3
		else
			s.nflags = -4;
		s.dots = 0;

		/* don't use next/prev: there is no bar in voice overlay */
		s2 = s.ts_next
		while (s2 && s2.time != s.time + s.dur)
			s2 = s2.ts_next;
		x = s2 ? s2.x : realwidth;
		while (s2.time != s.time + s.dur
		    && s2.ts_next)
			s2 = s2.ts_next
		x = s2.x - s2.wl
		s2 = s
		while (!s2.seqst)
			s2 = s2.ts_prev;
		s2 = s2.ts_prev;
		x = (x + s2.x) / 2
		x = (x + s2.x + s2.wr) / 2

		/* center the associated decorations */
		if (s.a_dd)
			deco_update(s, x - s.x);
		s.x = x
	} else {
		x = s.x
︙
996
997
998
999
1000
1001
1002
1003
1004
1005



1006
1007
1008
1009

1010
1011
1012
1013

1014
1015

1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

1033

1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071
1072




1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1064
1065
1066
1067
1068
1069
1070



1071
1072
1073




1074




1075


1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132


1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169







-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
+
-
-
+

















+
-
+











-
+


















-
+






-
-
+
+
+
+




-
+




















-
+







			yb += 12
		else
			yb += (p_staff.topbar + p_staff.botbar) / 2
		if (s.rep_nb < 0) {
			xygl(x, yb, "srep")
		} else {
			xygl(x, yb, "mrep")
			if (s.rep_nb > 2 && s.v == cur_sy.top_voice) {
				set_font("annotation");
				if (gene.curfont.box) {
			if (s.rep_nb > 2 && s.v == cur_sy.top_voice
			 && cfmt.measrepnb > 0
			 && !(s.rep_nb % cfmt.measrepnb))
					gene.curfont.box = false;
					bx = true
				}	
				xy_str(x, yb + p_staff.topbar - 9,
				nrep_out(x, yb + p_staff.topbar, s.rep_nb)
					s.rep_nb.toString(), "c")
				if (bx)
					gene.curfont.box = true
			}
		}
		}
		anno_stop(s)
		anno_a.push(s)
		return
	}

	set_scale(s);
	anno_start(s);

	if (s.notes[0].color)
		set_color(s.notes[0].color);

	y = s.y;

	i = 5 - s.nflags		/* rest_tb index (5 = C_XFLAGS) */
	if (i == 7 && y == 12
	 && p_staff.stafflines.length <= 2)
		y -= 6				/* semibreve a bit lower */

	// draw the rest
	if (!s.notes[0].invis)		// if not head replacement
	xygl(x, y + yb, s.notes[0].head || rest_tb[i])
		xygl(x, y + yb, rest_tb[i])

	/* output ledger line(s) when greater than minim */
	if (i >= 6) {
		j = y / 6
		switch (i) {
		default:
			switch (p_staff.stafflines[j + 1]) {
			case '|':
			case '[':
				break
			default:
				xygl(x, y + 6 + yb, "hl1")
				set_hl(p_staff, j + 1, x, -7, 7)
				break
			}
			if (i == 9) {			/* longa */
				y -= 6;
				j--
			}
			break
		case 7:					/* semibreve */
			y += 6;
			j++
		case 6:					/* minim */
			break
		}
		switch (p_staff.stafflines[j]) {
		case '|':
		case '[':
			break
		default:
			xygl(x, y + yb, "hl1")
			set_hl(p_staff, j, x, -7, 7)
			break
		}
	}
	if (s.dots) {
		x += 8;
		y += yb + 3
		for (i = 0; i < s.dots; i++) {
			xygl(x, y, "dot");
		j = s.dots
		i = (s.dur_orig / 12) >> ((5 - s.nflags) - j)
		while (j-- > 0) {
			xygl(x, y, (i & (1 << j)) ? "dot" : "dot+")
			x += 3.5
		}
	}
	set_color();
	anno_stop(s)
	anno_a.push(s)
}

/* -- draw grace notes -- */
/* (the staves are defined) */
function draw_gracenotes(s) {
    var	yy, x0, y0, x1, y1, x2, y2, x3, y3, bet1, bet2, slur,
	dy1, dy2, g, last, note,
	bm = {}

	/* draw the notes */
//	bm.s2 = undefined			/* (draw flags) */
	for (g = s.extra; g; g = g.next) {
		if (g.beam_st && !g.beam_end) {
			if (self.calculate_beam(bm, g))
				draw_beams(bm)
		}
		anno_start(g);
		draw_note(g, !bm.s2)
		if (g == bm.s2)
			bm.s2 = null			/* (draw flags again) */
		anno_stop(g)
		anno_a.push(s)
		if (g.sls || g.sl2)
			slur = true
		if (!g.next)
			break			/* (keep the last note) */
	}

	// if an acciaccatura, draw a bar 
︙
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1197







-
+







		note = g.notes[g.stem < 0 ? 0 : g.nhd];
		out_acciac(x_head(g, note), y_head(g, note),
				x1, y1, g.stem > 0)
	}

	/* slur */
//fixme: have a full key symbol in voice
	if (s.p_v.key.k_bagpipe			/* no slur when bagpipe */
	if (s.p_v.ckey.k_bagpipe		/* no slur when bagpipe */
	 || !cfmt.graceslurs
	 || slur				// explicit slur
	 || s.tie_s				// some tie
	 || !s.next
	 || s.next.type != C.NOTE)
		return
	last = g
︙
1281
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1345
1346
1347
1348
1349
1350
1351

1352
1353
1354
1355
1356


















1357
1358
1359
1360
1361
1362
1363







-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		y_note = y + staffb

//	/* special case for voice unison */
//	if (s.nohdi1 != undefined
//	 && m >= s.nohdi1 && m < s.nohdi2)
//		return

	var	elts = identify_note(s, note.dur),
    var	elts = identify_note(s, note.dur),
		head = elts[0],
		dots = elts[1],
		nflags = elts[2]

	/* output a ledger line if horizontal shift / chord
	 * and note on a line */
	if (y % 6 == 0
	 && shhd != (s.stem > 0 ? s.notes[0].shhd : s.notes[s.nhd].shhd)) {
		yy = 0
		if (y >= 30) {
			yy = y
			if (yy % 6)
				yy -= 3
		} else if (y <= -6) {
			yy = y
			if (yy % 6)
				yy += 3
		}
		if (yy)
			xygl(x_note, yy + staffb, "hl")
	}

	/* draw the head */
	if (note.invis) {
		;
	} else if (s.grace) {			// don't apply %%map to grace notes
		p = "ghd";
		x_note -= 4.5 * stv_g.scale
	} else if (note.map && note.map[0]) {
︙
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407







-
+







+







				break
			}
			// fall thru
		case C.SQUARE:
			if (nflags > -4) {
				p = "breve"
			} else {
				p =  "longa"
				p = "longa"
				inv = s.stem > 0
			}

			/* don't display dots on last note of the tune */
			if (!tsnext && s.next
			 && s.next.type == C.BAR && !s.next.next)
				dots = 0
			x_note += 1
			break
		case C.EMPTY:
			p = "Hd"		// white note
			break
		default:			// black note
			p = "hd"
			break
︙
1390
1391
1392
1393
1394
1395
1396
1397

1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415



1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1437
1438
1439
1440
1441
1442
1443

1444

1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458



1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469



















1470
1471
1472
1473
1474
1475
1476
1477







-
+
-


-
+











-
-
-
+
+
+





-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







		}
	}

	/* draw the accidental */
	if (note.acc) {
		x -= note.shac * stv_g.scale
		if (!s.grace) {
			draw_acc(x, y + staffb,
			draw_acc(x, y + staffb, note.acc)
				 note.acc, note.micro_n, note.micro_d)
		} else {
			g_open(x, y + staffb, 0, .75);
			draw_acc(0, 0, note.acc, note.micro_n, note.micro_d);
			draw_acc(0, 0, note.acc)
			g_close()
		}
	}
	if (old_color != false)
		set_color(old_color)
}

/* -- draw a note or a chord -- */
/* (the staves are defined) */
function draw_note(s,
		   fl) {		// draw flags
	var	s2, i, m, y, staffb, slen, c, hltype, nflags,
		x, y, note, x_hl,
		y_tb = new Array(s.nhd + 1)
    var	s2, i, m, y, staffb, slen, c, nflags,
	x, y, note,
	y_tb = new Array(s.nhd + 1)

	if (s.dots)
		setdoty(s, y_tb)

	note = s.notes[s.stem < 0 ? s.nhd : 0];	// master note head
	x_hl = x = x_head(s, note);
	x = x_head(s, note)
	staffb = staff_tb[s.st].y

	/* output the ledger lines */
	if (s.grace) {
		hltype = "ghl";
		x_hl += 1.5
	} else {
		hltype = "hl"
		switch (s.head) {
		case C.OVALBARS:
		case C.OVAL:
			x_hl -= .3;
			hltype = "hl1"
			break
		case C.SQUARE:
			x_hl -= 2;
			hltype = "hl1"
			break
		}
	}
	self.draw_hl(x_hl, s, hltype)
	self.draw_hl(s)

	/* draw the stem and flags */
	y = y_head(s, note)
	if (!s.stemless) {
		slen = s.ys - s.y;
		nflags = s.nflags
		if (s.ntrem)
︙
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612



1613
1614
1615
1616
1617
1618
1619
1625
1626
1627
1628
1629
1630
1631



1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647







-
-
-


-
+



+
+
+







	yy1 = y1 + beta * (yy1 - y1)

	var	xx2 = mx + alfa * (x2 - mx),
		yy2 = my + alfa * (y2 - my) + height;
	xx2 = x2 + beta * (xx2 - x2);
	yy2 = y2 + beta * (yy2 - y2);

	dx = .03 * (x2 - x1);
//	if (dx > 10.)
//		dx = 10.
//	dy = 1.6 * dir
	dy = 2 * dir;
	dz = .2 + .001 * (x2 - x1)
	dz = .2 + .001 * dx
	if (dz > .6)
		dz = .6;
	dz *= dir
	dx *= .03
//	if (dx > 10.)
//		dx = 10.

//	var scale_y = stv_g.st < 0 ? stv_g.scale : 1
	var scale_y = 1			// (see set_dscale())
	if (!dotted)
		output += '<path d="M'
	else
		output += '<path class="stroke" stroke-dasharray="5,5" d="M';
︙
1630
1631
1632
1633
1634
1635
1636
1637

1638
1639
1640
1641
1642
1643
1644
1658
1659
1660
1661
1662
1663
1664

1665
1666
1667
1668
1669
1670
1671
1672







-
+







		output += '\n\tv' +
			(-dz).toFixed(1) + 'c' +
			((xx2 - dx - x2) / stv_g.scale).toFixed(1) + ' ' +
			((y2 + dz - yy2 - dy) / scale_y).toFixed(1) + ' ' +
			((xx1 + dx - x2) / stv_g.scale).toFixed(1) + ' ' +
			((y2 + dz - yy1 - dy) / scale_y).toFixed(1) + ' ' +
			((x1 - x2) / stv_g.scale).toFixed(1) + ' ' +
			((y2 + dz - y1) / scale_y).toFixed(1);
			((y2 - y1) / scale_y).toFixed(1)
	output += '"/>\n'
}

// draw a slur between two chords / notes
/* (the staves are not yet defined) */
/* (delayed output) */
/* (not a pretty routine, this) */
︙
1959
1960
1961
1962
1963
1964
1965

1966

1967
1968
1969
1970
1971
1972
1973
1987
1988
1989
1990
1991
1992
1993
1994

1995
1996
1997
1998
1999
2000
2001
2002







+
-
+







			k.ymx = y
		else if (k.ymn > y)
			k.ymn = y
		if (i == i2 - 1) {
			dx = x2
			if (k2.sl1)
				dx -= 5;
			if (i)
			y -= height / 3
				y -= height / 3
		} else {
			dx = path[i + 1].x
		}
		if (i != 0)
			x1 = k.x
		else
			y -= height / 3
︙
2006
2007
2008
2009
2010
2011
2012
2013
2014


2015
2016
2017


2018
2019
2020
2021
2022




2023

2024
2025
2026
2027
2028
2029
2030
2035
2036
2037
2038
2039
2040
2041


2042
2043



2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054

2055
2056
2057
2058
2059
2060
2061
2062







-
-
+
+
-
-
-
+
+





+
+
+
+
-
+







		}

		// set the slur position
		switch (sl.ty & 0x07) {
		case C.SL_ABOVE: dir = 1; break
		case C.SL_BELOW: dir = -1; break
		default:
			if (s.v != s2.v)
				dir = -1	// always above ?
			dir = s.v != s2.v ?
				1 :		// always above ?
			else
				dir = slur_direction(s, s2);
			sl.ty &= ~0x07;
				slur_direction(s, s2)
			sl.ty &= ~0x07
			sl.ty |= dir > 0 ? C.SL_ABOVE : C.SL_BELOW
			break
		}

		// build the path of the symbols under the slur
		if (s.v == s2.v) {
			v = s.v
		} if (!cur_sy.voices[s.v] || !cur_sy.voices[s2.v]) {
			v = s.v > s2.v ? s.v : s2.v
		if (dir *			// if slur on first voice
		} else if (dir *			// if slur on first voice
			(cur_sy.voices[s.v].range <= cur_sy.voices[s2.v].range ?
				1 : -1) > 0)
			v = s.v
		else
			v = s2.v

		if (gr1				// if start on a grace note
︙
2041
2042
2043
2044
2045
2046
2047
2048

2049
2050
2051
2052
2053
2054
2055
2056
2057

2058
2059
2060
2061
2062
2063
2064
2073
2074
2075
2076
2077
2078
2079

2080
2081
2082
2083
2084
2085
2086
2087
2088

2089
2090
2091
2092
2093
2094
2095
2096







-
+








-
+







			if (s.grace)
				s = s.next
			else
				s = s.ts_next
		}

		if (!s2.grace) {		// if end on a normal note
			while (1) {
			while (s) {
				if (s.v == v)
					path.push(s)
				if (s == s2)
					break
				s = s.ts_next
			}
		} else if (s.grace) {		// if start/end in the same sequence
			while (1) {
				if (s.v == v)
//				if (s.v == v)
					path.push(s)
				if (s == s2)
					break
				s = s.next
			}
		} else {			// end on a grace note
			k = s2
︙
2138
2139
2140
2141
2142
2143
2144
2145

2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162






2163


2164



2165
2166
2167
2168
2169
2170
2171
2172
2173
2174







2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2170
2171
2172
2173
2174
2175
2176

2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188






2189
2190
2191
2192
2193
2194

2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222





2223
2224
2225
2226
2227
2228
2229







-
+











-
-
-
-
-
-
+
+
+
+
+
+
-
+
+

+
+
+










+
+
+
+
+
+
+





-
-
-
-
-







}

/* -- draw a tuplet -- */
/* (the staves are not yet defined) */
/* (delayed output) */
/* See http://moinejf.free.fr/abcm2ps-doc/tuplets.xhtml
 * for the value of 'tp.f' */
function draw_tuplet(s1, tp) {
function draw_tuplet(s1) {
    var	s2, s3, g, upstaff, nb_only, some_slur,
	x1, x2, y1, y2, xm, ym, a, s0, yy, yx, dy, a, dir, r,
	tp = s1.tp.shift()		// tuplet parameters

	if (!s1.tp.length)
		delete s1.tp		// last tuplet

	// treat the slurs and the nested tuplets
	upstaff = s1.st
	set_dscale(s1.st)
	for (s2 = s1; s2; s2 = s2.next) {
		if (s2.type != C.NOTE && s2.type != C.REST) {
			if (s2.type == C.GRACE) {
				for (g = s2.extra; g; g = g.next) {
					if (g.sls || g.sl1)
						draw_slurs(g)
				}
		switch (s2.type) {
		case C.GRACE:
			for (g = s2.extra; g; g = g.next) {
				if (g.sls || g.sl1)
					draw_slurs(g)
			}
			}
			// fall thru
		default:
			continue
		case C.NOTE:
		case C.REST:
			break
		}
		if (s2.sls || s2.sl1)
			draw_slurs(s2)
		if (s2.st < upstaff)
			upstaff = s2.st
		if (s2.tp)
			draw_tuplet(s2)
		if (s2.tpe)
			break
	}

	if (s2)
		s2.tpe--

	if (tp.f[0] == 1)		// if 'when' == never
		return			// accept tuplets on many lines

	if (!s2) {
		error(1, s1, "No end of tuplet in this music line")
		return
	}

	s2.tpe--

	if (tp.f[0] == 1)			/* if 'when' == never */
		return

	dir = tp.f[3]				// 'where'
	if (!dir) {				// if auto
		s3 = s1
		while (s3.type != C.NOTE)
			s3 = s3.next
		dir = s3.stem > 0 ? C.SL_ABOVE : C.SL_BELOW
	}
︙
2246
2247
2248
2249
2250
2251
2252

2253
2254
2255
2256


2257
2258


2259
2260
2261
2262
2263
2264
2265
2266
2267
2268


2269
2270

2271
2272
2273
2274
2275
2276
2277

2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292




























2293
2294
2295
2296
2297

2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2284
2285
2286
2287
2288
2289
2290
2291
2292



2293
2294
2295

2296
2297
2298
2299
2300
2301
2302
2303
2304
2305


2306
2307
2308

2309
2310
2311
2312
2313
2314
2315

2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363

2364
2365
2366
2367
2368
2369

2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
















2388
2389
2390
2391
2392
2393
2394







+

-
-
-
+
+

-
+
+








-
-
+
+

-
+






-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+





-


















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		}
	}

	/* if number only, draw it */
	if (nb_only) {
		if (tp.f[2] == 1)		/* if 'which' == none */
			return
		set_font("tuplet")
		xm = (s2.x + s1.x) / 2
		a = s2.x - s1.x			// width around the middle
		if (dir == C.SL_ABOVE)
			ym = y_get(upstaff, 1, xm - a / 2, a) + 2
		if (dir == C.SL_ABOVE)		// 8 = width around the middle
			ym = y_get(upstaff, 1, xm - 4, 8)
		else
			ym = y_get(upstaff, 0, xm - a / 2, a) - 10
			ym = y_get(upstaff, 0, xm - 4, 8) -
					gene.curfont.size

		if (s1.stem * s2.stem > 0) {
			if (s1.stem > 0)
				xm += 1.5
			else
				xm -= 1.5
		}

		if (tp.f[2] == 0)		/* if 'which' == number */
			out_bnum(xm, ym, tp.p)
		if (tp.f[2] == 0)		// if 'which' == number
			xy_str(xm, ym, tp.p.toString(), 'c')
		else
			out_bnum(xm, ym, tp.p + ':' + tp.q)
			xy_str(xm, ym, tp.p+':'+tp.q, 'c')

		for (s3 = s1; ; s3 = s3.next) {
			if (s3.x >= xm)
				break
		}
		if (dir == C.SL_ABOVE) {
			ym += 10
			ym += gene.curfont.size
			if (s3.ymx < ym)
				s3.ymx = ym;
			y_set(upstaff, true, xm - 3, 6, ym)
		} else {
			if (s3.ymn > ym)
				s3.ymn = ym;
			y_set(upstaff, false, xm - 3, 6, ym)
		}
		return
	}

	// here, what is square bracket

/*fixme: two staves not treated*/
/*fixme: to optimize*/

	// first, get the x offsets
	x1 = s1.x - 4

	// end the bracket according to the last note duration
	if (s2.dur > s2.prev.dur) {
		s3 = s2.next
		if (!s3	// maybe a note in an overlay voice
		 || s3.time != s2.time + s2.dur) {
			for (s3 = s2.ts_next; s3; s3 = s3.ts_next) {
				if (s3.seqst
				 && s3.time >= s2.time + s2.dur)
					break
			}
		}
//fixme: s3 cannot be null (bar at end of staff)
		x2 = s3 ? s3.x - s3.wl - 5 : realwidth - 6
	} else {
		x2 = s2.x + 4
		r = s2.stem >= 0 ? 0 : s2.nhd
		if (s2.notes[r].shhd > 0)
			x2 += s2.notes[r].shhd
		if (s2.st == upstaff
		 && s2.stem > 0)
			x2 += 3.5
	}

    // above
    if (dir == C.SL_ABOVE) {

	/* sole or upper voice: the bracket is above the staff */
	if (s1.st == s2.st) {
		y1 = y2 = staff_tb[upstaff].topbar + 4
		y1 = y2 = staff_tb[upstaff].topbar + 2
	} else {
		y1 = s1.ymx;
		y2 = s2.ymx
	}

	x1 = s1.x - 4;
	if (s1.st == upstaff) {
		for (s3 = s1; !s3.dur; s3 = s3.next)
			;
		ym = y_get(upstaff, 1, s3.x - 4, 8)
		if (ym > y1)
			y1 = ym
		if (s1.stem > 0)
			x1 += 3
	}

	if (s2.st == upstaff) {
		for (s3 = s2; !s3.dur; s3 = s3.prev)
			;
		ym = y_get(upstaff, 1, s3.x - 4, 8)
		if (ym > y2)
			y2 = ym
	}

	// end the bracket according to the last note duration
	if (s2.dur > s2.prev.dur) {
		if (s2.next)
			x2 = s2.next.x - s2.next.wl - 5
		else
			x2 = realwidth - 6
	} else {
		x2 = s2.x + 4;
		r = s2.stem >= 0 ? 0 : s2.nhd
		if (s2.notes[r].shhd > 0)
			x2 += s2.notes[r].shhd
		if (s2.st == upstaff
		 && s2.stem > 0)
			x2 += 3.5
	}

	xm = .5 * (x1 + x2);
	ym = .5 * (y1 + y2);

	a = (y2 - y1) / (x2 - x1);
	s0 = 3 * (s2.notes[s2.nhd].pit - s1.notes[s1.nhd].pit) / (x2 - x1)
	if (s0 > 0) {
		if (a < 0)
︙
2372
2373
2374
2375
2376
2377
2378
2379

2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392

2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407


2408
2409
2410
2411
2412
2413
2414
2415
2416
2422
2423
2424
2425
2426
2427
2428

2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445













2446
2447


2448
2449
2450
2451
2452
2453
2454







-
+













+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-







	}

	ym += dy;
	y1 = ym + a * (x1 - xm);
	y2 = ym + a * (x2 - xm);

	/* shift the slurs / decorations */
	ym += 8
	ym += 6
	for (s3 = s1; ; s3 = s3.next) {
		if (s3.st == upstaff) {
			yy = ym + (s3.x - xm) * a
			if (s3.ymx < yy)
				s3.ymx = yy
			if (s3 == s2)
				break
			y_set(upstaff, true, s3.x, s3.next.x - s3.x, yy)
		} else if (s3 == s2) {
			break
		}
	}

    // below
    } else {	/* lower voice of the staff: the bracket is below the staff */
/*fixme: think to all of that again..*/
	x1 = s1.x - 7
	if (s2.dur > s2.prev.dur) {
		if (s2.next)
			x2 = s2.next.x - s2.next.wl - 8
		else
			x2 = realwidth - 6
	} else {
		x2 = s2.x + 2
		if (s2.notes[s2.nhd].shhd > 0)
			x2 += s2.notes[s2.nhd].shhd
	}
	if (s1.stem >= 0) {
		x1 += 2;
	if (s1.stem < 0)
		x1 -= 2
		x2 += 2
	}

	if (s1.st == upstaff) {
		for (s3 = s1; !s3.dur; s3 = s3.next)
			;
		y1 = y_get(upstaff, 0, s3.x - 4, 8)
	} else {
		y1 = 0
︙
2455
2456
2457
2458
2459
2460
2461
2462

2463
2464
2465
2466
2467
2468
2469
2493
2494
2495
2496
2497
2498
2499

2500
2501
2502
2503
2504
2505
2506
2507







-
+







		yx = y_get(upstaff, 0, s3.x - 4, 8)
		if (yx - yy < dy)
			dy = yx - yy
		if (s3 == s2)
			break
	}

	ym += dy - 10;
	ym += dy - 8
	y1 = ym + a * (x1 - xm);
	y2 = ym + a * (x2 - xm);

	/* shift the slurs / decorations */
	ym -= 2
	for (s3 = s1; ; s3 = s3.next) {
		if (s3.st == upstaff) {
︙
2512
2513
2514
2515
2516
2517
2518
2519

2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535

2536
2537
2538
2539
2540
2541
2542
2550
2551
2552
2553
2554
2555
2556

2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572

2573
2574
2575
2576
2577
2578
2579
2580







-
+















-
+







			if (s1.notes[m + 1].shhd > sh)
				sh = s1.notes[m + 1].shhd
	} else {
		if (m > 0 && p == s1.notes[m - 1].pit + 1)
			if (s1.notes[m - 1].shhd > sh)
				sh = s1.notes[m - 1].shhd
	}
	x1 = s1.x + sh * .6
	x1 = s1.x + sh // * .6

	if (job != 2) {
		for (m = 0; m < s2.nhd; m++)
			if (s2.notes[m] == not2)
				break
		sh = s2.notes[m].shhd
		if (dir > 0) {
			if (m < s2.nhd && p + 1 == s2.notes[m + 1].pit)
				if (s2.notes[m + 1].shhd < sh)
					sh = s2.notes[m + 1].shhd
		} else {
			if (m > 0 && p == s2.notes[m - 1].pit + 1)
				if (s2.notes[m - 1].shhd < sh)
					sh = s2.notes[m - 1].shhd
		}
		x2 += sh * .6
		x2 += sh // * .6
	}

	switch (job) {
	case 0:
		p = (not1.pit & 1) ? not1.pit : not2.pit
		break
	case 3:				/* clef or staff change */
︙
2576
2577
2578
2579
2580
2581
2582
2583

2584
2585

2586
2587
2588
2589
2590
2591
2592
2614
2615
2616
2617
2618
2619
2620

2621
2622

2623
2624
2625
2626
2627
2628
2629
2630







-
+

-
+







	}

	if (s1.dots && !(not1.pit & 1)
	 && ((dir > 0 && !s1.dot_low)
	  || (dir < 0 && s1.dot_low)))
		x1 += 5

	y = staff_tb[st].y + 3 * (p - 18)
	y = staff_tb[st].y + 3 * (p - 18) + /* 1.0 * */ dir

	h = (.03 * (x2 - x1) + 16) * dir
	h = (.03 * (x2 - x1) + 16) * dir * cfmt.tieheight
//	anno_start(k1, 'slur')
	slur_out(x1, y, x2, y, dir, h, not1.tie_ty & C.SL_DOTTED)
//	anno_stop(k1, 'slur')
}

/* -- draw ties between neighboring notes/chords -- */
function draw_ties(k1, k2,
︙
2792
2793
2794
2795
2796
2797
2798
2799

2800
2801




























2802















2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814

2815



2816
2817
2818
2819
2820
2821
2822


2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855




2856
2857
2858
2859
2860
2861
2862
2830
2831
2832
2833
2834
2835
2836

2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894

2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914















2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925

2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936







-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
+

+
+
+







+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
+
+
+
+







 *   - chord symbols
 *   - staff decorations
 *   - lyrics
 *   - measure numbers
 * The buffer output is delayed until the definition of the staff system
 */
function draw_sym_near() {
    var	p_voice, p_st, s, v, st, y, g, w, i, st, dx, top, bot,
    var	p_voice, p_st, s, v, st, y, g, w, i, st, dx, top, bot, ymn,
	output_sav = output;

	// set the staff offsets of a beam
	function set_yab(s1, s2) {
	    var y,
		k = realwidth / YSTEP,
		i = (s1.x / k) | 0,
		j = (s2.x / k) | 0,
		a = (s1.ys - s2.ys) / (s1.xs - s2.xs),
		b = s1.ys - s1.xs * a,
		p_st = staff_tb[s1.st]

		k *= a
		if (s1.stem > 0) {
			while (i <= j) {
				y = k * i + b
				if (p_st.top[i] < y)
					p_st.top[i] = y
				i++
			}
		} else {
			while (i <= j) {
				y = k * i + b
				if (p_st.bot[i] > y)
					p_st.bot[i] = y
				i++
			}
		}
	} // set_yab()

	output = ""

	// initialize the min/max vertical offsets in the staves
	for (st = 0; st <= nstaff; st++) {
		p_st = staff_tb[st]
		if (!p_st.top) {
			p_st.top = new Float32Array(YSTEP)
			p_st.bot = new Float32Array(YSTEP)
		}
		for (i = 0; i < YSTEP; i++) {
			p_st.top[i] = 0
			p_st.bot[i] = 24
		}
//		p_st.top.fill(0.)
//		p_st.bot.fill(24.)
	}

	/* calculate the beams but don't draw them (the staves are not yet defined) */
	for (v = 0; v < voice_tb.length; v++) {
		var	bm = {},
			first_note = true;

		p_voice = voice_tb[v]
		for (s = p_voice.sym; s; s = s.next) {
			switch (s.type) {
			case C.GRACE:
				for (g = s.extra; g; g = g.next) {
					if (g.beam_st && !g.beam_end)
					if (g.beam_st && !g.beam_end) {
						self.calculate_beam(bm, g)
						if (bm.s2)
							set_yab(g, bm.s2)
					}
				}
				break
			case C.NOTE:
				if ((s.beam_st && !s.beam_end)
				 || (first_note && !s.beam_st)) {
					first_note = false;
					self.calculate_beam(bm, s)
					if (bm.s2)
						set_yab(s, bm.s2)
				}
				break
			}
		}
	}

	/* initialize the min/max vertical offsets */
	for (st = 0; st <= nstaff; st++) {
		p_st = staff_tb[st]
		if (!p_st.top) {
			p_st.top = new Float32Array(YSTEP);
			p_st.bot = new Float32Array(YSTEP)
		}
		for (i = 0; i < YSTEP; i++) {
			p_st.top[i] = 0;
			p_st.bot[i] = 24
		}
//		p_st.top.fill(0.);
//		p_st.bot.fill(24.)
	}

	set_tie_room();
	draw_deco_near()

	/* set the min/max vertical offsets */
	for (s = tsfirst; s; s = s.ts_next) {
		if (s.invis)
			continue
		switch (s.type) {
		case C.GRACE:
			for (g = s.extra; g; g = g.next) {
				y_set(s.st, true, g.x - 2, 4, g.ymx + 1);
				y_set(s.st, false, g.x - 2, 4, g.ymn - 1)
				y_set(s.st, false, g.x - 2, 4,
//fixme: hack for slur/accidental far under the staff
//						g.ymn - 1)
						g.ymn - 5)
			}
			continue
		case C.MREST:
			y_set(s.st, true, s.x + 16, 32, s.ymx + 2)
			continue
		default:
			y_set(s.st, true, s.x - s.wl, s.wl + s.wr, s.ymx + 2);
︙
2875
2876
2877
2878
2879
2880
2881




2882

2883
2884
2885
2886
2887
2888
2889
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959

2960
2961
2962
2963
2964
2965
2966
2967







+
+
+
+
-
+







				dx = 3;
				w = s.beam_end ? 4 : 10
			} else {
				dx = -8;
				w = s.beam_end ? 11 : 16
			}
			y_set(s.st, true, s.x + dx, w, s.ymx);
			ymn = s.ymn
			if (s.notes[0].acc	// set room for the accidental
			 && ymn > 3 * (s.notes[0].pit - 18) - 9)
				ymn = 3 * (s.notes[0].pit - 18) - 9
			y_set(s.st, false, s.x - s.wl, s.wl + s.wr, s.ymn)
			y_set(s.st, false, s.x - s.wl, s.wl + s.wr, ymn)
		} else {
			y_set(s.st, true, s.x - s.wl, s.wl + s.wr, s.ymx);
			if (s.stemless) {
				dx = -5;
				w = 10
			} else if (s.beam_st) {
				dx = -6;
︙
2928
2929
2930
2931
2932
2933
2934


2935
2936
2937
2938
2939
2940
2941
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021







+
+







//  if (st == undefined) {
//error(1, s, "BUG: no staff for voice " + p_voice.id)
//    continue
//  }

		// draw the slurs and tuplets
		for ( ; s; s = s.next) {
			if (s.play)
				continue
			if (s.tp)
				draw_tuplet(s)
			if (s.sls || s.sl1)
				draw_slurs(s)
		}
	}
	set_color()
︙
2970
2971
2972
2973
2974
2975
2976
2977

2978
2979
2980
2981
2982


2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994

2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010

3011
3012
3013
3014
3015
3016
3017
3018
3019
3020

3021
3022

3023
3024
3025
3026
3027
3028
3029
3030
3031

3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053



3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071

3072

3073
3074
3075
3076
3077
3078
3079

3080
3081
3082
3083
3084
3085




3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099

3100
3101
3102
3103

3104
3105
3106
3107
3108
3109
3110
3050
3051
3052
3053
3054
3055
3056

3057
3058
3059
3060


3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073

3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089

3090
3091
3092
3093
3094
3095
3096
3097
3098
3099

3100
3101

3102
3103
3104
3105
3106
3107
3108
3109
3110

3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131


3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153

3154
3155
3156
3157
3158
3159
3160

3161
3162
3163
3164
3165


3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182

3183
3184

3185
3186
3187
3188
3189
3190
3191
3192
3193
3194







-
+



-
-
+
+











-
+















-
+









-
+

-
+








-
+




















-
-
+
+
+


















+
-
+






-
+




-
-
+
+
+
+













-
+

-


+







	}

	set_dscale(-1);
	output = output_sav
}

/* -- draw the name/subname of the voices -- */
function draw_vname(indent) {
function draw_vname(indent, stl) {
    var	p_voice, n, st, v, a_p, p, y, name_type, h, h2,
	staff_d = []

	for (st = cur_sy.nstaff; st >= 0; st--) {
		if (cur_sy.st_print[st])
	for (st = stl.length; st >= 0; st--) {
		if (stl[st])
			break
	}
	if (st < 0)
		return

	// check if full or sub names
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (!p_voice.sym || !cur_sy.voices[v])
			continue
		st = cur_sy.voices[v].st
		if (!cur_sy.st_print[st])
		if (!stl[st])
			continue
		if (p_voice.new_name) {
			name_type = 2
			break
		}
		if (p_voice.snm)
			name_type = 1
	}
	if (!name_type)
		return
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (!p_voice.sym || !cur_sy.voices[v])
			continue
		st = cur_sy.voices[v].st
		if (!cur_sy.st_print[st])
		if (!stl[st])
			continue
		if (p_voice.new_name)
			delete p_voice.new_name;
		p = name_type == 2 ? p_voice.nm : p_voice.snm
		if (!p)
			continue
		if (!staff_d[st])
			staff_d[st] = p
		else
			staff_d[st] += "\\n" + p
			staff_d[st] += "\n" + p
	}
	if (staff_d.length == 0)
	if (!staff_d.length)
		return
	set_font("voice");
	h = gene.curfont.size
	h2 = h / 2
	indent = -indent * .5			/* center */
	for (st = 0; st < staff_d.length; st++) {
		if (!staff_d[st])
			continue
		a_p = staff_d[st].split('\\n');
		a_p = staff_d[st].split("\n");
		y = staff_tb[st].y
			+ staff_tb[st].topbar * .5
				* staff_tb[st].staffscale
			+ h2 * (a_p.length - 2)

		// if instrument with 2 staves, center the voice name
		if ((cur_sy.staves[st].flags & OPEN_BRACE)
		 && (cur_sy.staves[st + 1].flags & CLOSE_BRACE)
		 && !staff_d[st + 1])
			y -= (staff_tb[st].y - staff_tb[st + 1].y) * .5
		for (n = 0; n < a_p.length; n++) {
			p = a_p[n];
			xy_str(indent, y, p, "c");
			y -= h
		}
	}
}

// -- set the y offset of the staves and return the height of the whole system --
function set_staff() {
	var	s, i, st, prev_staff, v,
		y, staffsep, dy, maxsep, mbot, val, p_voice, p_staff
var	s, i, st, prev_staff, v,
	y, staffsep, dy, maxsep, mbot, val, p_voice, p_staff,
	sy = cur_sy

	/* set the scale of the voices */
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (p_voice.scale != 1)
			p_voice.scale_str = 
				'transform="scale(' + p_voice.scale.toFixed(2) + ')"'
	}

	// search the top staff
	for (st = 0; st <= nstaff; st++) {
		if (gene.st_print[st])
			break
	}
	y = 0
	if (st > nstaff) {
		st--;			/* one staff, empty */
		p_staff = staff_tb[st]
	}
	} else {
// else {
		p_staff = staff_tb[st]
		for (i = 0; i < YSTEP; i++) {
			val = p_staff.top[i]
			if (y < val)
				y = val
		}
	}
//	}

	/* draw the parts and tempo indications if any */
	y += draw_partempo(st, y)

	if (!gene.st_print[st])
		return y;
	if (!gene.st_print[st]) {
		p_staff.y = -y
		return y
	}

	/* set the vertical offset of the 1st staff */
	y *= p_staff.staffscale;
	staffsep = cfmt.staffsep * .5 +
			p_staff.topbar * p_staff.staffscale
	if (y < staffsep)
		y = staffsep
	if (y < p_staff.ann_top)	// absolute annotation
		y = p_staff.ann_top;
	p_staff.y = -y;

	/* set the offset of the other staves */
	prev_staff = st
	var sy_staff_prev = cur_sy.staves[prev_staff]
	var sy_staff_prev = sy.staves[prev_staff]
	for (st++; st <= nstaff; st++) {
		p_staff = staff_tb[st]
		if (!gene.st_print[st])
			continue
		p_staff = staff_tb[st]
		staffsep = sy_staff_prev.sep || cfmt.sysstaffsep;
		maxsep = sy_staff_prev.maxsep || cfmt.maxsysstaffsep;

		dy = 0
		if (p_staff.staffscale == staff_tb[prev_staff].staffscale) {
			for (i = 0; i < YSTEP; i++) {
				val = p_staff.top[i] -
︙
3128
3129
3130
3131
3132
3133
3134

3135





3136
3137
3138
3139
3140
3141
3142
3212
3213
3214
3215
3216
3217
3218
3219

3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231







+
-
+
+
+
+
+







		maxsep += p_staff.topbar * p_staff.staffscale
		if (dy > maxsep)
			dy = maxsep;
		y += dy;
		p_staff.y = -y;

		prev_staff = st;
		while (1) {
		sy_staff_prev = cur_sy.staves[prev_staff]
			sy_staff_prev = sy.staves[prev_staff]
			if (sy_staff_prev)
				break
			sy = sy.next
		}
	}
	mbot = 0
	for (i = 0; i < YSTEP; i++) {
		val = staff_tb[prev_staff].bot[i]
		if (mbot > val)
			mbot = val
	}
︙
3177
3178
3179
3180
3181
3182
3183

3184
3185
3186
3187
3188
3189
3190
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280







+







}

/* -- draw the staff systems and the measure bars -- */
function draw_systems(indent) {
	var	s, s2, st, x, x2, res, sy,
		staves_bar, bar_force,
		xstaff = [],
		stl = [],		// all staves in the line
		bar_bot = [],
		bar_height = [],
		ba = [],		// bars [symbol, bottom, height]
		sb = [],
		thb = []

	/* -- set the bottom and height of the measure bars -- */
︙
3210
3211
3212
3213
3214
3215
3216
3217

3218
3219
3220
3221
3222
3223
3224
3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3314







-
+







	} // bar_set()

	/* -- draw a staff -- */
	function draw_staff(st, x1, x2) {
		var	w, ws, i, dy, ty,
			y = 0,
			ln = "",
			stafflines = cur_sy.staves[st].stafflines,
			stafflines = staff_tb[st].stafflines,
			l = stafflines.length

		if (!/[\[|]/.test(stafflines))
			return				// no line
		w = x2 - x1;
		set_sscale(st);
		ws = w / stv_g.scale
︙
3306
3307
3308
3309
3310
3311
3312
3313

3314
3315
3316
3317
3318
3319
3320
3321
3396
3397
3398
3399
3400
3401
3402

3403

3404
3405
3406
3407
3408
3409
3410







-
+
-







			if (s.bar_mrep == 1) {
				for (s2 = s.prev; s2.type != C.REST; s2 = s2.prev)
					;
				xygl(s2.x, yb, "mrep")
			} else {
				xygl(x, yb, "mrep2")
				if (s.v == cur_sy.top_voice)
					xy_str(x, yb + p_staff.topbar - 9,
					nrep_out(x, yb + p_staff.topbar, s.bar_mrep)
						s.bar_mrep.toString(), "c")
			}
		}

		if (bar_type == '||:')
			bar_type = '[|:'

		for (i = bar_type.length; --i >= 0; ) {
︙
3358
3359
3360
3361
3362
3363
3364
3365
3366



3367
3368
3369
3370
3371
3372
3373
3374

3375
3376
3377
3378
3379
3380
3381
3447
3448
3449
3450
3451
3452
3453


3454
3455
3456


3457
3458
3459
3460
3461

3462
3463
3464
3465
3466
3467
3468
3469







-
-
+
+
+
-
-





-
+








	// output all the bars
	function out_bars() {
	    var	i, b, bx,
		l = ba.length

		set_font("annotation");
		if (gene.curfont.box) {
			gene.curfont.box = false
		bx = gene.curfont.box
		if (bx)
			gene.curfont.box = 0
			bx = true
		}
		for (i = 0; i < l; i++) {
			b = ba[i];		// symbol, bottom, height
			draw_bar(b[0], b[1], b[2])
		}
		if (bx)
			gene.curfont.box = true
			gene.curfont.box = bx

		set_sscale(-1)
		l = sb.length
		if (l) {			// single bars [x, y, h]
			output += '<path class="bW" d="'
			for (i = 0; i < l; i++) {
				b = sb[i];
︙
3391
3392
3393
3394
3395
3396
3397
3398

3399
3400
3401
3402

3403


3404
3405
3406
3407
3408
3409
3410
3479
3480
3481
3482
3483
3484
3485

3486

3487
3488

3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499







-
+
-


-
+

+
+







				b = thb[i];
				out_XYAB('MX Yv-F', b[0], b[1], b[2])
			}
			output += '"/>\n'
		}
	} // out_bars()

	// draw_systems()
	// ---- draw_systems() ----
	draw_vname(indent)

	/* draw the staff, skipping the staff breaks */
	for (st = 0; st <= nstaff; st++)
	for (st = 0; st <= nstaff; st++) {
		xstaff[st] = !cur_sy.st_print[st] ? -1 : 0;
		stl[st] = cur_sy.st_print[st]	// staff in the line
	}
	bar_set();
	draw_lstaff(0)
	for (s = tsfirst; s; s = s.ts_next) {
		if (bar_force && s.time != bar_force) {
			bar_force = 0
			for (st = 0; st <= nstaff; st++) {
				if (!cur_sy.st_print[st])
︙
3432
3433
3434
3435
3436
3437
3438
3439

3440
3441


3442
3443
3444
3445
3446
3447
3448
3521
3522
3523
3524
3525
3526
3527

3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539







-
+


+
+







			if (!s2)
				staves_bar = realwidth;
		    }
			sy = s.sy
			for (st = 0; st <= nstaff; st++) {
				x = xstaff[st]
				if (x < 0) {		// no staff yet
					if (sy.st_print[st])
					if (sy.st_print[st]) {
						xstaff[st] = staves_bar ?
							staves_bar : (s.x - s.wl - 2)
						stl[st] = true
					}
					continue
				}
				if (sy.st_print[st]	// if not staff stop
				 && sy.staves[st].stafflines ==
						cur_sy.staves[st].stafflines)
					continue
				if (staves_bar) {
︙
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496






3497
3498

3499
3500
3501


3502
3503
3504
3505
3506
3507
3508
3572
3573
3574
3575
3576
3577
3578






3579
3580
3581
3582
3583
3584
3585
3586
3587
3588

3589
3590


3591
3592
3593
3594
3595
3596
3597
3598
3599







-
-
-
-
-
-



+
+
+
+
+
+

-
+

-
-
+
+







							break
						nv--
					}
					if (nv == 0)
						draw_lstaff(s.x)
				}
			}
			s2 = s.prev
			if (!s2)
				break
			x2 = s2.x
			if (s2.type != C.BAR)
				x2 += s2.wr;
			st = s.st;
			x = xstaff[st]
			if (x >= 0) {
				s2 = s.prev
				if (!s2)
					break
				x2 = s2.type == C.BAR ?
					s2.x :
					s.x - s.xmx
				if (x >= x2)
					continue
					break
				draw_staff(st, x, x2)
			}
			xstaff[st] = s.x
				xstaff[st] = s.x
			}
			break
//		default:
//fixme:does not work for "%%staves K: M: $" */
//removed for K:/M: in empty staves
//			if (!cur_sy.st_print[st])
//				s.invis = true
//			break
︙
3517
3518
3519
3520
3521
3522
3523



3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538

3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559

3560
3561
3562
3563
3564
3565
3566

3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631

3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652

3653
3654
3655
3656
3657
3658


3659
3660
3661
3662
3663
3664
3665
3666
3667
3668

3669
3670
3671
3672
3673
3674
3675







+
+
+














-
+




















-
+





-
-
+









-







		if (x < 0 || x >= realwidth)
			continue
		draw_staff(st, x, realwidth)
	}

	// and the bars
	out_bars()

	draw_vname(indent, stl)

//	set_sscale(-1)
}

/* -- draw remaining symbols when the staves are defined -- */
// (possible hook)
Abc.prototype.draw_symbols = function(p_voice) {
	var	bm = {},
		s, g, x, y, st;

//	bm.s2 = undefined
	for (s = p_voice.sym; s; s = s.next) {
		if (s.invis) {
			switch (s.type) {
			case C.KEY:
				p_voice.key = s
				p_voice.ckey = s
			default:
				continue
			case C.NOTE:	// (beams may start on invisible notes)
				break
			}
		}
		st = s.st
		x = s.x;
		set_color(s.color)
		switch (s.type) {
		case C.NOTE:
//--fixme: recall set_scale if different staff
			set_scale(s)
			if (s.beam_st && !s.beam_end) {
				if (self.calculate_beam(bm, s))
					draw_beams(bm)
			}
			if (!s.invis) {
				anno_start(s);
				draw_note(s, !bm.s2);
				anno_stop(s)
				anno_a.push(s)
			}
			if (s == bm.s2)
				bm.s2 = null
			break
		case C.REST:
			if (s.invis
			 || !staff_tb[st].topbar)
			if (!staff_tb[st].topbar)
				break
			draw_rest(s);
			break
		case C.BAR:
			break			/* drawn in draw_systems */
		case C.CLEF:
			if (s.time >= staff_tb[st].clef.time)
				staff_tb[st].clef = s
			if (s.second
			 || s.invis
			 || !staff_tb[st].topbar)
				break
			set_color();
			set_sscale(st);
			anno_start(s);
			y = staff_tb[st].y
			if (s.clef_name)
︙
3595
3596
3597
3598
3599
3600
3601
3602

3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614


3615
3616
3617

3618
3619
3620
3621
3622
3623
3624
3625
3626

3627
3628
3629
3630
3631
3632
3633
3634
3635
3636

3637
3638
3639
3640
3641
3642
3643
3687
3688
3689
3690
3691
3692
3693

3694
3695
3696
3697
3698

3699
3700
3701
3702
3703


3704
3705
3706
3707

3708
3709

3710
3711
3712
3713
3714
3715

3716
3717
3718
3719
3720
3721
3722
3723
3724
3725

3726
3727
3728
3729
3730
3731
3732
3733







-
+




-





-
-
+
+


-
+

-






-
+









-
+







				} else {
					y += s.ymn + 6
					if (s.clef_small)
						y += 1
				}
				xygl(x - 2, y, "oct")
			}
			anno_stop(s)
			anno_a.push(s)
			break
		case C.METER:
			p_voice.meter = s
			if (s.second
//			 || s.invis
			 || !staff_tb[s.st].topbar)
				break
			set_color();
			set_sscale(s.st);
			anno_start(s);
			draw_meter(x, s);
			anno_stop(s)
			draw_meter(s);
			anno_a.push(s)
			break
		case C.KEY:
			p_voice.key = s
			p_voice.ckey = s
			if (s.second
			 || s.invis
			 || !staff_tb[s.st].topbar)
				break
			set_color();
			set_sscale(s.st);
			anno_start(s);
			self.draw_keysig(x, s);
			anno_stop(s)
			anno_a.push(s)
			break
		case C.MREST:
			set_scale(s);
			x += 32;
			anno_start(s);
			xygl(x, staff_tb[s.st].y + 12, "mrest");
			out_XYAB('<text style="font:bold 15px serif"\n\
	x ="X" y="Y" text-anchor="middle">A</text>\n',
				x, staff_tb[s.st].y + 28, s.nmes);
			anno_stop(s)
			anno_a.push(s)
			break
		case C.GRACE:
			set_scale(s);
			draw_gracenotes(s)
			break
		case C.SPACE:
		case C.STBRK:
︙
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669


3670













































3671
3672
3673
3674

3675



3676
3677
3678







3679
3680
3681
3682
3683
3684
3685
3744
3745
3746
3747
3748
3749
3750



3751
3752
3753
3754


3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805

3806
3807
3808
3809
3810



3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824







-
-
-




-
-
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+

+
+
+
-
-
-
+
+
+
+
+
+
+







			break
		default:
			error(2, s, "draw_symbols - Cannot draw symbol " + s.type)
			break
		}
	}
	set_scale(p_voice.sym);
	draw_all_ties(p_voice);
// no need to reset the scale as in abcm2ps
	set_color()
}

/* -- draw all symbols -- */
function draw_all_sym() {
	var	p_voice, v,
		n = voice_tb.length
    var	p_voice, v,
	n = voice_tb.length

	// draw all the helper/ledger lines
	function draw_all_hl() {
	    var	st, p_st

		function hlud(hla, d) {
		    var	hl, hll, i, xp, dx2, x2,
			n = hla.length

			if (!n)
				return
			for (i = 0; i < n; i++) {	// for all lines
				hll = hla[i]
				if (!hll || !hll.length)
					continue
				xp = sx(hll[0][0])	// previous x
				output +=
				    '<path class="stroke" stroke-width="1" d="M' +
					xp.toFixed(1) + ' ' +
					sy(p_st.y + d * i).toFixed(1)
				dx2 = 0
				while (1) {
					hl = hll.shift()
					if (!hl)
						break
					x2 = sx(hl[0])
					output += 'm' +
						(x2 - xp + hl[1] - dx2).toFixed(1) +
						' 0h' + (-hl[1] + hl[2]).toFixed(1)
					xp = x2
					dx2 = hl[2]
				}
				output += '"/>\n'
			}
		} // hlud()

		for (st = 0; st <= nstaff; st++) {
			p_st = staff_tb[st]
			if (!p_st.hlu)
				continue	// (staff not yet displayed)
			set_sscale(st)
			hlud(p_st.hlu, 6)
			hlud(p_st.hld, -6)
		}
	} // draw_all_hl()

	for (v = 0; v < n; v++) {
		p_voice = voice_tb[v]
		if (p_voice.sym
		 && p_voice.sym.x != undefined)
		 && p_voice.sym.x != undefined) {
			self.draw_symbols(p_voice)
			draw_all_ties(p_voice);
// no need to reset the scale as in abcm2ps
			set_color()
	}

	draw_all_deco();
		}
	}

	self.draw_all_deco()
	draw_all_hl()
	glout()			// output the symbols
	anno_put()		// before outputting the symbol annotations
	set_sscale(-1)				/* restore the scale */
}

/* -- set the tie directions for one voice -- */
function set_tie_dir(s) {
    var i, ntie, dir, sec, pit, ty

︙
Changes to core/format.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - format.js - formatting functions
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2021 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+







		'sans-serifBold': 1,
		Palatino: 1.1,
		monospace: 1.35
	},
	fmt_lock = {}

var cfmt = {
	annotationfont: {name: "sans-serif", size: 12 },
	annotationfont: {name: "sans-serif", size: 12},
	aligncomposer: 1,
	beamslope: .4,			// max slope of a beam
//	botmargin: .7 * IN,		// != 1.8 * CM,
	breaklimit: .7,
	breakoneoln: true,
	cancelkey: true,
	composerfont: { name: "serif", style: "italic", size: 14 },
︙
64
65
66
67
68
69
70

71
72

73
74
75
76
77
78
79
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81







+


+







	keywarn: true,
	leftmargin: 1.4 * CM,
	lineskipfac: 1.1,
	linewarn: true,
	maxshrink: .65,		// nice scores
	maxstaffsep: 2000,
	maxsysstaffsep: 2000,
	measrepnb: 1,
	measurefont: {name: "serif", style: "italic", size: 10},
	measurenb: -1,
	musicfont: {name: "music", src: musicfont, size: 24},
	musicspace: 6,
//	notespacingfactor: 1.33
	partsfont: {name: "serif", size: 15},
	parskipfac: .4,
	partsspace: 8,
//	pageheight: 29.7 * CM,
	pagewidth: 21 * CM,
︙
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117







+








+







	subtitlefont: {name: "serif", size: 16},
	subtitlespace: 3,
	sysstaffsep: 34,
	tempofont: {name: "serif", weight: "bold", size: 12},
	textfont: {name: "serif", size: 16},
//	textoption: undefined,
	textspace: 14,
	tieheight: 1.0,
	titlefont: {name: "serif", size: 20},
//	titleleft: false,
	titlespace: 6,
	titletrim: true,
//	transp: 0,			// global transpose
//	topmargin: .7 * IN,
	topspace: 22,
	tuplets: [0, 0, 0, 0],
	tupletfont: {name: "serif", style: "italic", size: 12},
	vocalfont: {name: "serif", weight: "bold", size: 13},
	vocalspace: 10,
	voicefont: {name: "serif", weight: "bold", size: 13},
//	voicescale: 1,
	writefields: "CMOPQsTWw",
	wordsfont: {name: "serif", size: 16},
	wordsspace: 5
︙
153
154
155
156
157
158
159
160



161
162
163
164
165


166
167
168
169
170
171
172
173

174

175
176









177
178
179
180
181
182
183
157
158
159
160
161
162
163

164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179

180
181
182


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198







-
+
+
+




-
+
+







-
+

+
-
-
+
+
+
+
+
+
+
+
+







			return
		xxxfont = "u" + n + "font"
	}

	// create a new font
	font = cfmt[xxxfont];
	if (!font) {			// set-font-<n> or new element
		font = {}
		font = {
			pad: 0
		}
	} else {
		font = {
			name: font.name,
			size: font.size,
			box: font.box
			box: font.box,
			pad: font.pad
		}
	}
	cfmt[xxxfont] = font;

	// fill the values
	a = p.match(/\s+(no)?box(\s|$)/)
	if (a) {				// if box
		if (a[1])
		if (a[1]) {
			font.box = false	// nobox
			font.pad = 0
		else
			font.box = true;
		} else {
			font.box = true
			font.pad = font.size * .4 - 3
		}
		p = p.replace(a[0], a[2])
	}
	a = p.match(/\s+padding=([\d.]+)(\s|$)/)
	if (a) {				// if padding
		font.pad = a[1] ? Number(a[1]) : 0
		p = p.replace(a[0], a[2])
	}

	a = p.match(/\s+class=(.*?)(\s|$)/)
	if (a) {
		font.class = a[1];
		p = p.replace(a[0], a[2])
︙
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
216
217
218
219
220
221
222

223
224


225
226
227
228
229
230
231







-
+

-
-







		}
		p = p.replace(a[0], a[2])
	}

	// the font size is the last item
	a = p.match(/\s+([0-9.]+|\*)$/)
	if (a) {
		if (a[1] != "*") {
		if (a[1] != "*")
			font.size = Number(a[1])
			font.swfac = 0
		}
		p = p.replace(a[0], "")
	}

	a = p.match(/[- ]?[nN]ormal/)
	if (a) {
		font.normal = true
		p = p.replace(a[0], '')
︙
229
230
231
232
233
234
235




236
237
238
239
240
241
242
243



244





245
246
247
248
249
250



251

252

253
254
255
256

257
258
259
260
261
262





263
264

265
266
267

268
269
270
271
272
273
274
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273

274
275
276
277
278

279

280


281

282




283
284
285
286
287


288

289

290
291
292
293
294
295
296
297







+
+
+
+








+
+
+
-
+
+
+
+
+





-
+
+
+

+
-
+
-

-
-
+
-

-
-
-
-
+
+
+
+
+
-
-
+
-

-
+







		p = p.replace(a[0], '')
	}
	a = p.match(/[- ]?[oO]blique/)
	if (a) {
		font.style = "oblique"
		p = p.replace(a[0], '')
	}
	if (font.size)
		set_font_fac(font)
	else
		font.swfac = 0
	switch (p) {
	case "":
	case "*": return
	case "Times-Roman":
	case "Times":	p = "serif"; break
	case "Helvetica": p = "sans-serif"; break
	case "Courier": p = "monospace"; break
	}

	// accept url(...) as the font name
	if (p[3] == '(') {
	font.swfac = 0
		font.src = p
		font.fid = font_tb.length
		font_tb.push(font)
		p = 'ft' + font.fid
	}
	font.name = p
}

// get a length with a unit - return the number of pixels
function get_unit(param) {
	var v = parseFloat(param)
    var	v = param.toLowerCase().match(/([\d.]+)(.*)/)
	if (!v)
		return NaN

	v[1] = Number(v[1])
	switch (param.slice(-2)) {
	switch (v[2]) {
	case "CM":
	case "cm":
		v *= CM
		break
		return v[1] * CM
	case "IN":
	case "in":
		v *= IN
		break
	case "PT":		// paper point in 1/72 inch
	case "pt":
		return v[1] * IN
	case "pt":		// paper point in 1/72 inch
		return v[1] * .75
	case "px":		// screen pixel in 1/96 inch
	case "":
		v *= .75
		break
		return v[1]
//	default:  // ('px')	// screen pixel in 1/96 inch
	}
	return v
	return NaN
}

// set the infoname
function set_infoname(param) {
//fixme: check syntax: '<letter> ["string"]'
	var	tmp = cfmt.infoname.split("\n"),
		letter = param[0]
︙
339
340
341
342
343
344
345
346
347
348
349
350

351
352

353
354
355

356
357

358
359
360
361
362
363
364
362
363
364
365
366
367
368





369


370



371
372

373
374
375
376
377
378
379
380







-
-
-
-
-
+
-
-
+
-
-
-
+

-
+







				cfmt.writefields = cfmt.writefields.replace(c, '')
		}
	}
}

// set a voice specific parameter
function set_v_param(k, v) {
	if (curvoice) {
		self.set_vp([k + '=', v])
		return
	}
	k = [k + '=', v];
	k = [k + '=', v]
	var vid = '*'
	if (!info.V)
	if (curvoice)
		info.V = {}
	if (info.V[vid])
		Array.prototype.push.apply(info.V[vid], k)
		set_kv_parm(k)
	else
		info.V[vid] = k
		memo_kv_parm('*', k)
}

function set_page() {
	if (!img.chg)
		return
	img.chg = false;
	img.lm = cfmt.leftmargin - cfmt.printmargin
︙
380
381
382
383
384
385
386



387

388
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450


451
452
453
454

455
456
457
458
459
460
461
396
397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425








426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461


462
463
464
465
466
467
468
469
470
471
472
473
474
475







+
+
+
-
+










+








-
-
-
-
-
-
-
-
















+



















-
-
+
+




+







// set a format parameter
// (possible hook)
Abc.prototype.set_format = function(cmd, param) {
	var f, f2, v, i

//fixme: should check the type and limits of the parameter values
	if (/.+font(-[\d])?$/.test(cmd)) {
		if (cmd == "soundfont")
			cfmt.soundfont = param
		else
		param_set_font(cmd, param)
			param_set_font(cmd, param)
		return
	}

	switch (cmd) {
	case "aligncomposer":
	case "barsperstaff":
	case "infoline":
	case "measurenb":
	case "rbmax":
	case "rbmin":
	case "measrepnb":
	case "shiftunison":
		v = parseInt(param)
		if (isNaN(v)) {
			syntax(1, "Bad integer value");
			break
		}
		cfmt[cmd] = v
		break
	case "microscale":
		f = parseInt(param)
		if (isNaN(f) || f < 4 || f > 256 || f % 1) {
			syntax(1, errs.bad_val, "%%" + cmd)
			break
		}
		set_v_param("uscale", f)
		break
	case "bgcolor":
	case "fgcolor":
	case "dblrepbar":
	case "titleformat":
		cfmt[cmd] = param
		break
	case "beamslope":
	case "breaklimit":			// float values
	case "lineskipfac":
	case "maxshrink":
	case "pagescale":
	case "parskipfac":
	case "scale":
	case "slurheight":
	case "stemheight":
	case "stretchlast":
	case "tieheight":
		f = parseFloat(param)
		if (isNaN(f)) {
			syntax(1, errs.bad_val, '%%' + cmd)
			break
		}
		switch (cmd) {
		case "scale":			// old scale
			f /= .75
		case "pagescale":
			cmd = "scale";
			img.chg = true
			break
		}
		cfmt[cmd] = f
		break
	case "annotationbox":
	case "gchordbox":
	case "measurebox":
	case "partsbox":
		cfmt[cmd.replace("box", "font")]	// font
			.box = get_bool(param)
		param_set_font(cmd.replace("box", "font"),	// font
			"* * " + (get_bool(param) ? "box" : "nobox"))
		break
	case "bstemdown":
	case "breakoneoln":
	case "cancelkey":
	case "checkbars":
	case "contbarnb":
	case "custos":
	case "decoerr":
	case "dynalign":
	case "flatbeams":
	case "graceslurs":
	case "graceword":
︙
470
471
472
473
474
475
476
477
478


479
480
481




482
483
484
485
486
487
488
484
485
486
487
488
489
490


491
492



493
494
495
496
497
498
499
500
501
502
503







-
-
+
+
-
-
-
+
+
+
+







	case "straightflags":
	case "stretchstaff":
	case "timewarn":
	case "titlecaps":
	case "titleleft":
		cfmt[cmd] = get_bool(param)
		break
	case "chordnames":
		v = param.split(',')
	case "chordalias":
		v = param.split(/\s+/)
		cfmt.chordnames = {}
		for (i = 0; i < v.length; i++)
			cfmt.chordnames['CDEFGAB'[i]] = v[i]
		if (!v.length)
			syntax(1, errs.bad_val, "%%chordalias")
		else
			abc2svg.ch_alias[v[0]] = v[1] || ""
		break
	case "composerspace":
	case "indent":
	case "infospace":
	case "maxstaffsep":
	case "maxsysstaffsep":
	case "musicspace":
︙
497
498
499
500
501
502
503



504
505
506
507
508
509
510
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528







+
+
+







	case "wordsspace":
		f = get_unit(param)	// normally, unit in points - 72 DPI accepted
		if (isNaN(f))
			syntax(1, errs.bad_val, '%%' + cmd)
		else
			cfmt[cmd] = f
		break
	case "page-format":
		user.page_format = get_bool(param)
		break
	case "print-leftmargin":	// to remove
		syntax(0, "$1 is deprecated - use %%printmargin instead", '%%' + cmd)
		cmd = "printmargin"
		// fall thru
	case "printmargin":
//	case "botmargin":
	case "leftmargin":
︙
648
649
650
651
652
653
654
655
656


657
658
659
660
661
662
663
664
665

666
667
668




669
670
671
672
673
674
675
676


677
678
679


680
681
682







683
684
685
686
687
688
689
666
667
668
669
670
671
672


673
674
675
676
677
678
679
680
681
682
683
684
685


686
687
688
689
690
691
692
693
694
695


696
697
698
699
700
701
702
703


704
705
706
707
708
709
710
711
712
713
714
715
716
717







-
-
+
+









+

-
-
+
+
+
+






-
-
+
+



+
+

-
-
+
+
+
+
+
+
+







    var	n = font.name,
	r = ""

	if (font.weight)
		r += font.weight + " "
	if (font.style)
		r += font.style + " "
	if (n.indexOf(' ') > 0)
		n = '"' + n.replace(/"/g, "") + '"'	// '
	if (n.indexOf('"') < 0 && n.indexOf(' ') > 0)
		n = '"' + n + '"'
	return r + font.size.toFixed(1) + 'px ' + n
}
function style_font(font) {
	return 'font:' + st_font(font)
}
Abc.prototype.style_font = style_font

// build a font class
function font_class(font) {
    var	f = 'f' + font.fid + cfmt.fullsvg
	if (font.class)
		return 'f' + font.fid + cfmt.fullsvg + ' ' + font.class
	return 'f' + font.fid + cfmt.fullsvg
		f += ' ' + font.class
	if (font.box)
		f += ' ' + 'box'
	return f
}

// use the font
function use_font(font) {
	if (!font.used) {
		font.used = true;
		if (font.fid == undefined) {
			font.fid = font_tb.length;
		if (font.fid == undefined) {	// if default font
			font.fid = font_tb.length
			font_tb.push(font)
			if (!font.swfac)
				set_font_fac(font)
			if (!font.pad)
				font.pad = 0
		}
		font_style += "\n.f" + font.fid + cfmt.fullsvg +
			" {" + style_font(font) + "}"
		add_fstyle(".f" + font.fid +
			(typeof document == "undefined" ? cfmt.fullsvg : "") +
			"{" + style_font(font) + "}")
		if (font.src)
			add_fstyle("@font-face{\n\
 font-family:" + font.name + ";\n\
 src:" + font.src + "}")
	}
}

// get the font of the 'xxxfont' parameter
function get_font(fn) {
    var	font, font2, fid, st

︙
705
706
707
708
709
710
711
712
713


714
715
716




717
718
719
720

721
722
723
724
725
726
733
734
735
736
737
738
739


740
741
742
743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758







-
-
+
+



+
+
+
+



-
+






				font2.style = null
		} else {
			if (font.weight)
				font2.weight = font.weight
			if (font.style)
				font2.style = font.style
		}
		if (font.class)
			font2.class = font.class
//		if (font.class)
//			font2.class = font.class
		if (font.size)
			font2.size = font.size
		st = st_font(font2)
		if (font.class) {
			font2.class = font.class
			st += ' '+ font.class
		}
		fid = font_st[st]
		if (fid != undefined)
			return font_tb[fid]
		font_st[st] = font_tb.length
		font_st[st] = font_tb.length	// will be the font id
		font2.fid = font2.used = undefined
		font = font2
	}
	use_font(font)
	return font
}
Changes to core/front.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - front.js - ABC parsing front-end
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+







	"2": "\u266d",
	"3": "\u266e",
	"4": "&#x1d12a;",
	"5": "&#x1d12b;"
}

// convert the escape sequences to utf-8
function cnv_escape(src) {
function cnv_escape(src, flag) {
	var	c, c2,
		dst = "",
		i, j = 0

	while (1) {
		i = src.indexOf('\\', j)
		if (i < 0)
︙
91
92
93
94
95
96
97
98






99
100
101
102
103




104
105
106
107
108
109
110
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119







-
+
+
+
+
+
+





+
+
+
+







		case 'u':
			j = Number("0x" + src.slice(i + 1, i + 5));
			if (isNaN(j) || j < 0x20) {
				dst += src[++i] + "\u0306"	// breve accent
				j = i + 1
				continue
			}
			dst += String.fromCharCode(j);
			c = String.fromCharCode(j)
			if (c == '\\') {
				i += 4
				break
			}
			dst += c
			j = i + 5
			continue
		case 't':			// TAB
			dst += ' ';
			j = i + 1
			continue
		case 'n':			// new line (voice name)
			dst += '\n';
			j = i + 1
			continue
		default:
			c2 = abc_utf[src.slice(i, i + 2)]
			if (c2) {
				dst += c2;
				j = i + 2
				continue
︙
170
171
172
173
174
175
176

177


178
179
180
181
182
183
184
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195







+
-
+
+







			case ';':
				dst += c2 + "\u0328"	// ogonek
				j = i + 2
				continue
			}
			break
		}
		if (flag == 'w')
		dst += '\\' + c;
			dst += '\\'
		dst += c
		j = i + 1
	}
	return dst + src.slice(j)
}

// ABC include
var include = 0
︙
237
238
239
240
241
242
243


244

245
246
247




248
249
250
251
252


253
254
255
256
257

258
259
260

261

262
263
264
265
266
267
268
269
248
249
250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266


267
268
269
270
271
272
273
274
275
276
277
278

279

280
281
282
283
284
285
286







+
+
-
+


-
+
+
+
+



-
-
+
+





+



+
-
+
-







			eol = re.lastIndex
		else
			eol = eof
		return false
	} // tune_selected()

	// remove the comment at end of text
	// if flag, handle the escape sequences
	// if flag is 'w' (lyrics), keep the '\'s
	function uncomment(src, do_escape) {
	function uncomment(src, flag) {
		if (!src)
			return src
		if (src.indexOf('%') >= 0)
	    var	i = src.indexOf('%')
		if (i == 0)
			return ''
		if (i > 0)
			src = src.replace(/([^\\])%.*/, '$1')
				 .replace(/\\%/g, '%');
		src = src.replace(/\s+$/, '')
		if (do_escape && src.indexOf('\\') >= 0)
			return cnv_escape(src)
		if (flag && src.indexOf('\\') >= 0)
			return cnv_escape(src, flag)
		return src
	} // uncomment()

	function end_tune() {
		generate()
		set_page()		// the page layout may have changed
		if (info.W)
			put_words(info.W);
		put_history();
		parse.state = 0		// file header
		blk_flush();
		blk_flush()		// (force end of block)
		parse.state = 0;		// file header
		cfmt = sav.cfmt;
		info = sav.info;
		char_tb = sav.char_tb;
		glovar = sav.glovar;
		maps = sav.maps;
		mac = sav.mac;
		maci = sav.maci;
︙
570
571
572
573
574
575
576
577
578



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
587
588
589
590
591
592
593


594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626







-
-
+
+
+














-








+







		}

		// music line (or free text)
		if (line1 != ':' || !/[A-Za-z+]/.test(line0)) {
			last_info = undefined;
			if (parse.state < 2)
				continue
			parse.line.buffer = uncomment(file.slice(bol, eol), true);
			parse_music_line()
			parse.line.buffer = uncomment(file.slice(bol, eol))
			if (parse.line.buffer)
				parse_music_line()
			continue
		}

		// information fields
		bol += 2
		while (1) {
			switch (file[bol]) {
			case ' ':
			case '\t':
				bol++
				continue
			}
			break
		}
		text = uncomment(file.slice(bol, eol), true)
		if (line0 == '+') {
			if (!last_info) {
				syntax(1, "+: without previous info field")
				continue
			}
			txt_add = ' ';		// concatenate
			line0 = last_info
		}
		text = uncomment(file.slice(bol, eol), line0)

		switch (line0) {
		case 'X':			// start of tune
			if (parse.state != 0) {
				syntax(1, errs.ignored, line0)
				continue
			}
︙
620
621
622
623
624
625
626



627
628
629
630
631
632
633
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654







+
+
+







			sav.char_tb = clone(char_tb);
			sav.glovar = clone(glovar);
			sav.maps = clone(maps, 1);
			sav.mac = clone(mac);
			sav.maci = clone(maci);
			info.X = text;
			parse.state = 1			// tune header
			if (user.page_format
			 && blkdiv < 1)		// (if no newpage)
				blkdiv = 1	// the tune starts by the next SVG
			if (parse.tune_opts)
				tune_filter()
			continue
		case 'T':
			switch (parse.state) {
			case 0:
				continue
︙
Changes to core/gchord.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49


50
51
52
53

54
55
56

57
58
59



60
61
62
63
64
65
66
67
68


69
70
71
72
73
74
75
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47


48
49
50
51
52

53
54


55



56
57
58

59
60
61





62
63
64
65
66
67
68
69
70


-
+




















-
-
+
+




















-
+

-
-
+
+



-
+

-
-
+
-
-
-
+
+
+
-



-
-
-
-
-
+
+







// abc2svg - gchord.js - chord symbols
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// -- parse a chord symbol / annotation --
// the result is added in the global variable a_gch
// 'type' may be a single '"' or a string '"xxx"' created by U:
function parse_gchord(type) {
	var	c, text, gch, x_abs, y_abs, type,
		i, istart, iend,
    var	c, text, gch, x_abs, y_abs, type,
	i, j, istart, iend,
		ann_font = get_font("annotation"),
		h_ann = ann_font.size,
		line = parse.line

	function get_float() {
		var txt = ''

		while (1) {
			c = text[i++]
			if ("1234567890.-".indexOf(c) < 0)
				return parseFloat(txt)
			txt += c
		}
	} // get_float()

	istart = parse.bol + line.index
	if (type.length > 1) {			// U:
		text = type.slice(1, -1);
		iend = istart + 1
	} else {
		text = ""
		i = ++line.index		// search the ending double quote
		while (1) {
			c = line.next_char()
			if (!c) {
			j = line.buffer.indexOf('"', i)
			if (j < 0) {
				syntax(1, "No end of guitar chord")
				return
			}
			if (c == '"')
			if (line.buffer[j - 1] != '\\')
				break
			if (c == '\\') {
				text += c;
			i = j + 1
				c = line.next_char()
			}
			text += c
		}
		text = cnv_escape(line.buffer.slice(line.index, j))
		line.index = j
		}
		iend = parse.bol + line.index + 1
	}

	if (curvoice.pos.gch == C.SL_HIDDEN)
		return

	if (ann_font.box)
		h_ann += 3;
	if (ann_font.pad)
		h_ann += ann_font.pad
	i = 0;
	type = 'g'
	while (1) {
		c = text[i]
		if (!c)
			break
		gch = {
︙
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179

180
181
182
183

184
185
186
187
188
189
190
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174

175
176
177
178

179
180
181
182
183
184
185
186







+
















-
+




-
+



-
+







				break
			case ';':
				break
			}
			i++
			break
		}
		gch.otext = gch.text	// save for play accompaniment
		if (!a_gch)
			a_gch = []
		a_gch.push(gch)
	}
}

// transpose a chord symbol
var	note_names = "CDEFGAB",
	acc_name = ["bb", "b", "", "#", "##"]

	function gch_tr1(p, transp) {
	    var	i, o, n, a, ip, b40,
		csa = p.split('/')

		for (i = 0; i < csa.length; i++) {	// main and optional bass
			p = csa[i];
			o = p.search(/[ABCDEFG]/);
			o = p.search(/[A-G]/)
			if (o < 0)
				continue		// strange chord symbol!
			ip = o + 1
			a = 0
			while (p[ip] == '#') {
			while (p[ip] == '#' || p[ip] == '\u266f') {
				a++;
				ip++
			}
			while (p[ip] == 'b') {
			while (p[ip] == 'b' || p[ip] == '\u266d') {
				a--;
				ip++
			}
			n = note_names.indexOf(p[o]) + 16
			b40 = (abc2svg.pab40(n, a) + transp + 200) % 40
			b40 = abc2svg.b40k[b40]
			csa[i] = p.slice(0, o) +
︙
202
203
204
205
206
207
208





209






210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255


256

257
258
259
260
261
262
263
264


265
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341

342
343
344
345
346
347
348
349
350
351



352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379













380
381
382

383
384
385


386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

















































































407






408
409
410
411
412























































413
414
415
416
417
418




419
420
421








198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218

219
220
221

222
223
224
225
226
227






228
229
230
231
232
233







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256


257
258


259
260
261
262
263
264
265
266
267


268
269
270
271
272
273


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289







290
291
292
293
294
295
296
297
298
299



300
301
302
303
304
305




306
307
308
309
310
311
312
313

314


315










316
317
318







319
320




















321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336



337
338
339
340
341


















342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429





430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484






485
486
487
488



489
490
491
492
493
494
495
496







+
+
+
+
+
-
+
+
+
+
+
+



-
+


-






-
-
-
-
-
-






-
-
-
-
-
-
-














+
+
-
+






-
-
+
+
-
-
+








-
-






-
-
















-
-
-
-
-
-
-










-
-
-






-
-
-
-








-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
	while (--i >= 0) {
		gch = s.a_gch[i]
		if (gch.type == 'g')
			gch.text = gch_tr1(gch.text, curvoice.vtransp)
	}
}

// parser: add the parsed list of chord symbols and annotations
//	to the symbol (note, rest or bar)
function csan_add(s) {
	s.a_gch = a_gch;
	a_gch = null
// -- build the chord indications / annotations --

	if (curvoice.vtransp)
		gch_transp(s)
} // csan_add

// generator: build the chord symbols / annotations
// (possible hook)
Abc.prototype.gch_build = function(s) {

	/* split the chord indications / annotations
	/* split the chord symbols / annotations
	 * and initialize their vertical offsets */
	var	gch, wh, xspc, ix,
		pos = curvoice.pos.gch == C.SL_BELOW ? -1 : 1,
		y_above = 0,
		y_below = 0,
		y_left = 0,
		y_right = 0,
		GCHPRE = .4;		// portion of chord before note

	s.a_gch = a_gch;
	a_gch = null

	if (curvoice.vtransp)
		gch_transp(s)

	// change the accidentals in the chord symbols,
	// convert the escape sequences in annotations, and
	// set the offsets
	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		if (gch.type == 'g') {
			if (cfmt.chordnames) {
				gch.otext = gch.text;	// save for %%diagram
				gch.text = gch.text.replace(/A|B|C|D|E|F|G/g,
					function(c){return cfmt.chordnames[c]})
				if (cfmt.chordnames.B == 'H')
					gch.text = gch.text.replace(/Hb/g, 'Bb')
			}
			gch.text = gch.text.replace(/##|#|=|bb|b|  /g,
				function(x) {
					switch (x) {
					case '##': return "&#x1d12a;"
					case '#': return "\u266f"
					case '=': return "\u266e"
					case 'b': return "\u266d"
					case '  ': return '  '
					}
					return "&#x1d12b;"
				});
		} else {
			if (gch.type == '@'
			 && !user.anno_start && !user.anno_stop) {
				set_font(gch.font)
				gch.text = str2svg(gch.text)
				gch.wh = [0, 0]
				gch.text.wh = [0, 0]
				continue		/* no width */
			}
		}

		/* set the offsets and widths */
		set_font(gch.font);
		wh = strwh(gch.text);
		gch.wh = wh
		gch.text = str2svg(gch.text)
		wh = gch.text.wh
		if (gch.font.box)
			wh[1] += 4
		wh[1] += gch.font.pad * 2
		switch (gch.type) {
		case '@':
			break
		case '^':			/* above */
			xspc = wh[0] * GCHPRE
			if (xspc > 8)
				xspc = 8;
			gch.x = -xspc;
			y_above -= wh[1];
			gch.y = y_above
			break
		case '_':			/* below */
			xspc = wh[0] * GCHPRE
			if (xspc > 8)
				xspc = 8;
			gch.x = -xspc;
			y_below -= wh[1];
			gch.y = y_below
			break
		case '<':			/* left */
			gch.x = -(wh[0] + 6);
			y_left -= wh[1];
			gch.y = y_left + wh[1] / 2
			break
		case '>':			/* right */
			gch.x = 6;
			y_right -= wh[1];
			gch.y = y_right + wh[1] / 2
			break
		default:			// chord symbol
			xspc = wh[0] * GCHPRE
			if (xspc > 8)
				xspc = 8;
			gch.x = -xspc;
			if (pos < 0) {		/* below */
				y_below -= wh[1];
				gch.y = y_below
			} else {
				y_above -= wh[1];
				gch.y = y_above
			}
			break
		}
	}

	/* move upwards the top and middle texts */
	y_left /= 2;
	y_right /= 2
	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		switch (gch.type) {
		case '^':			/* above */
			gch.y -= y_above
			break
		case '<':			/* left */
			gch.y -= y_left
			break
		case '>':			/* right */
			gch.y -= y_right
			break
		case 'g':			// chord symbol
			if (pos > 0)
				gch.y -= y_above
			break
		}
	}
}

// -- draw the chord symbols and annotations
// (the staves are not yet defined)
// (unscaled delayed output)
// (possible hook)
Abc.prototype.draw_gchord = function(s, gchy_min, gchy_max) {
Abc.prototype.draw_gchord = function(i, s, x, y) {
    var	gch, text, ix, x, y, y2, hbox, h, y_above, y_below,

    var	y2,
	// adjust the vertical offset according to the chord symbols
	w = 0,
		yav = s.dur ?
			(((s.notes[s.nhd].pit + s.notes[0].pit) >> 1) - 18) * 3 :
			12		// fixed offset on measure bars

	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		if (gch.wh[0] > w)
			w = gch.wh[0]
	an = s.a_gch[i],
	h = an.text.wh[1],
	pad = an.font.pad,
	}
	y_above = y_get(s.st, 1, s.x - 3, w);
	y_below = y_get(s.st, 0, s.x - 3, w)
	if (y_above < gchy_max)
		y_above = gchy_max
	if (y_below > gchy_min)
		y_below = gchy_min;
	w = an.text.wh[0] + pad * 2

	set_dscale(s.st);
	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix];
		use_font(gch.font);
		set_font(gch.font);
		h = gch.font.size;
		hbox = gch.font.box ? 2 : 0;
		w = gch.wh[0];
		x = s.x + gch.x;
		text = gch.text
		switch (gch.type) {
		case '_':			/* below */
			y = gch.y + y_below;
			y_set(s.st, 0, x, w, y - hbox)
			break
		case '^':			/* above */
			y = gch.y + y_above + hbox;
			y_set(s.st, 1, x, w, y + h + hbox)
			break
		case '<':			/* left */
	switch (an.type) {
	case '_':			// below
		y -= h + pad
		y_set(s.st, 0, x, w, y - pad)
		break
	case '^':			// above
		y = y_get(s.st, 1, x, w)
		y += pad
		y_set(s.st, 1, x, w, y + h + pad)
		break
	case '<':			// left
	case '>':			// right
		if (an.type == '<') {
/*fixme: what symbol space?*/
			if (s.notes[0].acc)
				x -= s.notes[0].shac;
				x -= s.notes[0].shac
			y = gch.y + yav - h / 2
			break
		case '>':			/* right */
			x -= pad
		} else {
			if (s.xmx)
				x += s.xmx
			if (s.dots)
				x += 1.5 + 3.5 * s.dots;
			y = gch.y + yav - h / 2
			break
		default:			// chord symbol
			if (gch.y >= 0) {
				y = gch.y + y_above + hbox;
				y_set(s.st, true, x, w, y + h + hbox)
			} else {
				y = gch.y + y_below;
				y_set(s.st, false, x, w, y - hbox)
			}
			break
		case '@':			/* absolute */
			y = gch.y + yav
			if (y > 0) {
				y2 = y + h
				if (y2 > staff_tb[s.st].ann_top)
					staff_tb[s.st].ann_top = y2
				x += 1.5 + 3.5 * s.dots
			x += pad
		}
		y += (s.type == C.NOTE ?
				(((s.notes[s.nhd].pit + s.notes[0].pit) >> 1) -
						18) * 3 :
				12)		// fixed offset on rests and bars
			- h / 2
		break
	default:			// chord symbol
		if (y >= 0) {
			y += pad
			y_set(s.st, 1, x, w, y + h + pad)
		} else {
			y -= h + pad
			y_set(s.st, 0, x, w, y - pad)
		}
		break
	case '@':			// absolute
		y += (s.type == C.NOTE ?
				(((s.notes[s.nhd].pit + s.notes[0].pit) >> 1) -
						18) * 3 :
				12)		// fixed offset on rests and bars
			+ h * .2
		if (y > 0) {
			y2 = y + h * .8
			if (y2 > staff_tb[s.st].ann_top)
				staff_tb[s.st].ann_top = y2
		} else {
			y2 = y
			if (y2 < staff_tb[s.st].ann_bot)
				staff_tb[s.st].ann_bot = y2
		}
		break
	}
	use_font(an.font)
	set_font(an.font)
	set_dscale(s.st)
	if (user.anno_start)
		user.anno_start("annot", an.istart, an.iend,
			x - 2, y + h + 2, w + 4, h + 4, s)
	xy_str(x, y, an.text)
	if (user.anno_stop)
		user.anno_stop("annot", an.istart, an.iend,
			x - 2, y + h + 2, w + 4, h + 4, s)
} // draw_gchord()

// draw all chord symbols
function draw_all_chsy() {
    var	s, san1, an, i, y, w,
	pos = curvoice.pos.gch == C.SL_BELOW ? -1 : 1,
	n_an = 0,		// max number of annotations
	minmax = new Array(nstaff + 1)

	if (curvoice.pos.gch == C.SL_HIDDEN)
		pos = 0

	// set a vertical offset to all the chord symbols/annotations
	function set_an_yu(j) {
	    var	an, i, s, x, y, w

		for (s = san1 ; s; s = s.ts_next) {
			an = s.a_gch
			if (!an)
				continue
			i = an.length - j - 1
			an = an[i]
			if (!an)
				continue
			if ((an.type == 'g' && pos > 0)
			 || an.type == '^') {
				x = s.x + an.x
				w = an.text.wh[0]
				if (w && x + w > realwidth)
					x = realwidth - w // let the text in the page
				y = y_get(s.st, 1, x, w)	// y / staff
				if (an.type == 'g' && y < minmax[s.st].yup)
					y = minmax[s.st].yup
			} else if ((an.type == 'g' && pos <= 0)
				|| an.type == '_') {
				continue
			} else {
				x = s.x + an.x
				y = an.y
			}
			self.draw_gchord(i, s, x, y)
		}
	} // set_an_yu()
				if (y < staff_tb[s.st].ann_bot)
					staff_tb[s.st].ann_bot = y
			}
			break
		}

	function set_an_yl(i) {
	    var	an, x, y, w

		for (var s = san1 ; s; s = s.ts_next) {
			an = s.a_gch
			if (!an)
				continue
			an = an[i]
			if (!an
			 || !((an.type == 'g' && pos < 0)
			   || an.type == '_'))
				continue
			x = s.x + an.x
			w = an.text.wh[0]
			if (w && x + w > realwidth)	// let the text inside the page
				x = realwidth - w
			y = y_get(s.st, 0, x, w)	// y / staff
			if (an.type == 'g' && y > minmax[s.st].ydn)
				y = minmax[s.st].ydn
			self.draw_gchord(i, s, x, y)
		}
	} // set_an_yl()

	// get the number of chord symbols / annotations
	// and the vertical offset for the chord symbols
	for (i = 0; i <= nstaff; i++)
		minmax[i] = {
			ydn: staff_tb[i].botbar - 3,
			yup: staff_tb[i].topbar + 4
		}
	for (s = tsfirst; s; s = s.ts_next) {
		an = s.a_gch
		if (!an)
			continue
		if (!san1)
			san1 = s	// first chord symbol / annotation
		i = an.length
		if (i > n_an)
			n_an = i
		while (--i >= 0) {
			if (an[i].type == 'g') {
				an = an[i]
				w = an.text.wh[0]
				if (pos > 0) {
					y = y_get(s.st, true, s.x, w)
					if (y > minmax[s.st].yup)
						minmax[s.st].yup = y
				} else if (pos < 0) {
					y = y_get(s.st, false, s.x, w)
					if (y < minmax[s.st].ydn)
						minmax[s.st].ydn = y
				}
				break
			}
		if (user.anno_start)
			user.anno_start("annot", gch.istart, gch.iend,
				x - 2, y + h + 2, w + 4, h + 4, s)
		xy_str(x, y, text, null, null, gch.wh)
		if (user.anno_stop)
			user.anno_stop("annot", gch.istart, gch.iend,
		}
	}
	if (!san1)
		return			// no chord symbol nor annotation
				x - 2, y + h + 2, w + 4, h + 4, s)
	}
}

	// draw the elements
	set_dscale(-1)			// restore the scale parameters
	for (i = 0; i < n_an; i++) {
		set_an_yu(i)		// upper offsets
		set_an_yl(i)		// lower offsets
	}
} // draw_all_chsy()
Changes to core/license.
1
2
3

1
2

3


-
+
// abc2svg - ABC to SVG translator
// @source: https://chiselapp.com/user/moinejf/repository/abc2svg
// Copyright (C) 2014-2019 Jean-Francois Moine - LGPL3+
// Copyright (C) 2014-2020 Jean-Francois Moine - LGPL3+
Changes to core/lyrics.js.
︙
105
106
107
108
109
110
111
112
113
114
115


116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
105
106
107
108
109
110
111

112


113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-

-
-
+
+










-
+







		default:
//		case '*':
			break
		case '!':
			deco_cnv([d.slice(1, -1)], s, s.prev)
			break
		case '"':
			a_gch = s.a_gch;
			parse_gchord(d)
			if (a_gch)
				self.gch_build(s)
			if (a_gch)			// if no error
				csan_add(s)
			break
		}
		s = s.next;
		i++
	}
	curvoice.lyric_cont = s
}

/* -- parse a lyric (vocal) line (w:) -- */
function get_lyrics(text, cont) {
	var s, word, p, i, j, ly
    var s, word, p, i, j, ly, dfnt

	if (curvoice.ignore)
		return
	if (curvoice.pos.voc != C.SL_HIDDEN)
		curvoice.have_ly = true

	// get the starting symbol of the lyrics
︙
152
153
154
155
156
157
158

159
160
161
162
163
164
165
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165







+







		if (!s) {
			syntax(1, "w: without music")
			return
		}
	}

	/* scan the lyric line */
	dfnt = gene.curfont			// font at start of line
	p = text;
	i = 0
	while (1) {
		while (p[i] == ' ' || p[i] == '\t')
			i++
		if (!p[i])
			break
︙
228
229
230
231
232
233
234
235
236


237
238

239
240
241
242
243
244
245
228
229
230
231
232
233
234


235
236


237
238
239
240
241
242
243
244







-
-
+
+
-
-
+







		if (!s) {
			syntax(1, "Too many words in lyric line")
			return
		}
		if (word
		 && s.pos.voc != C.SL_HIDDEN) {
			if (word.match(/^\$\d/)) {
				if (word[1] == '0')
					set_font("vocal")
				gene.curfont = word[1] == '0' ?
						dfnt :
				else
					set_font("u" + word[1]);
						get_font("u" + word[1])
				word = word.slice(2)
			}
			ly = {
				t: word,
				font: gene.curfont,
				wh: strwh(word),
				istart: j,
︙
Changes to core/mei.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - mei.js - MEI front-end
//
// Copyright (C) 2019 Jean-Francois Moine
// Copyright (C) 2019-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
796
797
798
799
800
801
802
803

804
805
806
807
808
809
810
796
797
798
799
800
801
802

803
804
805
806
807
808
809
810







-
+







//	parts: function(tag) {
//	}, // parts()

	// new page for text
	pb: function(tag) {
	    var	s
//fixme: tag.n (page number)
		if (parse.state == 3) {
		if (parse.state >= 2) {
			s = new_block("newpage")
			s.param = tag.n || ""
		} else {
			blk_flush()
			block.newpage = true
		}
	}, // pb()
︙
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
912
913
914
915
916
917
918

919
920
921
922
923
924
925
926







-
+








	revisionDesc: function(tag) {
		return true	// skip
	}, // revisionDesc()

	// newline for music
	sb: function(tag) {
		curvoice.last_sym.eoln = true
		voice_tb[0].eoln = true
	}, // sb()

//	score: function(tag) {
//		tag.n
//		tag.id
//	}, // score()

︙
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365


1366
1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1380
1381
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372

1373
1374

1375
1376
1377
1378
1379
1380
1381







-



+
+






-
+

-







			default:
//			case "above":
					s.pos.gch = C.SL_ABOVE; break
			case "below": s.pos.gch = C.SL_BELOW; break
			}
			break
		}
		a_gch = s.a_gch || []
		t = curr.text.split('\n')
		if (t[0][0] == ' ')
			t[0] = t[0].slice(1)
		if (!s.a_gch)
			s.a_gch = []
		for (i = 0; i < t.length; i++) {
			gch = {
				type: ty,
				font: font,
				text: t[i]
			}
			a_gch.push(gch)
			s.a_gch.push(gch)
		}
		self.gch_build(s)
		curr.text = undefined
	}, // dir()

	// end of division
	div: function(tag) {
	    var s
		switch (tag.type) {
︙
2274
2275
2276
2277
2278
2279
2280


2281
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283







+
+


	parse.file = mei
	cfmt.graceslurs = false
	glovar.ulen = C.BLEN / 4
	param_set_font("dynamfont", "serifItalicBold 16")

	parse_mei(xml2tree(mei)) // convert to internal music representation

	parse.state = 0		// end of tune
} // mei2mus()
Changes to core/modules.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - modules.js - module handling
//
// Copyright (C) 2018-2019 Jean-Francois Moine
// Copyright (C) 2018-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

























46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


64
65
66
67
68










69
70
71
72

73
74
75
76
77
78
79
80
81
82
83



84
85
86
87
88
89


90
91


92
93
94

95
96

97
98
99
100
101
102
103
104
22
23
24
25
26
27
28

















29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
107
108
109
110


111
112



113


114




115
116
117
118







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
















-
-
+
+





+
+
+
+
+
+
+
+
+
+



-
+









-
-
+
+
+






+
+
-
-
+
+
-
-
-
+
-
-
+
-
-
-
-




    abc2svg.loadjs = function(fn, onsuccess, onerror) {
	if (onerror)
		onerror()
    }
}

abc2svg.modules = {
		ambitus: { fn: 'ambitus-1.js' },
		beginps: { fn: 'psvg-1.js' },
		break: { fn: 'break-1.js' },
		capo: { fn: 'capo-1.js' },
		clip: { fn: 'clip-1.js' },
	clairnote: { fn: 'clair-1.js' },
		voicecombine: { fn: 'combine-1.js' },
		diagram: { fn: 'diag-1.js' },
	equalbars: { fn: 'equalbars-1.js' },
		grid: { fn: 'grid-1.js' },
		grid2: { fn: 'grid2-1.js' },
		MIDI: { fn: 'MIDI-1.js' },
	pageheight: { fn: 'page-1.js' },
		percmap: { fn: 'perc-1.js' },
	soloffs: { fn: 'soloffs-1.js' },
	sth: { fn: 'sth-1.js' },
	temperament: { fn: 'temper-1.js' },
	ambitus: {},
	begingrid: { fn: 'grid3' },
	beginps: { fn: 'psvg' },
	break: {},
	capo: {},
	chordnames: {},
	clip: {},
	clairnote: { fn: 'clair' },
	voicecombine: { fn: 'combine' },
	diagram: { fn: 'diag' },
	equalbars: {},
	gamelan: {},
	grid: {},
	grid2: {},
	jazzchord: {},
	jianpu: {},
	mdnn: {},
	MIDI: {},
	pageheight: { fn: 'page' },
	pedline: {},
	percmap: { fn: 'perc' },
	soloffs: {},
	sth: {},
	strtab: {},
	temperament: { fn: 'temper' },

	nreq: 0,
	hooks: [],
	g_hooks: [],

	// scan the file and find the required modules
	// @file: ABC file
	// @relay: (optional) callback function for continuing the treatment
	// @errmsg: (optional) function to display an error message if any
	//	This function gets one argument: the message
	// return true when all modules are loaded
	load: function(file, relay, errmsg) {

		function get_errmsg() {
			if (typeof user == 'object' && user.errmsg)
				return user.errmsg
			if (typeof printErr == 'function')
				return printErr
			if (typeof abc2svg.printErr == 'function')
				return abc2svg.printErr
			if (typeof alert == 'function')
				return function(m) { alert(m) }
			if (typeof console == 'object')
				return console.log
			return function(){}
		} // get_errmsg()

		// call back functions for loadjs()
		function load_end() {
			if (--abc2svg.modules.nreq == 0)
				abc2svg.modules.cbf()
		}
		function load_ko(fn) {
			abc2svg.modules.errmsg('Error loading the module ' + fn)
			load_end()
		}

		// test if some keyword in the file
	    var	m, r,
	    var	m, i, fn,
		nreq_i = this.nreq,
		ls = file.match(/(^|\n)(%%|I:).+?\b/g)

		if (!ls)
			return true
		this.cbf = relay ||		// (only one callback function)
			function(){}
		this.errmsg = errmsg || get_errmsg()

		for (var i = 0; i < ls.length; i++) {
			m = abc2svg.modules[ls[i].replace(/\n?(%%|I:)/, '')]
		for (i = 0; i < ls.length; i++) {
			fn = ls[i].replace(/\n?(%%|I:)/, '')
			m = abc2svg.modules[fn]
			if (!m || m.loaded)
				continue

			m.loaded = true

			// load the module
			if (m.fn)
				fn = m.fn
				this.nreq++;
				abc2svg.loadjs(m.fn,
			this.nreq++
			abc2svg.loadjs(fn + "-1.js",
				    function() {	// if success
					if (--abc2svg.modules.nreq == 0)
						abc2svg.modules.cbf()
					load_end,
				    },
				    function() {	// if error
					function() {load_ko(fn)})
					abc2svg.modules.errmsg('error loading ' + m.fn);
					if (--abc2svg.modules.nreq == 0)
						abc2svg.modules.cbf()
				    })
		}
		return this.nreq == nreq_i
	}
} // modules
Changes to core/music.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - music.js - music generation
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2021 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
49
50
51
52
53
54
55
56

57
58
59
60
61

62
63
64
65


66
67
68
69
70
71
72
49
50
51
52
53
54
55

56
57
58
59
60

61
62
63


64
65
66
67
68
69
70
71
72







-
+




-
+


-
-
+
+








// accidental x offset - index = note head type
var dx_tb = new Float32Array([
	10,		// FULL
	10,		// EMPTY
	11,		// OVAL
	13,		// OVALBARS
	13		// SQUARE
	15		// SQUARE
])

// head width  - index = note head type
var hw_tb = new Float32Array([
	4.5,		// FULL
	4.7,		// FULL
	5,		// EMPTY
	6,		// OVAL
	7,		// OVALBARS
	8		// SQUARE
	7.2,		// OVALBARS
	7.5		// SQUARE
])

/* head width for voice overlap - index = note head type */
var w_note = new Float32Array([
	3.5,		// FULL
	3.7,		// EMPTY
	5,		// OVAL
︙
86
87
88
89
90
91
92
93
94




95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112







-
-
+
+
+
+








-
+







	if (!dur)
		error(1, s, "Note too short")
	for (flags = 5; dur != 0; dur >>= 1, flags--) {
		if (dur & 1)
			break
	}
	dur >>= 1
	if ((dur + 1) & dur)
		error(0, s, "Non standard note duration $1", dur_o)
	if ((dur + 1) & dur) {
		if (s.type != C.REST || dur_o != s.p_v.wmeasure)
			error(0, s, "Non standard note duration $1", dur_o)
	}
	while (dur >> dots > 0)
		dots++

	flags -= dots
	if (flags >= 0) {
		head = C.FULL
	} else switch (flags) {
	default:
		error(1, s, "Note too long");
		error(1, s, "Note too long")
		flags = -4
		/* fall thru */
	case -4:
		head = C.SQUARE
		break
	case -3:
		head = cfmt.squarebreve ? C.SQUARE : C.OVALBARS
︙
333
334
335
336
337
338
339

340
341
342
343
344
345
346


347


















348
349
350
351
352
353
354
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375







+

-





+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	if (s.prev)
		s.prev.next = s
	else
		s.p_v.sym = s;
	next.prev = s
}
function lktsym(s, next) {	// time linkage
	s.ts_next = next
	if (next) {
		s.ts_next = next;
		s.ts_prev = next.ts_prev
		if (s.ts_prev)
			s.ts_prev.ts_next = s;
		next.ts_prev = s
	} else {
//fixme
error(2, s, "Bad linkage")
		s.ts_next = s.ts_prev = null
		s.ts_prev = null
	}
	s.seqst = !s.ts_prev
		|| s.time != s.ts_prev.time
		|| ((w_tb[s.ts_prev.type] != w_tb[s.type]
		  && w_tb[s.ts_prev.type] != 0)
		 || s.ts_prev.v == s.v)		// case cut bar
	if (!next)
		return
	next.seqst = next.time != s.time ||
			(w_tb[s.type] != w_tb[next.type]
			 && w_tb[s.type] != 0)
	if (next.seqst) {
		self.set_width(next)
		next.shrink = next.wl
		if (next.prev)
			next.shrink += next.prev.wr
		next.space = 0
	}
}

/* -- unlink a symbol -- */
function unlksym(s) {
	if (s.next)
		s.next.prev = s.prev
︙
362
363
364
365
366
367
368








369
370
371
372
373
374
375
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404







+
+
+
+
+
+
+
+







			s.ts_next.shrink += s.shrink;
			s.ts_next.space += s.space
		    } else {
			s.ts_next.seqst = true;
			s.ts_next.shrink = s.shrink;
			s.ts_next.space = s.space
		    }
		} else {
			if (s.ts_next.seqst
			 && s.ts_prev && s.ts_prev.seqst
			 && !w_tb[s.ts_prev.type]) {
				s.ts_next.seqst = false
				s.shrink = s.ts_next.shrink
				s.space = s.ts_next.space
			}
		}
		s.ts_next.ts_prev = s.ts_prev
	}
	if (s.ts_prev)
		s.ts_prev.ts_next = s.ts_next
	if (tsfirst == s)
		tsfirst = s.ts_next
︙
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
437
438
439
440
441
442
443


444
445
446
447
448
449
450







-
-







	}
	new_s.nhd = 0;

	/* link in time */
	while (!s.seqst)
		s = s.ts_prev;
	lktsym(new_s, s)
	if (new_s.ts_prev.type != C.CLEF)
		new_s.seqst = true
	return new_s
}

/* -- set the staff of the floating voices -- */
/* this function is called only once per tune */
function set_float() {
	var p_voice, st, staff_chg, v, s, s1, up, down
︙
583
584
585
586
587
588
589
590

591



592
593
594
595
596
597


598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621

622
623
624
625
626

627
628
629
630
631
632
633
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633

634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651

652
653
654
655
656

657
658
659
660
661
662
663
664







-
+

+
+
+





-
+
+





-
+

















-
+




-
+







		}
		if (!s.a_gch)
			continue
		for (i = 0; i < s.a_gch.length; i++) {
			ch = s.a_gch[i]
			if (ch.type != 'g' || ch.y < 0) // upper chord symbol only
				continue
			if (w0) {
			if (w0) {		// width of the previous chord symbol
				if (w0 > x + ch.x) {
					if (s.prev // (if not at start of a secondary voice)
					 && s.prev.type == C.BAR) // don't move away
						n--		// the symbol from a bar
					dw = (w0 - x - ch.x) / n
					while (1) {
						s0 = s0.ts_next
						if (s0.shrink)
							s0.shrink += dw
						if (s0 == s)
						if (s0 == s
						 || s0.type == C.BAR)
							break
					}
				}
			}
			s0 = s;
			w0 = ch.wh[0];
			w0 = ch.text.wh[0];
			n = 0;
//			x = ch.font.box ? -2 : 0
			x = 0
			break
		}
	}
}

// compute the width needed by the left and right annotations
function gchord_width(s, wlnote, wlw) {
    var	gch, w, ix,
	arspc = 0

	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		switch (gch.type) {
		case '<':		/* left */
			w = gch.wh[0] + wlnote
			w = gch.text.wh[0] + wlnote
			if (w > wlw)
				wlw = w
			break
		case '>':		/* right */
			w = gch.wh[0] + s.wr
			w = gch.text.wh[0] + s.wr
			if (w > arspc)
				arspc = w
			break
		}
	}
	if (s.wr < arspc)
		s.wr = arspc
︙
675
676
677
678
679
680
681
682


683
684

685
686
687
688
689
690
691
706
707
708
709
710
711
712

713
714
715

716
717
718
719
720
721
722
723







-
+
+

-
+







		}
		for (m = 0; m <= s.nhd; m++) {
			xx = s.notes[m].shhd
			if (xx < 0) {
				if (wlnote < -xx + 5)
					wlnote = -xx + 5
			}
			if (s.notes[m].acc) {
			acc = s.notes[m].acc
			if (acc) {
				tmp = s.notes[m].shac +
					(s.notes[m].micro ? 5.5 : 3.5)
					(typeof acc != "number" ? 5.5 : 3.5)
				if (wlnote < tmp)
					wlnote = tmp
			}
		}
		if (s2) {
			switch (s2.type) {
			case C.BAR:
︙
833
834
835
836
837
838
839



840
841
842
843
844
845
846
847
848
849




850
851
852
853
854
855
856
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882


883
884
885
886
887
888
889
890
891
892
893







+
+
+








-
-
+
+
+
+







			s.wl += deco_width(s)

		/* have room for the repeat numbers / chord indication */
		if (s.text && s.text.length < 4
		 && s.next && s.next.a_gch) {
			set_font("repeat");
			s.wr += strwh(s.text)[0] + 2
			if (cfmt.measurenb > 0 & s.bar_num
			 && s.bar_num % cfmt.measurenb)
				s.wr += 4
		}
		return
	case C.CLEF:
// (there may be invisible clefs in empty staves)
		if (s.invis) {
			s.wl = s.wr = 1		// (!! not 0 !!)
			return
		}
		s.wl = s.clef_small ? 9 : 12
		s.wr = s.clef_small ? 7 : 12
		s.wl = s.clef_small ? 11 : 12
		s.wr = s.clef_small ? 10 : 12
		if (s.next && s.next.type == C.BAR)
			s.wr -= 4
		return
	case C.KEY:
		if ((!s.k_a_acc && !s.k_sf && !s.k_old_sf) // if no accidental
		 || s.k_none				// or no key
		 || s.k_play) {				// or key for play
			s.wl = s.wr = 0			// no width
			return
︙
1022
1023
1024
1025
1026
1027
1028
1029
1030


1031
1032
1033
1034
1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1059
1060
1061
1062
1063
1064
1065


1066
1067

1068






1069
1070
1071
1072
1073
1074
1075
1076







-
-
+
+
-

-
-
-
-
-
-
+







					l / ((C.BLEN / 16 / 8) << i)
		}
	}
	return space
}

// set the natural space
function set_space(s) {
    var	space, prev_time, len,
function set_space(s, ptime) {
    var	space, len, s2, stemdir
	s2 = s.ts_prev

	if (s.play)
		return 0
	while (s2.play)				// if play symbol
		s2 = s2.ts_prev
	prev_time = s2.time
	len = s.time - prev_time		// time skip
	len = s.time - ptime		// time skip

	if (!len) {
		switch (s.type) {
		case C.MREST:
			return s.wl
///*fixme:do same thing at start of line*/
//		case C.NOTE:
︙
1094
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
1142







-
+


-
+







		}
	}

	/* decrease spacing when stem down followed by stem up */
/*fixme:to be done later, after x computed in sym_glue*/
	if (s.type == C.NOTE && s.nflags >= -1
	 && s.stem > 0) {
		var stemdir = true
		stemdir = true

		for (s2 = s.ts_prev;
		     s2 && s2.time == prev_time;
		     s2 && s2.time == ptime;
		     s2 = s2.ts_prev) {
			if (s2.type == C.NOTE
			 && (s2.nflags < -1 || s2.stem > 0)) {
				stemdir = false
				break
			}
		}
︙
1122
1123
1124
1125
1126
1127
1128
1129

1130
1131
1132
1133


1134
1135

1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155

1156
1157

1158
1159
1160

1161
1162
1163





1164
1165
1166
1167

1168
1169
1170

1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1206
1207

























1208
1209
1210
1211
1212
1213

1214
1215
1216
1217
1218

1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235



1236
1237
1238
1239
1240
1241
1242
















1243
1244
1245
1246

1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1153
1154
1155
1156
1157
1158
1159

1160
1161



1162
1163


1164




1165













1166



1167


1168


1169
1170



1171
1172
1173
1174
1175
1176
1177

1178
1179
1180

1181
1182
1183

1184
1185
1186
1187
1188

1189
1190
1191



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203



1204
1205

1206
1207








1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242

1243

1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257



1258
1259
1260
1261
1262
1263
1264
1265


1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299








1300
1301
1302
1303
1304
1305
1306
























1307
1308
1309
1310
1311
1312
1313







-
+

-
-
-
+
+
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-

+
-
-
-
+
+
+
+
+


-

+

-

+

-
+




-



-
-
-
+
+
+









-
-
-


-
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+




-
+
-



+










-
-
-
+
+
+





-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+

+












-
-
-
-
-
-
-
-







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







			if (stemdir)
				space *= .9
		}
	}
	return space
}

// set a fixed spacing inside tuplets
// set the spacing inside tuplets or L: factor
function set_sp_tup(s, s_et) {
    var	s2,
	tim = s.time,
	endtime = s_et.time + s_et.dur,
    var	tim = s.time,
	ttim = s_et.time - tim,
	ttim = endtime - tim,
	space = time2space(s, ttim / s.tp[0].q) * s.tp[0].q / ttim
	sp = time2space(s, ttim),	// whole time spacing

	// start on the second note/rest
	do {
		s = s.ts_next
	s2 = s,
	} while (!s.seqst)
//fixme: problem when BAR inside the tuplet sequence (in case user error)
//	while (!s.dur)
//		s = s.ts_next
//	while (!s.seqst)
//		s = s.ts_prev

	// stop outside the tuplet sequence
	// and add a measure bar when at end of tune
	do {
		if (!s_et.ts_next) {
			s2 = add_end_bar(s_et);
			s_et = s2
	wsp = 0
		} else {
			s_et = s_et.ts_next
		}

	} while (!s_et.seqst)

	// compute the whole spacing
	// check the minimum spacing
	s2 = s
	while (1) {
		s2 = s2.ts_next
		if (s2.dur
		 && s2.dur * space < s2.shrink)
			space = s2.shrink / s2.dur
		if (s2.seqst) {
			wsp += s2.space
			if (s2.bar_type)
				wsp += 10	// (fixme: not exact)
		}
		if (s2 == s_et)
			break
		s2 = s2.ts_next
	}
	sp = (sp + wsp) / 2 / ttim	// mean spacing per time unit

	// set the space values
	while (1) {
		s = s.ts_next
		if (s.seqst) {
			s.space = (s.time - tim) * space;
			s.space = sp * (s.time - tim)
			tim = s.time
		}
		if (s == s_et)
			break
		s = s.ts_next
	}
}

// create an invisible bar for end of music lines
function add_end_bar(s) {
    var bar = {
// return an empty bar
function _bar(s) {
	return {
		type: C.BAR,
		bar_type: "|",
		fname: s.fname,
		istart: s.istart,
		iend: s.iend,
		v: s.v,
		p_v: s.p_v,
		st: s.st,
		dur: 0,
		seqst: true,
		invis: true,
		time: s.time + s.dur,
		nhd: 0,
		notes: [{
			pit: s.notes[0].pit
			pit: s.notes ? s.notes[0].pit : 22
		}],
		wl: 0,
		wr: 0,
		prev: s,
		ts_prev: s,
		shrink: s.wr + 3
	}
	s.next = s.ts_next = bar
	return bar
		prev: s
	}
} // _bar()

// create an invisible bar for end of music lines
function add_end_bar(s) {
    var b = _bar(s)

	b.seqst = true
	b.invis = true
	b.time = s.time + s.dur / 2
	b.wl = 0
	b.wr = 0
	b.ts_prev = s
	b.next = s.next
	b.ts_next = s.ts_next
	b.shrink = s.wr + 3

	if (s.next)
		s.next.prev = b
	if (s.ts_next)
		s.ts_next.ts_prev = b
	s.next = s.ts_next = b
	b.space = set_space(b, s.time)
	return b
}

/* -- set the width and space of all symbols -- */
// this function is called once for the whole tune
function set_allsymwidth() {
    var	maxx, new_val, s_tupc, s_tupn, st, s_chs,
    var	maxx, val, st, s_chs, tim, stup,
	s = tsfirst,
	s2 = s,
	xa = 0,
	xl = [],
	wr = [],
	wr = []
	ntup = 0

	/* loop on all symbols */
	maxx = xa
	tim = s.time
	while (1) {
		do {
			if (s.a_gch && !s_chs)
				s_chs = s;
			self.set_width(s);
			st = s.st
			if (xl[st] == undefined)
				xl[st] = 0
			if (wr[st] == undefined)
				wr[st] = 0;
			new_val = xl[st] + wr[st] + s.wl
			if (new_val > maxx)
				maxx = new_val;
			val = xl[st] + wr[st] + s.wl
			if (val > maxx)
				maxx = val
			s = s.ts_next
		} while (s && !s.seqst);

		// set the spaces of the time sequence
		s2.shrink = maxx - xa
		if (!ntup)			// if not inside a tuplet sequence
			s2.space = s2.ts_prev ? set_space(s2) : 0
		s2.space = s2.ts_prev ? set_space(s2, tim) : 0

		if (s2.dur && s2.dur != s2.notes[0].dur) {
			if (!stup) {
				stup = s2
				while (stup.prev
				 && stup.prev.dur
				 && stup.prev.dur != stup.prev.notes[0].dur)
					stup = stup.prev
				while (!stup.seqst)
					stup = stup.ts_prev
			}
		} else if (stup && stup.v == s2.v) {
			set_sp_tup(stup, s2)
			stup = null
		}

		if (!s2.shrink && !s2.space && s2.type == C.CLEF) {
			delete s2.seqst;		/* no space */
			s2.time = s2.ts_prev.time
			s2.time = tim
		}
		tim = s2.time
		if (!s)
			break

		// update the min left space per staff
		for (st = 0; st < wr.length; st++)
			wr[st] = 0;
		xa = maxx
		do {
			st = s2.st;
			xl[st] = xa
			if (s2.wr > wr[st])
				wr[st] = s2.wr
			if (s2.tp) {		// start of tuplet
				if (!ntup
				 && !s_tupc)
					s_tupc = s2 // keep the first tuplet address
				ntup += s2.tp.length
			}
			if (s2.tpe)		// end of tuplet
				ntup -= s2.tpe;
			s2 = s2.ts_next
		} while (!s2.seqst)
	}

	// let the chord symbols at the same offset
	if (s_chs)
		set_w_chs(s_chs)

	// adjust the spacing inside the tuplets
	s = s_tupc
	if (!s)
		return
	do {
		s2 = s;			// start of tuplet
		ntup = 0
		while (1) {		// search the end of the tuplet sequence
			if (s.tp)
				ntup += s.tp.length
			if (s.tpe)
				ntup -= s.tpe
			if (!ntup)
				break
			s = s.ts_next
		}

		set_sp_tup(s2, s)

		do {			// search next tuplet
			s = s.ts_next
		} while (s && !s.tp)
	} while (s)
}

// insert a rest, this one replacing a sequence or a measure
function to_rest(so) {
    var	s = clone(so)

	s.prev.next = so.ts_prev = so.prev = s.ts_prev.ts_next = s
︙
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566


1567

















































































1568

1569
1570
1571
1572



1573
1574
1575

1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589

1590
1591
1592

1593
1594
1595
1596
1597
1598
1599



1600
1601
1602

1603
1604
1605
1606
1607
1608
1609
1610
1611
1612




1613
1614
1615
1616
1617
1618
1619








1620







1621
1622
1623
1624
1625
1626
1627
















1628
1629
1630
1631
1632
1633

1634

1635
1636
1637
1638
1639
1640
1641
1642
1643







1644
1645
1646
1647
1648
1649
1650
1651
1652
1653

1654



1655



1656
1657

1658
1659
1660
1661
1662
1663
1664
1665
1666
1667

1668

1669
1670
1671
1672

1673
1674
1675
1676

1677
1678
1679
1680

1681

1682
1683
1684
1685


1686

1687
1688
1689
1690
1691
1692
1693
1545
1546
1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571


1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655

1656
1657
1658
1659
1660
1661
1662
1663
1664
1665

1666














1667



1668







1669
1670
1671



1672
1673



1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685





1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701







1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717




1718

1719

1720
1721
1722







1723
1724
1725
1726
1727
1728
1729





1730
1731
1732
1733
1734
1735

1736
1737
1738
1739
1740
1741
1742
1743

1744


1745
1746
1747
1748
1749
1750
1751
1752
1753

1754
1755
1756
1757

1758
1759
1760
1761
1762
1763
1764
1765
1766

1767
1768
1769
1770
1771
1772
1773
1774
1775

1776
1777
1778
1779
1780
1781
1782
1783







-




















-
-
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+




+
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
-
-
-
+

-
-
-






+
+
+
+


-
-
-
-
-
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-

-
+
-
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-





+
-
+
+
+

+
+
+

-
+
-
-








+
-
+



-
+




+



-
+

+




+
+
-
+







//		p_voice.sym = null;
	p_voice.time = s.time;
	new_s = sym_add(p_voice, C.CUSTOS);
	new_s.next = s;
	s.prev = new_s;
	lktsym(new_s, s);

	new_s.seqst = true;
	new_s.shrink = s.shrink
	if (new_s.shrink < 8 + 4)
		new_s.shrink = 8 + 4;
	new_s.space = s2.space;
	new_s.wl = 0;
	new_s.wr = 4;

	new_s.nhd = s2.nhd;
	new_s.notes = []
	for (i = 0; i < s.notes.length; i++) {
		new_s.notes[i] = {
			pit: s2.notes[i].pit,
			shhd: 0,
			dur: C.BLEN / 4
		}
	}
	new_s.stemless = true
}

/* -- define the beginning of a new music line -- */
function set_nl(s) {
    var	s2, s3, p_voice, done
function set_nl(s) {			// s = start of line
    var	p_voice, done, tim, ptyp

	// divide the left repeat (|:) or variant bars (|1)
	// the new bars go in the next line
	function bardiv(so) {		// start of next line
	    var s, s1, s2, t1, t2, i

	    function new_type(s) {
	    var	t = s.bar_type.match(/(:*)([^:]*)(:*)/)
			// [1] = starting ':'s, [2] = middle, [3] = ending ':'s

		if (!t[3]) {		// if start of variant
			// |1 -> | [1
			// :|]1 -> :|] [1
			t1 = t[1] + t[2]
			t2 = '['
		} else if (!t[1]) {	// if left repeat only
			// [|: -> | [|:
			// ||: -> || [|:
			t1 = t[2][0] == '[' ? t[2].slice(1) : t[2]
			t2 = '[|' + t[3]
		} else {
			// :][: -> :|] [|:
			i = (t[2].length / 2) | 0
			t1 = t[1] + '|' + t[2].slice(0, i)
			t2 = t[2].slice(i) +'|' + t[3]
		}
	    } // new_typ()

		s = so				// start of sequence
		while (s.ts_prev
		 && s.ts_prev.time == so.time) {
			s = s.ts_prev
			if (s.bar_type)
				s1 = s		// first previous bar
		}
		if (!s1)
			return so

		// search the insertion point in the new line
		for (s = so; ; s = s.ts_next) {
			switch (s.type) {
			default:
				if (w_tb[s.type])
					break
			case C.KEY:
			case C.METER:
			case C.CLEF:
				continue
			}
			break
		}
		while (s1 != so) {
		    if (s1.bar_type
		     && (s1.bar_type.slice(-1) == ':'
		      || s1.text)
		     && s1.bar_type != ':') {
			new_type(s1)		// return t1 and t2
			s2 = clone(s1)
			s1.bar_type = t1
			s2.bar_type = t2
			lkvsym(s2, s1.next)	// voice
			while (1) {
				if (s.type != C.BAR
				 || s.v > s2.v)
					break
				s = s.ts_next
			}
			lktsym(s2, s)		// time
			if (s == so)
				so = s2
			if (s1.text) {
				s2.invis = true
				delete s1.text
				delete s1.rbstart
			}
			delete s2.a_dd
		    }
			s1 = s1.ts_next
		}
		return so
	} // bardiv()

	// set the end of line marker
	// set the start of line marker
	function set_eol(s) {
		if (cfmt.custos && voice_tb.length == 1)
			custos_add(s)
		s.nl = true
		s = s.ts_prev
		if (s.type != C.BAR)
			add_end_bar(s)
	} // set_eol()

	// set the eol on the next symbol
	// put the warning symbols
	function set_eol_next(s) {
		if (!s.next) {		// special case: the voice stops here
			set_eol(s)
			return s
		}
		for (s = s.ts_next; s; s = s.ts_next) {
			if (s.seqst) {
				set_eol(s)
				break
			}
		}
		return s
	} // set_eol_next()

	// the new symbols go in the previous line
	// go to the end of the time sequence
	// for adding keywarn or timewarn
	while (s) {
	function do_warn(s) {		// start of next line
		if (!s.ts_next)
			return // null
		if (s.ts_next.seqst)
			break
		s = s.ts_next
	}

	    var s1, s2, s3

		// advance in the next line
	// if keywarn or timewarn, move K: and M: to the end of the previous line
	if (cfmt.keywarn || cfmt.timewarn) {
		for (s2 = s.ts_next; s2; s2 = s2.ts_next) {
		for (s2 = s; s2; s2 = s2.ts_next) {
			switch (s2.type) {
			case C.BAR:
			case C.CLEF:
				continue
			case C.KEY:
				if (!cfmt.keywarn
				 || (!s2.k_a_acc && !s2.k_sf && !s2.k_old_sf)
				 || s2.k_none
				 || s2.k_play)		// play only
					continue
				for (s1 = s.ts_prev; s1 ;s1 = s1.ts_prev) {
					if (s1.type != C.METER)
						break
				}
				// fall thru
			case C.METER:
				if (s2.type == C.METER && !cfmt.timewarn)
					continue
				s3 = s2.ts_prev;
				if (s3 == s) {		// if next symbol
					s = s2		// advance the eol
				if (s2.type == C.METER) {
					if (!cfmt.timewarn)
						continue
					s1 = s.ts_prev
				}
				// fall thru
			case C.CLEF:
				if (!s2.prev)		// start of voice
					continue
				if (s2.type == C.CLEF) {
					for (s1 = s.ts_prev; s1; s1 = s1.ts_prev) {
						switch (s1.type) {
						case C.BAR:
						case C.KEY:
						case C.METER:
							continue
				}
				unlksym(s2);		// remove
				lktsym(s2, s.ts_next);	// link in time at eol
				s = s2
				while (1) {		// link in voice
					s2 = s2.ts_prev
					if (s2.v == s.v) {
						}
						break
					}
				}

				// put the warning symbol at end of line
				s3 = clone(s2)		// duplicate the K:/M:/clef

				lktsym(s3, s1.ts_next)	// time link
				if (s3.ts_next == s)
					s.seqst = true	// (M: eol M:)

				s1 = s3
				while (1) {
					s1 = s1.ts_next
					if (s1.v == s2.v)
						s.next = s2.next;
						s.prev = s2;
						s.next.prev = s;
						s2.next = s
						break
					}
				}
				}
				lkvsym(s3, s1)		// voice link

				// care with spacing
				if (s.type != s.ts_prev.type) {
					if (!s.seqst) {
						s.seqst = true;
						s.shrink = s.wl + s.prev.wr;
						s.space = s.ts_next.space;
						s.ts_next.space = 0
					}
				if (s3.seqst) {
					s3.shrink = s3.wl
					if (s3.prev)	// if not start of voice
						s3.shrink += s3.prev.wr
					s3.space = set_space(s3, s3.ts_prev.time)
					s3.next.shrink = s3.wr + s3.next.wl
				}
				} else {
					delete s.seqst
				}

				s2 = s3		// restart
				continue
			}
			if (w_tb[s2.type])
				break		// symbol with a width
		}
	} // do_warn()
	}

	// divide the left repeat and a variant bars
	s = bardiv(s)

	// add the warning symbols at the end of the previous line
	do_warn(s)

	/* if normal symbol, cut here */
	switch (s.type) {
	switch (s.ts_prev.type) {
	case C.CLEF:
	case C.BAR:
	case C.STAVES:
		break
	case C.GRACE:			/* don't cut on a grace note */
		s = s.next
		if (!s)
			return s
		/* fall thru */
	default:
		set_eol(s)
		return set_eol_next(s)
		return s
	}

	/* go back to handle the staff breaks at end of line */
	for (; s; s = s.ts_prev) {
	for (s = s.ts_prev; s; s = s.ts_prev) {
		if (s.seqst && s.type != C.CLEF)
			break
	}
	done = 0
	ptyp = s.type
	for ( ; ; s = s.ts_next) {
		if (!s)
			return s
		if (!s.seqst)
		if (s.type == ptyp)
			continue
		ptyp = s.type
		if (done < 0)
			break
		switch (s.type) {
		case C.STAVES:
			if (!s.ts_prev)
				return // null		// no music yet
			if (s.ts_prev && s.ts_prev.type == C.BAR)
			if (s.ts_prev.type == C.BAR)
				break
			while (s.ts_next) {
				if (w_tb[s.ts_next.type] != 0
				 && s.ts_next.type != C.CLEF)
					break
				s = s.ts_next
			}
︙
1726
1727
1728
1729
1730
1731
1732
1733

1734
1735
1736

1737
1738
1739
1740

1741
1742
1743

1744
1745
1746
1747
1748
1749

1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765



1766
1767
1768
1769
1770
1771

1772
1773
1774
1775


1776


1777
1778

1779
1780
1781
1782




1783
1784
1785
1786
1787
1788
1789



1790
1791
1792
1793
1794
1795
1796
1797
1798
1799



1800
1801
1802
1803
1804
1805
1806
1807

1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819




1820
1821
1822
1823
1824
1825

1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851


1852
1853
1854
1855
1856
1857
1858

1859
1860
1861
1862
1863
1864
1865
1816
1817
1818
1819
1820
1821
1822

1823
1824
1825

1826
1827
1828
1829

1830
1831
1832

1833
1834
1835
1836
1837
1838

1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849


1850



1851
1852
1853
1854
1855
1856
1857
1858

1859
1860
1861
1862

1863
1864
1865
1866
1867
1868

1869




1870
1871
1872
1873

1874
1875
1876



1877
1878
1879
1880
1881
1882
1883
1884
1885
1886



1887
1888
1889
1890
1891
1892
1893
1894
1895
1896

1897
1898
1899
1900
1901
1902
1903
1904
1905




1906
1907
1908
1909
1910
1911
1912

1913

1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932








1933
1934
1935
1936
1937
1938
1939


1940
1941
1942
1943
1944
1945
1946
1947







-
+


-
+



-
+


-
+





-
+










-
-

-
-
-
+
+
+





-
+



-
+
+

+
+

-
+
-
-
-
-
+
+
+
+
-



-
-
-
+
+
+







-
-
-
+
+
+







-
+








-
-
-
-
+
+
+
+



-

-
+


















-
-
-
-
-
-
-
-
+
+





-
-
+







//	r[0] = width of clef and key signature
//	r[1] = width of the meter
function get_ck_width() {
    var	r0, r1,
	p_voice = voice_tb[0]

	self.set_width(p_voice.clef);
	self.set_width(p_voice.key);
	self.set_width(p_voice.ckey);
	self.set_width(p_voice.meter)
	return [p_voice.clef.wl + p_voice.clef.wr +
			p_voice.key.wl + p_voice.key.wr,
			p_voice.ckey.wl + p_voice.ckey.wr,
		p_voice.meter.wl + p_voice.meter.wr]
}

// get the width of the symbols up to the next eoln or eof
// get the width of the symbols up to the next soln or eof
// also, set a x (nice spacing) to all symbols
// two returned values: width of nice spacing, width with max shrinking
function get_width(s, last) {
function get_width(s, next) {
    var	shrink, space,
	w = 0,
	wmx = 0,
	sp_fac = (1 - cfmt.maxshrink)

	do {
	while (s != next) {
		if (s.seqst) {
			shrink = s.shrink
			wmx += shrink
			if ((space = s.space) < shrink)
				w += shrink
			else
				w += shrink * cfmt.maxshrink
					+ space * sp_fac
			s.x = w
		}
		if (s == last)
			break
		s = s.ts_next
	} while (s)
	if (last)
		wmx += last.wr		// big key signatures may be wide enough
	}
	if (next)
		wmx += next.wr		// big key signatures may be wide enough
	return [w, wmx]
}

/* -- search where to cut the lines according to the staff width -- */
function set_lines(	s,		/* first symbol */
			last,		/* last symbol / null */
			next,		/* symbol of the next line / null */
			lwidth,		/* w - (clef & key sig) */
			indent) {	/* for start of tune */
    var	first, s2, s3, x, xmin, xmid, xmax, wwidth, shrink, space, ws,
	nlines, cut_here
	nlines,
	last = next ? next.ts_prev : null

	ws = get_width(s, next)		// 2 widths: nice and shrinked

	// take care of big key signatures at end of line
	if (cfmt.keywarn && last && last.type == C.BAR
	if (cfmt.keywarn && next
	 && last.next && last.next.time == last.next.time
	 && last.next.type == C.KEY)
		last = last.next

	 && next.type == C.KEY && !last.dur) {
		ws[0] += next.wr
		ws[1] += next.wr
	}
	ws = get_width(s, last)		// 2 widths: nice and shrinked

	// check if the symbols can enter in one line
	if (ws[1] + indent < lwidth) {
		if (last)
			last = set_nl(last)
		return last
		if (next)
			next = set_nl(next)
		return next || last
	}

	/* loop on cutting the tune into music lines */
	wwidth = ws[0] + indent
	while (1) {
		nlines = Math.ceil(wwidth / lwidth)
		if (nlines <= 1) {
			if (last)
				last = set_nl(last)
			return last
			if (next)
				next = set_nl(next)
			return next || last
		}

		s2 = first = s;
		xmin = s.x - s.shrink - indent;
		xmax = xmin + lwidth;
		xmid = xmin + wwidth / nlines;
		xmin += wwidth / nlines * cfmt.breaklimit;
		for (s = s.ts_next; s != last ; s = s.ts_next) {
		for (s = s.ts_next; s != next ; s = s.ts_next) {
			if (!s.x)
				continue
			if (s.type == C.BAR)
				s2 = s
			if (s.x >= xmin)
				break
		}
//fixme: can this occur?
		if (s == last) {
			if (last)
				last = set_nl(last)
			return last
		if (s == next) {
			if (next)
				next = set_nl(next)
			return next
		}

		/* try to cut on a measure bar */
		cut_here = false;
		s3 = null
		for ( ; s != last; s = s.ts_next) {
		for ( ; s != next; s = s.ts_next) {
			x = s.x
			if (!x)
				continue
			if (x > xmax)
				break
			if (s.type != C.BAR)
				continue

			// cut on the bar closest to the middle
			if (x < xmid) {
				s3 = s		// closest bar before middle
				continue
			}
			if (!s3 || x - xmid < xmid - s3.x)
				s3 = s		// closest bar after middle
			break
		}

		/* if a bar, cut here */
		if (s3) {
			s = s3;
			cut_here = true
		}

		/* try to avoid to cut a beam or a tuplet */
		if (!cut_here) {
		// no bar, try to avoid to cut a beam or a tuplet */
		if (!s3) {
			var	beam = 0,
				bar_time = s2.time;

			xmax -= 8; // (left width of the inserted bar in set_allsymwidth)
			s = s2;			// restart from start or last bar
			s3 = null
			for ( ; s != last; s = s.ts_next) {
			for ( ; s != next; s = s.ts_next) {
				if (s.beam_st)
					beam++
				if (s.beam_end && beam > 0)
					beam--
				x = s.x
				if (!x)
					continue
︙
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893

1894
1895

1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909

1910





1911
1912
1913
1914
1915
1916
1917

1918
1919
1920
1921
1922
1923
1924
1925
1926

1927
1928
1929
1930
1931
1932
1933
1961
1962
1963
1964
1965
1966
1967




1968
1969
1970

1971
1972

1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988

1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999

2000
2001
2002
2003
2004
2005
2006
2007
2008

2009
2010
2011
2012
2013
2014
2015
2016







-
-
-
-



-
+

-
+














+
-
+
+
+
+
+






-
+








-
+







				if (s3 > xmid)
					break
				if (xmid - s3.x < s.x - xmid)
					break
				s3 = s
				break
			}
			if (s3) {
				s = s3;
				cut_here = true
			}
		}

		// cut anyhere
		if (!cut_here) {
		if (!s3) {
			s3 = s = s2
			for ( ; s != last; s = s.ts_next) {
			for ( ; s != next; s = s.ts_next) {
				x = s.x
				if (!x)
					continue
				if (s.x < xmid) {
					s3 = s
					continue
				}
				if (s3 > xmid)
					break
				if (xmid - s3.x < s.x - xmid)
					break
				s3 = s
				break
			}
		}
			s = s3
		s = s3
		while (s.ts_next) {
			s = s.ts_next
			if (s.seqst)
				break
		}

		if (s.nl) {		/* already set here - advance */
			error(0, s,
			    "Line split problem - adjust maxshrink and/or breaklimit");
			nlines = 2
			for (s = s.ts_next; s != last; s = s.ts_next) {
			for (s = s.ts_next; s != next; s = s.ts_next) {
				if (!s.x)
					continue
				if (--nlines <= 0)
					break
			}
		}
		s = set_nl(s)
		if (!s
		 || (last && s.time >= last.time))
		 || (next && s.time >= next.time))
			break
		wwidth -= s.x - first.x;
		indent = 0
	}
	return s
}

︙
1964
1965
1966
1967
1968
1969
1970



1971

1972
1973
1974
1975
1976
1977
1978
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056

2057
2058
2059
2060
2061
2062
2063
2064







+
+
+
-
+







	if (cfmt.barsperstaff) {
		i = cfmt.barsperstaff;
		for (s2 = s; s2; s2 = s2.ts_next) {
			if (s2.type != C.BAR
			 || !s2.bar_num
			 || --i > 0)
				continue
			while (s2.ts_next && s2.ts_next.type == C.BAR)
				s2 = s2.ts_next
			if (s2.ts_next)
			s2.eoln = true;
				s2.ts_next.soln = true
			i = cfmt.barsperstaff
		}
	}

	/* cut at explicit end of line, checking the line width */
	s2 = s
	for ( ; s; s = s.ts_next) {
︙
1986
1987
1988
1989
1990
1991
1992
1993

1994
1995

1996
1997
1998







1999
2000
2001
2002
2003
2004
2005
2006
2007

2008
2009


2010
2011
2012
2013
2014
2015
2016
2072
2073
2074
2075
2076
2077
2078

2079
2080

2081
2082


2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093





2094


2095
2096
2097
2098
2099
2100
2101
2102
2103







-
+

-
+

-
-
+
+
+
+
+
+
+




-
-
-
-
-
+
-
-
+
+







//			case "scale":
//			case "staffwidth":
//				set_format(s.subtype, s.param)
//				break
//			}
//			continue
//		}
		if (!s.ts_next)
		if (!s.ts_next) {
			s = null
		else if (!s.eoln)
		} else if (!s.soln) {
			continue
		else
			s.eoln = false
		} else {
			s.soln = false
			while (!s.seqst)
//			 || s.ts_prev.type == C.GRACE
//			 || s.ts_prev.type == C.SPACE)
				s = s.ts_prev
		}
		s2 = set_lines(s2, s, lwidth, indent)
		if (!s2)
			break

		// (s2 may be tsfirst - no ts_prev - when only one
		//  embedded info in the first line after the first K:)
		if (!s2.ts_prev) {
			delete s2.nl
			continue
//--fixme
		}
		s = s2.ts_prev;		// don't miss an eoln
//		s = s2.ts_prev;		// don't miss an eoln
		s = s2
		indent = 0
	}

//fixme: not usable yet
//	// restore the page parameters at start of line
//	cfmt.leftmargin = pg_sav.leftmargin;
//	cfmt.rightmargin = pg_sav.rightmargin;
︙
2122
2123
2124
2125
2126
2127
2128
2129

2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142

2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
































































































































2155
2156
2157
2158
2159
2160
2161
2209
2210
2211
2212
2213
2214
2215

2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228

2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376







-
+












-
+












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		switch (s.type) {
		case C.REST:
			if (voice_tb.length == 1)
				break
		case C.NOTE:
			delta = staff_d[st]
			if (delta
			 && !s.p_v.key.k_drum) {
			 && !s.p_v.ckey.k_drum) {
				for (m = s.nhd; m >= 0; m--) {
					note = s.notes[m];
					if (!note.opit)
						note.opit = note.pit;
					note.pit += delta
				}
			}
			break
		case C.GRACE:
			for (g = s.extra; g; g = g.next) {
				delta = staff_d[st]
				if (delta
				 && !s.p_v.key.k_drum) {
				 && !s.p_v.ckey.k_drum) {
					for (m = 0; m <= g.nhd; m++) {
						note = g.notes[m]
						if (!note.opit)
							note.opit = note.pit
						note.pit += delta
					}
				}
			}
			break
		}
	}
}

// expand the multi-rests as needed
function mrest_expand() {
    var	s, s2

	// expand a multi-rest into a set of rest + bar
	function mexp(s) {
	    var	s2, s3, s4, next, tim, nbar,
		nb = s.nmes,
		dur = s.dur / nb

		// change the multi-rest into a single rest
		s.type = C.REST
		s.dur = s.dur_orig = dur
		s.nflags = -2
		s.head = C.FULL

		/* add the bar(s) and rest(s) */
		tim = s.time + dur
		s2 = next = s.next		// bar (always)
		while (!s2.bar_num)		// get the bar number
			s2 = s2.ts_prev
		nbar = s2.bar_num - s.nmes

		s3 = s2 = s
		while (--nb > 0) {

			// add the bar
			if (next) {
				s2 = clone(next)
				delete s2.soln
				delete s2.a_gch
				delete s2.a_dd
				lkvsym(s2, next)
			} else {
				s2 = _bar(s)		// end of tune
				s.next = s2
			}
			s2.time = tim
			while (s3.time < tim)
				s3 = s3.ts_next	// bar at end of measure
			while (s3 && s3.v < s.v && s3.type == C.BAR)
				s3 = s3.ts_next	// keep in order
			if (s3) {
				lktsym(s2, s3)
				if (s3.type == C.BAR)
					delete s3.bar_num
			} else {
				s3 = s
				while (s3.ts_next)
					s3 = s3.ts_next
				s3.ts_next = s2
				s2.ts_prev = s3
				s2.ts_next = null
			}
			nbar++
			if (s2.seqst) {
				s2.bar_num = nbar
				s4 = s2.ts_next
			} else {
				delete s2.bar_num
				s4 = s2.ts_prev
			}
			s2.bar_type = s4.bar_type || "|"
			if (s4.bar_num && !s4.seqst)
				delete s4.bar_num

			// add the rest
			s4 = clone(s)
			delete s4.a_dd
			delete s4.soln
			if (s2.next) {
				s4.next = s2.next
				s4.next.prev = s4
			} else {
				s4.next = null
			}
			s2.next = s4
			s4.prev = s2
			s4.time = tim

			while (s3 && !s3.dur && s3.time == tim)
				s3 = s3.ts_next
			while (s3 && s3.v < s.v) {
				s3 = s3.ts_next	// keep in order
				if (s3 && s3.seqst)
					break
			}
			if (s3) {
				lktsym(s4, s3)
			} else {
				s3 = s
				while (s3.ts_next)
					s3 = s3.ts_next
				s3.ts_next = s4
				s4.ts_prev = s3
				s4.ts_next = null
			}

			tim += dur
			s = s3 = s4
		}
	} // mexp()

	for (s = tsfirst; s; s = s.ts_next) {
		if (s.type != C.MREST)
			continue
		if (!s.seqst && w_tb[s.ts_prev.type]) {
			s2 = s
		} else {
			s2 = s.ts_next
			while (!s2.seqst) {
				if (s2.type != C.MREST
				 || s2.nmes != s.nmes)
					break
				s2 = s2.ts_next
			}
		}
		if (!s2.seqst) {
			while (s.type == C.MREST) {
				mexp(s)
				s = s.ts_next
			}
		} else {
			s = s2.ts_prev
		}
	}
} // mrest_expand()

// set the clefs (treble or bass) in a 'auto clef' sequence
// return the starting clef type
function set_auto_clef(st, s_start, clef_type_start) {
	var s, min, max, time, s2, s3;

	/* get the max and min pitches in the sequence */
︙
2172
2173
2174
2175
2176
2177
2178
2179

2180
2181
2182
2183
2184
2185
2186
2387
2388
2389
2390
2391
2392
2393

2394
2395
2396
2397
2398
2399
2400
2401







-
+







					break
				unlksym(s)
			}
			continue
		}
		if (s.notes[0].pit < min)
			min = s.notes[0].pit
		else if (s.notes[s.nhd].pit > max)
		if (s.notes[s.nhd].pit > max)
			max = s.notes[s.nhd].pit
	}

	if (min >= 19					/* upper than 'F' */
	 || (min >= 13 && clef_type_start != 'b'))	/* or 'G,' */
		return 't'
	if (max <= 13					/* lower than 'G,' */
︙
2322
2323
2324
2325
2326
2327
2328
2329
2330

2331
2332
2333
2334
2335
2336
2337
2537
2538
2539
2540
2541
2542
2543


2544
2545
2546
2547
2548
2549
2550
2551







-
-
+







	// set the starting clefs of the staves
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (!sy.voices[v])
			continue
		st = sy.voices[v].st
		if (!sy.voices[v].second) {		// main voices
			if (p_voice.staffnonote != undefined)
				sy.staves[st].staffnonote = p_voice.staffnonote
			sy.staves[st].staffnonote = p_voice.staffnonote
			if (p_voice.staffscale)
				sy.staves[st].staffscale = p_voice.staffscale
			if (sy.voices[v].sep)
				sy.staves[st].sep = sy.voices[v].sep
			if (sy.voices[v].maxsep)
				sy.staves[st].maxsep = sy.voices[v].maxsep;

︙
2368
2369
2370
2371
2372
2373
2374
2375
2376

2377
2378
2379
2380
2381
2382
2383
2582
2583
2584
2585
2586
2587
2588


2589
2590
2591
2592
2593
2594
2595
2596







-
-
+







				staff_clef[st].autoclef = true
			for (v = 0; v < voice_tb.length; v++) {
				if (!sy.voices[v])
					continue
				p_voice = voice_tb[v];
				st = sy.voices[v].st
				if (!sy.voices[v].second) {
					if (p_voice.staffnonote != undefined)
						sy.staves[st].staffnonote = p_voice.staffnonote
					sy.staves[st].staffnonote = p_voice.staffnonote
					if (p_voice.staffscale)
						sy.staves[st].staffscale = p_voice.staffscale
					if (sy.voices[v].sep)
						sy.staves[st].sep = sy.voices[v].sep
					if (sy.voices[v].maxsep)
						sy.staves[st].maxsep = sy.voices[v].maxsep
				}
︙
2578
2579
2580
2581
2582
2583
2584
2585

2586
2587
2588
2589
2590
2591
2592
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800
2801
2802
2803
2804
2805







-
+







			}
			set_yval(s)
			break
		case C.GRACE:
			for (g = s.extra; g; g = g.next) {
				delta = staff_delta[g.st]
				if (delta
				 && !s.p_v.key.k_drum) {
				 && !s.p_v.ckey.k_drum) {
					for (m = 0; m <= g.nhd; m++) {
						note = g.notes[m];
						note.opit = note.pit
						note.pit += delta
					}
				}
				g.ymn = 3 * (g.notes[0].pit - 18) - 2;
︙
2616
2617
2618
2619
2620
2621
2622
2623

2624
2625
2626
2627
2628
2629
2630
2631
2632
2633





2634
2635
2636
2637
2638
2639
2640
2829
2830
2831
2832
2833
2834
2835

2836
2837
2838
2839
2840
2841
2842




2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854







-
+






-
-
-
-
+
+
+
+
+







				s.ymn = 0
				break
			}
			// fall thru
		case C.NOTE:
			delta = staff_delta[st]
			if (delta
			 && !s.p_v.key.k_drum) {
			 && !s.p_v.ckey.k_drum) {
				for (m = s.nhd; m >= 0; m--) {
					note = s.notes[m]
					note.opit = note.pit
					note.pit += delta
				}
			}
			if (s.type == C.NOTE) {
				s.ymx = 3 * (s.notes[s.nhd].pit - 18) + 4;
				s.ymn = 3 * (s.notes[0].pit - 18) - 4;
			} else {
//			if (s.type == C.NOTE) {
//				s.ymx = 3 * (s.notes[s.nhd].pit - 18) + 4;
//				s.ymn = 3 * (s.notes[0].pit - 18) - 4;
//			} else {
			if (s.type == C.REST) {
				s.y = (((s.notes[0].pit - 18) / 2) | 0) * 6;
				s.ymx = s.y + rest_sp[5 - s.nflags][0];
				s.ymn = s.y - rest_sp[5 - s.nflags][1]
			}
			if (s.dur < dur)
				dur = s.dur
			break
︙
2811
2812
2813
2814
2815
2816
2817
2818

2819
2820
2821
2822
2823
2824
2825
3025
3026
3027
3028
3029
3030
3031

3032
3033
3034
3035
3036
3037
3038
3039







-
+







			} else {
				s.multi = 1	/* first voice(s) */

				/* if 3 voices, and vertical space enough,
				 * have stems down for the middle voice */
				if (i != 0 && i + 2 == st_v.length) {
					if (st_v[i].ymn - cfmt.stemheight
							> st_v[i + 1].ymx)
							>= st_v[i + 1].ymx)
						s.multi = -1;

					/* special case for unison */
					t = s.ts_next
//fixme: pb with ../lacerda/evol-7.5.5.abc
					if (s.ts_prev
					 && s.ts_prev.time == s.time
︙
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020



3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034



3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048







































3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070

3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3216
3217
3218
3219
3220
3221
3222






3223
3224
3225
3226


3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246














3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287


3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304

3305

3306
3307
3308
3309
3310
3311
3312

3313
3314
3315
3316
3317
3318
3319







-
-
-
-
-
-




-
-
+
+
+














+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-

















-
+
-







-







			s.next.prev = s;
		p_v.last_sym.next = s;
		s.prev = p_v.last_sym
	}
	p_v.last_sym = s;

	lktsym(s, last_s)
	if (s.ts_prev.type != s.type)
		s.seqst = true
	if (last_s.type == s.type && s.v != last_s.v) {
		delete last_s.seqst;
		last_s.shrink = 0
	}
}

/* -- init the symbols at start of a music line -- */
function init_music_line() {
	var	p_voice, s, s2, s3, last_s, v, st, shr, shrmx,
		nv = voice_tb.length
   var	p_voice, s, s1, s2, s3, last_s, v, st, shr, shrmx, shl,
	shlp, p_st, top,
	nv = voice_tb.length

	/* initialize the voices */
	for (v = 0; v < nv; v++) {
		if (!cur_sy.voices[v])
			continue
		p_voice = voice_tb[v];
		p_voice.second = cur_sy.voices[v].second;
		p_voice.last_sym = p_voice.sym;

		/* move the voice to a printed staff */
		st = cur_sy.voices[v].st
		while (st < nstaff && !cur_sy.st_print[st])
			st++;
		p_voice.st = st
		if (!p_voice.second) {
			staff_tb[st].key = p_voice.ckey
			staff_tb[st].meter = p_voice.meter
	}

	/* add a clef at start of the main voices */
	last_s = tsfirst
	while (last_s && last_s.type == C.CLEF) {	// move the starting clefs
		v = last_s.v
		if (cur_sy.voices[v]
		 && !cur_sy.voices[v].second) {
			delete last_s.clef_small;	/* normal clef */
			p_voice = last_s.p_v;
			p_voice.last_sym = p_voice.sym = last_s
		}
		last_s = last_s.ts_next
	}
		}
	}

	// move the first clefs, key signatures and time signatures
	// to the staves
	s = tsfirst
	while (s) {
		switch (s.type) {
		case C.CLEF:
		case C.KEY:
		case C.METER:
			switch (s.type) {
			case C.CLEF:
				staff_tb[s.st].clef = s
				break
			case C.KEY:
				s.p_v.ckey = s
				break
			case C.METER:
				s.p_v.meter = s
				insert_meter |= 1
				break
			}
			unlksym(s)
			// fall thru
		case C.PART:
		case C.TEMPO:
		case C.BLOCK:
		case C.REMARK:
			s = s.ts_next
			continue
		}
		break
	}

	// generate the starting clefs, key signatures and time signatures

	// add a clef at start of the main voices
	last_s = tsfirst
	for (v = 0; v < nv; v++) {
		p_voice = voice_tb[v]
		if (p_voice.sym && p_voice.sym.type == C.CLEF)
			continue
		if (!cur_sy.voices[v]
		 || (cur_sy.voices[v].second
		  && !p_voice.bar_start))	// needed for correct linkage
			continue
		st = cur_sy.voices[v].st
		if (!staff_tb[st]
		 || !staff_tb[st].clef)
			continue
		s = clone(staff_tb[st].clef);
		s.v = v;
		s.p_v = p_voice;
		s.st = st;
		s.time = tsfirst.time;
		s.prev = null;
		s.next = p_voice.sym
		if (s.next)
			s.next.prev = s;
		p_voice.sym = s;
		p_voice.sym = p_voice.last_sym = s
		p_voice.last_sym = s;
		s.ts_next = last_s;
		if (last_s)
			s.ts_prev = last_s.ts_prev
		else
			s.ts_prev = null
		if (!s.ts_prev) {
			tsfirst = s;
			s.seqst = true
		} else {
			s.ts_prev.ts_next = s
			delete s.seqst
		}
		if (last_s) {
			last_s.ts_prev = s
			if (last_s.type == C.CLEF)
︙
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109

3110
3111
3112

3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3329
3330
3331
3332
3333
3334
3335







3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354





3355
3356
3357
3358
3359
3360
3361







-
-
-
-
-
-
-
+



+














-
-
-
-
-







	/* add keysig */
	for (v = 0; v < nv; v++) {
		if (!cur_sy.voices[v]
		 || cur_sy.voices[v].second
		 || !cur_sy.st_print[cur_sy.voices[v].st])
			continue
		p_voice = voice_tb[v]
		if (last_s && last_s.v == v && last_s.type == C.KEY) {
			p_voice.last_sym = last_s;
			last_s.k_old_sf = last_s.k_sf;	// no key cancel
			last_s = last_s.ts_next
			continue
		}
		s2 = p_voice.key
		s2 = p_voice.ckey
		if (s2.k_sf || s2.k_a_acc) {
			s = clone(s2)
			new_sym(s, p_voice, last_s)
			delete s.invis
			s.k_old_sf = s2.k_sf	// no key cancel
		}
	}

	/* add time signature (meter) if needed */
	if (insert_meter & 1) {
		for (v = 0; v < nv; v++) {
			p_voice = voice_tb[v];
			s2 = p_voice.meter
			if (!cur_sy.voices[v]
			 || cur_sy.voices[v].second
			 || !cur_sy.st_print[cur_sy.voices[v].st]
			 || !s2.a_meter.length)
				continue
			if (last_s && last_s.v == v && last_s.type == C.METER) {
				p_voice.last_sym = last_s;
				last_s = last_s.ts_next
				continue
			}
			s = clone(s2)
			new_sym(s, p_voice, last_s)
		}
		insert_meter &= ~1		// no meter any more
	}

	// add an invisible bar for the various continued elements
︙
3149
3150
3151
3152
3153
3154
3155
3156

3157
3158
3159
3160
3161
3162
3163
3164
3165
3166















3167
3168
3169
3170
3171
3172
3173
3174




3175


3176
3177
3178
3179
3180
3181


3182
3183
3184

3185
3186
3187

3188
3189
3190
3191


3192
3193
3194
3195
3196
3197

3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210

3211

3212

















3213
3214
3215


3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227


3228
3229
3230
3231
3232
3233
3234
3235
3236
3237

3238
3239
3240
3241
3242
3243
3244
3245
3372
3373
3374
3375
3376
3377
3378

3379
3380
3381
3382
3383
3384
3385




3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412

3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424

3425
3426
3427

3428


3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442


3443
3444
3445
3446
3447
3448
3449

3450
3451
3452

3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497

3498

3499
3500
3501
3502
3503
3504
3505







-
+






-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








+
+
+
+
-
+
+






+
+


-
+


-
+
-
-


+
+






+



-
-







-
+

+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+
+












+
+









-
+
-







				sls: p_voice.sls
			}
			new_sym(s, p_voice, last_s)
			p_voice.sls = []
		}
	}

	/* add bar if needed (for repeat bracket) */
	// add a bar for the continuation of repeat brackets
	for (v = 0; v < nv; v++) {
		p_voice = voice_tb[v];
		s2 = p_voice.bar_start;
		p_voice.bar_start = null

		// if bar already, keep it in sequence
		if (last_s && last_s.v == v && last_s.type == C.BAR) {
			p_voice.last_sym = last_s;
			last_s = last_s.ts_next
			continue
		if (last_s && last_s.v == v) {
			for (s3 = last_s; s3; s3 = s3.ts_next) {
				if (s3.v != v)
					break
				switch (s3.type) {
				case C.PART:
				case C.TEMPO:
					continue
				case C.BAR:
					p_voice.last_sym = s3
					last_s = s3.ts_next
					break
				}
				break
			}
		}

		if (!s2)
			continue
		if (!cur_sy.voices[v]
		 || !cur_sy.st_print[cur_sy.voices[v].st])
			continue

		if (p_voice.last_sym.type == C.BAR) {
			if (!p_voice.last_sym.rbstop)
				p_voice.last_sym.rbstart = 1
		} else {
		new_sym(s2, p_voice, last_s)
			new_sym(s2, p_voice, last_s)
		}
	}

	// compute the spacing of the added symbols
	self.set_pitch(last_s);

	s = tsfirst
	s.seqst = true
	shlp = 0
	while (1) {
		s2 = s;
		shrmx = 0
		shl = shrmx = 0
		do {
			self.set_width(s);
			shr = s.wl
			shr = s.wl + shlp
			if (s.prev)
				shr += s.prev.wr
			if (shr > shrmx)
				shrmx = shr;
			if (s.wr > shl)
				shl = s.wr	// left width for next symbol
			s = s.ts_next
		} while (s != last_s && !s.seqst);
		s2.shrink = shrmx;
		s2.space = 0
		if (s == last_s)
			break
		shlp = shl
	}

	// update the spacing before the first old time sequence
	if (!s)
		return
	shr = 0
	do {
		self.set_width(s)
		if (shr < s.wl)
			shr = s.wl;
		s = s.ts_next
	} while (s && !s.seqst);
	last_s.shrink = s2.wr + shr
	last_s.shrink = shl + shr
	last_s.space = 0
} // init_music_line()
}

// check if the tune ends on a measure bar
function check_end_bar() {
    var	s2,
	s = tsfirst
	while (s.ts_next)
		s = s.ts_next
	if (s.type != C.BAR) {
		s2 = _bar(s)
		s2.seqst = true
		s2.invis = true
		s2.time = s.time + (s.dur || 0)
		s2.ts_prev = s

		s.next = s.ts_next = s2
	}
} // check_end_bar()

/* -- set a pitch in all symbols and the start/stop of the beams -- */
// and sort the pitches in the chords
// and build the chord symbols / annotations
// this function is called only once per tune
function set_words(p_voice) {
	var	s, s2, nflags, lastnote, res,
		start_flag = true,
		pitch = 127			/* no note */

	for (s = p_voice.sym; s; s = s.next) {
		if (s.type == C.NOTE) {
			pitch = s.notes[0].pit
			break
		}
	}
	for (s = p_voice.sym; s; s = s.next) {
		if (s.a_gch)
			self.gch_build(s)
		switch (s.type) {
		case C.MREST:
			start_flag = true
			break
		case C.BAR:
			s.bar_type = bar_cnv(s.bar_type)
			if (!s.beam_on)
				start_flag = true
			if (!s.next && s.prev
//			 && s.prev.type == C.NOTE
			 && !s.invis
//			 && s.prev.dur >= C.BLEN * 2)
			 && s.prev.head == C.OVALBARS)
				s.prev.head = C.SQUARE
			break
		case C.GRACE:
			for (s2 = s.extra; s2; s2 = s2.next)
				s2.notes.sort(abc2svg.pitcmp)
			break
︙
3279
3280
3281
3282
3283
3284
3285
3286


3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299

3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3539
3540
3541
3542
3543
3544
3545

3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559

3560
3561
3562
3563
3564
3565
3566

3567
3568
3569
3570
3571
3572
3573
3574







-
+
+












-
+






-
+







				break
			}

			nflags = s.nflags

			if (s.ntrem)
				nflags += s.ntrem
			if (s.type == C.REST && s.beam_end) {
			if (s.type == C.REST && s.beam_end
			 && !s.beam_on) {
				s.beam_end = false;
				start_flag = true
			}
			if (start_flag
			 || nflags <= 0) {
				if (lastnote) {
					lastnote.beam_end = true;
					lastnote = null
				}
				if (nflags <= 0) {
					s.beam_st = true;
					s.beam_end = true
				} else if (s.type == C.NOTE) {
				} else if (s.type == C.NOTE || s.beam_on) {
					s.beam_st = true;
					start_flag = false
				}
			}
			if (s.beam_end)
				start_flag = true
			if (s.type == C.NOTE)
			if (s.type == C.NOTE || s.beam_on)
				lastnote = s
			break
		}
		if (s.type == C.NOTE) {
			if (s.nhd)
				s.notes.sort(abc2svg.pitcmp)
			pitch = s.notes[0].pit
︙
3364
3365
3366
3367
3368
3369
3370
3371

3372
3373
3374
3375
3376
3377


3378
3379
3380
3381




3382
3383
3384
3385
3386
3387
3388
3389
3390
3391



3392
3393
3394
3395
3396

3397
3398
3399
3400
3401
3402

3403






3404
3405
3406
3407
3408
3409
3410
3625
3626
3627
3628
3629
3630
3631

3632
3633
3634
3635
3636


3637
3638




3639
3640
3641
3642
3643
3644
3645
3646

3647
3648
3649
3650
3651
3652
3653
3654
3655

3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666

3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679







-
+




-
-
+
+
-
-
-
-
+
+
+
+




-





+
+
+

-



+






+
-
+
+
+
+
+
+







				break
			}
		}
	}
}

/* -- initialize the generator -- */
/* this function is called only once per tune  */
// this function is called only once per tune

var delpit = [0, -7, -14, 0]

function set_global() {
	var p_voice, st, v, nv, sy

    var	p_voice, v,
	nv = voice_tb.length,
	/* get the max number of staves */
	sy = cur_sy;
	st = sy.nstaff;
//	sy.st_print = new Uint8Array(sy.staves.length)
	sy = cur_sy,
	st = sy.nstaff

	/* get the max number of staves */
	while (1) {
		sy = sy.next
		if (!sy)
			break
//		sy.st_print = new Uint8Array(sy.staves.length)
		if (sy.nstaff > st)
			st = sy.nstaff
	}
	nstaff = st;

	// there must be a bar at end of tune
	check_end_bar()

	/* set the pitches, the words (beams) and the repeat brackets */
	nv = voice_tb.length
	for (v = 0; v < nv; v++) {
		p_voice = voice_tb[v];
		set_words(p_voice)
		p_voice.ckey = p_voice.key	// starting key
// (test removed because v.second may change after %%staves)
//		if (!p_voice.second && !p_voice.norepbra)
			set_rb(p_voice)
	}

	/* set the staff of the floating voices */
	if (nv > 1) {
	set_float();
		set_float()

	// expand the multi-rests as needed
		if (glovar.mrest_p)
			mrest_expand()
	}

	if (glovar.ottava && cfmt.sound != "play")
		set_ottava();

	// set the clefs and adjust the pitches of all symbol
	set_clefs();
	self.set_pitch(null)
︙
3429
3430
3431
3432
3433
3434
3435
3436

3437
3438
3439
3440
3441
3442
3443
3698
3699
3700
3701
3702
3703
3704

3705
3706
3707
3708
3709
3710
3711
3712







-
+







			continue
		if (!font) {
			set_font("voice");
			font = gene.curfont
		}
		i = 0
		while (1) {
			j = p.indexOf("\\n", i)
			j = p.indexOf("\n", i)
			if (j < 0)
				w = strwh(p.slice(i))
			else
				w = strwh(p.slice(i, j))
			w = w[0]
			if (w > maxw)
				maxw = w
︙
3717
3718
3719
3720
3721
3722
3723
3724

3725
3726


3727
3728


3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739

3740
3741
3742
3743
3744
3745
3746
3986
3987
3988
3989
3990
3991
3992

3993
3994

3995
3996
3997

3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009

4010
4011
4012
4013
4014
4015
4016
4017







-
+

-
+
+

-
+
+










-
+







			s1.notes[i1].shhd += sh2
	}
	return true
}

/* handle unison with different accidentals */
function unison_acc(s1, s2, i1, i2) {
	var m, d
    var	m, d, acc

	if (!s2.notes[i2].acc) {
	acc = s2.notes[i2].acc
	if (!acc) {
		d = w_note[s2.head] * 2 + s2.xmx + s1.notes[i1].shac + 2
		if (s1.notes[i1].micro)
		acc = s1.notes[i1].acc
		if (typeof acc != "number")	// microtone
			d += 2
		if (s2.dots)
			d += 6
		for (m = 0; m <= s1.nhd; m++) {
			s1.notes[m].shhd += d;
			s1.notes[m].shac -= d
		}
		s1.xmx += d
	} else {
		d = w_note[s1.head] * 2 + s1.xmx + s2.notes[i2].shac + 2
		if (s2.notes[i2].micro)
		if (typeof acc != "number")	// microtone
			d += 2
		if (s1.dots)
			d += 6
		for (m = 0; m <= s2.nhd; m++) {
			s2.notes[m].shhd += d;
			s2.notes[m].shac -= d
		}
︙
3974
3975
3976
3977
3978
3979
3980

3981
3982
3983





3984
3985
3986
3987



3988
3989
3990
3991
3992
3993
3994
3995
4245
4246
4247
4248
4249
4250
4251
4252



4253
4254
4255
4256
4257




4258
4259
4260

4261
4262
4263
4264
4265
4266
4267







+
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
-







			s3 = null
		}
		d = -10
		for (i = 0; i < MAXPIT; i++) {
			if (left2[i] + right1[i] > d)
				d = left2[i] + right1[i]
		}

		if (d < -3) {			// no clash if no dots clash
			if (!s1.dots || !s2.dots
			 || !s2.dot_low
		if (d < -3			// no clash if no dots clash
		 && ((s2.notes[0].pit & 1)
		  || !(s1.dots || s2.dots)
		  || (!(s1.notes[s1.nhd].pit == s2.notes[0].pit + 2
		    && s1.dot_low)
			 || s1.stem > 0 || s2.stem < 0
			 || s1.notes[s1.nhd].pit + 2 != s2.notes[0].pit
			 || (s2.notes[0].pit & 1))
				continue
		   && !(s1.notes[s1.nhd].pit + 2 == s2.notes[0].pit
		    && s2.dot_low))))
			continue
		}

		right2 = set_right(s2);
		left1 = set_left(s1)
		if (s3) {
			right3 = set_left(s3)
			for (i = 0; i < MAXPIT; i++) {
				if (right3[i] > left1[i])
︙
4010
4011
4012
4013
4014
4015
4016










4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034

4035
4036
4037
4038



4039
4040
4041
4042
4043
4044
4045

4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314


4315




4316
4317
4318



4319
4320


4321

4322


4323
4324
4325
4326
4327
4328
4329







+
+
+
+
+
+
+
+
+
+
















-
-
+
-
-
-
-
+
+
+
-
-
-


-
-
+
-

-
-







		 * and clash of dots */
		t = 0;
		i1 = s1.nhd;
		i2 = s2.nhd
		while (1) {
			dp = s1.notes[i1].pit - s2.notes[i2].pit
			switch (dp) {
			case 2:
				if (!(s1.notes[i1].pit & 1))
					s1.dot_low = false
				break
			case 1:
				if (s1.notes[i1].pit & 1)
					s2.dot_low = true
				else
					s1.dot_low = false
				break
			case 0:
				if (s1.notes[i1].acc != s2.notes[i2].acc
				 && !s1.notes[i1].acc && !s2.notes[i2].acc) {
					t = -1
					break
				}
				if (s2.notes[i2].acc) {
					if (!s1.notes[i1].acc)
						s1.notes[i1].acc = s2.notes[i2].acc
					s2.notes[i2].acc = 0
				}
				if (s1.dots && s2.dots
				 && (s1.notes[i1].pit & 1))
					t = 1
				break
			case -1:
				if (s1.dots && s2.dots) {
					if (s1.notes[i1].pit & 1) {
				if (s1.notes[i1].pit & 1)
						s1.dot_low = false;
						s2.dot_low = false
					} else {
						s1.dot_low = true;
					s2.dot_low = false
				else
					s1.dot_low = true
						s2.dot_low = true
					}
				}
				break
			case -2:
				if (s1.dots && s2.dots
				 && !(s1.notes[i1].pit & 1)) {
				if (!(s1.notes[i1].pit & 1))
					s1.dot_low = false;
					s2.dot_low = false
					break
				}
				break
			}
			if (t < 0)
				break
			if (dp >= 0) {
				if (--i1 < 0)
					break
︙
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4538
4539
4540
4541
4542
4543
4544


4545
4546
4547
4548
4549
4550
4551







-
-







			if (s.stem >= 0) {
				s.y = ymn;
				s.ys = ymx
			} else {
				s.ys = ymn;
				s.y = ymx
			}
			if (nflags == -4)		/* if longa */
				ymn -= 6;
			s.ymx = ymx + 4;
			s.ymn = ymn - 4
		} else if (s.stem >= 0) {
			if (s.notes[s.nhd].pit > 26
			 && (nflags <= 0
			  || !s.beam_st
			  || !s.beam_end)) {
︙
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441

4442

4443
4444
4445
4446
4447
4448
4449
4450

4451
4452



































4453
4454

4455
4456
4457
4458
4459
4460






4461
4462
4463
4464
4465
4466
4467
4468
4469
4470

4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489




4490
4491
4492
4493
4494
4495
4496
4578
4579
4580
4581
4582
4583
4584
















































































































4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601

4602
4603
4604
4605
4606
4607
4608
4609

4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648

4649
4650
4651
4652



4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676

4677
4678
4679
4680
4681
4682
4683




4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















+
-
+







-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
-
-
+
+
+
+
+
+










+







-







-
-
-
-
+
+
+
+







			if (s.notes[s.nhd].tie)
				ymx += 3;
			s.ymx = ymx + 4
		}
	}
}

/* -- split up unsuitable bars at end of staff -- */
// return true if the bar type has changed
function check_bar(s) {
    var	bar_type, i, b1, b2, s_bs, s2,
	p_voice = s.p_v

	/* search the last bar */
	while (s.type == C.CLEF || s.type == C.KEY || s.type == C.METER) {
		if (s.type == C.METER
		 && s.time > p_voice.sym.time)	/* if not empty voice */
			insert_meter |= 1;	/* meter in the next line */
		s = s.prev
		if (!s)
			return
	}
	if (s.type != C.BAR)
		return

	if (s.text != undefined) {		// if repeat bar
		p_voice.bar_start = clone(s);
		p_voice.bar_start.bar_type = ""
		delete s.text
		delete s.a_gch
//		return
	}
	bar_type = s.bar_type
	if (bar_type == ":")
		return
	if (bar_type.slice(-1) != ':')		// if not left repeat bar
		return

	// add a left repeat bar in the next music line
	s2 = p_voice.s_next
	while (1) {
		switch (s2.type) {
		case C.BAR:
		case C.GRACE:
		case C.NOTE:
		case C.REST:
			break
		default:
			s2 = s2.next
			if (!s2)
				return
		}
		break
	}
	if (s2.type == C.BAR) {
		s_bs = s2		// bar start
	} else {
		s_bs = clone(s)
		s_bs.next = s2
		s_bs.prev = s2.prev
		if (s2 == p_voice.s_next)
			p_voice.s_next = s_bs
		else
			s2.prev.next = s_bs
		s2.prev = s_bs

		while (!s2.seqst)
			s2 = s2.ts_prev
		s_bs.ts_next = s2
		s_bs.ts_prev = s2.ts_prev
		if (s2 == tsnext)
			tsnext = s_bs
		else
			s2.ts_prev.ts_next = s_bs
		s2.ts_prev = s_bs
		delete s_bs.seqst
		if (s_bs == tsnext || s2.ts_prev.type != C.BAR) {
			if (s2.seqst) {
				s_bs.seqst = true
			} else {
				s2.seqst = true
				s2.shrink = s_bs.wr + s2.wl
				s2.space = 0
			}
		}
	}

	if (bar_type[0] != ':') {		// 'xx:' (not ':xx:')
		if (bar_type == "||:") {
			s_bs.bar_type = "[|:"
			s.bar_type = "||"
			return true
		}
		s_bs.bar_type = bar_type
		if (s.prev && s.prev.type == C.BAR)
			unlksym(s)
		else
			s.bar_type = "|"
		return
	}

	// ':xx:' -> ':x|]' and '[|x:'
	i = 0
	while (bar_type[i] == ':')
		i++
	if (i < bar_type.length) {
		s.bar_type = bar_type.slice(0, i) + '|]';
		i = bar_type.length - 1
		while (bar_type[i] == ':')
			i--;
		s_bs.bar_type = '[|' + bar_type.slice(i + 1)
	} else {
		i = (bar_type.length / 2) |0;			// '::::' !
		s.bar_type = bar_type.slice(0, i) + '|]';
		s_bs.bar_type = '[|' + bar_type.slice(i)
	}
	return true
}

/* -- move the symbols of an empty staff to the next one -- */
function sym_staff_move(st) {
	for (var s = tsfirst; s; s = s.ts_next) {
		if (s.nl)
			break
		if (s.st == st
		 && s.type != C.CLEF) {
			s.st++;
			s.invis = true
		}
	}
}

// generate a block symbol
var blocks = []		// array of delayed block symbols

// (possible hook)
function block_gen(s) {
Abc.prototype.block_gen = function(s) {
	switch (s.subtype) {
	case "leftmargin":
	case "rightmargin":
	case "pagescale":
	case "pagewidth":
	case "scale":
	case "staffwidth":
		svg_flush();
		blk_flush()
		self.set_format(s.subtype, s.param)
		break
	case "mc_start":		// multicol start
		multicol = {
			posy: posy,
			maxy: posy,
			lmarg: cfmt.leftmargin,
			rmarg: cfmt.rightmargin
		}
		break
	case "mc_new":			// multicol new
		if (!multicol) {
			error(1, s, "%%multicol new without start")
			break
		}
		if (posy > multicol.maxy)
			multicol.maxy = posy
		cfmt.leftmargin = multicol.lmarg
		cfmt.rightmargin = multicol.rmarg
		img.chg = true
		set_page()
		posy = multicol.posy
		break
	case "mc_end":			// multicol end
		if (!multicol) {
			error(1, s, "%%multicol new without start")
			break
		}
		if (posy < multicol.maxy)
			posy = multicol.maxy
		cfmt.leftmargin = multicol.lmarg
		cfmt.rightmargin = multicol.rmarg
		multicol = undefined
		blk_flush()
		img.chg = true
		set_page()
		break
	case "ml":
		svg_flush();
		blk_flush()
		user.img_out(s.text)
		break
	case "newpage":
		blk_flush();
		block.newpage = true;
		blk_out()
		svg_flush()
		if (!user.page_format)
			break
		if (blkdiv < 0)		// split the tune
			user.img_out('</div>')
		blkdiv = 2		// start the next SVG in a new page
		break
	case "sep":
		set_page();
		vskip(s.sk1);
		output += '<path class="stroke"\n\td="M';
		out_sxsy((img.width -s.l) / 2 - img.lm, ' ', 0)
		output += 'h' + s.l.toFixed(1) + '"/>\n';
		vskip(s.sk2);
		break
	case "text":
		set_font(s.font)
		write_text(s.text, s.opt)
		break
	case "title":
		write_title(s.text, true)
		break
	case "vskip":
		vskip(s.sk);
//		blk_out()
		break
	}
}

/* -- define the start and end of a piece of tune -- */
/* tsnext becomes the beginning of the next line */
function set_piece() {
	var	s, last, p_voice, st, v, nst, nv, tmp,
		non_empty = [],
		non_empty_gl = [],
		sy = cur_sy
    var	s, last, p_voice, st, v, nv, tmp,
	non_empty = [],
	non_empty_gl = [],
	sy = cur_sy

	function reset_staff(st) {
		var	p_staff = staff_tb[st],
			sy_staff = sy.staves[st]

		if (!p_staff)
			p_staff = staff_tb[st] = {}
︙
4528
4529
4530
4531
4532
4533
4534







4535
4536
4537
4538
4539
4540
4541
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746







+
+
+
+
+
+
+








	// set the top and bottom of the staves
	function set_top_bot() {
	    var	st, p_staff, i, j, l

		for (st = 0; st <= nstaff; st++) {
			p_staff = staff_tb[st]

			// ledger lines
			// index = line number
			// values = [x symbol, x start, x stop]
			p_staff.hlu = []	// above the staff
			p_staff.hld = []	// under the staff

			if (!non_empty_gl[st]) {
				p_staff.botbar = p_staff.topbar = 0
				continue
			}
			l = p_staff.stafflines.length;
			p_staff.topbar = 6 * (l - 1)

︙
4572
4573
4574
4575
4576
4577
4578
4579












4580
4581
4582


4583
4584
4585
4586
4587
4588
4589
4590

4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608

4609
4610

4611
4612
4613
4614
4615
4616
4617
4618

4619


4620
4621
4622
















4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649

4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797


4798
4799
4800
4801
4802
4803
4804
4805
4806

4807







4808



4809
4810
4811
4812
4813


4814


4815


4816
4817
4818
4819
4820

4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847






4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863

4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874


4875
4876
4877
4878
4879
4880
4881








+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+







-
+
-
-
-
-
-
-
-

-
-
-





-
-
+
-
-
+
-
-





-
+

+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
-
-
-
-
















-
+










-
-







					p_staff.hlmap[j] = 1;
					p_staff.hlmap[j + 1] = 1
					break
				}
			}
		}
	} // set_top_bot()

	// remove the staff system at start of line
	if (tsfirst.type == C.STAVES) {
		s = tsfirst
		tsfirst = tsfirst.ts_next
		tsfirst.ts_prev = null
		if (s.seqst)
			tsfirst.seqst = true
		s.p_v.sym = s.next
		if (s.next)
			 s.next.prev = null
	}

	/* reset the staves */
	nstaff = nst = sy.nstaff
	for (st = 0; st <= nst; st++)
	nstaff = sy.nstaff
	for (st = 0; st <= nstaff; st++)
		reset_staff(st);

	/*
	 * search the next end of line,
	 * and mark the empty staves
	 */
	for (s = tsfirst; s; s = s.ts_next) {
		if (s.nl) {
		if (s.nl)
//fixme: not useful
//			// delay the next block symbols
//			while (s && s.type == C.BLOCK) {
//				blocks.push(s);
//				unlksym(s);
//				s = s.ts_next
//			}
			break
		}
		if (!s.ts_next)
			last = s	// keep the last symbol of the tune
		switch (s.type) {
		case C.STAVES:
			set_brace();
			sy.st_print = new Uint8Array(non_empty);
			sy = s.sy;
			nst = sy.nstaff
			if (nstaff < nst) {
			while (nstaff < sy.nstaff)
				for (st = nstaff + 1; st <= nst; st++)
					reset_staff(st);
				reset_staff(++nstaff)
				nstaff = nst
			}
			non_empty = []
			continue

		// the block symbols will be treated after music line generation
		case C.BLOCK:
			if (!s.play)
			if (!s.play) {
				blocks.push(s)
				unlksym(s)
			}
			continue
		}
		st = s.st
		if (st > nstaff) {
			switch (s.type) {
			case C.CLEF:
				staff_tb[st].clef = s	// clef warning/change for new staff
				break
			case C.KEY:
				s.p_v.ckey = s
				break
//useless ?
			case C.METER:
				s.p_v.meter = s
				break
			}
			unlksym(s)
			continue
		}
		if (non_empty[st])
			continue
		switch (s.type) {
		default:
			continue
		case C.CLEF:
			if (st > nstaff) {	// if clef warning/change for new staff
				staff_tb[st].clef = s;
				unlksym(s)
			}
			continue
		case C.BAR:
			if (s.bar_mrep
			 || sy.staves[st].staffnonote > 1)
				break
			continue
		case C.GRACE:
			break
		case C.NOTE:
		case C.REST:
		case C.SPACE:
		case C.MREST:
			if (sy.staves[st].staffnonote > 1)
				break
			if (s.invis)
				continue
			if (sy.staves[st].staffnonote != 0
			if (sy.staves[st].staffnonote
			 || s.type == C.NOTE)
				break
			continue
		}
		non_empty_gl[st] = non_empty[st] = true
	}
	tsnext = s;

	/* set the last empty staves */
	set_brace()
//	for (st = 0; st <= nstaff; st++)
//		sy.st_print[st] = non_empty[st];
	sy.st_print = new Uint8Array(non_empty);

	/* define the offsets of the measure bars */
	set_top_bot()

	/* move the symbols of the empty staves to the next staff */
//fixme: could be optimized (use a old->new staff array)
︙
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4907
4908
4909
4910
4911
4912
4913





4914
4915
4916
4917
4918
4919
4920
4921
4922
4923









4924
4925
4926
4927
4928
4929
4930







-
-
-
-
-










-
-
-
-
-
-
-
-
-







			p_voice = voice_tb[v]
			if (p_voice.sym
			 && p_voice.sym.time <= tsnext.time) {
				for (s = tsnext.ts_prev; s; s = s.ts_prev) {
					if (s.v == v) {
						p_voice.s_next = s.next;
						s.next = null;
						if (check_bar(s)) {
							tmp = s.wl;
							self.set_width(s);
							s.shrink += s.wl - tmp
						}
						break
					}
				}
				if (s)
					continue
			}
			p_voice.s_next = p_voice.sym;
			p_voice.sym = null
		}
	}

	// if the last symbol is not a bar, add an invisible bar
	if (last.type != C.BAR) {
		s = add_end_bar(last);
		s.space = set_space(s)
		if (s.space < s.shrink
		 && last.type != C.KEY)
			s.space = s.shrink
	}
}

/* -- position the symbols along the staff -- */
// (possible hook)
Abc.prototype.set_sym_glue = function(width) {
    var	s, g, ll,
	some_grace,
︙
4877
4878
4879
4880
4881
4882
4883

4884
4885
4886
4887
4888
4889
4890


4891
4892
4893
4894

4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907


4908
4909
4910
4911
4912
4913
4914

4915
4916
4917

4918
4919
4920
4921

4922
4923
4924
4925
4926
4927
4928
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089

5090
5091
5092
5093
5094

5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107

5108
5109
5110
5111
5112
5113

5114

5115
5116
5117

5118
5119
5120
5121

5122
5123
5124
5125
5126
5127
5128
5129







+






-
+
+



-
+












-
+
+




-

-
+


-
+



-
+







			set_page()
			return
		}
		switch (s.type) {
		case C.NOTE:
		case C.REST:
		case C.MREST:
		case C.SPACE:
			set_page()
			return
		default:
			continue
		case C.STAVES:
			cur_sy = s.sy
			break
//			break
			continue
		case C.BLOCK:
			if (s.play)
				continue	// keep for play
			block_gen(s)
			self.block_gen(s)
			break
		}
		unlksym(s)
		if (s.p_v.s_next == s)
			s.p_v.s_next = s.next
	}
	tsfirst = null			/* no more notes */
}

/* -- generate the music -- */
// (possible hook)
Abc.prototype.output_music = function() {
    var v, lwidth, indent, line_height, ts1st, tslast, p_v
    var v, lwidth, indent, line_height, ts1st, tslast, p_v,
	nv = voice_tb.length

	gen_init()
	if (!tsfirst)
		return
	tunes.push([tsfirst, voice_tb])	// keep tune data for playing
	set_global()
	if (voice_tb.length > 1)	/* if many voices */
	if (nv > 1)			// if many voices
		self.set_stem_dir()	// set the stems direction in 'multi'

	for (v = 0; v < voice_tb.length; v++)
	for (v = 0; v < nv; v++)
		set_beams(voice_tb[v].sym);	/* decide on beams */

	self.set_stems()		// set the stem lengths
	if (voice_tb.length > 1) {	/* if many voices */
	if (nv > 1) {			// if many voices
		set_rest_offset();	/* set the vertical offset of rests */
		set_overlap();		/* shift the notes on voice overlap */
//		set_rp_bars()		// set repeat bars
	}
	set_acc_shft();			// set the horizontal offset of accidentals

	set_allsymwidth();		/* set the width of all symbols */
︙
4939
4940
4941
4942
4943
4944
4945
4946

4947
4948
4949
4950
4951
4952
4953
5140
5141
5142
5143
5144
5145
5146

5147
5148
5149
5150
5151
5152
5153
5154







-
+







	/* else, split the tune into music lines */
		lwidth = get_lwidth();
		cut_tune(lwidth, indent)
	}

	// save symbol pointers for play
	ts1st = tsfirst
	v = voice_tb.length
	v = nv
	while (--v >= 0)
		voice_tb[v].osym = voice_tb[v].sym

	spf_last = 1.2				// last spacing factor
	while (1) {				/* loop per music line */
		set_piece();
		self.set_sym_glue(lwidth - indent)
︙
4961
4962
4963
4964
4965
4966
4967
4968

4969
4970
4971
4972

4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995

4996
4997
4998
4999
5000
5001
5002
5162
5163
5164
5165
5166
5167
5168

5169
5170
5171


5172


5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192

5193
5194
5195
5196
5197
5198
5199
5200







-
+


-
-
+
-
-




















-
+







			delayed_update();
			vskip(line_height)
			if (indent) {
				posx -= indent;
				insert_meter &= ~2	// no more indentation
			}
			while (blocks.length)
				block_gen(blocks.shift())
				self.block_gen(blocks.shift())
		}

		if (cfmt.splittune)
			blk_flush()
		blk_flush()
		else
			svg_flush()
		if (tslast)
			tslast.ts_next.ts_prev = tslast
		if (!tsnext)
			break
		tsnext.ts_prev.ts_next =		// (restore for play)
			tsfirst = tsnext

		// next line
		gen_init()
		if (!tsfirst)
			break
		tslast = tsfirst.ts_prev
		tsfirst.ts_prev = null;
		set_sym_line();
		lwidth = get_lwidth()	// the image size may have changed
		indent = set_indent()
	}

	// restore for play
	tsfirst = ts1st
	v = voice_tb.length
	v = nv
	while (--v >= 0) {
		p_v = voice_tb[v]
		if (p_v.sym && p_v.s_prev)
			p_v.sym.prev = p_v.s_prev
		p_v.sym = p_v.osym
	}
}
︙
Changes to core/parse.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - parse.js - ABC parse
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
108
109
110
111
112
113
114


115
116
117
118
119


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139

140
141
142
143
144
145
146
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142

143
144
145
146
147
148
149
150







+
+





+
+
















-
+


-
+







	if (clef_def[i + 1] != '8')
		return s
	switch (clef_def[i]) {			// octave
	case '^':
		s.clef_oct_transp = true
	case '+':
		s.clef_octave = 7
		if (!s.clef_oct_transp)
			curvoice.snd_oct = 12	// MIDI higher octave
		break
	case '_':
		s.clef_oct_transp = true
	case '-':
		s.clef_octave = -7
		if (!s.clef_oct_transp)
			curvoice.snd_oct = -12	// MIDI lower octave
		break
	}
	return s
}

// convert an interval to a base-40 interval
function get_interval(param, score) {
    var	i, val, tmp, note, pit

	tmp = new scanBuf;
	tmp.buffer = param
	pit = []
	for (i = 0; i < 2; i++) {
		note = tmp.buffer[tmp.index] ? parse_acc_pit(tmp) : null
		if (!note) {
			if (i != 1 || !score) {
				syntax(1, "Bad transpose value")
				syntax(1, errs.bad_transp)
				return
			}
			pit[i] = 23			// 'c' (C5)
			pit[i] = 242			// 'c' (C5)
		} else {
			pit[i] = abc2svg.pab40(note.pit, note.acc)
		}
	}
	return pit[1] - pit[0]
}

︙
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194







-
+







		char_tb[item.charCodeAt(0)] = '\n'
	}
}

// set a new user character (U: or %%user)
function set_user(parm) {
    var	k, c, v,
	a = parm.match(/(.)[= ]*(\[I:.+\]|".+"|!.+!)$/)
	a = parm.match(/(.)[=\s]*(\[I:.+\]|".+"|!.+!)$/)

	if (!a) {
		syntax(1, 'Lack of starting [, ! or " in U: / %%user')
		return
	}
	c = a[1];
	v = a[2]
︙
256
257
258
259
260
261
262


263
264
265
266
267
268
269
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275







+
+







			type: C.BLOCK,
			subtype: subtype,
			dur: 0
		}

	if (parse.state == 2)
		goto_tune()
	if (subtype.slice(0, 4) != "midi")	// if not a play command
		curvoice = voice_tb[0]		// set the block in the first voice
	sym_link(s)
	return s
}

// set the voice parameters
// (possible hook)
Abc.prototype.set_vp = function(a) {
︙
300
301
302
303
304
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
306
307
308
309
310
311
312

313
314
315
316

317
318
319
320
321
322
323
324







-




-
+







					clefpit = 4 - val	// 4 = 'G'
					break
				}
			}
			syntax(1, errs.bad_val, item)
			break
		case "octave=":
		case "uscale=":			// %%microscale
			val = parseInt(a.shift())
			if (isNaN(val))
				syntax(1, errs.bad_val, item)
			else
				curvoice[item.slice(0, -1)] = val
				curvoice.octave = val
			break
		case "cue=":
			curvoice.scale = a.shift() == 'on' ? .7 : 1
			break
		case "instrument=":

			// instrument=M/N => score=MN and sound=cN
︙
336
337
338
339
340
341
342
343
344


345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365




366
367
368
369
370
371

372
373




374
375
376

377



378
379
380
381
382
383
384
341
342
343
344
345
346
347


348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400







-
-
+
+















-
+





+
+
+
+





-
+


+
+
+
+



+
-
+
+
+







		case "name=":
		case "nm=":
			curvoice.nm = a.shift()
			if (curvoice.nm[0] == '"')
				curvoice.nm = curvoice.nm.slice(1, -1);
			curvoice.new_name = true
			break
		case "stem=":
		case "pos=":
		case "stem=":			// compatibility
		case "pos=":			// from %%pos only
			if (item == "pos=")
				item = a.shift().split(' ')
			else
				item = ["stm", a.shift()];
			val = posval[item[1]]
			if (val == undefined) {
				syntax(1, errs.bad_val, item[0])
				break
			}
			if (!pos)
				pos = {}
			pos[item[0]] = val
			break
		case "scale=":			// %%voicescale
			val = parseFloat(a.shift())
			if (isNaN(val) || val < .6 || val > 1.5)
			if (isNaN(val) || val < .5 || val > 2)
				syntax(1, errs.bad_val, "%%voicescale")
			else
				curvoice.scale = val
			break
		case "score=":
			if (cfmt.nedo) {
				syntax(1, errs.notransp)
				break
			}
			// score=MN
			// (score=M == score=Mc)
			item = a.shift()
			if (cfmt.sound)
				break
			curvoice.transp = get_transp(item)
			curvoice.transp = get_interval(item, true)
			break
		case "shift=":
			if (cfmt.nedo) {
				syntax(1, errs.notransp)
				break
			}
			curvoice.shift = curvoice.sndsh = get_interval(a.shift())
			break
		case "sound=":
			if (cfmt.nedo) {
		case "transpose=":		// (abcMIDI compatibility)
				syntax(1, errs.notransp)
				break
			}
// concert-score display: apply sound=
// sounding-score display: apply sound= only if M != c/C
// sound: apply sound=
			curvoice.sndtran = get_interval(a.shift())
			if (cfmt.sound)
				curvoice.transp = curvoice.sndtran
			break
︙
407
408
409
410
411
412
413














414
415
416
417
418
419
420
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450







+
+
+
+
+
+
+
+
+
+
+
+
+
+







			break
		case "staffscale=":
			val = parseFloat(a.shift())
			if (isNaN(val) || val < .3 || val > 2)
				syntax(1, "Bad %%staffscale value")
			else
				curvoice.staffscale = val
			break
		case "transpose=":		// (abcMIDI compatibility)
			if (cfmt.nedo) {
				syntax(1, errs.notransp)
				break
			}
			val = get_transp(a.shift())
			if (val == undefined) {
				syntax(1, errs.bad_transp)
			} else {
				curvoice.sndtran = val
				if (cfmt.sound)
					curvoice.transp = val
			}
			break
		default:
			switch (item.slice(0, 4)) {
			case "treb":
			case "bass":
			case "alto":
			case "teno":
︙
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561








562
563
564
565
566
567























568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583


584
585
586
587
588
589
590
510
511
512
513
514
515
516

517
518
519
520
521
522
523

524


525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542




543
544
545
546
547
548




549
550
551
552
553
554
555
556
557







558
559
560
561
562
563
564
565
566
567
568






569
570
571
572
573
574
575
576






577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624







-
+






-
+
-
-


















-
-
-
-






-
-
-
-









-
-
-
-
-
-
-











-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
















+
+







// return the key and the voice/clef parameters
function new_key(param) {
    var	i, clef, key_end, c, tmp, exp,
	sf = "FCGDAEB".indexOf(param[0]) - 1,
	mode = 0,
	s = {
		type: C.KEY,
		dur:0
		dur: 0
	}

	// set the accidentals when K: with modified accidentals
	function set_k_acc(s, sf) {
	    var i, j, n, nacc, p_acc,
		accs = [],
		pits = [],
		pits = []
		m_n = [],
		m_d = []

		if (sf > 0) {
			for (nacc = 0; nacc < sf; nacc++) {
				accs[nacc] = 1;			// sharp
				pits[nacc] = [26, 23, 27, 24, 21, 25, 22][nacc]
			}
		} else {
			for (nacc = 0; nacc < -sf; nacc++) {
				accs[nacc] = -1;		// flat
				pits[nacc] = [22, 25, 21, 24, 20, 23, 26][nacc]
			}
		}
		n = s.k_a_acc.length
		for (i = 0; i < n; i++) {
			p_acc = s.k_a_acc[i]
			for (j = 0; j < nacc; j++) {
				if (pits[j] == p_acc.pit) {
					accs[j] = p_acc.acc
					if (p_acc.micro_n) {
						m_n[j] = p_acc.micro_n;
						m_d[j] = p_acc.micro_d
					}
					break
				}
			}
			if (j == nacc) {
				accs[j] = p_acc.acc;
				pits[j] = p_acc.pit
				if (p_acc.micro_n) {
					m_n[j] = p_acc.micro_n;
					m_d[j] = p_acc.micro_d
				}
				nacc++
			}
		}
		for (i = 0; i < nacc; i++) {
			p_acc = s.k_a_acc[i]
			if (!p_acc)
				p_acc = s.k_a_acc[i] = {}
			p_acc.acc = accs[i];
			p_acc.pit = pits[i]
			if (m_n[i]) {
				p_acc.micro_n = m_n[i];
				p_acc.micro_d = m_d[i]
			} else {
				delete p_acc.micro_n
				delete p_acc.micro_d
				}
		}
	} // set_k_acc()

	// code of new_key()
	set_ref(s);

	// tonic
	i = 1
    if (sf < -1) {
	switch (param[0]) {
	case 'H':				// bagpipe
		switch (param[1]) {
		case 'P':
		case 'p':
			s.k_bagpipe = param[1];
			sf = param[1] == 'P' ? 0 : 2;
			i++
		if (param[1].toLowerCase() != 'p') {
			syntax(1, "Unknown bagpipe-like key")
			key_end = true
			break
		}
		s.k_bagpipe = param[1];
		sf = param[1] == 'P' ? 0 : 2;
		i++
			break
		default:
			syntax(1, "Unknown bagpipe-like key")
			key_end = true
			break
		}

		// initialize the temperament if not done yet
		if (!cfmt.temper)
	// detune in cents for just intonation in A
	//  C    ^C     D    _E     E     F    ^F     G    _A     A    _B     B
	// 15.3 -14.0  -2.0 -10.0   1.9  13.3 -16.0 -31.8 -12.0   0.0  11.4   3.8
	// (C is ^C,			F is ^F and G is =G)
	// 86				 84
	// temp = [100-14, -14, -2, -10, 2, 100-16, -16, -32, -12, 0, 11, 4]
	// but 'A' bagpipe = 480Hz => raise Math.log2(480/440)*1200 = 151
			cfmt.temper = new Float32Array([
//	2.37, 1.37, 1.49, 1.41, 1.53, 2.35, 1.35, 1.19, 1.39, 1.51, 1.62, 1.55
   //   C    ^C     D    _E     E     F    ^F     G    _A      A     _B      B
11.62, 12.55,
     2.37, 2.37, 3.49, 0,
     2.37, 2.37, 3.49, 4.41, 5.53, 0,
		 3.49, 4.41, 5.53, 7.35, 7.35,
		       4.41, 5.53, 7.35, 7.35, 8.19, 0,
				   7.35, 7.35, 8.19, 9.39, 10.51, 0,
					       8.19, 9.39, 10.51, 11.62, 12.55, 0,
							   10.51, 11.62, 12.55,
									     2.37, 2.37
			])
		break
	case 'P':
		syntax(1, "K:P is deprecated");
		sf = 0;
		s.k_drum = true;
		key_end = true
		break
	case 'n':				// none
		if (param.indexOf("none") == 0) {
			sf = 0;
			s.k_none = true;
			i = 4
			break
		}
		// fall thru
	default:
		s.k_map = []
		s.k_mode = 0
		return [s, info_split(param)]
	}
    }

	if (!key_end) {
		switch (param[i]) {
		case '#': sf += 7; i++; break
︙
853
854
855
856
857
858
859

860
861
862
863
864
865
866
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901







+







		}
	}
}

/* Q: tempo */
function new_tempo(text) {
    var	i, c, d, nd,
	txt = text,			// (for info.Q)
	s = {
		type: C.TEMPO,
		dur: 0
	}

	// get a note duration
	function get_nd(p) {
︙
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
912
913
914
915
916
917
918

919
920
921
922
923
924
925
926







-
+







		}
		syntax(1, "Invalid note duration $1", c)
	} // get_nd()

	set_ref(s)

	if (cfmt.writefields.indexOf('Q') < 0)
		s.del = true			// don't display
		s.invis = true			// don't display

	/* string before */
	if (text[0] == '"') {
		c = text.match(/"([^"]*)"/)		// "
		if (!c) {
			syntax(1, "Unterminated string in Q:")
			return
︙
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951
952



953
954
955
956
957
958





959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976

977
978
979
980
981
982

983
984
985
986
987
988
989
971
972
973
974
975
976
977

978
979
980
981
982
983




984
985
986

987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015





1016
1017
1018
1019
1020
1021
1022
1023







-
+





-
-
-
-
+
+
+
-





+
+
+
+
+

















-
+

-
-
-
-
-
+







				return
			}
		}
	}

	if (parse.state != 3) {
		if (parse.state == 1) {			// tune header
			info.Q = text;
			info.Q = txt
			glovar.tempo = s
			return
		}
		goto_tune()
	}
	if (curvoice.v == par_sy.top_voice) {	/* tempo only for first voice */
		sym_link(s)
		if (glovar.tempo && curvoice.time == 0)
			glovar.tempo.del = true
	sym_link(s)
	if (glovar.tempo && curvoice.time == 0)
		glovar.tempo.invis = true
	}
}

// treat the information fields which may embedded
function do_info(info_type, text) {
	var s, d1, d2, a, vid

	// skip this line if the current voice is ignored
	if (curvoice && curvoice.ignore
	 && info_type != 'V')
		return

	switch (info_type) {

	// info fields in any state
	case 'I':
		self.do_pscom(text)
		break
	case 'L':
//fixme: ??
		if (parse.state == 2)
			goto_tune();
		a = text.match(/^1\/(\d+)(=(\d+)\/(\d+))?$/)
		if (a) {
			d1 = Number(a[1])
			if (!d1 || (d1 & (d1 - 1)) != 0)
				break
			d1 = C.BLEN / d1
			if (a[2]) {
			if (a[2]) {		// if '='
				d2 = Number(a[4])
				if (!d2 || (d2 & (d2 - 1)) != 0) {
					d2 = 0
					break
				}
				d2 = Number(a[3]) / d2 * C.BLEN
				d2 = d2 ? Number(a[3]) / d2 * C.BLEN : 0
			} else {
				d2 = d1
			}
		} else if (text == "auto") {
			d1 = d2 = -1
		}
		if (!d2) {
︙
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041

1042
1043
1044
1045
1046
1047
1048
1049
1050


1051
1052
1053
1054
1055
1056
1057
1044
1045
1046
1047
1048
1049
1050


1051
1052
1053
1054
1055

1056













1057




1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075







-
-





-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-








+
+







			break
		if (parse.state == 1) {
			info.P = text
			break
		}
		if (parse.state == 2)
			goto_tune()
		if (cfmt.writefields.indexOf(info_type) < 0)
			break
		s = {
			type: C.PART,
			text: text,
			dur: 0
		}

		if (cfmt.writefields.indexOf(info_type) < 0)
		/*
		 * If not in the main voice, then,
		 * if the voices are synchronized and no P: yet in the main voice,
		 * the misplaced P: goes into the main voice.
		 */
		var p_voice = voice_tb[par_sy.top_voice]
		if (curvoice.v != p_voice.v) {
			if (curvoice.time != p_voice.time)
				break
			if (p_voice.last_sym && p_voice.last_sym.type == C.PART)
				break		// already a P:
			var voice_sav = curvoice;
			curvoice = p_voice;
			s.invis = true
			sym_link(s);
			curvoice = voice_sav
		} else {
			sym_link(s)
		sym_link(s)
		}
		break
	case 'Q':
		if (parse.state == 0)
			break
		new_tempo(text)
		break
	case 'V':
		get_voice(text)
		if (parse.state == 3)
			curvoice.ignore = !par_sy.voices[curvoice.v]
		break

	// key signature at end of tune header or in tune body
	case 'K':
		if (!parse.state)	// ignore if in file header
			break
		get_key(text)
︙
1134
1135
1136
1137
1138
1139
1140
1141

1142
1143
1144
1145
1146
1147
1148
1149
1150
1151


1152
1153
1154
1155
1156
1157
1158
1152
1153
1154
1155
1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178







-
+










+
+







		for (i = 0; i <= s2.nhd; i++)
			s2.notes[i].dur *= fac
	}
	curvoice.time = s.time = time
}

/* -- parse a bar -- */
function new_bar() {
function new_bar(dotted) {
	var	s2, c, bar_type,
		line = parse.line,
		s = {
			type: C.BAR,
			fname: parse.fname,
			istart: parse.bol + line.index,
			dur: 0,
			multi: 0		// needed for decorations
		}

	if (dotted)
		s.bar_dotted = true
	if (vover && vover.bar)			// end of voice overlay
		get_vover('|')
	if (glovar.new_nbar) {			// %%setbarnb
		s.bar_num = glovar.new_nbar;
		glovar.new_nbar = 0
	}
	bar_type = line.char()
︙
1175
1176
1177
1178
1179
1180
1181
1182

1183
1184

1185
1186
1187
1188
1189
1190
1191
1195
1196
1197
1198
1199
1200
1201

1202
1203

1204
1205
1206
1207
1208
1209
1210
1211







-
+

-
+







		} else {
			s.rbstop = 2		// right repeat with end
			if (curvoice.tie_s)
				curvoice.tie_s.tie_s = s
		}
	}

	// set the guitar chord and the decorations
	// set the annotations and the decorations
	if (a_gch)
		self.gch_build(s)
		csan_add(s)
	if (a_dcn) {
		deco_cnv(a_dcn, s);
		a_dcn = null
	}

	// set the start/stop of ottava
	if (parse.ottava.length) {
︙
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213

1214
1215
1216
1217
1218
1219


1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1224
1225
1226
1227
1228
1229
1230

1231


1232

1233
1234
1235


1236
1237
1238


1239
1240
1241
1242
1243
1244
1245







-
+
-
-
+
-



-
-
+
+

-
-







		}
		s2.ottava = parse.ottava
		parse.ottava = []
	}

	/* if the last element is '[', it may start
	 * a chord or an embedded header */
	switch (bar_type.slice(-1)) {
	if (bar_type.slice(-1) == '['
	case '[':
		if (/[0-9" ]/.test(c))		// "
	 && !(/[0-9" ]/.test(c))) {		// "
			break
		bar_type = bar_type.slice(0, -1);
		line.index--;
		c = '['
		break
	case ':':				// left repeat
	}
	if (bar_type.slice(-1) == ':')		// left repeat
		s.rbstop = 2			// with bracket end
		break
	}

	// check if repeat bar
	if (c > '0' && c <= '9') {
		s.text = c
		while (1) {
			c = line.next_char()
			if ("0123456789,.-".indexOf(c) < 0)
︙
1264
1265
1266
1267
1268
1269
1270
1271


1272
1273
1274
1275
1276
1277
1278
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1294
1295







-
+
+







	if (s.rbstart
	 && curvoice.norepbra
	 && !curvoice.second)
		s.norepbra = true

	// handle the accidentals (ties and repeat)
	if (s.text) {
		if (bar_type.slice(-1) == '[')
		if (bar_type.slice(-1) == '['
		 && bar_type != '[')
			bar_type = bar_type.slice(0, -1)
		if (s.text[0] == '1') {
			if (curvoice.tie_s)
				curvoice.tie_s_rep = curvoice.tie_s
			if (curvoice.acc_tie)
				curvoice.acc_tie_rep = curvoice.acc_tie.slice()
			else if (curvoice.acc_tie_rep)
︙
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299


1300
1301


1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312







1313
1314
1315
1316
1317
1318
1319
1305
1306
1307
1308
1309
1310
1311


1312
1313
1314
1315
1316


1317
1318


1319
1320







1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334







-
-



+
+
-
-
+
+
-
-


-
-
-
-
-
-
-
+
+
+
+
+
+
+







						curvoice.tie_s
				}
			}
			if (curvoice.acc_tie_rep)
				curvoice.acc_tie = curvoice.acc_tie_rep.slice()
		}
	}
	curvoice.acc = []			// no accidental anymore

	if (curvoice.ulen < 0)			// L:auto
		adjust_dur(s);

	if ((bar_type == "[" || bar_type == "|:")
	 && !curvoice.eoln) {
	s2 = curvoice.last_sym
	if (s2 && s2.time == curvoice.time) {
		s2 = curvoice.last_sym
		if (s2 && s2.time == curvoice.time) {
		if (bar_type == "["
			|| bar_type == "|:") {

			// search if a previous bar at this time
			do {
				if (s2.type == C.BAR)
					break
				if (w_tb[s2.type]) // symbol with a width
					break
				s2 = s2.prev
			} while (s2)
//			do {
//				if (s2.type == C.BAR)
//					break
//				if (w_tb[s2.type]) // symbol with a width
//					break
//				s2 = s2.prev
//			} while (s2)
			if (s2 && s2.type == C.BAR) {
//		&& !s2.a_gch && !s2.a_dd
//		&& !s.a_gch && !s.a_dd) {

				// remove the invisible repeat bars
				// when no shift is needed
				if (bar_type == "["
︙
1401
1402
1403
1404
1405
1406
1407



1408
1409
1410
1411
1412
1413


1414
1415
1416
1417
1418
1419
1420
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430

1431
1432
1433
1434
1435
1436
1437
1438
1439







+
+
+





-
+
+







			rbstart: 2
		}
		sym_link(s2);
		s2.st = curvoice.st
		delete s.text;
		s.rbstart = 0
	}

	if (!s.bar_dotted && !s.invis)
		curvoice.acc = []		// no accidental anymore
}

// parse %%staves / %%score
// return an array of [vid, flags] / null
function parse_staves(p) {
	var	v, vid,
    var	v, vid,
	vids = {},
		a_vf = [],
		err = false,
		flags = 0,
		brace = 0,
		bracket = 0,
		parenth = 0,
		flags_st = 0,
︙
1520
1521
1522
1523
1524
1525
1526





1527


1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548

1549
1550
1551
1552
1553
1554
1555
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550

1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580







+
+
+
+
+
-
+
+




















-
+







					continue
				case '|':
					flags |= STOP_BAR
					continue
				}
				break
			}
			if (vids[vid]) {
				syntax(1, "Double voice in %%score")
//				err = true
			} else {
				vids[vid] = true
			a_vf.push([vid, flags]);
				a_vf.push([vid, flags])
			}
			flags = 0
			if (!e)
				break
			a.unshift(e)
			break
		}
	}
	if (flags_st != 0) {
		syntax(1, "'}', ')' or ']' missing in %%score");
		err = true
	}
	if (err || !a_vf.length)
		return //null
	return a_vf
}

// split an info string
function info_split(text) {
	if (!text)
		return []
    var	a = text.match(/=?[^\s"=]+=?|".+?"/g)	// "
    var	a = text.match(/[^\s"=]+=?|"[^"]+"/g)	// "
	if (!a) {
//fixme: bad error text
		syntax(1, "Unterminated string")
		return []
	}
	return a
}
︙
1571
1572
1573
1574
1575
1576
1577
1578
1579


1580
1581
1582
1583
1584
1585
1586
1596
1597
1598
1599
1600
1601
1602


1603
1604
1605
1606
1607
1608
1609
1610
1611







-
-
+
+







		den *= 1 << res[2].length;
	line.index = reg_dur.lastIndex
	return [num, den]
}

// parse the note accidental and pitch
function parse_acc_pit(line) {
	var	note, acc, micro_n, micro_d, pit, nd,
		c = line.char()
    var	note, acc, pit, d, nd,
	c = line.char()

	// optional accidental
	switch (c) {
	case '^':
		c = line.next_char()
		if (c == '^') {
			acc = 2;
︙
1601
1602
1603
1604
1605
1606
1607

1608
1609


1610



1611
1612
1613




1614
1615
1616
1617

1618
1619
1620
1621
1622
1623
1624
1626
1627
1628
1629
1630
1631
1632
1633


1634
1635
1636
1637
1638
1639



1640
1641
1642
1643



1644
1645
1646
1647
1648
1649
1650
1651
1652







+
-
-
+
+

+
+
+
-
-
-
+
+
+
+
-
-
-

+







		} else {
			acc = -1
		}
		break
	}

	/* look for microtone value */
	if (acc == 1 || acc == -1) {
	if (acc && acc != 3 && (c >= '1' && c <= '9')
	 || c == '/') {				// compatibility
	    if ((c >= '1' && c <= '9')
	     || c == '/') {			// shortcut
		nd = parse_dur(line);
		if (acc < 0)
			nd[0] = -nd[0]
		if (cfmt.nedo && nd[1] == 1) {
		micro_n = nd[0];
		micro_d = nd[1]
		if (micro_d == 1)
			nd[0] *= 12
			nd[1] *= cfmt.nedo
		}
		acc = nd
			micro_d = curvoice ? curvoice.uscale : 1
		else
			micro_d *= 2;	// 1/2 tone fraction -> tone fraction
		c = line.char()
	    }
	}

	/* get the pitch */
	pit = ntb.indexOf(c) + 16;
	c = line.next_char()
	if (pit < 16) {
		syntax(1, "'$1' is not a note", line.buffer[line.index - 1])
︙
1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1650
1651
1652

1653
1654
1655
1656
1657


1658
1659
1660
1661
1662
1663
1664
1665


1666
1667
1668



1669
1670
1671

1672

1673

1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685








1686
1687
1688
1689
1690
1691





1692
1693
1694
1695
1696
1697
1698
1663
1664
1665
1666
1667
1668
1669

1670
1671





1672
1673
1674

1675
1676
1677
1678


1679
1680
1681
1682
1683
1684
1685
1686


1687
1688



1689
1690
1691
1692
1693

1694
1695
1696

1697

1698
1699
1700
1701
1702
1703
1704




1705
1706
1707
1708
1709
1710
1711
1712
1713





1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725







-
+

-
-
-
-
-



-
+



-
-
+
+






-
-
+
+
-
-
-
+
+
+


-
+

+
-
+
-







-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+







		c = line.next_char()
	}
	note = {
		pit: pit,
		shhd: 0,
		shac: 0
	}
	if (acc) {
	if (acc)
		note.acc = acc
		if (micro_n) {
			note.micro_n = micro_n;
			note.micro_d = micro_d
		}
	}
	return note
}

/* set the mapping of a note */
// return the mapping of a note
//
// The global 'maps' object is indexed by the map name.
// Its content is an object ('map') indexed from the map type:
// - normal = b40 pitch
// - octave = 'o' + b40 pitch in C..B interval
// - normal = ABC note
// - octave = 'o' + ABC note in C..B interval
// - key    = 'k' + scale index
// - all    = 'all'
// The 'map' is stored in the note. It is an array of
//	[0] array of heads (glyph names)
//	[1] print (note)
//	[2] color
//	[3] play (b40)
function set_map(note) {
//	[3] play (note)
function set_map(note, acc) {
    var	map = maps[curvoice.map],	// never null
	n = note.b40,
	nn = n.toString()
    var	pit = note.pit,
	nn = not2abc(pit, acc),
	map = maps[curvoice.map]	// never null

	if (!map[nn]) {
		nn = 'o' + (n % 40).toString()		// octave
		nn = 'o' + nn.replace(/[',]+/, '')	// ' octave
		if (!map[nn]) {
			nn = 'k' + ntb[(pit + 75 -
			n += 2 - curvoice.ckey.k_b40	// key
					curvoice.ckey.k_sf * 11) % 7]
			nn = 'k' + (abc2svg.b40_p[n % 40]).toString()
			if (!map[nn]) {
				nn = 'all'		// 'all'
				if (!map[nn])
					return
			}
		}
	}
	note.map = map[nn]
	if (note.map[1]) {				// if print map
		note.pit = note.map[1].pit
		note.acc = note.map[1].acc
	note.map = map = map[nn]
	if (map[1]) {				// if print map
		note.pit = pit = map[1].pit
		note.acc = map[1].acc
		if (!note.acc			// if no accidental
		 && curvoice.acc[pit + 19])	// but one in the measure
			note.acc = 3
		curvoice.acc[pit + 19] = note.acc == 3 ? 0 : note.acc
	}
	if (note.map[2])				// if color
		note.color = note.map[2]
	nn = note.map[3]
	if (nn)						// if play map
		note.b40 = nn
	if (map[2])				// if color
		note.color = map[2]
	nn = map[3]
	if (nn)					// if play map
		note.midi = pit2mid(nn.pit + 19, nn.acc)
}

/* -- parse note or rest with pitch and length -- */
// 'line' is not always 'parse.line'
function parse_basic_note(line, ulen) {
	var	nd,
		note = parse_acc_pit(line)
︙
1782
1783
1784
1785
1786
1787
1788


1789
1790






















































1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808

1809
1810
1811

1812
1813
1814
1815
1816
1817
1818

1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829

1830
1831
1832
1833
1834
1835
1836
1809
1810
1811
1812
1813
1814
1815
1816
1817


1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880






1881
1882

1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893

1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904

1905
1906
1907
1908
1909
1910
1911
1912







+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-


-
+



+






-
+










-
+







				ty: C.SL_AUTO
			})
			if (e_is_note)
				s.sls[s.sls.length - 1].is_note = e_is_note
			return
		}
	}
	syntax(1, "End of slur without start")
}
	syntax(1, "Lack of starting slur")
}

// convert a diatonic pitch and accidental to a MIDI pitch with cents
function pit2mid(pit, acc) {
    var	p = [0, 2, 4, 5, 7, 9, 11][pit % 7],	// chromatic pitch
	o = ((pit / 7) | 0) * 12,		// octave
	p0, p1, s, b40

	if (curvoice.snd_oct)
		o += curvoice.snd_oct
	if (acc == 3)				// if natural accidental
		acc = 0
	if (acc) {
		if (typeof acc != "number") {
			s = acc[0] / acc[1]	// microtonal accidental
			if (acc[1] == 100)	// in cents
				return p + o + s
		} else {
			s = acc			// simple accidental
		}
	} else {
		if (cfmt.temper)
			return cfmt.temper[abc2svg.p_b40[pit % 7]] + o
		return p + o
	}
	if (!cfmt.nedo) {			// non equal temperament
		if (!cfmt.temper) {
			p += o + s		// standard temperament
			return p
		}
	} else {				// equal temperament
		if (typeof acc == "number") {	// if not a fraction
			b40 = abc2svg.p_b40[pit % 7] + acc
			return cfmt.temper[b40] + o
		}

		if (acc[1] == cfmt.nedo) { // fraction of the edo divider
			b40 = abc2svg.p_b40[pit % 7]
			return cfmt.temper[b40] + o + s
		}
	}

	p0 = cfmt.temper[abc2svg.p_b40[pit % 7]]	// main note
	if (s > 0) {					// sharp
		p1 = cfmt.temper[(abc2svg.p_b40[pit % 7] + 1) % 40]
		if (p1 < p0)
			p1 += 12
	} else {					// flat
		p1 = cfmt.temper[(abc2svg.p_b40[pit % 7] + 39) % 40]
		if (p1 > p0)
			p1 -= 12
		s = -s
	}
	return p0 + o + (p1 - p0) * s
} // pit2mid()

// (possible hook)
Abc.prototype.new_note = function(grace, sls) {
    var	note, s, in_chord, c, dcn, type, tie_s, acc_tie,
	i, n, s2, nd, res, num, dur, apit,
	sl1 = [],
	line = parse.line,
	a_dcn_sav = a_dcn		// save parsed decoration names

	if (!grace
	 && curvoice.tie_s) {		// if tie from previous note / grace note
		tie_s = curvoice.tie_s
		curvoice.tie_s = null
	}

	// handle the ties
	function do_ties(s, tie_s) {
	    var	m, note
	    var	m, note, mid

		for (m = 0; m <= s.nhd; m++) {
			note = s.notes[m]
			mid = note.midi
			if (tie_s.type != C.GRACE) {
				for (i = 0; i <= tie_s.nhd; i++) {
					if (!tie_s.notes[i].tie_ty)
						continue
					// (tie_s.notes[i].tie_n may exist
					//  on repeat restart)
					if (tie_s.notes[i].b40 == note.b40) {
					if (tie_s.notes[i].midi == mid) {
						tie_s.notes[i].tie_n = note
						note.s = s
						tie_s.tie_s = s
						break
					}
				}
			} else {
				for (s2 = tie_s.extra; s2; s2 = s2.next) {
					if (!s2.notes[0].tie_ty)
						continue
					if (s2.notes[0].b40 == note.b40) {
					if (s2.notes[0].midi == mid) {
						s2.tie_s = s
						s2.notes[0].tie_n = note
						note.s = s
						s2.notes[0].s = s2
						tie_s.tie_s = s
						break
					}
︙
1851
1852
1853
1854
1855
1856
1857




1858
1859
1860
1861
1862

1863
1864
1865
1866
1867
1868
1869
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941

1942
1943
1944
1945
1946
1947
1948
1949







+
+
+
+




-
+







		xmx: 0
	}
	s.istart = parse.bol + line.index

	if (curvoice.color)
		s.color = curvoice.color

	if (curvoice.tie_s) {		// if tie from previous note / grace note
		tie_s = curvoice.tie_s
		curvoice.tie_s = null
	}
	if (grace) {
		s.grace = true
	} else {
		if (a_gch)
			self.gch_build(s)
			csan_add(s)
		if (parse.repeat_n) {
			s.repeat_n = parse.repeat_n;
			s.repeat_k = parse.repeat_k;
			parse.repeat_n = 0
		}
	}
	c = line.char()
︙
1886
1887
1888
1889
1890
1891
1892


1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904

1905


1906
1907
1908
1909
1910
1911
1912
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985

1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996







+
+











-
+

+
+







		if (s.nmes == 1) {
			s.type = C.REST;
			s.dur_orig = s.dur;
			s.notes = [{
				pit: 18,
				dur: s.dur
			}]
		} else {
			glovar.mrest_p = true
		}
		break
	case 'y':
		s.type = C.SPACE;
		s.invis = true;
		s.dur = 0;
		c = line.next_char()
		if (c >= '0' && c <= '9')
			s.width = line.get_int()
		else
			s.width = 10
		if (tie_s)
		if (tie_s) {
			curvoice.tie_s = tie_s
			tie_s = null
		}
		break
	case 'x':
		s.invis = true
	case 'z':
		s.type = C.REST;
		line.index++;
		nd = parse_dur(line);
︙
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
2008
2009
2010
2011
2012
2013
2014


2015
2016
2017
2018
2019
2020
2021







-
-







		c = line.next_char()
		// fall thru
	default:			// accidental, chord, note
		if (curvoice.acc_tie) {
			acc_tie = curvoice.acc_tie
			curvoice.acc_tie = null
		}
		if (curvoice.uscale)
			s.uscale = curvoice.uscale;
		s.notes = []

		// loop on the chord
		while (1) {

			// when in chord, get the slurs and decorations
			if (in_chord) {
︙
1986
1987
1988
1989
1990
1991
1992
1993

1994
1995
1996
1997
1998
1999
2000
2001
2002

2003


2004


2005
2006
2007
2008

2009
2010
2011
2012
2013
2014
2015
2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080
2081
2082
2083

2084
2085
2086
2087

2088
2089
2090
2091
2092

2093
2094
2095
2096
2097
2098
2099
2100







-
+








-
+

+
+
-
+
+



-
+








			// transpose
			if (curvoice.octave)
				note.pit += curvoice.octave * 7
			apit = note.pit + 19		// pitch from C-1

			// get the explicit or implicit accidental
			// and keep the absolute pitch in base-40
			// and keep the absolute pitch in (MIDI + cents) format
			i = note.acc
			if (i) {
				curvoice.acc[apit] = i
			} else {
				i = curvoice.acc[apit]
				if (!i && acc_tie)
					i = acc_tie[apit]
				if (!i)
				    i = curvoice.ckey.k_map[apit % 7] || 0
					i = curvoice.ckey.k_map[apit % 7] || 0
			}
			note.midi = pit2mid(apit, i)
			if (curvoice.ckey.k_sndtran)
			note.b40 = abc2svg.pab40(note.pit, i)
				note.midi += abc2svg.b40m(curvoice.ckey.k_sndtran +
						122) - 36

			if (curvoice.map
			 && maps[curvoice.map])
				set_map(note)
				set_map(note, i)

			// starting slurs
			if (sl1.length) {
				while (1) {
					i = sl1.shift()
					if (!i)
						break
︙
2099
2100
2101
2102
2103
2104
2105




2106
2107
2108
2109
2110
2111
2112
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201







+
+
+
+







		// the duration of the chord is the duration of the 1st note
		s.dur_orig = s.notes[0].dur;
		s.dur = s.notes[0].dur * curvoice.dur_fact
	}
	if (s.grace && s.type != C.NOTE) {
		syntax(1, errs.bad_grace)
		return //null
	}
	if (tie_s && s.type != C.NOTE) {
		syntax(1, "Bad tie")
		tie_s = null
	}

	if (s.notes) {				// if note or rest
		if (!grace) {
			switch (curvoice.pos.stm) {
			case C.SL_ABOVE: s.stem = 1; break
			case C.SL_BELOW: s.stem = -1; break
︙
2219
2220
2221
2222
2223
2224
2225



2226

2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239

2240
2241
2242
2243
2244
2245
2246

2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317

2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330

2331
2332
2333
2334
2335
2336
2337

2338
2339
2340
2341
2342

2343
2344
2345
2346
2347
2348
2349







+
+
+
-
+












-
+






-
+




-







		if (!curvoice.sym_restart)
			curvoice.sym_restart = s
	}

	if (a_dcn_sav)
		deco_cnv(a_dcn_sav, s, s.prev)
	if (parse.ottava.length) {
		if (grace)
			grace.ottava = parse.ottava
		else
		s.ottava = parse.ottava
			s.ottava = parse.ottava
		parse.ottava = []
	}
	if (parse.stemless)
		s.stemless = true
	s.iend = parse.bol + line.index
	return s
}

// adjust the duration of the elements in a tuplet
function tp_adj(s, fact) {
    var	tim = s.time

	curvoice.time = s.time + (curvoice.time - s.time) * fact
	curvoice.time = tim + (curvoice.time - tim) * fact
	while (1) {
//fixme: tuplets in grace notes?
		s.in_tuplet = true
		if (!s.grace) {
			s.time = tim
			if (s.dur) {
				s.dur = Math.round(s.dur * fact)
				s.dur *= fact
				tim += s.dur
			}
		}
		if (!s.next) {
			s.dur = curvoice.time - s.time
			if (s.tpe)
				s.tpe++
			else
				s.tpe = 1
			break
		}
		s = s.next
︙
2426
2427
2428
2429
2430
2431
2432













2433
2434
2435
2436
2437
2438
2439
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543







+
+
+
+
+
+
+
+
+
+
+
+
+







	function parse_seq(in_mac) {
	    var	c, idx, type, k, s, dcn, i, n, text, note

		while (1) {
			c = line.char()
			if (!c)
				break

			// skip definitions if the current voice is ignored
			if (curvoice.ignore) {
				while (1) {
					if (c == '['
					 && line.buffer[line.index + 1] == 'V'
					 && line.buffer[line.index + 2] == ':')
						break		// [V:nn] found
					c = line.next_char()
					if (!c)
						return
				}
			}

			// special case for '.' (dot)
			if (c == '.') {
				switch (line.buffer[line.index + 1]) {
				case '(':
				case '-':
				case '|':
︙
2484
2485
2486
2487
2488
2489
2490
2491

2492
2493

2494
2495
2496
2497
2498
2499
2500
2588
2589
2590
2591
2592
2593
2594

2595


2596
2597
2598
2599
2600
2601
2602
2603







-
+
-
-
+







						grace.gr_shift = true
				}
				break
			case '\n':			// line break
				if (cfmt.barsperstaff)
					break
				if (par_sy.voices[curvoice.v]
				 && par_sy.voices[curvoice.v].range == 0
				 && par_sy.voices[curvoice.v].range == 0)
				 && curvoice.last_sym)
					curvoice.last_sym.eoln = true
					curvoice.eoln = true
				break
			case '&':			// voice overlay
				if (grace) {
					syntax(1, errs.bad_grace)
					break
				}
				c = line.next_char()
︙
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2658
2659
2660
2661
2662
2663
2664


2665
2666
2667
2668
2669
2670
2671







-
-







					get_vover('(')
					break
				}
				line.index--;
				sls.push(parse_vpos())
				continue
			case ')':			// slur end
				if (curvoice.ignore)
					break
				s = curvoice.last_sym
				if (s) {
					switch (s.type) {
					case C.SPACE:
						if (!s.notes) {
							s.notes = []
							s.notes[0] = {}
︙
2749
2750
2751
2752
2753
2754
2755
2756

2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2850
2851
2852
2853
2854
2855
2856

2857



2858
2859
2860
2861
2862
2863
2864







-
+
-
-
-







				}
				continue
			case '|':
				if (grace) {
					syntax(1, errs.bar_grace)
					break
				}
				c = line.buffer[line.index - 1];
				new_bar(line.buffer[line.index - 1] == '.')
				new_bar()
				if (c == '.')
					curvoice.last_sym.bar_dotted = true
				continue
			case '}':
				s = curvoice.last_note
				if (!grace || !s) {
					syntax(1, errs.bad_char, c)
					break
				}
︙
2799
2800
2801
2802
2803
2804
2805

2806
2807
2808
2809
2810
2811
2812
2813
2814

2815


2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829

2830
2831

2832
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930

2931


2932
2933







+









+

+
+













-
+
-
-
+

		if (parse.state != 2)
			return
		goto_tune()
	}

	if (parse.tp) {
		tp = parse.tp
		tpn = parse.tpn
		tps = parse.tps
		parse.tp = null
	}

	parse_seq()

	if (tp.length) {
		parse.tp = tp
		parse.tps = tps
		parse.tpn = tpn
	}
	if (sls.length)
		syntax(1, "Start of slur without note")
	if (grace) {
		syntax(1, "No end of grace note sequence");
		curvoice.last_sym = grace.prev;
		curvoice.last_note = last_note_sav
		if (grace.prev)
			grace.prev.next = null
	}
	if (cfmt.breakoneoln && curvoice.last_note)
		curvoice.last_note.beam_end = true
	if (no_eol || cfmt.barsperstaff)
		return
	if (char_tb['\n'.charCodeAt(0)] == '\n'
	 && par_sy.voices[curvoice.v]
	 && par_sy.voices[curvoice.v].range == 0
	 && par_sy.voices[curvoice.v].range == 0)
	 && curvoice.last_sym)
		curvoice.last_sym.eoln = true
		curvoice.eoln = true
}
Changes to core/subs.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19



























20
21
22
23
24
25
26
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


-
+
















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







// abc2svg - subs.js - text output
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// add font styles
    var	sheet
var add_fstyle = typeof document != "undefined" ?
    function(s) {
    var	e
	if (!sheet) {
		if (abc2svg.sheet) {	// if styles from a previous generation
			sheet = abc2svg.sheet
			e = sheet.cssRules.length
			while (--e >= 0)
				sheet.deleteRule(e)
		} else {
			e = document.createElement('style')
			document.head.appendChild(e)
			abc2svg.sheet = sheet = e.sheet
		}
	}
	s = s.match(/[^{]+{[^}]+}/g)	// insert each style
	while (1) {
		e = s.shift()
		if (!e)
			break
		sheet.insertRule(e, sheet.cssRules.length)
	}
    } // add_fstyle()
    : function(s) { font_style += "\n" + s }

// width of characters according to the font type
// these tables were created from the font 'Liberation'

// serif
  var
    sw_tb = new Float32Array([
	.000,.000,.000,.000,.000,.000,.000,.000,	// 00
︙
76
77
78
79
80
81
82
83
84
85
86






87
88
89


90
91
92
93
94
95
96
97


98






99
100
101
102
103
104
105
103
104
105
106
107
108
109




110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143







-
-
-
-
+
+
+
+
+
+



+
+








+
+
-
+
+
+
+
+
+







	return cwid(c) * gene.curfont.swfac
}

// estimate the width and height of a string ..
var strwh = typeof document != "undefined" ?

    // .. by the browser
    (function(el) {
	el.style.position = 'absolute';
	el.style.top = '-1000px';
	el.style.padding = '0';
    (function() {
	// (re)create a text element
    var	el = document.createElement('text')
	el.style.position = 'absolute'
	el.style.top = '-1000px'
	el.style.padding = '0'
	document.body.appendChild(el)

	return function(str) {
		if (str.wh)
			return str.wh
	    var	c,
		font = gene.curfont,
		h = font.size,
		w = 0,
		n = str.length,
		i0 = 0,
		i = 0

		el.className = font_class(font)
		el.style.lineHeight = 1
		el.style.font = style_font(font).slice(5);

		if (typeof str == "object") {	// if string already converted
			el.innerHTML = str
			str.wh = [ el.clientWidth, el.clientHeight ]
			return str.wh
		}

		str = str.replace(/<|>|&[^&]*?;|&|  /g, function(c){
			switch (c) {
			case '<': return "&lt;"
			case '>': return "&gt;"
			case '&': return "&amp;"
			case "  ": return '  '	// space + nbspace
︙
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184







+













-
+







				font = get_font("u" + c)
			} else {
				i++
				continue
			}
			el.innerHTML = str.slice(i0, i);
			w += el.clientWidth
//fixme: bad result if space(s) at end of string
			if (font.size > h)
				h = font.size;

			el.style.font = style_font(font).slice(5);
			i += 2;
			i0 = i
		}
		el.innerHTML = str.slice(i0);
		w += el.clientWidth;

		gene.curfont = font
		return [w, h]
	}
    })(document.createElement('div')) :
    })() :

    // .. by internal tables
    function(str) {
    var	font = gene.curfont,
	swfac = font.swfac,
	h = font.size,
	w = 0,
︙
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188












189
190
191
192
193














194
195

196
197
198
199

200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220

221
222
223
224
225
226

227
228





















229
230
231
232
233
234
235
236
237


238
239
240
241
242

243
244
245
246
247
248
249
213
214
215
216
217
218
219








220
221
222
223
224
225
226
227
228
229
230
231





232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250

251


252

253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268
269

270

271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312

313
314
315
316
317
318
319
320







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
+
-
-
+
-













-
+



-
+
-




-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+
+




-
+







		}
		w += cwid(c) * swfac
	}
	gene.curfont = font
	return [w, h]
}

// set the default and current font
function set_font(xxx) {
	if (typeof xxx == "string")
		xxx = get_font(xxx);
	cw_tb = xxx.name.slice(0, 4) == 'sans' ? ssw_tb : sw_tb;
	gene.curfont = gene.deffont = xxx
}

// convert a string to a SVG text, handling the font changes
// The string size is memorized into the String.
function str2svg(str) {
	// check if the string is already converted
	if (typeof str == "object")
		return str

    var	o, n_font, wh,
	o_font = gene.curfont,
	c_font = o_font

	// start a '<tspan>' element
// output a string handling the font changes
function out_str(str) {
	var	n_font,
		o_font = gene.curfont,
		c_font = o_font;
	function tspan(nf, of) {
	    var	cl

		if (nf.class
		 && nf.name == of.name
		 && nf.size == of.size
		 && nf.weight == of.weight
		 && nf.style == of.style)
			cl = nf.class		// change only the class
		 else
			cl = font_class(nf)

		return '<tspan\n\tclass="' + cl + '">'
	} // tspan()

	output += str.replace(/<|>|&[^&]*?;|&|  |\$./g, function(c){
	o = str.replace(/<|>|&[^&]*?;|&|  |\$./g, function(c){
			switch (c) {
			case '<': return "&lt;"
			case '>': return "&gt;"
			case '&':
			case '&': return "&amp;"
				 return "&amp;"
			case '  ':
			case '  ': return '  '	// space + nbspace
				return '  '		// space + nbspace
			default:
				if (c[0] != '$')
					break
				if (c[1] == '0')
					n_font = gene.deffont
				else if (c[1] >= '1' && c[1] <= '9')
					n_font = get_font("u" + c[1])
				else
					break
				c = ''
				if (n_font == c_font)
					return c
				if (c_font != o_font)
					c = "</tspan>";
					c = "</tspan>"
				c_font = n_font
				if (c_font == o_font)
					return c
				return c + '<tspan\n\tclass="' +
				return c + tspan(c_font, o_font)
						font_class(n_font) + '">'
			}
			return c		// &xxx;
		})
	if (c_font != o_font) {
		output += "</tspan>";
		o += "</tspan>"
		gene.curfont = c_font	// keep current font for next paragraph
	}

	// convert to String and memorize the string width and height
	o = new String(o)
	if (typeof document != "undefined")
		strwh(o)		// browser
	else
		o.wh = strwh(str)	// CLI
	return o
} // str2svg()

// set the default and current font
function set_font(xxx) {
	if (typeof xxx == "string")
		xxx = get_font(xxx)
	cw_tb = xxx.name.slice(0, 4) == 'sans' ? ssw_tb : sw_tb
	gene.curfont = gene.deffont = xxx
}

// output a string handling the font changes
function out_str(str) {
	output += str2svg(str)
}

// output a string, handling the font changes
// the action is:
//	'c' align center
//	'r' align right
//	'j' justify - w is the line width
//	otherwise align left
function xy_str(x, y, str,
function xy_str(x, y,
		str,		// string or object String with attribute 'wh'
		action,		// default: align left
		w,		// needed for justify
		wh) {		// optional [width, height]
	if (!wh)
		wh = strwh(str);
		wh = str.wh || strwh(str)

	output += '<text class="' + font_class(gene.curfont)
	if (action != 'j' && str.length > 5
	 && gene.curfont.wadj)
		output += '" lengthAdjust="' + gene.curfont.wadj +
			'" textLength="' + wh[0].toFixed(1);
	output += '" x="';
︙
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279
280
281
282

283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300


301
302
303
304
305
306
307
308
309
310
311
312
313
333
334
335
336
337
338
339

340













341


342

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363


364
365
366
367
368
369
370







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-















+
+




-
-







		break
	default:
		output += '">'
		break
	}
	out_str(str);
	output += "</text>\n"

}
	if (!w && gene.curfont.box) {
// not in the SVG documentation,
// but this works for almost all browsers but firefox
//		output += '<g style="outline: solid black;\
//			outline-width: 1px">\n';
//	//	xy_str(x, y, str, action, w);
//		output += '</g>\n'
		output += '<rect class="stroke" x="';
		out_sxsy(x - 2, '" y="', y + wh[1]);
		output += '" width="' + (wh[0] + 4).toFixed(1) +
			'" height="' + (wh[1] + 2).toFixed(1) +
			'"/>\n'
	}

}

// move last capitalized word to front when after a comma
/* -- move trailing "The" to front, set to uppercase letters or add xref -- */
function trim_title(title, is_subtitle) {
	var i

	if (cfmt.titletrim) {
		i = title.lastIndexOf(", ")
		if (i < 0 || title[i + 2] < 'A' || title[i + 2] > 'Z') {
			i = 0
		} else if (cfmt.titletrim == true) {	// compatibility
			if (i < title.length - 7
			 || title.indexOf(' ', i + 3) >= 0)
				i = 0
		} else {
			if (i < title.length - cfmt.titletrim - 2)
				i = 0
		}
		if (i)
			title = title.slice(i + 2).trim() + ' ' + title.slice(0, i)
	}
	if (!is_subtitle
	 && cfmt.writefields.indexOf('X') >= 0)
		title = info.X + '.  ' + title
	if (i)
		title = title.slice(i + 2).trim() + ' ' + title.slice(0, i)
	if (cfmt.titlecaps)
		return title.toUpperCase()
	return title
}

// return the width of the music line
function get_lwidth() {
︙
327
328
329
330
331
332
333
334
335




336
337

338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362

363
364
365
366
367
368
369
370
371
372
373
374
375

376
377
378
379


380
381
382
383
384
385
386

387
388
389
390


391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406

407
408
409
410


411
412
413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

432
433
434

435
436
437
438
439


440
441
442
443

444
445
446


447
448
449
450
451


452
453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473



474
475
476

477
478
479
480
481
482
483
384
385
386
387
388
389
390


391
392
393
394
395

396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

419
420

421
422
423
424
425


426
427

428
429
430
431
432
433
434


435
436
437
438

439
440
441

442




443
444

445
446
447
448

449
450
451
452
453
454
455
456

457

458




459
460

461
462
463
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482

483





484
485

486
487
488
489
490


491
492





493
494
495
496

497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
513
514

515
516
517
518
519

520
521
522
523
524
525
526
527







-
-
+
+
+
+

-
+

-
+




















-

+
-
+




-
-


-




+


-
-
+
+


-



-
+
-
-
-
-
+
+
-




-
+







-

-
+
-
-
-
-
+
+
-




-
+














-
+


-
+
-
-
-
-
-
+
+
-



+

-
-
+
+
-
-
-
-
-
+
+


-
+








-









-
+
+
+


-
+







	if (is_subtitle) {
		set_font("subtitle");
		h = cfmt.subtitlespace
	} else {
		set_font("title");
		h = cfmt.titlespace
	}
	wh = strwh(title);
	vskip(wh[1] + h)
	wh = strwh(title)
	wh[1] += gene.curfont.pad * 2
	vskip(wh[1] + h + gene.curfont.pad)
	h = gene.curfont.pad
	if (cfmt.titleleft)
		xy_str(0, 0, title, null, null, wh)
		xy_str(0, h, title, null, null, wh)
	else
		xy_str(get_lwidth() / 2, 0, title, "c", null, wh)
		xy_str(get_lwidth() / 2, h, title, "c", null, wh)
}

/* -- output a header format '111 (222)' -- */
function put_inf2r(x, y, str1, str2, action) {
	if (!str1) {
		if (!str2)
			return
		str1 = str2;
		str2 = null
	}
	if (!str2)
		xy_str(x, y, str1, action)
	else
		xy_str(x, y, str1 + ' (' + str2 + ')', action)
}

/* -- write a text block (%%begintext / %%text / %%center) -- */
function write_text(text, action) {
	if (action == 's')
		return				// skip
	set_font("text");
	set_page();

    var	wh, font,
    var	wh, font, o,
	strlw = get_lwidth(),
		sz = gene.curfont.size,
		lineskip = sz * cfmt.lineskipfac,
		parskip = sz * cfmt.parskipfac,
		p_start = block.started ? function(){} : blk_out,
		p_flush = block.started ? svg_flush : blk_flush,
		i, j, x, words, w, k, ww, str;

	p_start()
	switch (action) {
	default:
//	case 'c':
//	case 'r':
		font = gene.curfont
		switch (action) {
		case 'c': x = strlw / 2; break
		case 'r': x = strlw; break
		default: x = 0; break
		case 'r': x = strlw - font.pad; break
		default: x = font.pad; break
		}
		j = 0
		font = gene.curfont
		while (1) {
			i = text.indexOf('\n', j)
			if (i < 0) {
				str = text.slice(j);
				str = str2svg(text.slice(j))
				wh = strwh(str);
				gene.curfont = font;
				vskip(wh[1]  * cfmt.lineskipfac);
				xy_str(x, 0, str, action, null, wh);
				vskip(str.wh[1]  * cfmt.lineskipfac + font.pad * 2)
				xy_str(x, font.pad, str, action)
				font = gene.curfont
				break
			}
			if (i == j) {			// new paragraph
				vskip(parskip);
				p_flush();
				blk_flush()
				use_font(gene.curfont)
				while (text[i + 1] == '\n') {
					vskip(lineskip);
					i++
				}
				if (i == text.length)
					break
				p_start()
			} else {
				str = text.slice(j, i);
				str = str2svg(text.slice(j, i))
				wh = strwh(str);
				gene.curfont = font;
				vskip(wh[1]  * cfmt.lineskipfac);
				xy_str(x, 0, str, action, null, wh);
				vskip(str.wh[1]  * cfmt.lineskipfac + font.pad * 2)
				xy_str(x, font.pad, str, action)
				font = gene.curfont
			}
			j = i + 1
		}
		vskip(parskip);
		p_flush()
		blk_flush()
		break
	case 'f':
	case 'j':
		j = 0
		while (1) {
			i = text.indexOf('\n\n', j)
			if (i < 0)
				words = text.slice(j)
			else
				words = text.slice(j, i);
			words = words.split(/\s+/);
			w = k = 0
			font = gene.curfont
			for (j = 0; j < words.length; j++) {
				ww = strwh(words[j] + ' ')[0];
				ww = strwh(words[j])[0];
				w += ww
				if (w >= strlw) {
					str = words.slice(k, j).join(' ');
					str = str2svg(words.slice(k, j).join(' '))
					gene.curfont = font;
					wh = strwh(str);
					gene.curfont = font;
					vskip(wh[1]  * cfmt.lineskipfac);
					xy_str(0, 0, str, action, strlw, wh);
					vskip(str.wh[1]  * cfmt.lineskipfac)
					xy_str(0, 0, str, action, strlw)
					font = gene.curfont;
					k = j;
					w = ww
				}
				w += cwidf(' ')
			}
			if (w != 0) {
				str = words.slice(k).join(' ');
			if (w != 0) {			// last line
				str = str2svg(words.slice(k).join(' '))
				gene.curfont = font;
				wh = strwh(str);
				gene.curfont = font;
				vskip(wh[1]  * cfmt.lineskipfac);
				xy_str(0, 0, str, null, null, wh)
				vskip(str.wh[1]  * cfmt.lineskipfac)
				xy_str(0, 0, str)
			}
			vskip(parskip);
			p_flush()
			blk_flush()
			if (i < 0)
				break
			while (text[i + 2] == '\n') {
				vskip(lineskip);
				i++
			}
			if (i == text.length)
				break
			p_start();
			use_font(gene.curfont);
			j = i + 2
		}
		break
	}
}

/* -- output the words after tune -- */
function put_words(words) {
	var p, i, j, n, nw, i2, i_end, have_text;
    var	p, i, j, nw, w, lw, x1, x2, i1, i2, do_flush,
	maxn = 0,			// max number of characters per line
	n = 1				// number of verses

	// output a line of words after tune
	function put_wline(p, x, right) {
	function put_wline(p, x) {
		var i = 0, j, k

		if (p[i] == '$' && p[i +  1] >= '0' && p[i + 1] <= '9')
			i += 2;
		k = 0;
		j = i
		if ((p[i] >= '0' && p[i] <= '9') || p[i + 1] == '.') {
︙
493
494
495
496
497
498
499
500
501
502
503


504
505
506

507
508
509

510
511
512
513
514
515
516
517
518

519
520
521
522






523
524
525
526
527
528







529
530
531
532
533
534
535
536









537







538
539
540






541
542
543
544
545
546
547










548
549




550
551
552
553
554
555
556
557


558
559
560
561
562
563

564
565

566
567

568
569


570
571
572

573








574
575
576
577
578
579
580
537
538
539
540
541
542
543

544
545
546
547
548
549


550



551
552
553
554





555
556




557
558
559
560
561
562






563
564
565
566
567
568
569








570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586



587
588
589
590
591
592







593
594
595
596
597
598
599
600
601
602


603
604
605
606
607







608
609






610
611

612
613

614


615
616
617
618
619
620

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635







-



+
+

-
-
+
-
-
-
+



-
-
-
-
-

+
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+

-
+

-
+
-
-
+
+



+
-
+
+
+
+
+
+
+
+







				i++
		}

		if (k != 0)
			xy_str(x, 0, p.slice(j, k), 'r')
		if (i < p.length)
			xy_str(x + 5, 0, p.slice(i), 'l')
		return i >= p.length && k == 0
	} // put_wline()

	set_font("words")
	vskip(cfmt.wordsspace)
	svg_flush()

	/* see if we may have 2 columns */
	var	middle = get_lwidth() / 2,
	// estimate the width of the lines
		max2col = (middle - 45.) / cwidf('a');
	n = 0;
	words = words.split('\n');
	words = words.split('\n')
	nw = words.length
	for (i = 0; i < nw; i++) {
		p = words[i]
/*fixme:utf8*/
		if (p.length > max2col) {
			n = 0
			break
		}
		if (!p) {
			while (i + 1 < nw && !words[i + 1])
			if (have_text) {
				n++;
				have_text = false
			}
				i++
			n++
		} else if (p.length > maxn) {
			maxn = p.length
			i1 = i		// keep this line
		}
		} else {
			have_text = true
		}
	}
	if (n > 0) {
		i = n = ((n + 1) / 2) | 0;
	}

	w = get_lwidth() / 2		// half line width
	lw = strwh(words[i1])[0]
	i1 = i2 = 0
	if (lw < w) {			// if 2 columns
		j = n >> 1
		have_text = false
		for (i_end = 0; i_end < nw; i_end++) {
			p = words[i_end];
			j = 0
			while (p[j] == ' ')
				j++
			if (j == p.length) {
				if (have_text && --i <= 0)
		for (i = 0; i < nw; i++) {
			p = words[i]
			if (!p) {
				if (--j <= 0)
					i1 = i
				while (i + 1 < nw && !words[i + 1])
					i++
				if (j <= 0) {
					i2 = i + 1
					break
				}
			}
		}
		n >>= 1
	}
	if (i2) {
		x1 = (w - lw) / 2 + 10
				have_text = false
			} else {
				have_text = true
		x2 = x1 + w
	} else {				// one column
		x2 = w - lw / 2 + 10
	}

	do_flush = true
			}
		}
		i2 = i_end + 1
	} else {
		i2 = i_end = nw
	}

	for (i = 0; i < i1 || i2 < nw; i++, i2++) {
		vskip(cfmt.lineskipfac * gene.curfont.size)
		if (i < i1) {
			p = words[i]
			if (p)
				put_wline(p, x1)
			else
				use_font(gene.curfont)
		}
		if (i2 < nw) {
	/* output the text */
	vskip(cfmt.wordsspace)
			p = words[i2]
			if (p) {
				put_wline(p, x2)
			} else {

	for (i = 0; i < i_end || i2 < nw; i++) {
//fixme:should also permit page break on stanza start
		if (i < i_end && words[i].length == 0) {
			blk_out();
			use_font(gene.curfont)
		}
		vskip(cfmt.lineskipfac * gene.curfont.size)

				if (--n == 0) {
		if (i < i_end)
			put_wline(words[i], 45., 0)
		if (i2 < nw) {
			if (put_wline(words[i2], 20. + middle, 1)) {
				if (--n == 0) {
					if (i < i_end) {
					if (i < i1) {
						n++
					} else if (i2 < words.length - 1) {
					} else if (i2 < nw - 1) {

						/* center the last words */
						// center the last verse
/*fixme: should compute the width average.. */
						middle *= .6
						x2 = w - lw / 2 + 10
						svg_flush()
					}
				}
			}
		}
			i2++

		if (!words[i + 1] && !words[i2 + 1]) {
			if (do_flush) {
				svg_flush()
				do_flush = false
			}
		} else {
			do_flush = true
		}
	}
}

/* -- output history -- */
function put_history() {
	var	i, j, c, str, font, h, w, wh, head,
︙
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
659
660
661
662
663
664
665

666
667
668
669
670
671
672







-







		str = str.split('\n');
		xy_str(w, 0, str[0])
		for (j = 1; j < str.length; j++) {
			vskip(h);
			xy_str(w, 0, str[j])
		}
		vskip(h * .3);
		blk_out();
		use_font(gene.curfont)
	}
}

/* -- write heading with format -- */
var info_font_init = {
	A: "info",
︙
641
642
643
644
645
646
647

648

649
650
651


652
653
654
655
656
657
658
659
660

































661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697
698
699
695
696
697
698
699
700
701
702

703
704

705
706
707









708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750

751

















752



753
754
755
756
757
758
759







+
-
+

-

+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-









-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-







		p = cfmt.titleformat,
		j = 0,
		i = 0

	while (1) {
		while (p[i] == ' ')
			i++
		c = p[i++]
		if (i >= p.length)
		if (!c)
			break
		c = p[i++]
		if (c < 'A' || c > 'Z') {
			switch (c) {
			case '+':
			if (c == '+') {
				if (fmt.length == 0
				 || fmt.slice(-1) == '+')
					continue
				fmt = fmt.slice(0, -1) + '+'
			} else if (c == ',') {
				if (fmt.slice(-1) == '+')
					fmt = fmt.slice(0, -1) + 'l'
				fmt += '\n'
				align = '+'
				c = p[i++]
				break
			case ',':
				fmt += '\n'
				// fall thru
			default:
				continue
			case '<':
				align = 'l'
				c = p[i++]
				break
			case '>':
				align = 'r'
				c = p[i++]
				break
			}
		} else {
			switch (p[i]) {		// old syntax
			case '-':
				align = 'l'
				i++
				break
			case '1':
				align = 'r'
				i++
				break
			case '0':
				i++
				// fall thru
			default:
				align = 'c'
				break
			}
			continue
		}
		if (!info_val[c]) {
			if (!info[c])
				continue
			info_val[c] = info[c].split('\n');
			info_nb[c] = 1
		} else {
			info_nb[c]++
		}
		fmt += c
		fmt += align + c
		switch (p[i]) {
		case '-':
			fmt += 'l'
			i++
			break
		case '0':
			fmt += 'c'
			i++
			break
		case '1':
			fmt += 'r'
			i++
			break
		default:
			fmt += 'c'
			break
		}
	}
	}
	if (fmt.slice(-1) == '+')
		fmt = fmt.slice(0, -1) + 'l';
	fmt += '\n'

	// loop on the blocks
	var	ya = {
			l: cfmt.titlespace,
			c: cfmt.titlespace,
			r: cfmt.titlespace
︙
709
710
711
712
713
714
715
716
717


718
719
720


721
722
723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743


744
745
746


747
748
749

750
751
752
753



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

774
775
776
777
778
779
780
781
782
783
784



785
786
787
788
789
790
791
769
770
771
772
773
774
775


776
777
778


779
780


781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800


801
802
803


804
805
806
807

808
809



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853







-
-
+
+

-
-
+
+
-
-

+


















-
-
+
+

-
-
+
+


-
+

-
-
-
+
+
+



















-
+











+
+
+







	i = 0
	while (1) {

		// get the y offset of the top text
		yb.l = yb.c = yb.r = y = 0;
		j = i
		while (1) {
			c = p[j++]
			if (c == '\n')
			align = p[j++]
			if (align == '\n')
				break
			align = p[j++]
			if (align == '+')
			c = p[j++]
			if (align == '+' || yb[align])
				align = p[j + 1]
			else if (yb[align] != 0)
				continue

			str = info_val[c]
			if (!str)
				continue
			font_name = info_font[c]
			if (!font_name)
				font_name = "history";
			font = get_font(font_name);
			sz = font.size * 1.1
			if (info_sz[c])
				sz += info_sz[c]
			if (y < sz)
				y = sz;
			yb[align] = sz
		}
		ya.l += y - yb.l;
		ya.c += y - yb.c;
		ya.r += y - yb.r
		while (1) {
			c = p[i++]
			if (c == '\n')
			align = p[i++]
			if (align == '\n')
				break
			align = p[i++]
			if (info_val[c].length == 0)
			c = p[i++]
			if (!info_val[c].length)
				continue
			str = info_val[c].shift()
			if (align == '+') {
			if (p[i] == '+') {
				info_nb[c]--;
				c = p[i++];
				align = p[i++]
				if (info_val[c].length > 0) {
				i++
				c = p[i++];
				if (info_val[c].length) {
					if (str)
						str += ' ' + info_val[c].shift()
					else
						str = ' ' + info_val[c].shift()
				}
			}
			font_name = info_font[c]
			if (!font_name)
				font_name = "history";
			font = get_font(font_name);
			sz = font.size * 1.1
			if (info_sz[c])
				sz += info_sz[c];
			set_font(font);
			x = xa[align];
			y = ya[align] + sz

			if (c == 'Q') {			/* special case for tempo */
				self.set_width(glovar.tempo)
				if (!glovar.tempo.del) {
				if (!glovar.tempo.invis) {
					if (align != 'l') {
						tempo_build(glovar.tempo)
						w = glovar.tempo.tempo_wh[0]

						if (align == 'c')
							w *= .5;
						x -= w
					}
					writempo(glovar.tempo, x, -y)
				}
			} else if (str) {
				if (c == 'T')
					str = trim_title(str,
							 info_font.T[0] == 's')
				xy_str(x, -y, str, align)
			}

			if (c == 'T') {
				font_name = info_font.T = "subtitle";
				info_sz.T = cfmt.subtitlespace
			}
︙
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
868
869
870
871
872
873
874

875
876
877
878
879
880
881
882
883
884
885
886

887
888
889
890
891
892
893







-
+











-







			info_nb[c]--;
			ya[align] = y
		}
		if (ya.c > ya.l)
			ya.l = ya.c
		if (ya.r > ya.l)
			ya.l = ya.r
		if (i >= fmt.length)
		if (i >= p.length)
			break
		ya.c = ya.r = ya.l
	}
	vskip(ya.l)
}

/* -- output the tune heading -- */
function write_heading() {
	var	i, j, area, composer, origin, rhythm, down1, down2,
		lwidth = get_lwidth()

	blk_out();
	vskip(cfmt.topspace)

	if (cfmt.titleformat) {
		write_headform(lwidth);
		vskip(cfmt.musicspace)
		return
	}
︙
Changes to core/svg.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50




51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58




59
60
61
62
63
64
65


-
+


















-






-
+




















+
-
+
+
+
+





-
-
-
-







// abc2svg - svg.js - svg functions
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

var	output = "",		// output buffer
	style = '\
\ntext, tspan{fill:currentColor}\
\n.stroke{stroke:currentColor;fill:none}\
\n.bW{stroke:currentColor;fill:none;stroke-width:1}\
\n.bthW{stroke:currentColor;fill:none;stroke-width:3}\
\n.slW{stroke:currentColor;fill:none;stroke-width:.7}\
\n.slthW{stroke:currentColor;fill:none;stroke-width:1.5}\
\n.sW{stroke:currentColor;fill:none;stroke-width:.7}\
\n.mtx{font:130% music}',
\n.box{outline: 1px solid black;outline-offset: 1px}',
	font_style = '',
	posx = cfmt.leftmargin / cfmt.scale,	// default x offset of the images
	posy = 0,		// y offset in the block
	img = {			// image
		width: cfmt.pagewidth,	// width
		lm: cfmt.leftmargin,	// left and right margins
		rm: cfmt.rightmargin
//		chg: false
	},
	defined_glyph = {},
	defs = '',
	fulldefs = '',		// unreferenced defs as <filter>
	stv_g = {		/* staff/voice graphic parameters */
		scale: 1,
		dy: 0,
		st: -1,
		v: -1,
		g: 0
//		color: undefined
	},
	blkdiv = 0		// block of contiguous SVGs
	block = {}		/* started & newpage */
				// -1: block started
				//  0: no block
				//  1: start a block
				//  2: start a new page

// glyphs in music font
var tgls = {
 "mtr ": {x:0, y:0, c:"\u0020"},	// space
  brace: {x:0, y:0, c:"\ue000"},
  hl: {x:-4, y:0, c:"\ue022"},
  hl1: {x:-6, y:0, c:"\ue023"},
//  hl2: {x:-6, y:0, c:"\ue023"},		// (unused)
  ghl: {x:-4, y:0, c:"\ue024"},
  lphr: {x:0, y:24, c:"\ue030"},
  mphr: {x:0, y:24, c:"\ue038"},
  sphr: {x:0, y:27, c:"\ue039"},
  rdots: {x:-1, y:0, c:"\ue043"},	// repeat dots
  dsgn: {x:-4, y:-4, c:"\ue045"},	// D.S.
  dcap: {x:-4, y:-4, c:"\ue046"},	// D.C.
  sgno: {x:-6, y:0, c:"\ue047"},	// segno
︙
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119









120
121
122
123
124
125




126
127
128
129
130
131
132
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115



116
117
118
119
120
121
122
123
124
125
126




127
128
129
130
131
132
133
134
135
136
137







-
+










-
-
-
+
+
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+







  pfthd: {x:-3.7, y:0, c:"\ue0b3"},
  x: {x:-3.7, y:0, c:"\ue0a9"},		// 'x' note head
  "circle-x": {x:-3.7, y:0, c:"\ue0b3"}, // 'circle-x' note head
  srep: {x:-5, y:0, c:"\ue101"},
  "dot+": {x:-5, y:0, sc:.7, c:"\ue101"},
  diamond: {x:-4, y:0, c:"\ue1b9"},
  triangle: {x:-4, y:0, c:"\ue1bb"},
  dot: {x:-2, y:0, c:"\ue1e7"},
  dot: {x:-1, y:0, c:"\ue1e7"},
  flu1: {x:-.3, y:0, c:"\ue240"},	// flags
  fld1: {x:-.3, y:0, c:"\ue241"},
  flu2: {x:-.3, y:0, c:"\ue242"},
  fld2: {x:-.3, y:0, c:"\ue243"},
  flu3: {x:-.3, y:3.5, c:"\ue244"},
  fld3: {x:-.3, y:-4, c:"\ue245"},
  flu4: {x:-.3, y:8, c:"\ue246"},
  fld4: {x:-.3, y:-9, c:"\ue247"},
  flu5: {x:-.3, y:12.5, c:"\ue248"},
  fld5: {x:-.3, y:-14, c:"\ue249"},
 "acc-1": {x:-1, y:0, c:"\ue260"},	// flat
  acc3: {x:-1, y:0, c:"\ue261"},	// natural
  acc1: {x:-2, y:0, c:"\ue262"},	// sharp
 "acc-1": {x:-1, y:0, c:"\ue260"},		// flat
 "cacc-1": {x:-18, y:0, c:"\ue26a\ue260\ue26b"}, // courtesy flat (note deco)
 "sacc-1": {x:-1, y:0, sc:.7, c:"\ue260"},	// small flat (editorial)
  acc3: {x:-1, y:0, c:"\ue261"},		// natural
 "cacc3": {x:-18, y:0, c:"\ue26a\ue261\ue26b"},	// courtesy natural (note deco)
  sacc3: {x:-1, y:0, sc:.7, c:"\ue261"},	// small natural (editorial)
  acc1: {x:-2, y:0, c:"\ue262"},		// sharp
 "cacc1": {x:-18, y:0, c:"\ue26a\ue262\ue26b"},	// courtesy sharp (note deco)
  sacc1: {x:-2, y:0, sc: .7, c:"\ue262"},	// small sharp (editorial)
  acc2: {x:-3, y:0, c:"\ue263"},	// double sharp
 "acc-2": {x:-3, y:0, c:"\ue264"},	// double flat
 "acc-1_1_4": {x:-2, y:0, c:"\ue280"},	// quarter-tone flat
 "acc-1_3_4": {x:-3, y:0, c:"\ue281"},	// three-quarter-tones flat
  acc1_1_4: {x:-1, y:0, c:"\ue282"},	// quarter-tone sharp
  acc1_3_4: {x:-3, y:0, c:"\ue283"},	// three-quarter-tones sharp
 "acc-1_2": {x:-2, y:0, c:"\ue280"},	// quarter-tone flat
 "acc-3_2": {x:-3, y:0, c:"\ue281"},	// three-quarter-tones flat
  acc1_2: {x:-1, y:0, c:"\ue282"},	// quarter-tone sharp
  acc3_2: {x:-3, y:0, c:"\ue283"},	// three-quarter-tones sharp
  accent: {x:-3, y:0, c:"\ue4a0"},
  stc: {x:-1, y:-2, c:"\ue4a2"},	// staccato
  emb: {x:-4, y:-2, c:"\ue4a4"},
  wedge: {x:-1, y:0, c:"\ue4a8"},
  marcato: {x:-3, y:0, c:"\ue4ac"},
  hld: {x:-7, y:0, c:"\ue4c0"},		// fermata
  brth: {x:0, y:0, c:"\ue4ce"},
︙
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193







-
+







  mtro:   {x:0, y:0, c:"\ue911"},		// tempus perfectum
// "mtro|": {x:0, y:0, c:"\ue912"},	// (unused)
// "mtrc.": {x:0, y:0, c:"\ue914"},	// (unused)
  mtrc:   {x:0, y:0, c:"\ue915"},	// tempus imperfectum
// "mtrc|": {x:0, y:0, c:"\ue918"},	// (unused)
 "mtr.":  {x:0, y:0, c:"\ue920"},	// prolatione perfecta
 "mtr|":  {x:0, y:0, c:"\ue925"},	// (twice as fast)
  longa: {x:-3.7, y:0, c:"\ue95d"},
  longa: {x:-4.7, y:0, c:"\ue95d"},
  custos: {x:-4, y:3, c:"\uea02"},
  ltr: {x:2, y:6, c:"\ueaa4"}		// long trill element
}

// glyphs to put in <defs>
var glyphs = {
}
︙
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299







-
+











+








+







			tag = text.slice(is + 1, i);
			ie = text.indexOf('</' + tag + '>', ie)
			if (ie < 0)
				break
			ie += 3 + tag.length
		}
		if (text.substr(is, 7) == '<filter')
			fulldefs += '\n' + text.slice(is, ie)
			fulldefs += text.slice(is, ie) + '\n'
		else
			glyphs[gl] = text.slice(is, ie)
	}
}

// output the stop/start of a graphic sequence
function set_g() {

	// close the previous sequence
	if (stv_g.started) {
		stv_g.started = false;
		glout()
		output += "</g>\n"
	}

	// check if new sequence needed
	if (stv_g.scale == 1 && !stv_g.color)
		return

	// open the new sequence
	glout()
	output += '<g '
	if (stv_g.scale != 1) {
		if (stv_g.st < 0)
			output += voice_tb[stv_g.v].scale_str
		else if (stv_g.v < 0)
			output += staff_tb[stv_g.st].scale_str
		else
︙
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433





























434
435
436
437
438
439
440
402
403
404
405
406
407
408






409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470







-
-
-
-
-
-











-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			staff_tb[st].output +
			'</g>\n';
		staff_tb[st].output = ""
	}
}

// output the annotations
// !! tied to the symbol types in abc2svg.js !!
var anno_type = ['bar', 'clef', 'custos', '', 'grace',
		'key', 'meter', 'Zrest', 'note', 'part',
		'rest', 'yspace', 'staves', 'Break', 'tempo',
		'', 'block', 'remark']

function anno_out(s, t, f) {
	if (s.istart == undefined)
		return
	var	type = s.type,
		h = s.ymx - s.ymn + 4,
		wl = s.wl || 2,
		wr = s.wr || 2

	if (s.grace)
		type = C.GRACE

	f(t || anno_type[type], s.istart, s.iend,
	f(t || abc2svg.sym_name[type], s.istart, s.iend,
		s.x - wl - 2, staff_tb[s.st].y + s.ymn + h - 2,
		wl + wr + 4, h, s);
}

function a_start(s, t) {
	anno_out(s, t, user.anno_start)
}
function a_stop(s, t) {
	anno_out(s, t, user.anno_stop)
}
function empty_function() {
}
var	anno_start = user.anno_start ? a_start : empty_function,
	anno_stop = user.anno_stop ? a_stop : empty_function

// output the stop user annotations
function anno_put() {
    var	s
	while (1) {
		s = anno_a.shift()
		if (!s)
			break
		switch (s.type) {
		case C.CLEF:
		case C.METER:
		case C.KEY:
		case C.REST:
			if (s.type != C.REST || s.rep_nb) {
				set_sscale(s.st)
				break
			}
			// fall thru
		case C.GRACE:
		case C.NOTE:
		case C.MREST:
			set_scale(s)
			break
//		default:
//			continue
		}
		anno_stop(s)
	}
} // anno_put()

// output a string with x, y, a and b
// In the string,
//	X and Y are replaced by scaled x and y
//	A and B are replaced by a and b as string
//	F and G are replaced by a and b as float
function out_XYAB(str, x, y, a, b) {
︙
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510







+














+







		default: return b.toFixed(1)
		}
		})
}

// open / close containers
function g_open(x, y, rot, sx, sy) {
	glout()
	out_XYAB('<g transform="translate(X,Y', x, y);
	if (rot)
		output += ') rotate(' + rot.toFixed(2)
	if (sx) {
		if (sy)
			output += ') scale(' + sx.toFixed(2) +
						', ' + sy.toFixed(2)
		else
			output += ') scale(' + sx.toFixed(2)
	}
	output += ')">\n';
	stv_g.g++
}
function g_close() {
	glout()
	stv_g.g--;
	output += '</g>\n'
}

// external SVG string
Abc.prototype.out_svg = function(str) { output += str }

︙
522
523
524
525
526
527
528
















































529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

544
545
546
547






548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622

623
624
625


626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649






650
651
652
653
654
655
656







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
+


-
-
+
+
+
+
+
+


















-
-
-
-
-
-







function xypath(x, y, fill) {
	if (fill)
		out_XYAB('<path d="mX Y', x, y)
	else
		out_XYAB('<path class="stroke" d="mX Y', x, y)
}
Abc.prototype.xypath = xypath

// output the list of glyphs and the stems
// [0] = x glyph
// [1] = y glyph
// [2] = glyph code
// [3] = x, y, h of stem (3 values per stem)
var gla = [[], [], "", [], [], []]
function glout() {
    var	e,
	v = []

	// glyphs (notes, accidentals...)
    if (gla[0].length) {
	while (1) {
		e = gla[0].shift()
		if (e == undefined)
			break
		v.push(e.toFixed(1))
	}
	output += '<text x="' + v.join(',')

	v = []
	while (1) {
		e = gla[1].shift()
		if (e == undefined)
			break
		v.push(e.toFixed(1))
	}
	output += '"\ny="' + v.join(',')

	output += '"\n>' + gla[2] + '</text>\n'
	gla[2] = ""
    }

	// stems
	if (!gla[3].length)
		return
	output += '<path class="sW" d="'
	while (1) {
		e = gla[3].shift()
		if (e == undefined)
			break
		output += 'M' + e.toFixed(1) +
			' ' + gla[3].shift().toFixed(1) +
			'v' + gla[3].shift().toFixed(1)
	}
	output += '"/>\n'
} // glout()

// output a glyph
function xygl(x, y, gl) {
// (avoid ps<->js loop)
//	if (psxygl(x, y, gl))
//		return
	if (glyphs[gl]) {
		def_use(gl)
		out_XYAB('<use x="X" y="Y" xlink:href="#A"/>\n', x, y, gl)
	} else {
	    var	tgl = tgls[gl]
		if (tgl) {
			x += tgl.x * stv_g.scale;
			y -= tgl.y
			if (tgl.sc)
			if (tgl.sc) {
				out_XYAB('<text transform="translate(X,Y) scale(A)">B</text>\n',
					x, y, tgl.sc, tgl.c);
			else
				out_XYAB('<text x="X" y="Y">A</text>\n', x, y, tgl.c)
			} else {
//				out_XYAB('<text x="X" y="Y">A</text>\n', x, y, tgl.c)
				gla[0].push(sx(x))
				gla[1].push(sy(y))
				gla[2] += tgl.c
			}
		} else {
			error(1, null, 'no definition of $1', gl)
		}
	}
}
// - specific functions -
// gua gda (acciaccatura)
function out_acciac(x, y, dx, dy, up) {
	if (up) {
		x -= 1;
		y += 4
	} else {
		x -= 5;
		y -= 4
	}
	out_XYAB('<path class="stroke" d="mX YlF G"/>\n',
		x, y, dx, -dy)
}
// tuplet value - the staves are not defined
function out_bnum(x, y, str) {
	out_XYAB('<text style="font:italic 12px serif"\n\
	x="X" y="Y" text-anchor="middle">A</text>\n',
		x, y, str.toString())
}
// staff system brace
function out_brace(x, y, h) {
//fixme: '-6' depends on the scale
	x += posx - 6;
	y = posy - y;
	h /= 24;
	output += '<text transform="translate(' +
︙
615
616
617
618
619
620
621
622
623



624
625
626
627
628
629
630
693
694
695
696
697
698
699


700
701
702
703
704
705
706
707
708
709







-
-
+
+
+







		slen = -h

	if (h < 0)
		dx = -dx;		// down
	x += dx * stv_g.scale
	if (stv_g.v >= 0)
		slen /= voice_tb[stv_g.v].scale;
	out_XYAB('<path class="sW" d="mX YvF"/>\n',	// stem
		x, y, slen)
	gla[3].push(sx(x))
	gla[3].push(sy(y))
	gla[3].push(slen)
	if (!nflags)
		return

	y += h
	if (h > 0) {				// up
		if (!straight) {
			if (!grace) {
︙
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
720
721
722
723
724
725
726

727


728
729
730
731
732
733
734







-

-
-







	1.4 -4.8 -2.4 -5.4 -3.2 -5.2\n', x, y);
						y -= 3.5
					}
				}
			}
		} else {			// straight
			output += '<path d="'
//fixme: to do
			if (!grace) {
//fixme: check endpoints
				y += 1
				while (--nflags >= 0) {
					out_XYAB('MX Yl7 3.2 0 3.2 -7 -3.2z\n',
						x, y);
					y -= 5.4
				}
			} else {		// grace
				while (--nflags >= 0) {
︙
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
755
756
757
758
759
760
761


762
763
764
765
766
767
768







-
-







						y += 3.5
					}
				}
			}
		} else {			// straight
			output += '<path d="'
			if (!grace) {
//fixme: check endpoints
				y += 1
				while (--nflags >= 0) {
					out_XYAB('MX Yl7 -3.2 0 -3.2 -7 3.2z\n',
						x, y);
					y += 5.4
				}
//			} else {		// grace
//--fixme: error?
︙
721
722
723
724
725
726
727
728

729
730
731



732
733
734
735
736
737
738
795
796
797
798
799
800
801

802



803
804
805
806
807
808
809
810
811
812







-
+
-
-
-
+
+
+







		'v' + (-h).toFixed() + '"/>\n'
}
// tuplet bracket with number - the staves are not defined
function out_tubrn(x, y, dx, dy, up, str) {
    var	sw = str.length * 10,
	h = up ? -3 : 3;

	out_XYAB('<text style="font:italic 12px serif"\n\
	set_font("tuplet")
	x="X" y="Y" text-anchor="middle">A</text>\n',
		x + dx / 2, y + dy / 2, str);
	dx /= stv_g.scale
	xy_str(x + dx / 2, y + dy / 2 - gene.curfont.size * .5 + 2,
		str, 'c')
		dx /= stv_g.scale
	if (!up)
		y += 6;
	output += '<path class="stroke" d="m';
	out_sxsy(x, ' ', y);
	output += 'v' + h.toFixed(1) +
		'm' + dx.toFixed(1) + ' ' + (-dy).toFixed(1) +
		'v' + (-h).toFixed(1) + '"/>\n' +
︙
834
835
836
837
838
839
840
841

842
843
844
845
846
847
848
908
909
910
911
912
913
914

915
916
917
918
919
920
921
922







-
+







	y += 4;
	val = Math.ceil(val / 6)
	while (--val >= 0) {
		xygl(x, y, "ltr");
		x += 6
	}
}
function out_lped(x, y, val, defl) {
Abc.prototype.out_lped = function(x, y, val, defl) {
	y += 4;
	if (!defl.nost)
		xygl(x, y, "ped");
	if (!defl.noen)
		xygl(x + val + 6, y, "pedoff")
}
function out_8va(x, y, val, defl) {
︙
914
915
916
917
918
919
920

921


922
923
924
925
926
927
928
988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
1004







+
-
+
+







		out_XYAB('<path class="stroke" d="mX Yv-6"/>\n', x + val, y)
}
var deco_val_tb = {
	arp:	out_arp,
	cresc:	out_cresc,
	dim:	out_dim,
	ltr:	out_ltr,
	lped:	function(x, y, val, defl) {
	lped:	out_lped,
			self.out_lped(x, y, val, defl)
		},
	"8va":	out_8va,
	"8vb":	out_8vb,
	"15ma":	out_15ma,
	"15mb": out_15mb
}

function out_deco_val(x, y, name, val, defl) {
︙
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023





1024
1025
1026
1027
1028
1029
1030
1031
1032
1033





1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051





1052
1053
1054
1055
1056
1057
1058
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147







-
+












+
+
+
+
+









-
+
+
+
+
+

















-
+
+
+
+
+







			break
		default:
			p = "\ueca5"
			break
		}
		break
	}
	if (elts[1])
	if (elts[1])			// dot
		p += '<tspan dx=".1em">\uecb7</tspan>'
	return p
} // tempo_note()

// build the tempo string
function tempo_build(s) {
    var	i, j, bx, p, wh, dy,
	w = 0,
	str = []

	if (s.tempo_str)	// already done
		return

	// the music font must be defined
	if (!cfmt.musicfont.used)
		get_font("music")

	set_font("tempo")
	if (s.tempo_str1) {
		str.push(s.tempo_str1)
		w += strwh(s.tempo_str1)[0]
	}
	if (s.tempo_notes) {
		dy = ' dy="-.05em"'			// notes a bit higher
		for (i = 0; i < s.tempo_notes.length; i++) {
			p = tempo_note(s, s.tempo_notes[i])
			str.push('<tspan\n\tclass="mtx"' + dy + '>' +
			str.push('<tspan\nclass="' +
					font_class(cfmt.musicfont) +
				'" style="font-size:' +
				(gene.curfont.size * 1.3).toFixed(1) + 'px"' +
				dy + '>' +
				p + '</tspan>')
			j = p.length > 1 ? 2 : 1	// (note and optional dot)
			w += j * gene.curfont.swfac
			dy = ''
		}
		str.push('<tspan dy=".065em">=</tspan>')
		w += cwidf('=')
		if (s.tempo_ca) {
			str.push(s.tempo_ca)
			w += strwh(s.tempo_ca)[0]
			j = s.tempo_ca.length + 1
		}
		if (s.tempo) {			// with a number of beats per minute
			str.push(s.tempo)
			w += strwh(s.tempo.toString())[0]
		} else {			// with a beat as a note
			p = tempo_note(s, s.new_beat)
			str.push('<tspan\n\tclass="mtx" dy="-.05em">' +
			str.push('<tspan\nclass="' +
					font_class(cfmt.musicfont) +
				'" style="font-size:' +
				(gene.curfont.size * 1.3).toFixed(1) +
				'px" dy="-.05em">' +
				p + '</tspan>')
			j = p.length > 1 ? 2 : 1
			w += j * gene.curfont.swfac
			dy = 'y'
		}
	}
	if (s.tempo_str2) {
︙
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116

1117
1118
1119


1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130



1131

1132
1133
1134

1135
1136
1137
1138

1139
1140
1141


1142
1143
1144



1145
1146
1147
1148


1149
1150
1151
1152
1153
1154
1155


1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172







1173
1174
1175
1176
1177

1178
1179

1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207

1208
1209
1210

1211
1212

1213
1214
1215
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227


1228
1229
1230
1231

1232
1233
1234
1235
1236
1237



1238
1239
1240




1241
1242







1243
1244

1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271

1272
1273

1274
1275
1276

1277
1278
1279
1280
1281
1282
1283


















1284
1285
1286

1287

1288
1289
1290
1291
1292







-
+












+
-
+



+
+










-
+
+
+

+

-
-
+



-
+



+
+
-
-
-
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
















+
+
+
+
+
+
+




-
+

-
+


-







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
+
-

+



		out_sxsy(bx - 2, '" y="', y + bh - 1)
		output += '" width="' + (s.tempo_wh[0] + 2).toFixed(1) +
			'" height="' + bh.toFixed(1) +
			'"/>\n'
	}

	// don't display anymore
	s.del = true
	s.invis = true
} // writempo()

// update the vertical offset
function vskip(h) {
	posy += h
}

// create the SVG image of the block
function svg_flush() {
	if (multicol || !output || !user.img_out || posy == 0)
		return

    var	i, font,
    var	head = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	head = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	xmlns:xlink="http://www.w3.org/1999/xlink"\n\
	color="',
	g = ''

	glout()

	if (cfmt.fgcolor)
		head += cfmt.fgcolor + '" fill="' + cfmt.fgcolor + '"'
	else
		head += 'black"';
	head += ' stroke-width=".7"'

	if (cfmt.bgcolor)
		head += ' style="background-color: ' + cfmt.bgcolor + '"';

	posy *= cfmt.scale
	font = get_font("music")
	head += ' class="' + font_class(font) +
		' tune' + tunes.length + '"\n'	// tune index for play

	posy *= cfmt.scale
	if (user.imagesize) {
		head += '\n' +
			user.imagesize +
		head += user.imagesize +
			' viewBox="0 0 ' + img.width.toFixed(0) + ' ' +
			 posy.toFixed(0) + '">\n'
	} else {
		head += '\n\twidth="' + img.width.toFixed(0) +
		head += ' width="' + img.width.toFixed(0) +
			'px" height="' + posy.toFixed(0) + 'px">\n'
	}

	head += fulldefs

	if (style || font_style || musicfont) {
		head += '<style type="text/css">' + style + font_style
		if (musicfont) {
	if (style || font_style)
		head += '<style>\n.' +
				font_class(font) +	// for fill color
			if (musicfont.indexOf('(') > 0) {
				head += '\nsvg{font:24px music}\n\
@font-face {\n\
  font-family:"music";\n\
					' text,tspan{fill:currentColor}' +
			font_style + style +
  src:' + musicfont + '}';
			} else {
				head += '\nsvg{font:24px '+ musicfont +'}'
			}
		}
		head += '\n</style>\n'
	}
			'\n</style>\n'

	defs += fulldefs
	if (defs)
		head += '<defs>' + defs + '\n</defs>\n'

	// if %%pagescale != 1, do a global scale
	// (with a container: transform scale in <svg> does not work
	//	the same in all browsers)
	// the class is used to know that the container is global
	if (cfmt.scale != 1) {
		head += '<g class="g" transform="scale(' +
			cfmt.scale.toFixed(2) + ')">\n';
		g = '</g>\n'
	}

	if (psvg)			// if PostScript support
		psvg.ps_flush(true);	// + setg(0)

	// start a block if needed
	if (blkdiv > 0) {
		user.img_out(blkdiv == 1 ?
			'<div class="nobrk">' :
			'<div class="nobrk newpage">')
		blkdiv = -1		// block started
	}
	user.img_out(head + output + g + "</svg>");
	output = ""

	font_style = ''
	if (cfmt.fullsvg) {
	if (cfmt.fullsvg && typeof document == "undefined") {
		defined_glyph = {}
		for (var i = 0; i < font_tb.length; i++)
		for (i = 0; i < font_tb.length; i++)
			font_tb[i].used = false
	} else {
		musicfont = '';
		style = '';
		fulldefs = ''
	}
	defs = '';
	posy = 0
}

// output a part of a block of images
function blk_out() {
	if (multicol || !user.img_out)
		return
	blk_flush()
	if (user.page_format && !block.started) {
		block.started = true
		if (block.newpage) {
			block.newpage = false;
			user.img_out('<div class="nobrk newpage">')
		} else {
			user.img_out('<div class="nobrk">')
		}
	}
}
Abc.prototype.blk_out = blk_out

// output the end of a block (or tune)
// mark the end of a <div> block
function blk_flush() {
	svg_flush()
	if (block.started) {
	if (blkdiv < 0 && (!parse.state || cfmt.splittune)) {
		block.started = false;
		user.img_out('</div>')
		blkdiv = 0
	}
}
Abc.prototype.blk_flush = blk_flush
Changes to core/tail.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41


-
+




















+




+
+




-







// abc2svg - tail.js
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// initialize
	init_tune()

// Abc functions used by the modules
Abc.prototype.a_de = function() { return a_de }
Abc.prototype.add_style = function(s) { style += s };
Abc.prototype.cfmt = function() { return cfmt };
Abc.prototype.clone = clone;
Abc.prototype.deco_cnv = deco_cnv;
Abc.prototype.defs_add = defs_add
Abc.prototype.draw_meter = draw_meter
Abc.prototype.draw_note = draw_note;
Abc.prototype.errs = errs;
Abc.prototype.font_class = font_class;
Abc.prototype.gch_tr1 = gch_tr1;
Abc.prototype.get_a_gch = function() { return a_gch };
Abc.prototype.get_bool = get_bool;
Abc.prototype.get_cur_sy = function() { return cur_sy };
Abc.prototype.get_curvoice = function() { return curvoice };
Abc.prototype.get_delta_tb = function() { return delta_tb };
Abc.prototype.get_decos = function() { return decos };
Abc.prototype.get_font = get_font;
Abc.prototype.get_font_style = function() { return font_style };
︙
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69



70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







+














+
+
+










+







};
Abc.prototype.get_posy = function() { var t = posy; posy = 0; return t };
Abc.prototype.get_staff_tb = function() { return staff_tb };
Abc.prototype.get_top_v = function() { return par_sy.top_voice };
Abc.prototype.get_tsfirst = function() { return tsfirst };
Abc.prototype.get_unit = get_unit;
Abc.prototype.get_voice_tb = function() { return voice_tb };
Abc.prototype.glout = glout
Abc.prototype.goto_tune = goto_tune;
Abc.prototype.info = function() { return info };
Abc.prototype.new_block = new_block;
Abc.prototype.out_arp = out_arp;
Abc.prototype.out_deco_str = out_deco_str;
Abc.prototype.out_deco_val = out_deco_val;
Abc.prototype.out_ltr = out_ltr;
Abc.prototype.param_set_font = param_set_font;
Abc.prototype.parse = parse;
Abc.prototype.psdeco = empty_function;
Abc.prototype.psxygl = empty_function;
Abc.prototype.set_cur_sy = function(sy) { cur_sy = sy };
Abc.prototype.set_dscale = set_dscale;
Abc.prototype.set_font = set_font;
Abc.prototype.set_a_gch = function(s, a) { a_gch = a; csan_add(s) }
Abc.prototype.set_hl = set_hl
Abc.prototype.set_pagef = function() { blkdiv = 1 }
Abc.prototype.set_scale = set_scale;
Abc.prototype.set_tsfirst = function(s) { tsfirst = s };
Abc.prototype.set_v_param = set_v_param;
Abc.prototype.strwh = strwh;
Abc.prototype.stv_g = function() { return stv_g };
Abc.prototype.svg_flush = svg_flush;
Abc.prototype.syntax = syntax;
Abc.prototype.tunes = tunes
Abc.prototype.unlksym = unlksym;
Abc.prototype.use_font = use_font;
Abc.prototype.vskip = vskip
Abc.prototype.xy_str = xy_str;
Abc.prototype.xygl = xygl;

    var	hook_init		// set after setting the first module hooks

    // export functions and/or set module hooks
    function set_hooks() {
︙
Changes to core/tune.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - tune.js - tune generation
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81




82
83
84
85
86
87
88
55
56
57
58
59
60
61

62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90







-







-











+
+
+
+







	}
}

/* -- link a ABC symbol into the current voice -- */
function sym_link(s) {
	if (!s.fname)
		set_ref(s)
	if (!curvoice.ignore) {
		parse.last_sym = s;
		s.prev = curvoice.last_sym
		if (curvoice.last_sym)
			curvoice.last_sym.next = s
		else
			curvoice.sym = s;
		curvoice.last_sym = s
	}
	s.v = curvoice.v;
	s.p_v = curvoice;
	s.st = curvoice.cst;
	s.time = curvoice.time
	if (s.dur && !s.grace)
		curvoice.time += s.dur;
	s.pos = curvoice.pos
	if (curvoice.second)
		s.second = true
	if (curvoice.floating)
		s.floating = true
	if (curvoice.eoln) {
		s.soln = true
		curvoice.eoln = false
	}
}

/* -- add a new symbol in a voice -- */
function sym_add(p_voice, type) {
	var	s = {
			type:type,
			dur:0
︙
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
102
103
104
105
106
107
108



































109
110
111
112
113
114
115







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		s.fname = s2.fname;
		s.istart = s2.istart;
		s.iend = s2.iend
	}
	return s
}

/* -- expand a multi-rest into single rests and measure bars -- */
function mrest_expand(s) {
	var	p_voice, s2, next,
		nb = s.nmes,
		dur = s.dur / nb

	/* change the multi-rest (type bar) to a single rest */
	var a_dd = s.a_dd;
	s.type = C.REST;
	s.dur = s.dur_orig = dur;

	/* add the bar(s) and rest(s) */
	next = s.next;
	p_voice = s.p_v;
	p_voice.last_sym = s;
	p_voice.time = s.time + dur;
	p_voice.cst = s.st;
	s2 = s
	while (--nb > 0) {
		s2 = sym_add(p_voice, C.BAR);
		s2.bar_type = "|";
		s2 = sym_add(p_voice, C.REST);
		if (s.invis)
			s2.invis = true;
		s2.dur = s2.dur_orig = dur;
		p_voice.time += dur
	}
	s2.next = next
	if (next)
		next.prev = s2;

	/* copy the mrest decorations to the last rest */
	s2.a_dd = a_dd
}

/* -- sort all symbols by time and vertical sequence -- */
// weight of the symbols !! depends on the symbol type !!
var w_tb = new Uint8Array([
	4,	// bar
	1,	// clef
	8,	// custos
	0,	// (free)
︙
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
131
132
133
134
135
136
137

138
139
140
141
142
143
144







-








function sort_all() {
    var	s, s2, p_voice, v, time, w, wmin, ir, multi,
	prev, nb, ir2, v2, fl, new_sy,
	nv = voice_tb.length,
	vtb = [],
	vn = [],			// voice indexed by range
	mrest_time = -1,
	sy = cur_sy

	for (v = 0; v < nv; v++)
		vtb.push(voice_tb[v].sym)

	// set the first symbol
	ir2 = nv
︙
222
223
224
225
226
227
228
229
230
231
232
233
234
235


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
188
189
190
191
192
193
194







195
196

197
198
199


































200
201
202
203
204
205
206







-
-
-
-
-
-
-
+
+
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







			w = w_tb[s.type]
			if (s.time < time) {
				time = s.time;
				wmin = w
			} else if (w < wmin) {
				wmin = w
			}
			if (s.type == C.MREST) {
				if (s.nmes == 1)
					mrest_expand(s)
				else if (multi > 0)
					mrest_time = time
			}
		}
		}


		if (wmin > 127)
			break			// done

		/* if some multi-rest and many voices, expand */
		if (time == mrest_time) {
			nb = 0
			for (ir = 0; ir < nv; ir++) {
				v = vn[ir]
				if (v == undefined)
					break
				s = vtb[v]
				if (!s || s.time != time
				 || w_tb[s.type] != wmin)
					continue
				if (s.type != C.MREST) {
					mrest_time = -1 /* some note or rest */
					break
				}
				if (nb == 0) {
					nb = s.nmes
				} else if (nb != s.nmes) {
					mrest_time = -1	/* different duration */
					break
				}
			}
			if (mrest_time < 0) {
				for (ir = 0; ir < nv; ir++) {
					v = vn[ir]
					if (v == undefined)
						break
					s = vtb[v]
					if (s && s.type == C.MREST)
						mrest_expand(s)
				}
			}
		}

		/* link the vertical sequence */
		for (ir = 0; ir < nv; ir++) {
			v = vn[ir]
			if (v == undefined)
				break
			s = vtb[v]
			if (!s || s.time != time
︙
353
354
355
356
357
358
359






360


361
362


363
364

365



366
367
368
369
370

371

372
373
374


375
376
377
378
379
380
381
382



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294

295
296
297
298
299

300
301
302
303
304
305
306
307
308

309
310


311
312
313
314
315
316
317



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

341


342
343
344
345
346
347
348







+
+
+
+
+
+
-
+
+

-
+
+


+
-
+
+
+





+
-
+

-
-
+
+





-
-
-
+
+
+




















-
+
-
-







				t += d
			}
		}
		s.dur = s.time + s.dur - t;
		s.time = t
	} // end set_feathered_beam()

	// terminate voice cloning
	if (curvoice && curvoice.clone) {
		parse.istart = parse.eol
		do_cloning()
	}

	/* if Q: from tune header, put it at start of the music */
	// if Q: from tune header, put it at start of the music
	// (after the staff system)
	s = glovar.tempo
	if (s && staves_found <= 0) {	// && !s.del) {		- play problem
	if (s && staves_found <= 0) {	// && !s.invis) {	- play problem
					//fixme: which play problem?
		v = par_sy.top_voice;
		p_voice = voice_tb[v];
		if (p_voice.sym
		if (p_voice.sym && p_voice.sym.type != C.TEMPO) {
		 && p_voice.sym.type != C.TEMPO
		 && (!p_voice.sym.next
		  || p_voice.sym.next.type != C.TEMPO)) {
			s = clone(s);
			s.v = v;
			s.p_v = p_voice;
			s.st = p_voice.st;
			s.time = 0;
			s.prev = p_voice.sym
			s.next = p_voice.sym
			s.next = p_voice.sym.next
			if (s.next)
				s.next.prev = s;
			p_voice.sym = s
				s.next.prev = s
			p_voice.sym.next = s
		}
	}

	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (!sys_chg			// if not %%score
		 && p_voice.sls.length) {	// and no end of slur
			while (1) {
		if (!sys_chg) {			// if not %%score
			delete p_voice.eoln
			while (1) {		// set the end of slurs
			    var	sl = p_voice.sls.shift()

				if (!sl)
					break
				s = sl.note.s
				for (s2 = s.next; s2; s2 = s2.next) {
					if (s2.bar_type && s2.bar_type[0] == ':')
						break
				}
				if (s2) {
					if (!s.sls)
						s.sls = []
					s.sls.push({
						ty: sl.ty,
						note: {s: s2}
					})
				} else {
					syntax(1, "Lack of ending slur(s)")
				}
			}
		}
		} // not %%score
		if (p_voice.ignore)
			p_voice.ignore = false
		for (s = p_voice.sym; s; s = s.next) {
			if (s.time >= staves_found)
				break
		}
		for ( ; s; s = s.next) {
			switch (s.type) {
			case C.GRACE:
︙
428
429
430
431
432
433
434














435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

































































393
394
395
396
397
398
399







+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







						s.a_ly = s2.a_ly;
						s2.a_ly = null
						break
					}
					break
				}
				continue
			case C.MREST:
				if (s.next && s.next.type != C.BAR) {
					syntax(1, "Lack of bar after multi-measure rest")
					s2 = clone(s)
					s2.type = C.BAR
					s2.bar_type = '|'
					s2.dur = 0
					s2.time = s.next.time
					s2.prev = s
					s2.next = s.next
					s2.next.prev = s2
					s.next = s2
				}
				continue
			}

			if (s.feathered_beam)
				set_feathered_beam(s)
		}
	}
}

/* -- duplicate the voices as required -- */
function dupl_voice() {
	var	p_voice, p_voice2, s, s2, g, g2, v, i,
		nv = voice_tb.length

	for (v = 0; v < nv; v++) {
		p_voice = voice_tb[v];
		p_voice2 = p_voice.clone
		if (!p_voice2)
			continue
		p_voice.clone = null
		for (s = p_voice.sym; s; s = s.next) {
//fixme: there may be other symbols before the %%staves at this same time
			if (s.time >= staves_found)
				break
		}
		p_voice2.clef = clone(p_voice.clef);
		curvoice = p_voice2
		for ( ; s; s = s.next) {
			if (s.type == C.STAVES)
				continue
			s2 = clone(s)
			if (s.notes) {
				s2.notes = []
				for (i = 0; i <= s.nhd; i++)
					s2.notes.push(clone(s.notes[i]))
			}
			sym_link(s2)
//			s2.time = s.time
			if (p_voice2.second)
				s2.second = true
			else
				delete s2.second
			if (p_voice2.floating)
				s2.floating = true
			else
				delete s2.floating
			delete s2.a_ly;
			g = s2.extra
			if (!g)
				continue
			g2 = clone(g);
			s2.extra = g2;
			s2 = g2;
			s2.v = p_voice2.v;
			s2.p_v = p_voice2;
			s2.st = p_voice2.st
			for (g = g.next; g; g = g.next) {
				g2 = clone(g)
				if (g.notes) {
					g2.notes = []
					for (i = 0; i <= g.nhd; i++)
						g2.notes.push(clone(g.notes[i]))
				}
				s2.next = g2;
				g2.prev = s2;
				s2 = g2;
				s2.v = p_voice2.v;
				s2.p_v = p_voice2;
				s2.st = p_voice2.st
			}
		}
	}
}

/* -- create a new staff system -- */
function new_syst(init) {
	var	st, v,
		sy_new = {
			voices: [],
			staves: [],
			top_voice: 0
︙
522
523
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548





549
550
551

552
553
554
555
556
557

558
559
560
561
562
563
564


565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590







591
592
593
594
595
596
597
598


599
600


601
602
603
604
605
606
607
608
609
610
611











612
613
614
615
616







617
618
619
620
621
622







623
624
625
626





627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642


























643
644


645
646
647
648
649
650
651
652










653
654
655
656
657
658
659
660













661
662
663








664
665
666
667
668
669
670
671
672



673
674
675
676
677
678
679
680
681
682
683
684
685


686

687
688
689
690
691
692
693
694
695
696
697
698
699
700








701
702
703
704
705
706
707
708
709
710
711


712

713

714
715
716



717
718

719
720
721

722
723
724
725


726
727
728
729
730
731
732
407
408
409
410
411
412
413


414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429



430
431
432
433
434

435

436
437
438
439
440
441
442
443
444
445
446
447
448


449
450











451
452
453
454
455
456









457
458
459
460
461
462
463

464
465
466
467


468
469
470
471
472
473
474
475








476
477
478
479
480
481
482
483
484
485
486
487
488





489
490
491
492
493
494
495






496
497
498
499
500
501
502




503
504
505
506
507
















508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533


534
535








536
537
538
539
540
541
542
543
544
545
546







547
548
549
550
551
552
553
554
555
556
557
558
559



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574


575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593


594











595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614

615
616
617



618
619
620
621

622
623
624

625
626
627


628
629
630
631
632
633
634
635
636







-
-
+















-
-
-
+
+
+
+
+
-

-
+






+





-
-
+
+
-
-
-
-
-
-
-
-
-
-
-






-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-




-
-

+
+


+
+

-
-
-
-
-
-
-
-


+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+







-
-
+
+
+













+
+
-
+
-
-

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-










+
+
-
+

+
-
-
-
+
+
+

-
+


-
+


-
-
+
+







	// update the previous system
	for (v = 0; v < voice_tb.length; v++) {
	    if (par_sy.voices[v]) {
		st = par_sy.voices[v].st
		var	sy_staff = par_sy.staves[st],
			p_voice = voice_tb[v]

		if (p_voice.staffnonote != undefined)
			sy_staff.staffnonote = p_voice.staffnonote
		sy_staff.staffnonote = p_voice.staffnonote
		if (p_voice.staffscale)
			sy_staff.staffscale = p_voice.staffscale;
	    }
	}
	for (st = 0; st < par_sy.staves.length; st++) {
		sy_new.staves[st] = clone(par_sy.staves[st]);
		sy_new.staves[st].flags = 0
	}
	par_sy.next = sy_new;
	par_sy = sy_new
}

/* -- set the bar numbers -- */
// (possible hook)
Abc.prototype.set_bar_num = function() {
	var	s, s2, tim, bar_time, bar_num, rep_dtime,
		v = cur_sy.top_voice,
		wmeasure = voice_tb[v].meter.wmeasure,
    var	s, s2, tim, rep_tim, k, n,
	bar_num = gene.nbar,
	bar_tim = 0,			// time of previous repeat variant
	ptim = 0,			// time of previous bar
	wmeasure = voice_tb[cur_sy.top_voice].meter.wmeasure
		bar_rep = gene.nbar

	/* don't count a bar at start of line */
	// don't count a bar at start of tune
	for (s = tsfirst; ; s = s.ts_next) {
		if (!s)
			return
		switch (s.type) {
		case C.METER:
			wmeasure = s.wmeasure
			// fall thru
		case C.CLEF:
		case C.KEY:
		case C.STBRK:
			continue
		case C.BAR:
			if (s.bar_num) {
				gene.nbar = s.bar_num	/* (%%setbarnb) */
			if (s.bar_num)
				bar_num = s.bar_num	// %%setbarnb)
				break
			}
			if (s.text			// if repeat bar
			 && !cfmt.contbarnb) {
				if (s.text[0] == '1') {
					bar_rep = gene.nbar
				} else {
					gene.nbar = bar_rep; /* restart bar numbering */
					s.bar_num = gene.nbar
				}
			}
			break
		}
		break
	}

	// at start of tune, check for an anacrusis
	bar_time = s.time + wmeasure
	if (s.time == 0) {
		for (s2 = s.ts_next; s2; s2 = s2.ts_next) {
			if (s2.type == C.BAR && s2.time) {
				if (s2.time < bar_time) {	// if anacrusis
					s = s2;
					bar_time = s.time + wmeasure
				}
				break
	for (s2 = s.ts_next; s2; s2 = s2.ts_next) {
		if (s2.type == C.BAR && s2.time) {
			if (s2.time < wmeasure) {	// if anacrusis
				s = s2
				bar_tim = s.time
			}
			break
			}
		}
	}

	// set the measure number on the top bars
	bar_num = gene.nbar

	for ( ; s; s = s.ts_next) {
		if (!s.seqst)
			continue
		switch (s.type) {
		case C.METER:
			bar_num += (s.time - bar_tim) / wmeasure
			bar_tim = s.time
			wmeasure = s.wmeasure
			if (s.time < bar_time)
				bar_time = s.time + wmeasure
			break
		case C.MREST:
			bar_num += s.nmes - 1
			while (s.ts_next
			    && s.ts_next.type != C.BAR)
				s = s.ts_next
			break
		case C.BAR:
			if (s.invis)
				break
			tim = s.time
			if (s.bar_num) {
				bar_num = s.bar_num	// (%%setbarnb)
				ptim = bar_tim = tim
				continue
			}
			if (wmeasure == 1) {		// if M:none
				if (s.bar_dotted)
					continue
			if (s.time < bar_time) {	// incomplete measure
				if (s.text && s.text[0] == '1') {
					bar_rep = bar_num;
					rep_dtime = bar_time - s.time
				}
				if (s.text) {
					if (!cfmt.contbarnb) {
						if (s.text[0] == '1')
							rep_tim = bar_num
						else
							bar_num = rep_tim
					}
				break
			}

			/* check if any repeat bar at this time */
			tim = s.time;
			s2 = s
				}
				s.bar_num = ++bar_num
				continue
			}

			n = bar_num + (tim - bar_tim) / wmeasure
			k = n - (n | 0)
			do {
				if (s2.dur)
					break
				if (s2.type == C.BAR && s2.text)	// if repeat bar
			if (cfmt.checkbars
			 && ((k && !s.bar_dotted && s.next)
			  || (tim > ptim + wmeasure && s.prev.type != C.MREST)))
				error(0, s, "Bad measure duration")
			if (tim > ptim + wmeasure) {	// if more than one measure
					break
				s2 = s2.next
			} while (s2 && s2.time == tim);

			if (s.bar_num)
				bar_num = s.bar_num	// (%%setbarnb)
			else
				bar_num++

			if (s2 && s2.type == C.BAR && s2.text) {
				if (s2.text[0] == '1') {
					rep_dtime = 0;
					bar_rep = bar_num
				} else {			// restart bar numbering
					if (!cfmt.contbarnb)
						bar_num = bar_rep
				n |= 0
				k = 0
				bar_tim = tim		// re-synchronize
				bar_num = n
			}
			if (s.text) {
				if (s.text[0] == '1') {
					if (cfmt.contbarnb)
						rep_tim = bar_tim + k * wmeasure
					else
						rep_tim = tim
					if (!k)
						s.bar_num = n
				} else {
					if (cfmt.contbarnb)
						bar_tim = rep_tim
					else
						bar_tim += tim - rep_tim
					n = bar_num + (tim - bar_tim) / wmeasure
					if (n == (n | 0))
						s.bar_num = n
				}
			} else {
				if (k)
					n -= k
				s.bar_num = n
					if (rep_dtime) {	// [1 inside measure
						if (cfmt.contbarnb)
			}
			if (!k)
							bar_num--;
						bar_time = tim + rep_dtime
						break
					}
				}
			}
			s.bar_num = bar_num;
			bar_time = tim + wmeasure
				ptim = tim
			break
		}
	}
}

// convert a note to ABC
function not2abc(pit, acc) {
    var	i,
	nn = ''

			// skip the bars of the other voices
			while (s.ts_next
			    && !s.ts_next.seqst)
				s = s.ts_next
			break
		}
	}
	if (acc && acc != 3) {
		if (typeof acc == "number") {
			nn = ['__', '_', '', '^', '^^'][acc + 2]
		} else {
			i = acc[0]
			if (i > 0) {
				nn += '^'
			} else {
				nn += '_'
				i = -i
			}
			nn += i + '/' + acc[1]
		}
	if (cfmt.measurenb < 0)		/* if no display of measure bar */
		gene.nbar = bar_num	/* update in case of more music to come */
}
	}
	nn += ntb[(pit + 75) % 7]
	for (i = pit; i >= 21; i -= 7)
		nn += "'"
	for (i = pit; i < 14; i += 7)
		nn += ","
	return nn
} // not2abc()

// note mapping
// %%map map_name note [print [note_head]] [param]*
function get_map(text) {
	if (!text)
		return

    var	i, note, notes, map, tmp, ns, ty,
	a = info_split(text)
    var	i, note, notes, map, tmp, ns,
	ty = '',
	a = text.split(/\s+/)

	if (a.length < 3) {
		syntax(1, not_enough_p)
		return
	}
	ns = a[1]
	if (ns[0] == '*' || ns.indexOf("all") == 0) {
		ns = 'all'
	} else {
		if (ns.indexOf("octave,") == 0	// remove the octave part
		 || ns.indexOf("key,") == 0) {
			ty = ns[0]
			ns = ns.split(',')[1]
			ns = ns.replace(/[,']+/, '').toUpperCase() //'
			if (ns.indexOf("key,") == 0)
			ns = ns.replace(/[,']*/, '').toUpperCase(); //'
				ns = ns.replace(/[=^_]+/, '')
		} else {
			ty = ''
		}
		if (ty == 'k') {
			ns = 'k' + ntb.indexOf(ns)
		} else {
			tmp = new scanBuf;
			tmp.buffer = ns
			note = parse_acc_pit(tmp)
			if (!note) {
				syntax(1, "Bad note in %%map")
				return
			}
			ns = ty + abc2svg.pab40(note.pit, note.acc).toString()
		tmp = new scanBuf
		tmp.buffer = ns
		note = parse_acc_pit(tmp)
		if (!note) {
			syntax(1, "Bad note in %%map")
			return
		}
		ns = ty + not2abc(note.pit, note.acc)
		}
	}

	notes = maps[a[0]]
	if (!notes)
		maps[a[0]] = notes = {}
	map = notes[ns]
	if (!map)
		notes[ns] = map = []

	// try the optional 'print' and 'heads' parameters
	a.shift()
	a.shift()
	if (!a[2])
	if (!a.length)
		return
	a = info_split(a.join(' '))
	i = 2
	if (a[2].indexOf('=') < 0) {
		if (a[2][0] != '*') {
	i = 0
	if (a[0].indexOf('=') < 0) {
		if (a[0][0] != '*') {
			tmp = new scanBuf;		// print
			tmp.buffer = a[2];
			tmp.buffer = a[0];
			map[1] = parse_acc_pit(tmp)
		}
		if (!a[3])
		if (!a[1])
			return
		i++
		if (a[3].indexOf('=') < 0) {
			map[0] = a[3].split(',')	// heads
		if (a[1].indexOf('=') < 0) {
			map[0] = a[1].split(',')	// heads
			i++
		}
	}

	for (; i < a.length; i++) {
		switch (a[i]) {
		case "heads=":
︙
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682







-
+



















-
+







			}
			tmp = new scanBuf;
			tmp.buffer = a[i];
			note = parse_acc_pit(tmp)
			if (a[i - 1][1] == 'r')
				map[1] = note
			else
				map[3] = abc2svg.pab40(note.pit, note.acc)
				map[3] = note
			break
		case "color=":
			if (!a[++i]) {
				syntax(1, not_enough_p)
				break
			}
			map[2] = a[i]
			break
		}
	}
}

// set the transposition in the previous or first key signature
function set_transp() {
    var	s, transp, sndtran

	if (curvoice.ckey.k_bagpipe || curvoice.ckey.k_drum)
		return

	if (cfmt.transp && curvoice.transp)	// if %%transpose and score=
	if (cfmt.transp && curvoice.shift)	// if %%transpose and shift=
		syntax(0, "Mix of old and new transposition syntaxes");


	if (cfmt.transp != undefined
	 || curvoice.transp != undefined
	 || curvoice.shift != undefined)
		transp = (cfmt.transp || 0) +	 // %%transpose
︙
794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712







-
+







	} else {
		s = curvoice.last_sym
		while (1) {	// set the transposition in the previous K:
			if (s.type == C.KEY)
				break
			s = s.prev
			if (!s) {
				s = curvoice.key
				s = curvoice.key	// first key
				break
			}
		}
	}
	if (transp != undefined)
		s.k_transp = transp
	if (sndtran != undefined)
︙
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
752
753
754
755
756
757
758







































759
760
761
762
763
764
765







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







			return			// no change
		ak = sk.k_map[(note.pit + 19) % 7]
		if (ak)
			an = 3		// natural
	} else {
		return			// same accidental (in the key)
	}

	d = note.micro_d
	if (d				/* microtone */
	 && a != an) {			/* different accidental type */
		n = note.micro_n
//fixme: double sharps/flats ?*/
//fixme: does not work in all cases (tied notes, previous accidental)
		switch (an) {
		case 3:			// natural
			if (n > d / 2) {
				n -= d / 2;
				note.micro_n = n;
				an = a
			} else {
				an = -a
			}
			break
		case 2:			// double sharp
			if (n > d / 2) {
				note.pit += 1;
				n -= d / 2
			} else {
				n += d / 2
			}
			an = a
			note.micro_n = n
			break
		case -2:		// double flat
			if (n >= d / 2) {
				note.pit -= 1;
				n -= d / 2
			} else {
				n += d / 2
			}
			an = a
			note.micro_n = n
			break
		}
	}
	note.acc = an
}

// adjust the pitches according to the transposition(s)
function pit_adj() {
    var	i, p_v, s, sk, g,
	nv = voice_tb.length
︙
947
948
949
950
951
952
953
954

955
956
957
958
959
960
961
962
963
964
965

966
967
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982
983
984
985













986
987
988
989
990
991
992
993



994
995
996

997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879


880
881
882
883
884
885
886
887
888
889
890







-
+










-
+








-
+











+
+
+
+
+
+
+
+
+
+
+
+
+








+
+
+



+

-
-



+







				break
			}
			sk = null
		}
	}
} // pit_adj()

// get a transposition value as a base-40 interval
// get a abcm2ps/abcMIDI compatible transposition value as a base-40 interval
// The value may be
// - [+|-]<number of semitones>[s|f]
// - <note1>[<note2>]  % <note2> default is 'c'
function get_transp(param) {
	if (param[0] == '0')
		return 0
	if ("123456789-+".indexOf(param[0]) >= 0) {	// by semi-tone
	    var	val = parseInt(param)
		if (isNaN(val) || val < -36 || val > 36) {
//fixme: no source reference...
			syntax(1, "Bad transpose value")
			syntax(1, errs.bad_transp)
			return
		}
		val += 36
		return (((val / 12) | 0) - 3) * 40 +
			(param.slice(-1) == 'b' ?
					abc2svg.ifb40 :
					abc2svg.isb40)[val % 12]
	}
	return get_interval(param, true)
	// return undefined
} // get_transp()

/* -- process a pseudo-comment (%% or I:) -- */
// (possible hook)
Abc.prototype.do_pscom = function(text) {
    var	h1, val, s, cmd, param, n, k, b

	cmd = text.match(/(\w|-)+/)
	if (!cmd)
		return
	cmd = cmd[0];

	// ignore the command if the voice is ignored,
	// but not if %%score/%%staves!
	if (curvoice && curvoice.ignore) {
		switch (cmd) {
		case "staves":
		case "score":
			break
		default:
			return
		}
	}

	param = text.replace(cmd, '').trim()

	if (param.slice(-5) == ' lock') {
		fmt_lock[cmd] = true;
		param = param.slice(0, -5).trim()
	} else if (fmt_lock[cmd]) {
		return
	}

	if (cmd.slice(0, 5) == "title" && parse.state == 2)
		goto_tune()

	switch (cmd) {
	case "center":
		set_font("text")
		if (parse.state >= 2) {
			if (parse.state == 2)
				goto_tune()
			s = new_block("text");
			s.text = param
			s.opt = 'c'
			s.font = cfmt.textfont
			return
		}
		write_text(param, 'c')
		return
	case "clef":
		if (parse.state >= 2) {
			if (parse.state == 2)
︙
1020
1021
1022
1023
1024
1025
1026





1027

1028
1029
1030
1031

1032






1033
1034
1035
1036
1037
1038

1039
1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
901
902
903
904
905
906
907
908
909
910
911
912

913
914
915
916
917
918

919
920
921
922
923
924
925
926

927


928
929

930

931
932
933
934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964



965
966
967
968
969
970
971







+
+
+
+
+
-
+




+
-
+
+
+
+
+
+


-

-
-
+

-
+
-













-
+




















-
-
-







		set_linebreak(param)
		return
	case "map":
		get_map(param)
		return
	case "maxsysstaffsep":
		if (parse.state == 3) {
			val = get_unit(param)
			if (isNaN(val)) {
				syntax(1, errs.bad_val, "%%maxsysstaffsep")
				return
			}
			par_sy.voices[curvoice.v].maxsep = get_unit(param)
			par_sy.voices[curvoice.v].maxsep = val
			return
		}
		break
	case "multicol":
		if (parse.state >= 2) {
		generate(1)
			if (parse.state == 2)
				goto_tune()
			curvoice = voice_tb[0]
			s = new_block("mc_" + param)
			break
		}
		switch (param) {
		case "start":
			blk_out();
			multicol = {
				posy: posy,
				maxy: posy,
				maxy: 0,
				lmarg: cfmt.leftmargin,
				rmarg: cfmt.rightmargin,
				rmarg: cfmt.rightmargin
				state: parse.state
			}
			break
		case "new":
			if (!multicol) {
				syntax(1, "%%multicol new without start")
				break
			}
			if (posy > multicol.maxy)
				multicol.maxy = posy;
			cfmt.leftmargin = multicol.lmarg;
			cfmt.rightmargin = multicol.rmarg;
			img.chg = true;
			set_page();
			posy = multicol.posy
			posy = 0
			break
		case "end":
			if (!multicol) {
				syntax(1, "%%multicol end without start")
				break
			}
			if (posy < multicol.maxy)
				posy = multicol.maxy;
			cfmt.leftmargin = multicol.lmarg;
			cfmt.rightmargin = multicol.rmarg;
			multicol = undefined;
			blk_flush();
			img.chg = true;
			set_page()
			break
		default:
			syntax(1, "Unknown keyword '$1' in %%multicol", param)
			break
		}
		return
	case "musicfont":
		musicfont = param
		return
	case "ottava":
		if (parse.state != 3) {
			if (parse.state != 2)
				return
			goto_tune()
		}
		n = parseInt(param)
︙
1139
1140
1141
1142
1143
1144
1145




1146
1147
1148
1149
1150
1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057







+
+
+
+







-
+







-







			values = param.split(/\s+/);
			h1 = get_unit(values[0])
			if (values[1]) {
				h2 = get_unit(values[1])
				if (values[2])
					len = get_unit(values[2])
			}
			if (isNaN(h1) || isNaN(h2) || isNaN(len)) {
				syntax(1, errs.bad_val, "%%sep")
				return
			}
		}
		if (h1 < 1)
			h1 = 14
		if (h2 < 1)
			h2 = h1
		if (len < 1)
			len = 90
		if (parse.state == 3) {
		if (parse.state >= 2) {
			s = new_block(cmd);
			s.x = (lwidth - len) / 2 / cfmt.scale;
			s.l = len / cfmt.scale;
			s.sk1 = h1;
			s.sk2 = h2
			return
		}
		blk_out();
		vskip(h1);
		output += '<path class="stroke"\n\td="M';
		out_sxsy((lwidth - len) / 2 / cfmt.scale, ' ', 0);
		output += 'h' + (len / cfmt.scale).toFixed(1) + '"/>\n';
		vskip(h2);
		blk_flush()
		return
︙
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216











1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1095
1096
1097
1098
1099
1100
1101




1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114


1115
1116
1117
1118
1119
1120
1121







-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-







				return
			goto_tune()
		}
		s = {
			type: C.STBRK,
			dur:0
		}
		if (param[0] >= '0' && param[0] <= '9') {
			s.xmx = get_unit(param)
			if (param.slice(-1) == 'f')
				s.stbrk_forced = true
		if (param.slice(-1) == 'f') {
			s.stbrk_forced = true
			param = param.replace(/\sf$/, '')
		}
		if (param) {
			val = get_unit(param)
			if (isNaN(val)) {
				syntax(1, errs.bad_val, "%%staffbreak")
				return
			}
			s.xmx = val
		} else {
			s.xmx = 14
			if (param[0] == 'f')
				s.stbrk_forced = true
		}
		sym_link(s)
		return
	case "stafflines":
	case "staffscale":
	case "staffnonote":
		set_v_param(cmd, param)
︙
1237
1238
1239
1240
1241
1242
1243





1244

1245
1246
1247
1248

1249
1250
1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261








1262
1263
1264
1265
1266
1267
1268
1269
1270

1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287


1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304




1305
1306
1307
1308
1309

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333



1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357

1358
1359
1360
1361
1362
1363
1364
1365

1366
1367

1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

1143
1144
1145
1146
1147
1148
1149


1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174



1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218

1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234


1235
1236
1237
1238
1239


1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282

1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301



1302
1303


1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314







+
+
+
+
+
-
+




+

-
-



+







+
+
+
+
+
+
+
+






-
-
-
+
















-
+
+

















+
+
+
+




-
+















-
-





-
-
+
+
+



















-
+



-
+







-
+


+





-
+


















-
-
-
+

-
-



+







		} else {
			get_staves(cmd, param)
		}
		return
	case "sysstaffsep":
//--fixme: may be global
		if (parse.state == 3) {
			val = get_unit(param)
			if (isNaN(val)) {
				syntax(1, errs.bad_val, "%%sysstaffsep")
				return
			}
			par_sy.voices[curvoice.v].sep = get_unit(param)
			par_sy.voices[curvoice.v].sep = val
			return
		}
		break
	case "text":
		set_font("text")
		if (parse.state >= 2) {
			if (parse.state == 2)
				goto_tune()
			s = new_block(cmd);
			s.text = param
			s.opt = cfmt.textoption
			s.font = cfmt.textfont
			return
		}
		write_text(param, cfmt.textoption)
		return
	case "transpose":		// (abcm2ps compatibility)
		if (cfmt.sound)
			return
		val = get_transp(param)
		if (val == undefined) {		// accept note interval
			val = get_interval(param)
			if (val == undefined) {
				syntax(1, errs.bad_transp)
				return
			}
		}
		switch (parse.state) {
		case 0:
			cfmt.transp = 0
			// fall thru
		case 1:
		case 2:
			val = get_transp(param)
			if (val)
				cfmt.transp = (cfmt.transp || 0) + val
			cfmt.transp = (cfmt.transp || 0) + val
			return
		}
		for (s = curvoice.last_sym; s; s = s.prev) {
			switch (s.type) {
			case C.NOTE:		// insert a key
				s = clone(curvoice.okey);
				s.k_old_sf = curvoice.ckey.k_sf;
				sym_link(s)
				break
			case C.KEY:
				break
			default:
				continue
			}
			break
		}
		do_info('V', curvoice.id + ' score=' + param)
		curvoice.transp = val
		set_transp()
		return
	case "tune":
//fixme: to do
		return
	case "user":
		set_user(param)
		return
	case "voicecolor":
		if (parse.state != 3) {
			if (parse.state != 2)
				return
			goto_tune()
		}
		curvoice.color = param
		return
	case "vskip":
		val = get_unit(param)
		if (isNaN(val)) {
			syntax(1, errs.bad_val, "%%vskip")
			return
		}
		if (val < 0) {
			syntax(1, "%%vskip cannot be negative")
			return
		}
		if (parse.state == 3) {
		if (parse.state >= 2) {
			s = new_block(cmd);
			s.sk = val
			return
		}
		vskip(val);
		return
	case "newpage":
	case "leftmargin":
	case "rightmargin":
	case "pagescale":
	case "pagewidth":
	case "printmargin":
	case "scale":
	case "staffwidth":
		if (parse.state >= 2) {
			if (parse.state == 2)
				goto_tune()
			s = new_block(cmd);
			s.param = param
			return
		}
		if (cmd == "newpage") {
			blk_flush();
			block.newpage = true;
			blk_flush()
			if (user.page_format)
				blkdiv = 2	// start the next SVG in a new page
			return
		}
		break
	}
	self.set_format(cmd, param)
}

// treat the %%beginxxx / %%endxxx sequences
// (possible hook)
Abc.prototype.do_begin_end = function(type,
			opt,
			text) {
	var i, j, action, s

	switch (type) {
	case "js":
		js_inject(text)
		break
	case "ml":
		if (parse.state == 3) {
		if (parse.state >= 2) {
			s = new_block(type);
			s.text = text
		} else {
			svg_flush();
			blk_flush()
			if (user.img_out)
				user.img_out(text)
		}
		break
	case "svg":
		j = 0
		while (1) {
			i = text.indexOf('<style type="text/css">\n', j)
			i = text.indexOf('<style', j)
			if (i < 0)
				break
			i = text.indexOf('>', i)
			j = text.indexOf('</style>', i)
			if (j < 0) {
				syntax(1, "No </style> in %%beginsvg sequence")
				break
			}
			style += text.slice(i + 23, j).replace(/\s+$/, '')
			style += text.slice(i + 1, j).replace(/\s+$/, '')
		}
		j = 0
		while (1) {
			i = text.indexOf('<defs>\n', j)
			if (i < 0)
				break
			j = text.indexOf('</defs>', i)
			if (j < 0) {
				syntax(1, "No </defs> in %%beginsvg sequence")
				break
			}
			defs_add(text.slice(i + 6, j))
		}
		break
	case "text":
		action = get_textopt(opt);
		if (!action)
			action = cfmt.textoption
		if (text.indexOf('\\') >= 0)	// convert the escape sequences
			text = cnv_escape(text)

		set_font("text")
		if (parse.state >= 2) {
			if (parse.state == 2)
				goto_tune()
			s = new_block(type);
			s.text = text
			s.opt = action
			s.font = cfmt.textfont
			break
		}
		write_text(text, action)
		break
	}
}

︙
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434



1435
1436
1437

1438
1439
1440



1441
1442
1443
1444
1445
1446
1447
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359







-






+
+
+


-
+



+
+
+







		syntax(1, "No end of voice overlay");
		get_vover(vover.bar ? '|' : ')')
	}

	if (!voice_tb.length)
		return
	voice_adj();
	dupl_voice();
	sort_all()			/* define the time / vertical sequences */
	if (!tsfirst)
		return
	self.set_bar_num()
	pit_adj()

	if (info.P)
		tsfirst.parts = info.P	// for play

	// give the parser result to the application
	if (user.get_abcmodel)
		user.get_abcmodel(tsfirst, voice_tb, anno_type, info)
		user.get_abcmodel(tsfirst, voice_tb, abc2svg.sym_name, info)

	if (user.img_out)		// if SVG generation
		self.output_music()

	if (tsfirst)		// if non void, keep tune data for upper layers
		tunes.push([tsfirst, voice_tb, info, cfmt])

	// if inside multicol, reset the parser
	if (!in_mc)
		return
	voice_tb = Object.create(voice_tb)
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v];
︙
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1442
1443
1444
1445
1446
1447
1448

1449
1450


1451
1452
1453
1454
1455
1456
1457







-
+

-
-







	var	s, p_voice, p_voice2, i, flags, v, vid,
		st, range,
		a_vf = parse_staves(parm) // array of [vid, flags]

	if (!a_vf)
		return

	if (voice_tb.length) {
	if (voice_tb.length)
		voice_adj(true);
		dupl_voice()
	}

	/* create a new staff system */
	var	maxtime = 0,
		no_sym = true

	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
︙
1590
1591
1592
1593
1594
1595
1596
1597
1598


1599
1600
1601



1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612
1613
1614




1615
1616
1617
1618
1619
1620

1621
1622
1623
1624
1625
1626
1627
1500
1501
1502
1503
1504
1505
1506


1507
1508
1509


1510
1511
1512



1513










1514
1515
1516
1517


1518


1519
1520
1521
1522
1523
1524
1525
1526
1527







-
-
+
+

-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-

-
-

+







	}
	range = 0
	for (i = 0; i < a_vf.length; i++) {
		vid = a_vf[i][0];
		p_voice = new_voice(vid);
		p_voice.time = maxtime;
		v = p_voice.v
		if (i == 0)
			par_sy.top_voice = p_voice.v

		a_vf[i][0] = p_voice;

		// if the voice is already here, clone it
		if (par_sy.voices[v]) {
		// set the range and add the overlay voices
		while (1) {
			par_sy.voices[v] = {}
			p_voice2 = clone(p_voice);
//			p_voice2.id += "_c"		// for tests
			par_sy.voices[voice_tb.length] = clone(par_sy.voices[v]);
			par_sy.voices[v].range = range++
			v = voice_tb.length;
			p_voice2.v = v;
			p_voice2.sym = p_voice2.last_sym = null;
			p_voice2.time = maxtime;
			voice_tb.push(p_voice2)
			delete p_voice2.clone
			while (p_voice.clone)
				p_voice = p_voice.clone;
			p_voice.clone = p_voice2;
			p_voice = p_voice2
			p_voice = p_voice.voice_down
			if (!p_voice)
				break
			v = p_voice.v
		} else {
			par_sy.voices[v] = {}
		}
		a_vf[i][0] = p_voice;
		par_sy.voices[v].range = range++
	}
	par_sy.top_voice = a_vf[0][0].v

	/* change the behavior from %%staves to %%score */
	if (cmd[1] == 't') {				/* if %%staves */
		for (i = 0; i < a_vf.length; i++) {
			flags = a_vf[i][1]
			if (!(flags & (OPEN_BRACE | OPEN_BRACE2)))
				continue
︙
1665
1666
1667
1668
1669
1670
1671
1672

1673
1674
1675
1676
1677
1678
1679
1565
1566
1567
1568
1569
1570
1571

1572
1573
1574
1575
1576
1577
1578
1579







-
+







		if (flags & FL_VOICE) {
			p_voice.floating = true;
			p_voice.second = true
		} else {
			st++;
			if (!par_sy.staves[st]) {
				par_sy.staves[st] = {
					stafflines: '|||||',
					stafflines: p_voice.stafflines || "|||||",
					staffscale: 1
				}
			}
			par_sy.staves[st].flags = 0
		}
		v = p_voice.v;
		p_voice.st = p_voice.cst =
︙
1707
1708
1709
1710
1711
1712
1713
1714

1715
1716
1717










1718
1719
1720
1721
1722
1723
1724
1607
1608
1609
1610
1611
1612
1613

1614

1615

1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632







-
+
-

-
+
+
+
+
+
+
+
+
+
+







	if (cmd[1] == 'c') {				/* if %%score */
		for (st = 0; st < nstaff; st++)
			par_sy.staves[st].flags ^= STOP_BAR
	}

	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v]
		if (!par_sy.voices[v]) {
		if (!par_sy.voices[v])
			p_voice.ignore = true
			continue
		}

		// set the staff of the overlay voices
		p_voice2 = p_voice.voice_down
		while (p_voice2) {
			i = p_voice2.v
			p_voice2.st = p_voice2.cst =
					par_sy.voices[i].st = st
			p_voice2 = p_voice2.voice_down
		}

		par_sy.voices[v].second = p_voice.second;
		st = p_voice.st
		if (st > 0 && !p_voice.norepbra
		 && !(par_sy.staves[st - 1].flags & STOP_BAR))
			p_voice.norepbra = true
	}

︙
1736
1737
1738
1739
1740
1741
1742

1743
1744
1745
1746
1747
1748
1749
1750
1751
1752

1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781

1782
1783
1784
1785
1786
1787
1788
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673


1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697







+










+











-
-
















+







		}
		p_voice = clone(curvoice);
		p_voice.v = voice_tb.length;
		p_voice.id = id;
		p_voice.sym = p_voice.last_sym = null;

		p_voice.key = clone(curvoice.key)
		p_voice.sls = []

		delete p_voice.nm
		delete p_voice.snm
		delete p_voice.new_name
		delete p_voice.lyric_restart
		delete p_voice.lyric_cont
		delete p_voice.ly_a_h;
		delete p_voice.sym_restart
		delete p_voice.sym_cont
		delete p_voice.have_ly
		delete p_voice.tie_s

		voice_tb.push(p_voice)
		return p_voice
	} // clone_voice()

/* -- get a voice overlay -- */
function get_vover(type) {
    var	p_voice2, p_voice3, range, s, time, v, v2, v3,
	line = parse.line

	/* treat the end of overlay */
	if (curvoice.ignore)
		return
	if (type == '|'
	 || type == ')')  {
		if (!curvoice.last_note) {
			syntax(1, errs.nonote_vo)
			return
		}
		curvoice.last_note.beam_end = true
		if (!vover) {
			syntax(1, "Erroneous end of voice overlay")
			return
		}
		if (curvoice.time != vover.p_voice.time) {
			syntax(1, "Wrong duration in voice overlay");
			if (curvoice.time > vover.p_voice.time)
				vover.p_voice.time = curvoice.time
		}
		curvoice.acc = []		// no accidental anymore
		curvoice = vover.p_voice;
		vover = null
		return
	}

	/* treat the full overlay start */
	if (type == '(') {
︙
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823

1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840

1841
1842
1843
1844
1845
1846
1847
1720
1721
1722
1723
1724
1725
1726

1727
1728
1729
1730

1731
1732
1733










1734
1735
1736


1737
1738
1739
1740
1741
1742
1743
1744







-




-
+


-
-
-
-
-
-
-
-
-
-



-
-
+







		p_voice2.time = 0;
		p_voice2.second = true;
		v2 = p_voice2.v;
		par_sy.voices[v2] = {
			st: curvoice.st,
			second: true
		}
		var f_clone = curvoice.clone != undefined ? 1 : 0;
		range = par_sy.voices[curvoice.v].range
		for (v = 0; v < par_sy.voices.length; v++) {
			if (par_sy.voices[v]
			 && par_sy.voices[v].range > range)
				par_sy.voices[v].range += f_clone + 1
				par_sy.voices[v].range++
		}
		par_sy.voices[v2].range = range + 1
		if (f_clone) {
			p_voice3 = clone_voice(p_voice2.id + 'c');
			p_voice3.second = true;
			v3 = p_voice3.v;
			par_sy.voices[v3] = {
				second: true,
				range: range + 2
			}
			p_voice2.clone = p_voice3
		}
	}
	p_voice2.ulen = curvoice.ulen
	p_voice2.dur_fact = curvoice.dur_fact
	if (curvoice.uscale)
		p_voice2.uscale = curvoice.uscale
	p_voice2.acc = []			// no accidental

	if (!vover) {				/* first '&' in a measure */
		vover = {
			bar: true,
			p_voice: curvoice
		}
		time = p_voice2.time
︙
1874
1875
1876
1877
1878
1879
1880
1881
1882


1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902

















1903
1904
1905
1906
1907
1908
1909
1771
1772
1773
1774
1775
1776
1777


1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789


1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821







-
-
+
+










-
-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	}
}

// check if a clef, key or time signature may go at start of the current voice
function is_voice_sig() {
	var s

	if (!curvoice.sym)
		return true	// new voice (may appear in the middle of a tune)
//	if (!curvoice.sym)
//		return true	// new voice (may appear in the middle of a tune)
	if (curvoice.time != 0)
		return false
	for (s = curvoice.last_sym; s; s = s.prev)
		if (w_tb[s.type] != 0)
			return false
	return true
}

// treat a clef found in the tune body
function get_clef(s) {
	var	s2, s3

	if (is_voice_sig()) {
		curvoice.clef = s
		return
	}

	// clef change
	sym_link(s);
	s.clef_small = true

	// move the clef before a (not right repeat) bar
    var	s2 = s.prev
	if (s2 && s2.type == C.BAR
	 && s2.bar_type[0] != ':') {
		s.next = s2
		s.prev = s2.prev
		if (s.prev)
			s.prev.next = s
		s2.prev = s
		s2.next = null
		curvoice.last_sym = s2
		if (s.soln) {
			delete s.soln
			curvoice.eoln = true
		}
	}
}

// treat K: (kp = key signature + parameters)
function get_key(parm) {
	var	v, p_voice, s, transp, sndtran,
//		[s_key, a] = new_key(parm)	// KO with nodejs
		a = new_key(parm),
︙
1932
1933
1934
1935
1936
1937
1938
1939

1940
1941
1942
1943
1944
1945
1946
1844
1845
1846
1847
1848
1849
1850

1851
1852
1853
1854
1855
1856
1857
1858







-
+







		parse.state = 2;		// in tune header after K:
		return
	case 2:					// K: at start of tune body
		goto_tune(true)
		break
	}
	if (a.length)
		set_kv_parm(a);
		set_kv_parm(a)

	if (!curvoice.ckey.k_bagpipe && !curvoice.ckey.k_drum
	 && (cfmt.transp != undefined
	  || curvoice.transp != undefined
	  || curvoice.shift != undefined))
	    transp = (cfmt.transp || 0) +
		(curvoice.transp || 0) +
︙
2026
2027
2028
2029
2030
2031
2032
2033
2034


2035
2036
2037

2038
2039
2040
2041
2042
2043
2044
1938
1939
1940
1941
1942
1943
1944


1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957







-
-
+
+



+







			vol: 0
		},
		scale: 1,
//		st: 0,
//		cst: 0,
		ulen: glovar.ulen,
		dur_fact: 1,
		key: clone(parse.ckey),	// key at start of tune (parse) / line (gene)
		ckey: clone(parse.ckey),	// current key (parse)
		key: clone(parse.ckey),		// key at start of tune (parse / gene)
		ckey: clone(parse.ckey),	// current key (parse / gene)
		okey: clone(parse.ckey),	// key without transposition (parse)
		meter: clone(glovar.meter),
		wmeasure: glovar.meter.wmeasure,
		staffnonote: 1,
		clef: {
			type: C.CLEF,
			clef_auto: true,
			clef_type: "a",		// auto
			time: 0
		},
		acc: [],		// accidentals of the measure (parse)
︙
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075







2076
2077
2078

2079
2080

2081
2082


2083
2084

2085
2086
2087
2088


2089
2090
2091
2092
2093


2094
2095


2096
2097

2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108




2109
2110
2111
2112





2113
2114
2115
2116
2117
2118










2119
2120
2121
2122
2123
2124
2125

2126














2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157

2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
1976
1977
1978
1979
1980
1981
1982






1983
1984
1985
1986
1987
1988
1989



1990


1991


1992
1993
1994

1995




1996
1997

1998
1999

2000
2001
2002


2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022




2023
2024
2025
2026
2027






2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045

2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079







2080
2081
2082

2083
2084
2085
2086
2087
2088



2089
2090
2091
2092
2093
2094
2095







-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
+
-
-
+
+

-
+
-
-
-
-
+
+
-


-

+
+
-
-
+
+


+











+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
-
-
-
-
-
-



-
+





-
-
-







	new_syst(true);
	staves_found = -1;
	gene = {}
	a_de = []			// remove old decorations
}

// treat V: with many voices
function do_cloning(vs) {
    var	i, eol,
	file = parse.file,
	start = parse.eol + 1,		// next line after V:
	bol = start

function do_cloning() {
    var	i,
	clone = curvoice.clone,
	vs = clone.vs,
	a = clone.a,
	bol = clone.bol,
	eol = parse.istart,
	// search the end of the music to be cloned
	while (1) {
		eol = file.indexOf('\n', bol)
	parse_sav = parse,
		if (eol < 0) {
			eol = 0
	file = parse.file
			break
		}

	delete curvoice.clone

		// stop on comment, or information field
	if (file[eol - 1] == '[')	// if stop on [V:xx]
		if (/%.*|\n.*|.:.|\[.:/.test(file.slice(eol + 1, eol + 4)))
			break
		bol = eol + 1
	}
		eol--


	// insert the music sequence in each voice
	include++;
	tosvg(parse.fname, file, start, eol)	// first voice
	for (i = 0; i < vs.length; i++) {
		parse = Object.create(parse_sav) // create a new parse context
		parse.line = Object.create(parse_sav.line)
		get_voice(vs[i]);
		tosvg(parse.fname, file, start, eol)
		get_voice(vs[i], a)
		tosvg(parse.fname, file, bol, eol)
	}
	include--
	parse = parse_sav	// restore the parse context
}

// treat a 'V:' info
function get_voice(parm) {
    var	v, vs,
	a = info_split(parm),
	vid = a.shift()

	if (!vid)
		return				// empty V:

	// if end of sequence with many voices, load the other voices
	if (curvoice && curvoice.clone)
		do_cloning()

	if (vid.indexOf(',') > 0) {		// if many voices
		vs = vid.split(',');
		vid = vs.shift()
	}
	if (vid.indexOf(',') > 0)		// if many voices
		vs = vid.split(',')
	else
		vs = [vid]


	if (parse.state < 2) {
		if (a.length)
			memo_kv_parm(vid, a)
		if (vid != '*' && parse.state == 1)
			curvoice = new_voice(vid)
	if (parse.state < 2) {			// memorize the voice parameters
		while (1) {
			vid = vs.shift()
			if (!vid)
				break
			if (a.length)
				memo_kv_parm(vid, a)
			if (vid != '*' && parse.state == 1)
				curvoice = new_voice(vid)
		}
		return
	}

	if (vid == '*') {
		syntax(1, "Cannot have V:* in tune body")
		return
	}

	curvoice = new_voice(vid);
	curvoice = new_voice(vs[0])

	// if many voice, memorize the start of sequence
	if (vs.length > 1) {
		vs.shift()
		curvoice.clone = {
			vs: vs,
			a: a,
			bol: parse.iend
		}
		if (parse.file[curvoice.clone.bol - 1] != ']')
			curvoice.clone.bol++	// start of new line
	}

	set_kv_parm(a)
	if (parse.state == 2)			// if first voice
		goto_tune();
	set_transp();

	v = curvoice.v
	if (curvoice.new) {			// if new voice
		delete curvoice.new
		if (staves_found < 0) {		// if no %%score/%%staves
			curvoice.st = curvoice.cst = ++nstaff;
			par_sy.nstaff = nstaff;
			par_sy.voices[v] = {
				st: nstaff,
				range: v
			}
			par_sy.staves[nstaff] = {
				stafflines: curvoice.stafflines || "|||||",
				staffscale: 1
			}
		}
	
		if (!par_sy.voices[v]) {
//			if (cfmt.alignbars)
//				syntax(1, "V: does not work with %%alignbars")
			if (staves_found >= 0)
				curvoice.ignore = true
		}
	}

	if (!curvoice.filtered
	 && !curvoice.ignore
	 && par_sy.voices[v]
	 && (parse.voice_opts
	  || parse.tune_v_opts)) {
		curvoice.filtered = true;
		voice_filter()
	}

	if (vs)
		do_cloning(vs)
}

// change state from 'tune header after K:' to 'in tune body'
// curvoice is defined when called from get_voice()
function goto_tune(is_K) {
	var	v, p_voice,
		s = {
︙
2195
2196
2197
2198
2199
2200
2201
2202

2203
2204
2205
2206
2207
2208
2209
2118
2119
2120
2121
2122
2123
2124

2125
2126
2127
2128
2129
2130
2131
2132







-
+







//		nstaff = 0;
		curvoice.default = true
	} else if (!curvoice) {
		curvoice = voice_tb[staves_found < 0 ? 0 : par_sy.top_voice]
	}

	if (!curvoice.init && !is_K) {
		set_kv_parm([]);
		set_kv_parm([])
		set_transp()
	}

	// update some voice parameters
	for (v = 0; v < voice_tb.length; v++) {
		p_voice = voice_tb[v];
		p_voice.ulen = glovar.ulen
︙
Changes to editor/edit.css.
1
2

3
4

5
6
7
8

9
10
11
12
13

14
15
16
17
18
19
20
1

2
3

4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21

-
+

-
+




+



-

+







/* edit.css - file used in the abc2svg editor */
@page {margin-top: 1cm; margin-left: 0cm; margin-right: 0cm}
@page {margin:0}
text tspan {white-space:pre; fill:currentColor}
svg {display:block}
svg {display:block;background-color:#ffffff}
.abcr {fill: #d00000; fill-opacity: 0; z-index: 15}
@media screen {
	body, html {height: 90%}
	text, path {pointer-events: none}
	svg {margin-left:auto;margin-right:0}
	#dleft {
		width: auto;
		position: absolute; top: 0; bottom:0; left: 0;
		background-color:#faf0e6;
		z-index: 2;
		background-color:#faf0e6;
		overflow: auto;
	}
	#nav {
		position:relative;
		padding: 0;
		margin: 2px 0 0 2px;
	}
︙
37
38
39
40
41
42
43
44

45
46

47
48
49
50

51
52
53
54
55
56
57
38
39
40
41
42
43
44

45
46

47
48
49
50
51
52
53
54
55
56
57
58
59







-
+

-
+




+







		padding: 0;
		margin: 0;
	}
	.droplinks li:hover { outline: solid; outline-width: 2px }
	.droplinks li { padding: 0 5px 0 5px; margin: 2px }
	#dright {
		width: 80%;
		max-width: 800px;
		max-width: 840px;
		position: absolute; top: 0; bottom:0; right:0;
		background-color: white;
		background-color:#faf0e6;
		overflow: auto
	}
	#dright:hover {z-index: 10 !important}
	#dright:active {z-index: 10 !important}
	textarea {background-color:#ffffff}
	.popup {
		position: absolute; top: 0; right: 20px;
		padding: 10px;
		background-color:#e0e0e0;
		border-radius: 5px;
		visibility: hidden;
		z-index:20;
︙
97
98
99
100
101
102
103
104
99
100
101
102
103
104
105








-
		margin:0; padding:0; border:0;
		background-color: white;
	}
	#dright { margin:0; padding:0; border:0 }
	.newpage { page-break-before: always }
	.nobrk { page-break-inside: avoid }
}
@page{margin:0}
Changes to editor/edit.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// edit.js - file used in the abc2svg editor
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
228
229
230
231
232
233
234

235
236
237
238
239
240
241







-







				return new Date(files[0].lastModified)
			return new Date()
		}
	}

	abc = new abc2svg.Abc(user);
	abc_images = '';
	abc.tosvg('edit', '%%bgcolor white');

//	document.body.style.cursor = "wait";
	syms = []
	try {
		abc.tosvg(abc_fname[0], content)
	} catch(e) {
		alert(e.message + '\nabc2svg tosvg bug - stack:\n' + e.stack)
︙
253
254
255
256
257
258
259

















260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301

302
303
304
305
306
307
308
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278


279










280
281

282
283
284
285
286
287


288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304

305
306
307
308
309
310
311
312







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-

-
-
-
-
-
-
-
-
-
-
+

-
+





-
-
+









-
+






-
+







		return
	}

	// show the 'Error' button if some error
	document.getElementById("er").style.display =
				elt_ref.diverr.innerHTML ? 'inline' : 'none';
}

// get the source offset from the row and column numbers
function soffs(r, c) {
    var	m,
	s = elt_ref.source,
	o = 0
	while (--r >= 0) {
		o = s.value.indexOf('\n', o) + 1
		if (o <= 0)
			return s.value.length - 1
	}
	m = s.value.indexOf('\n', o)	// check if inside the line
	o += c
	if (o > m)
		o = m
	return o
} // soffs()

// select a source ABC element on error
function gotoabc(l, c) {
	var	s = elt_ref.source,
		idx = 0;
	selsrc(0)
	while (--l >= 0) {
		idx = s.value.indexOf('\n', idx) + 1
		if (idx <= 0) {
			alert(texts.bad_nb);
			idx = s.value.length - 1;
			c = 0
			break
		}
	}
	c = Number(c) + idx;
	c = soffs(l, Number(c))
	s.focus();
	s.setSelectionRange(c, syms[c].iend || c + 1)
	s.setSelectionRange(c, syms[c] ? syms[c].iend : c + 1)
}

// click in the target
function selsvg(evt) {
    var	v,
	elt = evt.target,
	cl = elt.getAttribute('class')
	cl = evt.target.getAttribute('class')

	play.loop = false;

	evt.stopImmediatePropagation();
	evt.preventDefault()

	// remove the context menu if active
	if (ctxMenu && ctxMenu.style.display == "block") {
		ctxMenu.style.display = "none"
		return false
		return
	}

	// stop playing
	if (play.playing && !play.stop) {
		play.stop = -1;
		play.abcplay.stop()
		return false
		return
	}

	// highlight the clicked element or clear the selection start
	s = elt_ref.source;
	if (cl && cl.substr(0, 4) == 'abcr') {
		v = Number(cl.slice(6, -1));
		s.setSelectionRange(v, syms[v].iend)
︙
496
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511
500
501
502
503
504
505
506

507

508
509
510
511
512
513
514







-
+
-







//	0: Tune
//	1: Selection
//	2: Loop
//	3: Continue
function play_tune(what) {
    var	i, si, ei, elt,
	C = abc2svg.C,
	tunes = abc.tunes,
	tunes = abc.tunes
	s = elt_ref.source.value

	if (play.playing) {
		if (!play.stop) {
			play.stop = -1;
			play.abcplay.stop()
		}
		return
︙
622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639







-
+







	if (tunes.length) {		// if new display

		// generate the play data of all tunes
		while (1) {
			elt = tunes.shift()
			if (!elt)
				break
			play.abcplay.add(elt[0], elt[1])
			play.abcplay.add(elt[0], elt[1], elt[3])
		}

		play.si = play.ei = null
		play.stop = 0
		play.loop = false
	}

︙
817
818
819
820
821
822
823
824

825
826


827
828

829
830
831
832
833
834














835
836
837
838
839
840

841
842
843
844
845
846
847

848
849
850
851

852
853
854
855
856
857
858
859
860

820
821
822
823
824
825
826

827
828
829
830
831
832

833
834
835
836
837


838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863

864
865
866
867

868
869
870
871
872
873
874
875
876

877







-
+


+
+

-
+




-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+






-
+



-
+








-
+
			return false
		} // oncontextmenu
	}
	set_pref()	// set the preferences from local storage
}

// drag and drop
function drag_over(evt) {
function drag_enter(evt) {
	evt.stopImmediatePropagation();
	evt.preventDefault()	// allow drop
//fixme: "move" does not work
//	evt.dataTransfer.dropEffect = evt.ctrlKey ? "move" : "copy"
}
function dropped(evt) {
function drop(evt) {
	evt.stopImmediatePropagation();
	evt.preventDefault()
	// check if text
	var data = evt.dataTransfer.getData("text")
	if (data) {
		evt.target.value = data;
	if (data) {			// insert the text at the mouse location
	    var	x = evt.layerX,
		y = elt_ref.source.scrollTop + evt.layerY,
		h = elt_ref.source.offsetHeight / elt_ref.source.rows,
		w = elt_ref.source.offsetWidth / elt_ref.source.cols

		w = (x / w) | 0		// column
		h = (y / h) | 0		// row
		h = soffs(h, w)

	    var	e = evt.target
		e.value = e.value.slice(0, h)
			+ data
			+ e.value.slice(h)
		src_change()
		return
	}
	// check if file
	data = evt.dataTransfer.files	// FileList object.
	if (data.length != 0) {
	if (data.length) {
		var reader = new FileReader();
		reader.onload = function(evt) {
			elt_ref.source.value = evt.target.result;
			src_change()
		}
		reader.readAsText(data[0],"UTF-8")
		return
//		return
	}
}

// render the music after 2 seconds on textarea change
// render the music 2 seconds after source change
var timer
function src_change() {
	clearTimeout(timer);
	if (!play.playing)
		timer = setTimeout(render, 2000)
}

// wait for scripts to be loaded
setTimeout(edit_init, 500)
window.addEventListener("load", edit_init)
Changes to editor/edit.xhtml.
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19











-
+







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="edit-@MAJOR@.css" rel="stylesheet" type="text/css"/>
<script src="edit-@MAJOR@.js" type="text/javascript" async="true"></script>
<script src="abc2svg-@MAJOR@.js" type="text/javascript" async="true"></script>
<title>ABC edit with abc2svg</title>

</head>
<body ontouchstart="">
<body ontouchstart="" bgcolor="#faf0e6">

<!-- left -->
<div id="dleft">

<!-- menu bar -->
    <ul id="nav">
	<li class="dropbutton"><label id="f">File</label>
︙
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
86
87
88
89
90
91
92

93

94
95
96
97
98
99
100







-
+
-







<label id="er" onclick="popshow('errlist', true)"
 style="display: none; background: #ff8080">Errors</label>

<!-- ABC source in textarea (main and include) -->
</p>
<textarea id="source" rows="40" cols="73" wrap="off"
	style="font: 14px monospace"
	ondrop="dropped(event)" ondragenter="drag_over(event)"
	ondrop="drop(event)" ondragenter="drag_enter(event)"
	ondragover="drag_over(event)"
	oninput="src_change()"></textarea>
<textarea id="src1" rows="40" cols="73" wrap="off"
	style="font: 14px monospace; display: none"
	oninput="src_change()"></textarea>
</div>

<!-- right - needed for the scrollbars -->
︙
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153
154
155
156
157
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157







-
+
+











</ul>
</div>

<!-- about popup window -->
<div id="about" class="popup" style="width: 350px">
<div class="close" onclick="popshow('about')">x</div>
<p id="abc2svg">abc2svg</p>
<p>Copyright &#x00A9; 2016-2019 Jean-François Moine</p>
<p>Copyright &#x00A9; 2016-2021 <a
href="http://moinejf.free.fr">Jean-François Moine</a></p>
</div>

<!-- javascript must be enabled -->
<noscript>
<div id="okjs" class="popup" style="width:50%;background:#ff8080;visibility:visible">
Please enable Javascript.
</div>
</noscript>

</body>
</html>
Changes to err-de.js.
︙
10
11
12
13
14
15
16
17

18
19
20

21
22

23
24
25
26
27
28
29

30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57
58
59
60

61
62
63
64
65
66

67
68
69
70
71

72
73
74
75

76



77
78
79
80
81
82



83
84
85


86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102

103
104
105
106
107
108
109
110

111
112
113
114
115
116
117


118
119
120
121
122
123



124
125
126
127
128
129

130
131
132


133
134
135
136
137


138
10
11
12
13
14
15
16

17
18
19

20
21

22
23
24
25
26
27


28
29
30

31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58

59
60
61
62
63
64

65
66
67
68
69

70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107

108
109
110
111
112
113
114
115

116
117
118
119
120
121


122
123
124
125
126



127
128
129
130
131
132
133
134

135
136


137
138
139
140
141


142
143
144







-
+


-
+

-
+





-
-
+


-

-
+




















-
+
+




-
+





-
+




-
+




+
-
+
+
+






+
+
+


-
+
+











-
+




-
+







-
+





-
-
+
+



-
-
-
+
+
+





-
+

-
-
+
+



-
-
+
+

// grace note "vorschlagnote" 
//


user.textrans = {
    "+: lyric without music": "+: Liedtext ohne Musik",
	"+: symbol line without music": "+: Symbolzeile ohne Musik",
    "+: without previous info field": "+: ohne vorhergehends Info-Feld",
	"+: without previous info field": "+: ohne vorhergehendes Info-Feld",
    "'{' in grace note": "'{' in Verzierungsnote",
    "'}', ')' or ']' missing in %%score": "'}', ')' oder ']' fehlt in  %%score",
    "',' lacking in annotation '@x,y'": "',' fehlt in Beschriftung  '@x,y'",
	"',' lacking in annotation '@x,y'": "',' fehlt in Beschriftung '@x,y'",
	"'$1' is not a note": "'$1' is keine Note",
    "'$1:' line ignored": "'$1:' Zeile ignoreirt",
	"'$1:' line ignored": "'$1:' Zeile ignoriert",
    "$1: inside tune - ignored": "$1: innerhalb der Stimme ignoriert",
    "!$1! must be on a note": "!$1! muss an einer Note stehen",
    "!$1! must be on a note or a rest": "!$1! muss an einer Note oder Pause stehen",
    "!$1! must be on the last of a couple of notes": "!$1! muss an der letzten Notengruppe stehen",
    "!beamon! must be on a bar": "!beamon! muss an einem Taktstrich stehen",
    "!xstem! must be on a note": "!xstem! muss an einer Note stehen",
    "%%deco: abnormal h/wl/wr value '$1'": "%%deco: falscher Wert '$1'  für h/wl/wr",
	"%%deco: abnormal h/wl/wr value '$1'": "%%deco: falscher Wert '$1' für h/wl/wr",
    "%%deco: bad C function index '$1'": "%%deco: falscher C Funktionsindex '$1'",
    "%%deco: bad C function value '$1'": "%%deco: falscher C Funtionswert '$1'",
    "%%deco: cannot have a negative value '$1'": "%%deco: '$1' kann keinen egativen Wert haben",
    "%%multicol end without start": "%%multicol end ohne start",
    "%%multicol new without start": "%%multicol new ohne stand",
	"%%multicol new without start": "%%multicol new ohne start",
    "%%repeat cannot start a tune": "%%repeat kann nicht am Anfang einer Stimme stehen",
    "%%staffwidth too big": "%%staffwidth zu groß",
    "%%staffwidth too small": "%%staffwidth zu klein",
    "%%tune not treated yet": "%%tune noch nicht behandelt",
    "%%vskip cannot be negative": "%%vskip kann nicht negativ sein",
    "Bad !xstem!": "!xstem! fehlerhaft",
    "Bad %%setbarnb value": "fehlerhaft Wert für %%setbarnb",
    "Bad %%staff number $1 (cur $2, max $3)": "falsche %%staff Nummer $1 (cur $2, max $3)",
    "Bad %%staff value '$1'": "fehlerhafte %%staff Nummer '$1'",
    "Bad %%stafflines value": "fehlerhafter Wert für %%stafflines",
    "Bad %%staffscale value": "fehlerhafter Wert für %%staffscale",
    "Bad char '$1' in M:": "fehlerhaftes Zeichen '$1' in M:",
    "Bad character '$1'": "fehlerhaftes Zeichen '$1'",
	"Bad character in grace note sequence":
				"fehlerhaftes Zeichen in Sequenz von Vorschlagnoten",
	"Bad controller number in %%MIDI": "Bad controller number in %%MIDI",
	"Bad controller value in %%MIDI": "Bad controller value in %%MIDI",
    "Bad duration '$1' in M:": "fehlerhafte Dauer '$1' in M:",
    "Bad integer value": "fehlerhafte Ganzzahl",
	"Bad instr= value": "fehlerhafter Wert für instr=",
    "Bad L: value": "Fehlerhafter Wert für  L:",
	"Bad L: value": "fehlerhafter Wert für  L:",
	"Bad measure duration": "Bad measure duration",
    "Bad note in %%map": "fehlerhafte Note in %%map",
    "Bad page width": "fehlerhafte Seitenbreite",
	"Bad program in %%MIDI": "falsches Program in %%MIDI",
    "Bad scale value in %%font": "fehlerhafter Wert für scale in %%font",
	"Bad tempo value": "Bad tempo value",
	"Bad tempo value": "fehlerhafter Wert für tempo",
    "Bad tie": "fehlerhafter Haltebogen",
    "Bad transpose value": "fehlerhafter Wert für transpose",
    "Bad user character '$1'": "falsches benutzerdefiniertes Zeichen '$1' in U:/%%user",
    "Bad value '$1' in %%linebreak - ignored": "fehlerhafter Wert '$1' in %%linebreak - ignoriert",
    "Bad value in $1": "fehlerhafter Wert in $1",
    "Bad voice ID in %%score": "Fehlerhafte ID für Stimme in %%score",
	"Bad voice ID in %%score": "fehlerhafte ID für Stimme in %%score",
    "Bar in repeat sequence": "Taktstrich in Wiederholungssequenz",
    "Cannot have !$1! on a head": "!$1! im Kopfbereich nicht erlaubt",
    "Cannot have '$1' inside a tune": "'$1' innerhalb einer Stimme nicht erlaubt",
    "Cannot have a bar in grace notes": "Taktstrich in Vorschlagnote nicht erlaubt",
	  "Cannot have a broken rhythm in grace notes": "gebrochener Rythmus in Ziernoten nicht erlaubt ",
	"Cannot have a broken rhythm in grace notes": "gebrochener Rythmus in Ziernoten nicht erlaubt",
    "Cannot have V:* in tune body": "V:* im Notenbereich nicht erlaubt",
    "Cannot read file '$1'": "File '$1' kann nicht gelesen werden",
    "Decoration ignored": "Dekoration ignoriert",
    "Empty line in tune header - ignored": "Leerzeile in Kopfbereich - ignoriert",
	"End of slur without start": "End of slur without start",
    "Erroneous end of voice overlay": "Fehlerhaftes Ende einer Stimme in überlagerten Stimmen",
	"Erroneous end of voice overlay":
			"Fehlerhaftes Ende einer Stimme in Stimm-Überlagerung",
	"Error loading the module $1": "Error loading the module $1",
    "Incorrect 1st value in %%repeat": "erster Wert fehlerhaft in %%repeat",
    "Incorrect 2nd value in %%repeat": "zweiter Wert fehlerhaft in %%repeat",
    "Invalid 'r' in tuplet": "'r' fehlerhaft in Tuplet",
    "Invalid decoration '$1'": "fehlerhafte Dekoration '$1'",
    "Invalid note duration $1": "Fehlerhafte Notendekoration '$1'",
    "Lack of ']'": "']' fehlt",
	"Lack of bar after multi-measure rest":
				"Lack of bar after multi-measure rest",
	"Lack of ending slur(s)": "Lack of ending slur(s)",
	"Lack of starting [, ! or \" in U: / %%user":
				"[, ! or \" fehlt in U: / %%user",
    "Line split problem - adjust maxshrink and/or breaklimit": "Probleme beim Aufteilen der Zeile - justiere maxshrink und/oder breaklimit",
	"Line split problem - adjust maxshrink and/or breaklimit":
		"Probleme beim Aufteilen der Zeile - justiere maxshrink und/oder breaklimit",
    "Line too much shrunk $1 $2 $3": "Zeile zu stark geschrumpft $1 $2 $3",
    "Line underfull ($1pt of $2pt)": "Zeile nicht voll genug ($1pt of $2pt)",
    "Misplaced '$1' in %%score": "'$1' fehlerhaft platziert in %%score",
    "Misplaced dot": "fehlerhaft platzierter Punkt",
	"Mix of old and new transposition syntaxes":
				"Mix von alter und neuer Transponierungs-syntax",
    "No $1 after %%$2": "kein $1 nach %%$2",
    "No </defs> in %%beginsvg sequence": "kein </defs> in %%beginsvg squenz",
    "No </style> in %%beginsvg sequence": "kein </style> in %%beginsvg sequenz",
    "No accidental after 'exp'": "kein Vorzeichen nach 'exp'",
    "No end of decoration": "kein Ende der Dekoration",
    "No end of grace note sequence": "kein ende der Vorschlagnoten",
	"No end of grace note sequence": "kein Ende der Vorschlagnoten",
    "No end of guitar chord": "kein Ende des Akkordsymbols",
    "No end of repeat string": "kein Ende des Wiederholungszeichens",
    "No end of tuplet": "kein Ende des Tuplets",
    "No end of tuplet in this music line":
			"Kein ende des Tuplets in dieser Zeile",
			"Kein Ende des Tuplets in dieser Zeile",
	"No end of voice overlay": "kein Ende der Stimmüberlagerung",
    "No function for decoration '$1'": "keine Funktion für Dekoration '$1'",
    "No note before '-'": "keine Note vor '-'",
    "No note before '<'": "keine Note vor '<'",
    "No note in voice overlay": "keine Note in Stimmüberlagerung",
//	"Non standard note duration $1": "??",
    "No read_file support": "Einlesen von Files nicht unterstützt",
    "No start of !$1!": "kein Start von  !$1!",
	"No start of !$1!": "kein Start von  !$1!",
    "Not an ASCII character": "kein ASCII - Zeichen",
    "Not enough measure bars for lyric line": "nicht genug Takte für Liedtextzeile",
	"Not enough measure bars for symbol line":
				"Nicht genügend Takte für eine Symbolzeile",
    "Not enough measures for %%repeat": "nicht genug Takte für %%repeat",
    "Not enough parameters in %%map":  "nicht genug Parameter in  %%map",
    "Not enough symbols after repeat sequence":  "nicht genug Symbole nach einer Wiederholungssequenz",
	"Not enough parameters in %%map": "nicht genug Parameter in %%map",
	"Not enough symbols after repeat sequence": "nicht genug Symbole nach einer Wiederholungssequenz",
    "Not enough notes/rests for %%repeat": "nicht genug Noten/Pausen für %%repeat",
    "Note too long": "Note zu lang",
    "Note too short": "Note zu kurz",
	"s: without music": "s: without music",
	"Too many elements in symbol line": "Too many elements in symbol line",
    "Too many include levels": "Verschachtelung für include zu tiefr",
	"s: without music": "s: ohne Musik",
	"Too many elements in symbol line": "zu viele elemente in einer Symbolzeile",
	"Too many include levels": "Verschachtelung für include zu tief",
    "Too many ties": "zu viele Haltebogen",
    "Too many words in lyric line": "zu viele Worte in Liedtextzeile",
    "Unknown bagpipe-like key": "unbekante Dudelsackartige Tonart",
    "Unknown clef '$1'": "unbekannter Schlüssel '$1'",
    "Unknown decoration '$1'": "unbekannte Dekoration '$1'",
    "Unknown font $1": "unbekannte schriftart '$1' ",
	"Unknown font $1": "unbekannte Schriftart '$1'",
    "Unknown glyph: '$1'": "Unbekanntes Schriftsybol '$1'",
    "Unknown keyword '$1' in %%multicol": "unbekanntes Schlüsselwort  '$1' in %%multicol",
	"Unsecure code": "Unsecure code",
	"Unknown keyword '$1' in %%multicol": "unbekanntes Schlüsselwort '$1' in %%multicol",
	"Unsecure code": "Unsicherer Code",
    "Unterminated string": "nicht abgeschlossene Zeichenkette",
    "Unterminated string in Q:": "nicht abgeschlossene Zeichenkette in Q:",
    "Voice overlay already started": "Stimmüberlagerung bereits gestartet",
    "w: without music": "w: ohne noten",
    "Wrong duration in voice overlay":  "fehlerhafte Notenwerte in Stimmüberlagerung"
	"w: without music": "w: ohne Noten",
	"Wrong duration in voice overlay": "fehlerhafte Notenwerte in Stimmüberlagerung"
}
Changes to err-fr.js.
︙
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
19
20
21
22
23
24
25

26
27
28
29
30
31


32
33
34
35
36
37
38







-






-
-







	"$1: inside tune - ignored": "$1: en milieu de morceau - ignoré",
	"!$1! must be on a note": "!$1! doit être sur une note",
	"!$1! must be on a note or a rest":
				"!$1! doit être sur une note ou un silence",
	"!$1! must be on the last of a couple of notes":
				"!$1! doit être sur la 2ème note d'un couple",
	"!beamon! must be on a bar": "!beamon! doit être sur une barre",
	"!xstem! must be on a note": "!xstem! doit être sur une note",
	"%%deco: abnormal h/wl/wr value '$1'":
				"%%deco: valeur '$1' anormale pour h/wl/wr",
	"%%deco: bad C function index '$1'":
				"%%deco: mauvais index de fonction '$1'",
	"%%deco: bad C function value '$1'":
				"%%deco: mauvaise valeur de fonction '$1'",
	"%%deco: cannot have a negative value '$1'":
				"%%deco: '$1' ne peut pas avoir de valeur négative",
	"%%multicol end without start": "%%multicol end sans start",
	"%%multicol new without start": "%%multicol new sans start",
	"%%repeat cannot start a tune": "%%repeat ne peut pas être en début de morceau",
	"%%staffwidth too big": "%%staffwidth trop grand",
	"%%staffwidth too small": "%%staffwidth trop petit",
	"%%tune not treated yet": "%%tune n'est pas encore traité",
	"%%vskip cannot be negative": "%%vskip ne peut pas être négatif",
︙
52
53
54
55
56
57
58

59
60
61
62
63
64
65
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63







+







				"Caractère incorrect dans notes d'agrément",
	"Bad controller number in %%MIDI": "Mauvais numéro de controleur dans %%MIDI",
	"Bad controller value in %%MIDI": "Mauvaise valeur de controle dans %%MIDI",
	"Bad duration '$1' in M:": "Durée '$1' incorrecte dans M:",
	"Bad integer value": "Mauvaise valeur entière",
	"Bad instr= value": "Mauvaise valeur de instr=",
	"Bad L: value": "Mauvaise valeur pour L:",
	"Bad measure duration": "Mauvaise durée de la mesure",
	"Bad note in %%map": "Note incorrecte dans %%map",
	"Bad page width": "Mauvaise largeur de page",
	"Bad program in %%MIDI": "Mauvais 'program' dans %%MIDI",
	"Bad scale value in %%font": "Mauvaise échelle dans %%font",
	"Bad tempo value": "Mauvaise valeur de tempo",
	"Bad tie": "Mauvaise liaison de prolongation",
	"Bad transpose value": "Mauvaise valeur de transposition",
︙
77
78
79
80
81
82
83

84

85
86
87
88
89
90



91
92
93
94
95
96
97
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+

+






+
+
+







			"Il ne peut pas y avoir '<' ou '>' dans les notes d'agrément",
	"Cannot have V:* in tune body":
			"Il ne peut pas y avoir V:* dans le corps du morceau",
	"Cannot read file '$1'": "Fichier '$1' inexistant",
	"Decoration ignored": "Décoration ignorée",
	"Empty line in tune header - ignored":
				"Ligne vide dans en-tête de morceau - ignorée",
	"End of slur without start": "Fin de liaison sans début",
	"Erroneous end of voice overlay": "Fin de superposition de voix erronée",
	"Error loading the module $1": "Erreur de chargement du module $1",
	"Incorrect 1st value in %%repeat": "Première valeur incorrecte dans %%repeat",
	"Incorrect 2nd value in %%repeat": "Deuxième valeur incorrecte dans %%repeat",
	"Invalid 'r' in tuplet": "'r' invalide dans le tuplet",
	"Invalid decoration '$1'": "Décoration '$1' invalide",
	"Invalid note duration $1": "Durée de note $1 invalide",
	"Lack of ']'": "']' manquant",
	"Lack of bar after multi-measure rest":
		"Manque de barre de mesure après silence multiple",
	"Lack of ending slur(s)": "Pas de fin de liaison(s)",
	'Lack of starting [, ! or " in U: / %%user':
				'U: / %%user ne commence pas par [, ! ou "',
	"Line split problem - adjust maxshrink and/or breaklimit":
		"Problème de découpe en lignes - ajuster maxshrink et/ou breaklimit",
	"Line too much shrunk $1 $2 $3": "Ligne trop compressée $1 $2 $3",
	"Line underfull ($1pt of $2pt)": "Trop d'espacement ($1pt of $2pt)",
	"Misplaced '$1' in %%score": "'$1' mal placé dans %%score",
︙
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129







-
+







	"No end of tuplet in this music line":
				"Pas de fin de tuplet dans cette ligne de musique",
	"No end of voice overlay": "Pas de fin de superposition de voix",
	"No function for decoration '$1'": "Pas de fonction pour décoration '$1'",
	"No note before '-'": "Pas de note devant '-'",
	"No note before '<'": "Pas de note devant '<'",
	"No note in voice overlay": "Pas de note dans voix superposée",
	"Non standard note duration $1": "Durée de note $1 non standard"
	"Non standard note duration $1": "Durée de note $1 non standard",
	"No read_file support": "La fonction read_file n'existe pas",
	"No start of !$1!": "Pas de début pour !$1!",
	"Not an ASCII character": "Ce n'est pas un caractère ASCII",
	"Not enough measure bars for lyric line":
				"Pas assez de barres pour la ligne de paroles",
	"Not enough measure bars for symbol line":
				"Pas assez de barres pour ligne s:",
︙
Changes to err-it.js.
︙
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
19
20
21
22
23
24
25

26
27
28
29
30
31


32
33
34
35
36
37
38







-






-
-







	"$1: inside tune - ignored": "$1: nel corpo del brano - ignorato",
	"!$1! must be on a note": "!$1! deve stare su di una nota",
	"!$1! must be on a note or a rest":
				"!$1! deve stare su una nota o su una pausa",
	"!$1! must be on the last of a couple of notes":
				"!$1! deve stare sulla seconda di due note",
	"!beamon! must be on a bar": "!beamon! deve stare su una stanghetta",
	"!xstem! must be on a note": "!xstem! deve stare su una nota",
	"%%deco: abnormal h/wl/wr value '$1'":
				"%%deco: valore '$1' illegale per h/wl/wr",
	"%%deco: bad C function index '$1'":
				"%%deco: indice errato per la funzione C '$1'",
	"%%deco: bad C function value '$1'":
				"%%deco: valore errato per la funzione C '$1'",
	"%%deco: cannot have a negative value '$1'":
				"%%deco: '$1' non può avere un valore negativo",
	"%%multicol end without start": "%%multicol end senza start",
	"%%multicol new without start": "%%multicol new senza start",
	"%%repeat cannot start a tune": "%%repeat non può stare all'inizio del brano",
	"%%staffwidth too big": "%%staffwidth troppo grande",
	"%%staffwidth too small": "%%staffwidth troppo piccolo",
	"%%tune not treated yet": "%%tune non ancora gestito",
	"%%vskip cannot be negative": "%%vskip non può essere negativo",
︙
52
53
54
55
56
57
58

59
60
61
62
63
64
65
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63







+







				"Carattere errato nelle note di abbellimento",
	"Bad controller number in %%MIDI": "Numero errato del controller in %%MIDI",
	"Bad controller value in %%MIDI": "Valore errato del controller in %%MIDI",
	"Bad duration '$1' in M:": "Durata '$1' errata in M:",
	"Bad integer value": "Valore intero errato",
	"Bad instr= value": "Valore errato di instr=",
	"Bad L: value": "Valore errato per L:",
	"Bad measure duration": "Bad measure duration",
	"Bad note in %%map": "Nota errata in %%map",
	"Bad page width": "Larghezza di pagina errata",
	"Bad program in %%MIDI": "Numero di programma non valido in %%MIDI",
	"Bad scale value in %%font": "Valore di scala non valido in %%font",
	"Bad tempo value": "Bad tempo value",
	"Bad tie": "Legatura non valida",
	"Bad transpose value": "Valore non valido per la trasposizione",
︙
77
78
79
80
81
82
83

84

85
86
87
88
89
90



91
92
93
94
95
96
97
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+

+






+
+
+







			"'Broken rhythm' non consentito nelle note di abbellimento",
	"Cannot have V:* in tune body":
			"V:* non consentito nel corpo del brano",
	"Cannot read file '$1'": "File '$1' inesistente",
	"Decoration ignored": "Decorazione ignorata",
	"Empty line in tune header - ignored":
				"Linea vuota nella testata - ignorata",
	"End of slur without start": "End of slur without start",
	"Erroneous end of voice overlap": "Fine di voice overlay errata",
	"Error loading the module $1": "Error loading the module $1",
	"Incorrect 1st value in %%repeat": "Primo valore in %%repeat errato",
	"Incorrect 2nd value in %%repeat": "Secondo valore in %%repeat errato",
	"Invalid 'r' in tuplet": "'r' non valido in gruppo irregolare",
	"Invalid decoration '$1'": "Decorazione '$1' non valida",
	"Invalid note duration $1": "Durée de note $1 non valida",
	"Lack of ']'": "']' mancante",
	"Lack of bar after multi-measure rest":
				"Lack of bar after multi-measure rest",
	"Lack of ending slur(s)": "Lack of ending slur(s)",
	'Lack of starting [, ! or " in U: / %%user':
				'U: / %%user non inizia con [, ! o "',
	"Line split problem - adjust maxshrink and/or breaklimit":
		"Problema di linea divisa - modificare maxshrink e/o breaklimit",
	"Line too much shrunk $1 $2 $3": "Linea troppo compressa $1 $2 $3",
	"Line underfull ($1pt of $2pt)": "Linea troppo vuota ($1pt di $2pt)",
	"Misplaced '$1' in %%score": "'$1' in posizione errata in %%score",
︙
Changes to err-pt_BR.js.
︙
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
18
19
20
21
22
23
24

25
26
27
28
29
30


31
32
33
34
35
36
37







-






-
-







	"$1: inside tune - ignored": "$1: no meio da música - ignorando",
	"!$1! must be on a note": "!$1! deveria estar em uma nota",
	"!$1! must be on a note or a rest":
				"!$1! deveria estar em uma nota ou pausa",
	"!$1! must be on the last of a couple of notes":
				"!$1! deveria estar na segunda nota de um par de notas",
	"!beamon! must be on a bar": "!beamon! deveria estar em uma barra de compasso",
	"!xstem! must be on a note": "!xstem! deveria estar em uma nota",
	"%%deco: abnormal h/wl/wr value '$1'":
				"%%deco: '$1' é um valor anormal para h/wl/wr",
	"%%deco: bad C function index '$1'":
				"%%deco: índice de função '$1' incorreto",
	"%%deco: bad C function value '$1'":
				"%%deco: valor de função '$1' incorreto",
	"%%deco: cannot have a negative value '$1'":
				"%%deco: valor '$1' não pode ser negativo",
	"%%multicol end without start": "%%multicol end sem 'start'",
	"%%multicol new without start": "%%multicol new sem 'start'",
	"%%repeat cannot start a tune": "%%repeat não pode estar no início de uma música",
	"%%staffwidth too big": "%%staffwidth muito grande",
	"%%staffwidth too small": "%%staffwidth muito pequeno",
	"%%tune not treated yet": "%%tune ainda não é tratado",
	"%%vskip cannot be negative": "%%vskip não pode ser negativo",
︙
51
52
53
54
55
56
57

58
59
60
61
62
63
64
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+







				"Caráter inválido em grupo de notinhas ornamentais",
	"Bad controller number in %%MIDI": "Número inválido do controlador em %%MIDI",
	"Bad controller value in %%MIDI": "Valor incorreto para controlador em %%MIDI",
	"Bad duration '$1' in M:": "Duração '$1' incorreta em M:",
	"Bad integer value": "Número inteiro incorreto",
	"Bad instr= value": "Valor incorreto para instr=",
	"Bad L: value": "Valor incorreto de L:",
	"Bad measure duration": "Bad measure duration",
	"Bad note in %%map": "Nota incorreta em %%map",
	"Bad page width": "Largura de página incorreta",
	"Bad program in %%MIDI": "Valor incorreto de instrumento %%MIDI",
	"Bad scale value in %%font": "Tamanho incorreto em %%font",
	"Bad tempo value": "Bad tempo value",
	"Bad tie": "Ligadura de prolongamento incorreta",
	"Bad transpose value": "Valor incorreto de transposição",
︙
75
76
77
78
79
80
81

82

83
84
85
86
87
88



89
90
91
92
93
94
95
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98







+

+






+
+
+







	"Cannot have a broken rhythm in grace notes":
			"Não pode haver ritmo quebrado em notinhas ornamentais",
	"Cannot have V:* in tune body": "Não pode haver V:* no corpo da música",
	"Cannot read file '$1'": "Arquivo '$1' não pôde ser aberto ou não existe",
	"Decoration ignored": "Decoração ignorada",
	"Empty line in tune header - ignored":
				"Linha em branco no cabeçalho da música - ignorada",
	"End of slur without start": "End of slur without start",
	"Erroneous end of voice overlay": "Terminação incorreta de superposição de vozes",
	"Error loading the module $1": "Error loading the module $1",
	"Incorrect 1st value in %%repeat": "Primeiro valor incorreto em %%repeat",
	"Incorrect 2nd value in %%repeat": "Segundo valor incorreto em %%repeat",
	"Invalid 'r' in tuplet": "'r' inválido em quiáltera",
	"Invalid decoration '$1'": "Decoração '$1' inválida",
	"Invalid note duration $1": "Duração de nota $1 inválida",
	"Lack of ']'": "']' faltando",
	"Lack of bar after multi-measure rest":
				"Lack of bar after multi-measure rest",
	"Lack of ending slur(s)": "Lack of ending slur(s)",
	'Lack of starting [, ! or " in U: / %%user':
				'U: / %%user não começou com [, ! ou "',
	"Line split problem - adjust maxshrink and/or breaklimit":
		"Problema de quebra de linha - ajuste maxshrink e/ou breaklimit",
	"Line too much shrunk $1 $2 $3": "Linha muito encolhida $1 $2 $3",
	"Line underfull ($1pt of $2pt)": "Linha muito espaçada ($1pt de $2pt)",
	"Misplaced '$1' in %%score": "'$1' deslocado em %%score",
︙
Changes to font/abc2svg.sfd.
︙
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29







-
+







Layer: 0 1 "Back" 1
Layer: 1 0 "Fore" 0
XUID: [1021 296 1430826605 13506888]
OS2Version: 0
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 0
CreationTime: 1433498007
ModificationTime: 1572276737
ModificationTime: 1596553937
PfmFamily: 17
TTFWeight: 400
TTFWidth: 5
LineGap: 92
VLineGap: 92
Panose: 2 0 5 3 0 0 0 0 0 0
OS2TypoAscent: 0
︙
46
47
48
49
50
51
52
53

54
55
56
57

58
59
60
61
62
63
64
46
47
48
49
50
51
52

53
54
55
56

57
58
59
60
61
62
63
64







-
+



-
+







Encoding: Custom
Compacted: 1
UnicodeInterp: none
NameList: Adobe Glyph List
DisplaySize: -96
AntiAlias: 1
FitToEm: 1
WinInfo: 128 8 2
WinInfo: 64 8 2
BeginPrivate: 0
EndPrivate
TeXData: 1 0 0 346030 173015 115343 0 1048576 115343 783286 444596 497025 792723 393216 433062 380633 303038 157286 324010 404750 52429 2506097 1059062 262144
BeginChars: 143 143
BeginChars: 142 142

StartChar: .nodef
Encoding: 0 0 0
Width: 400
Flags: M
LayerCount: 2
Fore
︙
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
109
110
111
112
113
114
115
















































116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+















-
+















-
+















-
+




















-
+







 0 193 5 228 18 269 c 0
 42 335 53 385 53 419 c 0
 53 463 35 499 0 515 c 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE022
Encoding: 3 57378 3
Width: 330
Flags: MW
LayerCount: 2
Fore
SplineSet
-80 20 m 5
 410 20 l 5
 410 -20 l 5
 -80 -20 l 5
 -80 20 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE023
Encoding: 4 57379 4
Width: 531
Flags: MW
LayerCount: 2
Fore
SplineSet
-80 20 m 1
 610 20 l 5
 610 -20 l 1
 -80 -20 l 1
 -80 20 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE024
Encoding: 5 57380 5
Width: 210
Flags: HMW
LayerCount: 2
Fore
SplineSet
-80 20 m 1
 290 20 l 1
 290 -20 l 1
 -80 -20 l 1
 -80 20 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE030
Encoding: 6 57392 6
Encoding: 3 57392 3
Width: 35
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 1000 m 5
 35 1000 l 5
 35 0 l 5
 0 0 l 5
 0 1000 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE038
Encoding: 7 57400 7
Encoding: 4 57400 4
Width: 35
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 1000 m 1
 35 1000 l 1
 35 500 l 1
 0 500 l 1
 0 1000 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE039
Encoding: 8 57401 8
Encoding: 5 57401 5
Width: 35
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 1100 m 1
 35 1110 l 5
 35 760 l 1
 0 760 l 1
 0 1100 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE043
Encoding: 9 57411 9
Encoding: 6 57411 6
Width: 100
Flags: MW
LayerCount: 2
Fore
SplineSet
50 570 m 3
 22 570 0 592 0 620 c 3
 0 648 22 670 50 670 c 3
 78 670 100 648 100 620 c 3
 100 592 78 570 50 570 c 3
50 320 m 7
 22 320 0 342 0 370 c 7
 0 398 22 420 50 420 c 7
 78 420 100 398 100 370 c 7
 100 342 78 320 50 320 c 7
EndSplineSet
Validated: 1
EndChar

StartChar: uniE045
Encoding: 10 57413 10
Encoding: 7 57413 7
Width: 1059
Flags: HMW
LayerCount: 2
Fore
SplineSet
590 0 m 24
 590 160 l 24
︙
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251







-
+







 470 60 370 0 220 0 c 0
 147 0 73 0 0 0 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE046
Encoding: 11 57414 11
Encoding: 8 57414 8
Width: 1061
Flags: HMW
LayerCount: 2
Fore
SplineSet
770 0 m 0
 636 0 550 70 550 210 c 0
︙
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302







-
+







 470 60 370 0 220 0 c 0
 147 0 73 0 0 0 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE047
Encoding: 12 57415 12
Encoding: 9 57415 9
Width: 480
Flags: HMW
LayerCount: 2
Fore
SplineSet
398 338 m 3
 376 338 358 356 358 378 c 3
︙
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352







-
+







 328 5 299 2 271 2 c 0
 203 2 167 51 167 91 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE048
Encoding: 13 57416 13
Encoding: 10 57416 10
Width: 862
Flags: MW
LayerCount: 2
Fore
SplineSet
472 596 m 1
 512 596 l 1
︙
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396







-
+







 412 409 364 361 360 216 c 1
 472 216 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE050
Encoding: 14 57424 14
Encoding: 11 57424 11
Width: 779
Flags: HMW
LayerCount: 2
Fore
SplineSet
364 851 m 0
 359 812 357 782 357 751 c 0
︙
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452







-
+







 387 -222 397 -221 408 -220 c 0
 375 138 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE05C
Encoding: 15 57436 15
Encoding: 12 57436 12
Width: 722
Flags: MW
LayerCount: 2
Fore
SplineSet
478 -480 m 0
 567 -480 614 -375 614 -286 c 0
︙
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518







-
+







 0 -514 l 1
 0 510 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE062
Encoding: 16 57442 16
Encoding: 13 57442 13
Width: 703
Flags: HMW
LayerCount: 2
Fore
SplineSet
19 29 m 0
 19 161 125 255 261 255 c 0
︙
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556







-
+







 681 174 702 153 702 127 c 0
 702 94 682 72 655 72 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE069
Encoding: 17 57449 17
Encoding: 14 57449 14
Width: 470
Flags: W
VStem: 0 150<-250 250> 220 150<-250 250>
LayerCount: 2
Fore
SplineSet
220 250 m 1
︙
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
564
565
566
567
568
569
570

571
572
573
574
575
576
577
578







-
+







 0 -250 l 1
 0 250 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE07A
Encoding: 18 57466 18
Encoding: 15 57466 15
Width: 779
Flags: MW
LayerCount: 2
Fore
SplineSet
329 117 m 1
 329 117 348 -79 354 -170 c 1
︙
672
673
674
675
676
677
678
679

680
681
682
683
684
685
686
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638







-
+







 442 749 433 790 401 820 c 1
 331 792 299 728 290 658 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE07B
Encoding: 19 57467 19
Encoding: 16 57467 16
Width: 782
Flags: MW
LayerCount: 2
Fore
SplineSet
382 -384 m 0
 453 -384 491 -300 491 -229 c 0
︙
738
739
740
741
742
743
744
745

746
747
748
749
750
751
752
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704







-
+







 0 -411 l 1
 0 408 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE07C
Encoding: 20 57468 20
Encoding: 17 57468 17
Width: 807
Flags: MW
LayerCount: 2
Fore
SplineSet
15 33 m 0
 15 139 104 204 209 204 c 0
︙
776
777
778
779
780
781
782
783

784
785
786
787
788
789
790
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742







-
+







 545 139 562 123 562 102 c 0
 562 76 546 58 524 58 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE07D
Encoding: 21 57469 21
Encoding: 18 57469 18
Width: 200
Flags: HMW
LayerCount: 2
Fore
SplineSet
80 119 m 1
 55 105 45 90 45 70 c 0
︙
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
758
759
760
761
762
763
764

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793







-
+




















-
+







 164 110 180 90 180 70 c 0
 180 27 140 0 90 0 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE080
Encoding: 22 57472 22
Encoding: 19 57472 19
Width: 430
Flags: HMW
LayerCount: 2
Fore
SplineSet
138 0 m 1
 138 -130 168 -218 215 -218 c 1
 260 -218 292 -130 292 0 c 1
 292 130 268 218 215 218 c 1
 165 218 138 130 138 0 c 1
0 3 m 1
 0 140 95 250 215 250 c 1
 335 250 430 140 430 0 c 1
 430 -140 335 -250 215 -250 c 1
 95 -250 0 -140 0 3 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE081
Encoding: 23 57473 23
Encoding: 20 57473 20
Width: 290
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 25
 100 250 l 25
︙
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863
801
802
803
804
805
806
807

808
809
810
811
812
813
814
815







-
+







 115 100 l 29
 0 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE082
Encoding: 24 57474 24
Encoding: 21 57474 21
Width: 400
Flags: HMW
HStem: -250 500
VStem: 0 400
LayerCount: 2
Fore
SplineSet
︙
884
885
886
887
888
889
890
891

892
893
894
895
896
897
898
836
837
838
839
840
841
842

843
844
845
846
847
848
849
850







-
+







 28 25 0 60 0 128 c 0
 0 213 102 250 199 250 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE083
Encoding: 25 57475 25
Encoding: 22 57475 22
Width: 380
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
102 170 m 1
︙
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
873
874
875
876
877
878
879

880
881
882
883
884
885
886
887







-
+







 252 177 223 213 175 213 c 0
 131 213 109 193 102 170 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE084
Encoding: 26 57476 26
Encoding: 23 57476 23
Width: 400
Flags: HMW
HStem: -250 500
VStem: 0 400
LayerCount: 2
Fore
SplineSet
︙
952
953
954
955
956
957
958
959

960
961
962
963
964
965
966
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918







-
+







 325 -160 l 5
 325 -209 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE085
Encoding: 27 57477 27
Encoding: 24 57477 24
Width: 400
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
18 -95 m 0
︙
987
988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
939
940
941
942
943
944
945

946
947
948
949
950
951
952
953







-
+







 25 -217 0 -176 0 -152 c 0
 0 -135 3 -113 18 -95 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE086
Encoding: 28 57478 28
Encoding: 25 57478 25
Width: 385
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
200 -210 m 0
︙
1017
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
969
970
971
972
973
974
975

976
977
978
979
980
981
982
983







-
+







 1 133 74 250 200 250 c 0
 257 250 298 244 340 205 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE087
Encoding: 29 57479 29
Encoding: 26 57479 26
Width: 400
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
97 161 m 0
︙
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006







-
+







 305 125 280 121 268 121 c 0
 194 121 173 161 97 161 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE088
Encoding: 30 57480 30
Encoding: 27 57480 27
Width: 400
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
154 -42 m 1
︙
1071
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037







-
+







 93 -250 0 -194 0 -130 c 0
 0 -77 50 -44 108 -16 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE089
Encoding: 31 57481 31
Encoding: 28 57481 28
Width: 385
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
185 210 m 0
︙
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110
1111
1112
1113
1114
1115
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067







-
+







 384 -133 311 -250 185 -250 c 0
 128 -250 87 -244 45 -205 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE08A
Encoding: 32 57482 32
Encoding: 29 57482 29
Width: 409
Flags: HMW
LayerCount: 2
Fore
SplineSet
303 164 m 1
 311 163 315 162 321 161 c 1
︙
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1085
1086
1087
1088
1089
1090
1091

1092
1093
1094
1095
1096
1097
1098
1099







-
+







 244 130 265 164 302 164 c 2
 303 164 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE08B
Encoding: 33 57483 33
Encoding: 30 57483 30
Width: 408
Flags: MW
LayerCount: 2
Fore
SplineSet
303 164 m 1
 311 163 315 162 321 161 c 1
︙
1178
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1144







-
+







 119 -58 126 -133 158 -175 c 0
 165 -184 172 -191 180 -197 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE08C
Encoding: 34 57484 34
Encoding: 31 57484 31
Width: 500
Flags: HMW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
0 35 m 25
︙
1203
1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180

1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1206







-
+


















-
+

















-
+







 0 -35 l 25
 0 35 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE094
Encoding: 35 57492 35
Encoding: 32 57492 32
Width: 260
Flags: MW
HStem: -250 500
LayerCount: 2
Fore
SplineSet
220 -490 m 0
 228 -500 208 -509 200 -500 c 4
 105 -388 20 -171 20 0 c 0
 20 170 105 388 200 500 c 0
 211 513 231 503 220 490 c 0
 136 388 90 170 90 0 c 0
 90 -169 138 -388 220 -490 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE095
Encoding: 36 57493 36
Encoding: 33 57493 33
Width: 260
Flags: HMW
LayerCount: 2
Fore
SplineSet
20 -490 m 0
 102 -388 150 -169 150 0 c 0
 150 170 104 388 20 490 c 0
 9 503 29 513 40 500 c 0
 135 388 220 170 220 0 c 0
 220 -171 135 -388 40 -500 c 0
 32 -509 12 -500 20 -490 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A0
Encoding: 37 57504 37
Encoding: 34 57504 34
Width: 619
Flags: HMW
LayerCount: 2
Fore
SplineSet
424 -32 m 0
 424 38 361 99 280 99 c 0
︙
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281
1282
1283
1284
1285
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1237







-
+







 87 85 176 130 312 130 c 0
 448 130 537 80 537 0 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A1
Encoding: 38 57505 38
Encoding: 35 57505 35
Width: 530
Flags: HMW
LayerCount: 2
Fore
SplineSet
30 65 m 25
 30 -65 l 25
︙
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287







-
+




















-
+







 0 -220 l 25
 0 220 l 29
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A2
Encoding: 39 57506 39
Encoding: 36 57506 36
Width: 450
Flags: HMW
LayerCount: 2
Fore
SplineSet
337 -30 m 4
 337 40 264 101 193 101 c 4
 154 101 109 75 109 31 c 4
 109 -40 186 -97 257 -97 c 4
 298 -97 337 -75 337 -30 c 4
450 0 m 4
 450 -70 361 -129 225 -129 c 4
 89 -129 0 -70 0 0 c 4
 0 70 89 129 225 129 c 4
 361 129 450 70 450 0 c 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A3
Encoding: 40 57507 40
Encoding: 37 57507 37
Width: 329
Flags: MW
LayerCount: 2
Fore
SplineSet
292 68 m 4
 283 84 264 91 242 91 c 4
︙
1346
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328







-
+















-
+







 0 70 105 148 198 148 c 4
 245 148 288 128 313 81 c 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A4
Encoding: 41 57508 41
Encoding: 38 57508 38
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
320 40 m 4
 320 -51 231 -135 110 -135 c 4
 40 -135 0 -90 0 -40 c 4
 0 50 90 135 210 135 c 4
 280 135 320 90 320 40 c 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0A9
Encoding: 42 57513 42
Encoding: 39 57513 39
Width: 330
Flags: HMW
LayerCount: 2
Fore
SplineSet
-2 113 m 1
 25 145 l 1
︙
1386
1387
1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399
1400
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352







-
+







 132 -0 l 1
 -2 113 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE0B3
Encoding: 43 57523 43
Encoding: 40 57523 40
Width: 300
Flags: HMW
LayerCount: 2
Fore
SplineSet
150 -18 m 1
 79 -90 l 1
︙
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480

1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414

1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
1476







-
+















-
+

















-
+
















-
+















-
+




















-
+







 300 -83 233 -150 150 -150 c 24
 67 -150 0 -83 0 0 c 24
EndSplineSet
Validated: 1
EndChar

StartChar: uniE101
Encoding: 44 57601 44
Encoding: 41 57601 41
Width: 560
Flags: W
LayerCount: 2
Fore
SplineSet
0 -250 m 5
 440 250 l 5
 560 250 l 5
 119 -250 l 5
 0 -250 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1B9
Encoding: 45 57785 45
Encoding: 42 57785 42
Width: 330
Flags: W
HStem: -140 280
VStem: 0 330
LayerCount: 2
Fore
SplineSet
0 0 m 1
 165 140 l 1
 330 0 l 1
 165 -140 l 1
 0 0 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1BB
Encoding: 46 57787 46
Encoding: 43 57787 43
Width: 330
Flags: W
HStem: -140 280
VStem: 0 330
LayerCount: 2
Fore
SplineSet
0 -140 m 29
 165 140 l 25
 330 -140 l 29
 0 -140 l 29
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1E7
Encoding: 47 57831 47
Encoding: 44 57831 44
Width: 100
Flags: MW
LayerCount: 2
Fore
SplineSet
50 -50 m 3
 22 -50 0 -28 0 0 c 3
 0 28 22 50 50 50 c 3
 78 50 100 28 100 0 c 3
 100 -28 78 -50 50 -50 c 3
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1F2
Encoding: 48 57842 48
Encoding: 45 57842 45
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 680 m 1
 320 680 l 1
 320 40 l 2
 320 -51 231 -135 110 -135 c 0
 40 -135 0 -90 0 -40 c 0
 0 50 90 135 210 135 c 0
 244 135 271 124 290 107 c 1
 290 560 l 1
 0 560 l 1
 0 680 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1F4
Encoding: 49 57844 49
Encoding: 46 57844 46
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 680 m 1
 320 680 l 1
︙
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613

1614
1615
1616
1617
1618
1619
1620
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546

1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564

1565
1566
1567
1568
1569
1570
1571
1572







-
+















-
+




















-
+















-
+

















-
+







 0 560 l 1
 0 680 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1F7
Encoding: 50 57847 50
Encoding: 47 57847 47
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 680 m 25
 320 680 l 29
 320 560 l 25
 0 560 l 25
 0 680 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1F9
Encoding: 51 57849 51
Encoding: 48 57849 48
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 500 m 25
 320 500 l 25
 320 380 l 25
 0 380 l 29
 0 500 l 25
0 680 m 25
 320 680 l 25
 320 560 l 25
 0 560 l 25
 0 680 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1FC
Encoding: 52 57852 52
Encoding: 49 57852 49
Width: 100
Flags: HMW
LayerCount: 2
Fore
SplineSet
50 -38 m 7
 22 -38 0 -16 0 12 c 7
 0 40 22 62 50 62 c 7
 78 62 100 40 100 12 c 7
 100 -16 78 -38 50 -38 c 7
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1FE
Encoding: 53 57854 53
Encoding: 50 57854 50
Width: 310
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 960 m 29
 310 960 l 29
 310 930 l 29
 30 930 l 29
 30 770 l 29
 0 770 l 29
 0 960 l 29
EndSplineSet
Validated: 1
EndChar

StartChar: uniE1FF
Encoding: 54 57855 54
Encoding: 51 57855 51
Width: 230
Flags: HMW
LayerCount: 2
Fore
SplineSet
80 810 m 0
 27 810 0 833 0 864 c 0
︙
1640
1641
1642
1643
1644
1645
1646
1647

1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665

1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684

1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703

1704
1705
1706
1707
1708
1709
1710
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1662







-
+

















-
+


















-
+


















-
+







 160 933 180 916 180 890 c 0
 180 847 149 810 80 810 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE200
Encoding: 55 57856 55
Encoding: 52 57856 52
Width: 310
Flags: HMW
LayerCount: 2
Fore
SplineSet
310 960 m 25
 310 770 l 25
 280 770 l 25
 280 930 l 25
 0 930 l 25
 0 960 l 25
 310 960 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE240
Encoding: 56 57920 56
Encoding: 53 57920 53
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -239 m 13
 0 0 l 5
 30 0 l 5
 51 -195 315 -321 315 -584 c 4
 315 -643 302 -710 269 -785 c 5
 282 -738 287 -691 287 -647 c 4
 287 -452 175 -294 30 -239 c 5
 0 -239 l 13
EndSplineSet
Validated: 1
EndChar

StartChar: uniE241
Encoding: 57 57921 57
Encoding: 54 57921 54
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 1
 0 239 l 1
 30 239 l 1
 178 280 288 445 288 642 c 0
 288 688 282 736 269 785 c 1
 302 711 315 647 315 588 c 0
 315 328 51 195 30 0 c 0
 0 0 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE242
Encoding: 58 57922 58
Encoding: 55 57922 55
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -343 m 13
 0 0 l 5
︙
1721
1722
1723
1724
1725
1726
1727
1728

1729
1730
1731
1732
1733
1734
1735
1673
1674
1675
1676
1677
1678
1679

1680
1681
1682
1683
1684
1685
1686
1687







-
+







 291 -485 292 -479 292 -472 c 4
 292 -278 101 -171 30 -171 c 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE243
Encoding: 59 57923 59
Encoding: 56 57923 56
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -1 m 9
 0 342 l 1
︙
1746
1747
1748
1749
1750
1751
1752
1753

1754
1755
1756
1757
1758
1759
1760
1698
1699
1700
1701
1702
1703
1704

1705
1706
1707
1708
1709
1710
1711
1712







-
+







 292 479 291 484 291 491 c 1
 226 365 56 278 30 171 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE244
Encoding: 60 57924 60
Encoding: 57 57924 57
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -368 m 9
 0 145 l 1
︙
1779
1780
1781
1782
1783
1784
1785
1786

1787
1788
1789
1790
1791
1792
1793
1731
1732
1733
1734
1735
1736
1737

1738
1739
1740
1741
1742
1743
1744
1745







-
+







 292 -135 105 -28 32 -28 c 0
 31 -28 31 -28 30 -28 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE245
Encoding: 61 57925 61
Encoding: 58 57925 58
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 343 m 17
 30 343 l 1
︙
1810
1811
1812
1813
1814
1815
1816
1817

1818
1819
1820
1821
1822
1823
1824
1762
1763
1764
1765
1766
1767
1768

1769
1770
1771
1772
1773
1774
1775
1776







-
+







 292 480 291 486 291 493 c 1
 226 367 56 280 30 171 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE246
Encoding: 62 57926 62
Encoding: 59 57926 59
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -344 m 9
 0 340 l 1
︙
1847
1848
1849
1850
1851
1852
1853
1854

1855
1856
1857
1858
1859
1860
1861
1799
1800
1801
1802
1803
1804
1805

1806
1807
1808
1809
1810
1811
1812
1813







-
+







 291 -145 292 -139 292 -132 c 0
 292 62 101 169 30 169 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE247
Encoding: 63 57927 63
Encoding: 60 57927 60
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -370 m 9
 0 314 l 1
︙
1884
1885
1886
1887
1888
1889
1890
1891

1892
1893
1894
1895
1896
1897
1898
1836
1837
1838
1839
1840
1841
1842

1843
1844
1845
1846
1847
1848
1849
1850







-
+







 292 450 291 457 291 464 c 1
 226 338 56 251 30 142 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE248
Encoding: 64 57928 64
Encoding: 61 57928 61
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -325 m 9
 0 530 l 1
︙
1927
1928
1929
1930
1931
1932
1933
1934

1935
1936
1937
1938
1939
1940
1941
1879
1880
1881
1882
1883
1884
1885

1886
1887
1888
1889
1890
1891
1892
1893







-
+







 291 45 292 51 292 58 c 0
 292 252 101 359 30 359 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE249
Encoding: 65 57929 65
Encoding: 62 57929 62
Width: 315
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 -580 m 9
 0 275 l 1
︙
1970
1971
1972
1973
1974
1975
1976
1977

1978
1979
1980
1981
1982
1983
1984
1922
1923
1924
1925
1926
1927
1928

1929
1930
1931
1932
1933
1934
1935
1936







-
+







 292 411 291 418 291 425 c 1
 226 299 56 213 30 103 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE260
Encoding: 66 57952 66
Encoding: 63 57952 63
Width: 269
Flags: HMW
LayerCount: 2
Fore
SplineSet
103 122 m 0
 77 122 40 90 40 65 c 2
︙
1995
1996
1997
1998
1999
2000
2001
2002

2003
2004
2005
2006
2007
2008
2009
1947
1948
1949
1950
1951
1952
1953

1954
1955
1956
1957
1958
1959
1960
1961







-
+







 40 108 l 1
 63 142 93 160 133 160 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE261
Encoding: 67 57953 67
Encoding: 64 57953 64
Width: 200
Flags: MW
LayerCount: 2
Fore
SplineSet
28 -101 m 1
 172 -56 l 1
︙
2021
2022
2023
2024
2025
2026
2027
2028

2029
2030
2031
2032
2033
2034
2035
1973
1974
1975
1976
1977
1978
1979

1980
1981
1982
1983
1984
1985
1986
1987







-
+







 1 377 l 1
 28 378 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE262
Encoding: 68 57954 68
Encoding: 65 57954 65
Width: 255
Flags: HMW
LayerCount: 2
Fore
SplineSet
83 70 m 21
 83 -97 l 5
︙
2066
2067
2068
2069
2070
2071
2072
2073

2074
2075
2076
2077
2078
2079
2080
2018
2019
2020
2021
2022
2023
2024

2025
2026
2027
2028
2029
2030
2031
2032







-
+







 83 -189 l 5
 83 -360 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE263
Encoding: 69 57955 69
Encoding: 66 57955 66
Width: 267
Flags: MW
LayerCount: 2
Fore
SplineSet
195 -124 m 9
 195 -65 l 25
︙
2102
2103
2104
2105
2106
2107
2108
2109

2110
2111
2112
2113
2114
2115
2116
2054
2055
2056
2057
2058
2059
2060

2061
2062
2063
2064
2065
2066
2067
2068







-
+







 267 -124 l 1
 195 -124 l 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE264
Encoding: 70 57956 70
Encoding: 67 57956 67
Width: 366
Flags: HMW
LayerCount: 2
Fore
SplineSet
78 125 m 1
 55 124 31 100 31 78 c 2
︙
2147
2148
2149
2150
2151
2152
2153
2154




































2155
2156

2157
2158
2159
2160
2161
2162
2163
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143

2144
2145
2146
2147
2148
2149
2150
2151








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+







 189 432 l 1
 219 432 l 1
 219 113 l 1
 235 143 256 163 291 163 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE26a
Encoding: 68 57962 68
Width: 140
Flags: HMW
LayerCount: 2
Fore
SplineSet
140 250 m 9
 140 230 l 17
 110 205 60 145 60 0 c 0
 60 -145 110 -206 140 -230 c 9
 140 -250 l 17
 90 -220 0 -160 0 0 c 0
 0 160 90 220 140 250 c 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE26b
Encoding: 69 57963 69
Width: 140
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 250 m 17
 50 220 140 160 140 0 c 0
 140 -160 50 -220 0 -250 c 9
 0 -230 l 17
 30 -206 80 -145 80 0 c 0
 80 145 30 205 0 230 c 9
 0 250 l 17
EndSplineSet
Validated: 1
EndChar

StartChar: uniE280
Encoding: 71 57984 71
Encoding: 70 57984 70
Width: 269
Flags: HMW
LayerCount: 2
Fore
SplineSet
171 122 m 0
 140 122 116 92 116 57 c 0
︙
2174
2175
2176
2177
2178
2179
2180
2181

2182
2183
2184
2185
2186
2187
2188
2162
2163
2164
2165
2166
2167
2168

2169
2170
2171
2172
2173
2174
2175
2176







-
+







 76 -20 50 28 50 75 c 0
 50 124 97 160 141 160 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE281
Encoding: 72 57985 72
Encoding: 71 57985 71
Width: 366
Flags: HMW
LayerCount: 2
Fore
SplineSet
87 125 m 1
 86 125 l 2
︙
2221
2222
2223
2224
2225
2226
2227
2228

2229
2230
2231
2232
2233
2234
2235
2209
2210
2211
2212
2213
2214
2215

2216
2217
2218
2219
2220
2221
2222
2223







-
+







 219 113 l 1
 235 143 256 163 291 163 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE282
Encoding: 73 57986 73
Encoding: 72 57986 72
Width: 169
Flags: HMW
LayerCount: 2
Fore
SplineSet
68 320 m 8
 98 320 l 1
︙
2253
2254
2255
2256
2257
2258
2259
2260

2261
2262
2263
2264
2265
2266
2267
2241
2242
2243
2244
2245
2246
2247

2248
2249
2250
2251
2252
2253
2254
2255







-
+







 68 152 l 1
 68 320 l 8
EndSplineSet
Validated: 1
EndChar

StartChar: uniE283
Encoding: 74 57987 74
Encoding: 73 57987 73
Width: 314
Flags: HMW
LayerCount: 2
Fore
SplineSet
233 192 m 17
 233 360 l 1
︙
2311
2312
2313
2314
2315
2316
2317
2318

2319
2320
2321
2322
2323
2324
2325
2299
2300
2301
2302
2303
2304
2305

2306
2307
2308
2309
2310
2311
2312
2313







-
+







 233 101 l 1
 172 83 l 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4A0
Encoding: 75 58528 75
Encoding: 74 58528 74
Width: 320
Flags: W
HStem: 0 244<5 15>
VStem: -3 322
LayerCount: 2
Fore
SplineSet
︙
2338
2339
2340
2341
2342
2343
2344
2345

2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362


2363
2364
2365
2366
2367
2368
2369
2370



2371
2372
2373
2374
2375
2376
2377

2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393

2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413

2414
2415
2416
2417
2418
2419
2420
2326
2327
2328
2329
2330
2331
2332

2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348


2349
2350
2351
2352
2353
2354
2355



2356
2357
2358
2359
2360
2361
2362
2363
2364

2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380

2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400

2401
2402
2403
2404
2405
2406
2407
2408







-
+















-
-
+
+





-
-
-
+
+
+






-
+















-
+



















-
+







 319 109 314 101 305 98 c 1
 18 1 l 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4A2
Encoding: 76 58530 76
Encoding: 75 58530 75
Width: 80
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 40 m 24
 0 63 17 80 40 80 c 24
 62 80 80 63 80 40 c 24
 80 18 63 0 40 0 c 24
 18 0 0 18 0 40 c 24
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4A4
Encoding: 77 58532 77
Width: 320
Encoding: 76 58532 76
Width: 340
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 25
 0 40 l 25
 320 40 l 25
 320 0 l 25
 0 50 l 25
 340 50 l 25
 340 0 l 25
 0 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4A8
Encoding: 78 58536 78
Encoding: 77 58536 77
Width: 100
Flags: HMW
LayerCount: 2
Fore
SplineSet
40 0 m 25
 0 280 l 25
 100 280 l 25
 60 0 l 25
 40 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4AC
Encoding: 79 58540 79
Encoding: 78 58540 78
Width: 280
Flags: W
HStem: 0 309
VStem: 0 280
LayerCount: 2
Fore
SplineSet
0 0 m 1
 140 309 l 25
 280 0 l 1
 215 0 l 1
 127 198 l 25
 37 0 l 1
 0 0 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4C0
Encoding: 80 58560 80
Encoding: 79 58560 79
Width: 600
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 1
 0 214 150 330 300 330 c 3
︙
2429
2430
2431
2432
2433
2434
2435
2436

2437
2438
2439
2440
2441
2442
2443
2417
2418
2419
2420
2421
2422
2423

2424
2425
2426
2427
2428
2429
2430
2431







-
+







 332 120 359 92 359 60 c 3
 359 27 333 0 299 0 c 3
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4CE
Encoding: 81 58574 81
Encoding: 80 58574 80
Width: 182
Flags: HMW
LayerCount: 2
Fore
SplineSet
86 301 m 0
 123 301 136 294 156 272 c 0
︙
2451
2452
2453
2454
2455
2456
2457
2458

2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474

2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490

2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506

2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522

2523
2524
2525
2526
2527
2528
2529
2439
2440
2441
2442
2443
2444
2445

2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461

2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477

2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493

2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509

2510
2511
2512
2513
2514
2515
2516
2517







-
+















-
+















-
+















-
+















-
+







 32 156 -0 184 -0 222 c 0
 -0 258 27 301 86 301 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E1
Encoding: 82 58593 82
Encoding: 81 58593 81
Width: 130
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 250 m 1
 130 250 l 1
 130 -250 l 5
 0 -250 l 1
 0 250 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E2
Encoding: 83 58594 83
Encoding: 82 58594 82
Width: 130
Flags: MW
LayerCount: 2
Fore
SplineSet
0 250 m 1
 130 250 l 1
 130 0 l 1
 0 0 l 1
 0 250 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E3
Encoding: 84 58595 84
Encoding: 83 58595 83
Width: 300
Flags: MW
LayerCount: 2
Fore
SplineSet
0 0 m 1
 300 0 l 1
 300 -125 l 1
 0 -125 l 1
 0 0 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E4
Encoding: 85 58596 85
Encoding: 84 58596 84
Width: 300
Flags: MW
LayerCount: 2
Fore
SplineSet
0 125 m 1
 300 125 l 1
 300 0 l 1
 0 0 l 1
 0 125 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E5
Encoding: 86 58597 86
Encoding: 85 58597 85
Width: 238
Flags: MW
LayerCount: 2
Fore
SplineSet
41 391 m 1
 230 162 l 1
︙
2539
2540
2541
2542
2543
2544
2545
2546

2547
2548
2549
2550
2551
2552
2553
2527
2528
2529
2530
2531
2532
2533

2534
2535
2536
2537
2538
2539
2540
2541







-
+







 122 193 l 1
 41 391 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E6
Encoding: 87 58598 87
Encoding: 86 58598 86
Width: 255
Flags: W
HStem: 48 33<112 170.038>
VStem: 0 135<81.9955 177.625>
LayerCount: 2
Fore
SplineSet
︙
2563
2564
2565
2566
2567
2568
2569
2570

2571
2572
2573
2574
2575
2576
2577
2551
2552
2553
2554
2555
2556
2557

2558
2559
2560
2561
2562
2563
2564
2565







-
+







 58 -227 l 1
 171 60 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E7
Encoding: 88 58599 88
Encoding: 87 58599 87
Width: 329
Flags: MW
LayerCount: 2
Fore
SplineSet
171 -196 m 1
 151 -202 140 -208 98 -208 c 0
︙
2592
2593
2594
2595
2596
2597
2598
2599

2600
2601
2602
2603
2604
2605
2606
2580
2581
2582
2583
2584
2585
2586

2587
2588
2589
2590
2591
2592
2593
2594







-
+







 86 -488 l 1
 171 -196 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E8
Encoding: 89 58600 89
Encoding: 88 58600 88
Width: 399
Flags: MW
LayerCount: 2
Fore
SplineSet
246 60 m 1
 226 54 217 48 175 48 c 0
︙
2628
2629
2630
2631
2632
2633
2634
2635

2636
2637
2638
2639
2640
2641
2642
2616
2617
2618
2619
2620
2621
2622

2623
2624
2625
2626
2627
2628
2629
2630







-
+







 158 -176 182 -160 188 -142 c 1
 246 60 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4E9
Encoding: 90 58601 90
Encoding: 89 58601 89
Width: 472
Flags: MW
LayerCount: 2
Fore
SplineSet
171 -452 m 1
 151 -458 140 -464 98 -464 c 0
︙
2671
2672
2673
2674
2675
2676
2677
2678

2679
2680
2681
2682
2683
2684
2685
2659
2660
2661
2662
2663
2664
2665

2666
2667
2668
2669
2670
2671
2672
2673







-
+







 86 -744 l 1
 171 -452 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4EA
Encoding: 91 58602 91
Encoding: 90 58602 90
Width: 472
Flags: MW
LayerCount: 2
Fore
SplineSet
319 52 m 1
 299 46 288 40 246 40 c 0
︙
2721
2722
2723
2724
2725
2726
2727
2728

2729
2730
2731
2732
2733
2734
2735
2709
2710
2711
2712
2713
2714
2715

2716
2717
2718
2719
2720
2721
2722
2723







-
+







 233 -178 257 -162 263 -144 c 1
 319 52 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE4EE
Encoding: 92 58606 92
Encoding: 91 58606 91
Width: 851
Flags: W
HStem: -105 210<25 825>
VStem: 0 25<-230 -105 105 230> 825 25<-230 -105 105 230>
LayerCount: 2
Fore
SplineSet
︙
2747
2748
2749
2750
2751
2752
2753
2754

2755
2756
2757
2758
2759
2760
2761
2735
2736
2737
2738
2739
2740
2741

2742
2743
2744
2745
2746
2747
2748
2749







-
+







 0 -230 l 25
 0 230 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE500
Encoding: 93 58624 93
Encoding: 92 58624 92
Width: 563
Flags: MW
LayerCount: 2
Fore
SplineSet
55 75 m 3
 22 75 -5 102 -5 135 c 3
︙
2773
2774
2775
2776
2777
2778
2779
2780

2781
2782
2783
2784
2785
2786
2787
2761
2762
2763
2764
2765
2766
2767

2768
2769
2770
2771
2772
2773
2774
2775







-
+







 109 -250 l 1
 -16 -250 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE501
Encoding: 94 58625 94
Encoding: 93 58625 93
Width: 800
Flags: W
HStem: -195 120<659.745 752.255> 75 120<-6.25464 86.2546>
VStem: -20 120<88.7454 181.255> 646 120<-181.255 -88.7454>
LayerCount: 2
Fore
SplineSet
︙
2806
2807
2808
2809
2810
2811
2812
2813

2814
2815
2816
2817
2818
2819
2820
2794
2795
2796
2797
2798
2799
2800

2801
2802
2803
2804
2805
2806
2807
2808







-
+







 334 -250 l 5
 212 -250 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE520
Encoding: 95 58656 95
Encoding: 94 58656 94
Width: 379
Flags: HMW
LayerCount: 2
Fore
SplineSet
197 40 m 0
 199 39 201 39 204 39 c 0
︙
2844
2845
2846
2847
2848
2849
2850
2851

2852
2853
2854
2855
2856
2857
2858
2832
2833
2834
2835
2836
2837
2838

2839
2840
2841
2842
2843
2844
2845
2846







-
+







 341 280 380 248 380 180 c 0
 380 87 319 0 220 0 c 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniE521
Encoding: 96 58657 96
Encoding: 95 58657 95
Width: 440
Flags: MW
LayerCount: 2
Fore
SplineSet
80 21 m 4
 76 11 74 1 57 0 c 4
︙
2892
2893
2894
2895
2896
2897
2898
2899

2900
2901
2902
2903
2904
2905
2906
2880
2881
2882
2883
2884
2885
2886

2887
2888
2889
2890
2891
2892
2893
2894







-
+







 170 213 153 206 148 193 c 4
 80 21 l 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniE522
Encoding: 97 58658 97
Encoding: 96 58658 96
Width: 278
Flags: HMW
LayerCount: 2
Fore
SplineSet
-50 -160 m 0
 -90 -160 -130 -135 -130 -90 c 0
︙
2928
2929
2930
2931
2932
2933
2934
2935

2936
2937
2938
2939
2940
2941
2942
2916
2917
2918
2919
2920
2921
2922

2923
2924
2925
2926
2927
2928
2929
2930







-
+







 233 230 229 230 196 230 c 1
 153 -26 80 -160 -50 -160 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE523
Encoding: 98 58659 98
Encoding: 97 58659 97
Width: 275
Flags: HMW
LayerCount: 2
Fore
SplineSet
208 231 m 0
 218 237 218 245 208 245 c 0
︙
2957
2958
2959
2960
2961
2962
2963
2964

2965
2966
2967
2968
2969
2970
2971
2945
2946
2947
2948
2949
2950
2951

2952
2953
2954
2955
2956
2957
2958
2959







-
+







 212 165 190 182 190 200 c 0
 190 216 196 224 208 231 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE524
Encoding: 99 58660 99
Encoding: 98 58660 98
Width: 220
Flags: HMW
LayerCount: 2
Fore
SplineSet
80 0 m 0
 41 0 0 33 0 70 c 0
︙
2987
2988
2989
2990
2991
2992
2993
2994

2995
2996
2997
2998
2999
3000
3001
2975
2976
2977
2978
2979
2980
2981

2982
2983
2984
2985
2986
2987
2988
2989







-
+







 186 137 200 115 200 85 c 0
 200 26 156 0 80 0 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE525
Encoding: 100 58661 100
Encoding: 99 58661 99
Width: 232
Flags: HMW
LayerCount: 2
Fore
SplineSet
-10 3 m 0
 -22 -6 -34 16 -23 26 c 0
︙
3023
3024
3025
3026
3027
3028
3029
3030

3031
3032
3033
3034
3035
3036
3037
3011
3012
3013
3014
3015
3016
3017

3018
3019
3020
3021
3022
3023
3024
3025







-
+







 56 2 50 23 31 23 c 0
 19 23 6 15 -10 3 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE529
Encoding: 101 58665 101
Encoding: 100 58665 100
Width: 703
Flags: HMW
LayerCount: 2
Fore
SplineSet
522 40 m 0
 524.179123831 39.0525548563 526.555731167 38.5988184777 529.0907001 38.5988184777 c 0
︙
3139
3140
3141
3142
3143
3144
3145
3146

3147
3148
3149
3150
3151
3152
3153
3127
3128
3129
3130
3131
3132
3133

3134
3135
3136
3137
3138
3139
3140
3141







-
+







 835.665333312 135.693575703 831.068143327 108.945807045 831.068143327 87.1471403297 c 0
 831.068143327 62.5417301443 836.925393958 44.2419393862 847 40 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE52A
Encoding: 102 58666 102
Encoding: 101 58666 101
Width: 563
Flags: W
HStem: -120 30<-74.2249 10 108 169.668 250.775 335 433 494.668 575.775 660 758 819.668> 0 38.5988<191.014 237.319 516.014 562.319 841.014 887.319> 240 40<80.1149 147.5 239.117 318 404.386 472.5 564.117 643 729.386 797.5 889.117 973>
VStem: 120.421 60.6474<87.1471 224.606> 298.898 81.1023<108.679 217.246> 445.421 60.6474<87.1471 224.606> 623.898 81.1023<108.679 217.246> 770.421 60.6474<87.1471 224.606> 948.898 81.1023<108.462 239.669>
LayerCount: 2
Fore
SplineSet
︙
3231
3232
3233
3234
3235
3236
3237
3238

3239
3240
3241
3242
3243
3244
3245
3219
3220
3221
3222
3223
3224
3225

3226
3227
3228
3229
3230
3231
3232
3233







-
+







 185.665333312 135.693575703 181.068143327 108.945807045 181.068143327 87.1471403297 c 0
 181.068143327 62.5417301443 186.925393958 44.2419393862 197 40 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE52B
Encoding: 103 58667 103
Encoding: 102 58667 102
Width: 703
Flags: HMW
LayerCount: 2
Fore
SplineSet
200 0 m 0
 183 0 173 6 153 32 c 1
︙
3295
3296
3297
3298
3299
3300
3301
3302

3303
3304
3305
3306
3307
3308
3309
3283
3284
3285
3286
3287
3288
3289

3290
3291
3292
3293
3294
3295
3296
3297







-
+







 510.665333312 135.693575703 506.068143327 108.945807045 506.068143327 87.1471403297 c 0
 506.068143327 62.5417301443 511.925393958 44.2419393862 522 40 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE52C
Encoding: 104 58668 104
Encoding: 103 58668 103
Width: 811
Flags: HMW
LayerCount: 2
Fore
SplineSet
429 119 m 0
 480 232 500 280 556 280 c 0
︙
3367
3368
3369
3370
3371
3372
3373
3374

3375
3376
3377
3378
3379
3380
3381
3355
3356
3357
3358
3359
3360
3361

3362
3363
3364
3365
3366
3367
3368
3369







-
+







 616.665333312 135.693575703 612.068143327 108.945807045 612.068143327 87.1471403297 c 0
 612.068143327 62.5417301443 617.925393958 44.2419393862 628 40 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE52D
Encoding: 105 58669 105
Encoding: 104 58669 104
Width: 351
Flags: HMW
LayerCount: 2
Fore
SplineSet
80 21 m 0
 76 11 74 1 57 0 c 0
︙
3440
3441
3442
3443
3444
3445
3446
3447

3448
3449
3450
3451
3452
3453
3454
3428
3429
3430
3431
3432
3433
3434

3435
3436
3437
3438
3439
3440
3441
3442







-
+







 676 230 672 230 639 230 c 1
 596 -26 523 -160 393 -160 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE52F
Encoding: 106 58671 106
Encoding: 105 58671 105
Width: 617
Flags: HMW
LayerCount: 2
Fore
SplineSet
351 230 m 9
 196 230 l 1
︙
3494
3495
3496
3497
3498
3499
3500
3501

3502
3503
3504
3505
3506
3507
3508
3482
3483
3484
3485
3486
3487
3488

3489
3490
3491
3492
3493
3494
3495
3496







-
+







 192 -120 202 -124 217 -124 c 0
 280 -124 284 -35 351 230 c 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE530
Encoding: 107 58672 107
Encoding: 106 58672 106
Width: 351
Flags: HMW
LayerCount: 2
Fore
SplineSet
204 270 m 9
 360 270 l 1
︙
3566
3567
3568
3569
3570
3571
3572
3573

3574
3575
3576
3577
3578
3579
3580
3554
3555
3556
3557
3558
3559
3560

3561
3562
3563
3564
3565
3566
3567
3568







-
+







 295 400 285 404 270 404 c 0
 228 404 217 332 204 270 c 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE531
Encoding: 108 58673 108
Encoding: 107 58673 107
Width: 617
Flags: HMW
LayerCount: 2
Fore
SplineSet
472 271 m 9
 628 270 l 1
︙
3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666
3667
3668
3669
3670
3644
3645
3646
3647
3648
3649
3650

3651
3652
3653
3654
3655
3656
3657
3658







-
+







 562 400 552 404 537 404 c 0
 495 404 485 332 472 271 c 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE539
Encoding: 109 58681 109
Encoding: 108 58681 108
Width: 351
Flags: HMW
LayerCount: 2
Fore
SplineSet
80 0 m 0xd8
 41 0 0 33 0 70 c 0xe8
︙
3734
3735
3736
3737
3738
3739
3740
3741

3742
3743
3744
3745
3746
3747
3748
3722
3723
3724
3725
3726
3727
3728

3729
3730
3731
3732
3733
3734
3735
3736







-
+







 465 230 461 230 428 230 c 1
 385 -26 312 -160 182 -160 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE566
Encoding: 110 58726 110
Encoding: 109 58726 109
Width: 509
Flags: HMW
LayerCount: 2
Fore
SplineSet
310 265 m 1
 183 258 l 1
︙
3774
3775
3776
3777
3778
3779
3780
3781

3782
3783
3784
3785
3786
3787
3788
3762
3763
3764
3765
3766
3767
3768

3769
3770
3771
3772
3773
3774
3775
3776







-
+







 230 0 l 1
 242 40 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE567
Encoding: 111 58727 111
Encoding: 110 58727 110
Width: 437
Flags: W
HStem: -3 72<49.5596 110.739> 0 49<319.775 397.094> 141 71<327.059 386.441> 161 47<36.904 118.027>
VStem: 0 24<64.6579 145.71> 413 24<63.9568 143.617>
LayerCount: 2
Fore
SplineSet
︙
3811
3812
3813
3814
3815
3816
3817
3818

3819
3820
3821
3822
3823
3824
3825
3799
3800
3801
3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813







-
+







 323 68 l 1
 342 55 353 49 368 49 c 0x5c
EndSplineSet
Validated: 1
EndChar

StartChar: uniE569
Encoding: 112 58729 112
Encoding: 111 58729 111
Width: 437
Flags: HMW
LayerCount: 2
Fore
SplineSet
77 -3 m 0
 33 -3 0 54 0 102 c 0
︙
3853
3854
3855
3856
3857
3858
3859
3860

3861
3862
3863
3864
3865
3866
3867
3841
3842
3843
3844
3845
3846
3847

3848
3849
3850
3851
3852
3853
3854
3855







-
+







 92 61 102 51 102 32 c 0
 102 11 93 -1 77 -3 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE56C
Encoding: 113 58732 113
Encoding: 112 58732 112
Width: 580
Flags: W
HStem: 0 224
LayerCount: 2
Fore
SplineSet
34 46 m 13
︙
3878
3879
3880
3881
3882
3883
3884
3885

3886
3887
3888
3889
3890
3891
3892
3866
3867
3868
3869
3870
3871
3872

3873
3874
3875
3876
3877
3878
3879
3880







-
+







 109 124 l 5
 34 46 l 13
EndSplineSet
Validated: 1
EndChar

StartChar: uniE56D
Encoding: 114 58733 114
Encoding: 113 58733 113
Width: 580
Flags: W
HStem: -53 326<278 305> 0 21G<197.065 232.286 418.065 453.137>
VStem: 278 27<-53 70 150 273>
LayerCount: 2
Fore
SplineSet
︙
3912
3913
3914
3915
3916
3917
3918
3919

3920
3921
3922
3923
3924
3925
3926
3900
3901
3902
3903
3904
3905
3906

3907
3908
3909
3910
3911
3912
3913
3914







-
+







 278 -53 l 25
 278 70 l 1xa0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE582
Encoding: 115 58754 115
Encoding: 114 58754 114
Width: 280
Flags: HMW
LayerCount: 2
Fore
SplineSet
123 0 m 25
 123 123 l 25
︙
3936
3937
3938
3939
3940
3941
3942
3943

3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959

3960
3961
3962
3963
3964
3965
3966
3924
3925
3926
3927
3928
3929
3930

3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946

3947
3948
3949
3950
3951
3952
3953
3954







-
+















-
+







 157 0 l 25
 123 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE5D0
Encoding: 116 58832 116
Encoding: 115 58832 115
Width: 310
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 1
 0 60 l 1
 93 79 229 114 280 370 c 1
 310 370 l 1
 310 175 152 13 0 0 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE5E2
Encoding: 117 58850 117
Encoding: 116 58850 116
Width: 300
Flags: W
HStem: 0 62<198.921 262.211> 96 64<38.8054 112.592>
VStem: 283 16<88.1179 101.401>
LayerCount: 2
Fore
SplineSet
︙
3976
3977
3978
3979
3980
3981
3982
3983

3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003

4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022

4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043

4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061

4062
4063
4064
4065
4066
4067
4068
3964
3965
3966
3967
3968
3969
3970

3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990

3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009

4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030

4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048

4049
4050
4051
4052
4053
4054
4055
4056







-
+



















-
+


















-
+




















-
+

















-
+







 55 96 32 79 17 61 c 0
 10 53 -2 61 1 70 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE610
Encoding: 118 58896 118
Encoding: 117 58896 117
Width: 300
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 0 m 25
 0 300 l 25
 300 300 l 25
 300 0 l 25
 265 0 l 25
 265 180 l 25
 35 180 l 29
 35 0 l 29
 0 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE612
Encoding: 119 58898 119
Encoding: 118 58898 118
Width: 250
Flags: HMW
LayerCount: 2
Fore
SplineSet
105 0 m 29
 0 450 l 25
 40 450 l 25
 125 90 l 25
 210 450 l 25
 250 450 l 25
 145 0 l 25
 105 0 l 29
EndSplineSet
Validated: 1
EndChar

StartChar: uniE614
Encoding: 120 58900 120
Encoding: 119 58900 119
Width: 200
Flags: HMW
LayerCount: 2
Fore
SplineSet
100 25 m 28
 141 25 175 59 175 100 c 28
 175 141 141 175 100 175 c 28
 59 175 25 141 25 100 c 28
 25 59 59 25 100 25 c 28
100 0 m 28
 45 0 0 45 0 100 c 28
 0 155 45 200 100 200 c 28
 155 200 200 155 200 100 c 28
 200 45 155 0 100 0 c 28
EndSplineSet
Validated: 1
EndChar

StartChar: uniE618
Encoding: 121 58904 121
Encoding: 120 58904 120
Width: 280
Flags: HMW
LayerCount: 2
Fore
SplineSet
-200 0 m 1
 -200 110 -110 200 0 200 c 24
 110 200 200 110 200 0 c 1
 170 0 l 1
 170 99 99 170 0 170 c 24
 -99 170 -170 99 -170 0 c 1
 -200 0 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE624
Encoding: 122 58916 122
Encoding: 121 58916 121
Width: 250
Flags: HMW
LayerCount: 2
Fore
SplineSet
90 120 m 0
 110 120 132 165 132 200 c 28
︙
4078
4079
4080
4081
4082
4083
4084
4085

4086
4087
4088
4089
4090
4091
4092
4066
4067
4068
4069
4070
4071
4072

4073
4074
4075
4076
4077
4078
4079
4080







-
+







 108 0 l 25
 72 0 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniE630
Encoding: 123 58928 123
Encoding: 122 58928 122
Width: 200
Flags: HMW
LayerCount: 2
Fore
SplineSet
84 102 m 1
 37 109 -0 150 0 200 c 24
︙
4109
4110
4111
4112
4113
4114
4115
4116

4117
4118
4119
4120
4121
4122
4123
4097
4098
4099
4100
4101
4102
4103

4104
4105
4106
4107
4108
4109
4110
4111







-
+







 116 127 l 1
 116 126 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE650
Encoding: 124 58960 124
Encoding: 123 58960 123
Width: 1037
Flags: W
HStem: -2 60<361.035 435.033 953.253 1010.82> 0 49<543.265 652.027> 286 36<514.943 580.797> 359 66<58.4784 125.129> 402 58<367.211 444.917> 607 32<177.106 261>
VStem: 0 57<406 505.924> 148 26<463.933 475.584> 200 67<410.241 442> 274.641 84.3586<205.588 329> 425 56<126.64 255.856> 452 64<466.983 558.522> 585 40<194.878 284.873> 675 60<72.5613 225.441> 887 59<79.8865 267.532> 952 60<-0.820206 56.8202>
LayerCount: 2
Fore
SplineSet
︙
4188
4189
4190
4191
4192
4193
4194
4195

4196
4197
4198
4199
4200
4201
4202
4176
4177
4178
4179
4180
4181
4182

4183
4184
4185
4186
4187
4188
4189
4190







-
+







 758 262 735 202 735 117 c 0
 735 73 753 50 797 40 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE655
Encoding: 125 58965 125
Encoding: 124 58965 124
Width: 540
Flags: W
HStem: 68 93<79.5149 155.133> 182 17<220 222.173 252.655 264.303> 192 94<18.5323 100.176 375.888 460.387> 230 56<60.9363 133.273> 230 18<300.618 361.695> 274 18<213.64 227.572 256.894 258> 315 97<73.5817 155.121 322.704 406.413>
VStem: 179 23<209.875 223.47 254.181 264.625> 192 98<17.9339 97.9009 381.276 451.65> 230 18<113.95 174.519 300.936 363.797> 278 17<212.458 224.186 254.5 261>
LayerCount: 2
Fore
SplineSet
︙
4261
4262
4263
4264
4265
4266
4267
4268

4269
4270
4271
4272
4273
4274
4275
4249
4250
4251
4252
4253
4254
4255

4256
4257
4258
4259
4260
4261
4262
4263







-
+







 173 186 179 196 179 204 c 0
 179 219 166 230 141 230 c 0xcb40
EndSplineSet
Validated: 1
EndChar

StartChar: uniE910
Encoding: 126 59664 126
Encoding: 125 59664 125
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
45 0 m 28
 45 -113 137 -205 250 -205 c 28
︙
4287
4288
4289
4290
4291
4292
4293
4294

4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315

4316
4317
4318
4319
4320
4321
4322
4275
4276
4277
4278
4279
4280
4281

4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302

4303
4304
4305
4306
4307
4308
4309
4310







-
+




















-
+







 283 60 310 33 310 0 c 7
 310 -33 283 -60 250 -60 c 7
EndSplineSet
Validated: 1
EndChar

StartChar: uniE911
Encoding: 127 59665 127
Encoding: 126 59665 126
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
45 0 m 24
 45 -113 137 -205 250 -205 c 24
 363 -205 455 -113 455 0 c 24
 455 113 363 205 250 205 c 24
 137 205 45 113 45 0 c 24
0 0 m 24
 0 139 111 250 250 250 c 24
 388 250 500 139 500 0 c 24
 500 -138 389 -250 250 -250 c 24
 112 -250 0 -138 0 0 c 24
EndSplineSet
Validated: 1
EndChar

StartChar: uniE912
Encoding: 128 59666 128
Encoding: 127 59666 127
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
228 350 m 5
 273 350 l 5
︙
4338
4339
4340
4341
4342
4343
4344
4345

4346
4347
4348
4349
4350
4351
4352
4326
4327
4328
4329
4330
4331
4332

4333
4334
4335
4336
4337
4338
4339
4340







-
+







 455 105 375 193 273 204 c 5
 273 -204 l 5
EndSplineSet
Validated: 1
EndChar

StartChar: uniE914
Encoding: 129 59668 129
Encoding: 128 59668 128
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
463 130 m 0
 464 127 465 123 465 120 c 0
︙
4371
4372
4373
4374
4375
4376
4377
4378

4379
4380
4381
4382
4383
4384
4385
4359
4360
4361
4362
4363
4364
4365

4366
4367
4368
4369
4370
4371
4372
4373







-
+







 283 60 310 33 310 0 c 3
 310 -33 283 -60 250 -60 c 3
EndSplineSet
Validated: 1
EndChar

StartChar: uniE915
Encoding: 130 59669 130
Encoding: 129 59669 129
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
463 130 m 0
 464 127 465 123 465 120 c 0
︙
4399
4400
4401
4402
4403
4404
4405
4406

4407
4408
4409
4410
4411
4412
4413
4387
4388
4389
4390
4391
4392
4393

4394
4395
4396
4397
4398
4399
4400
4401







-
+







 0 139 111 250 250 250 c 0
 344 250 420 210 463 130 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniE918
Encoding: 131 59672 131
Encoding: 130 59672 130
Width: 500
Flags: HMW
LayerCount: 2
Fore
SplineSet
273 249 m 1
 356 243 424 203 463 130 c 0
︙
4436
4437
4438
4439
4440
4441
4442
4443

4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459

4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475

4476
4477
4478
4479
4480
4481
4482
4424
4425
4426
4427
4428
4429
4430

4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446

4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462

4463
4464
4465
4466
4467
4468
4469
4470







-
+















-
+















-
+







 125 193 45 106 45 0 c 0
 45 -106 125 -193 228 -204 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniE920
Encoding: 132 59680 132
Encoding: 131 59680 131
Width: 120
Flags: HMW
LayerCount: 2
Fore
SplineSet
60 -60 m 3
 27 -60 0 -33 0 0 c 3
 0 33 27 60 60 60 c 3
 93 60 120 33 120 0 c 3
 120 -33 93 -60 60 -60 c 3
EndSplineSet
Validated: 1
EndChar

StartChar: uniE925
Encoding: 133 59685 133
Encoding: 132 59685 132
Width: 45
Flags: HMW
LayerCount: 2
Fore
SplineSet
45 350 m 9
 45 -350 l 1
 0 -350 l 9
 0 350 l 1
 45 350 l 9
EndSplineSet
Validated: 1
EndChar

StartChar: uniE95D
Encoding: 134 59741 134
Encoding: 133 59741 133
Width: 540
Flags: HMW
LayerCount: 2
Fore
SplineSet
30 70 m 25
 30 -70 l 25
︙
4497
4498
4499
4500
4501
4502
4503
4504

4505
4506
4507
4508
4509
4510
4511
4485
4486
4487
4488
4489
4490
4491

4492
4493
4494
4495
4496
4497
4498
4499







-
+







 0 -190 l 25
 0 190 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniEA02
Encoding: 135 59906 135
Encoding: 134 59906 134
Width: 250
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 65 m 25
 137 250 l 25
︙
4521
4522
4523
4524
4525
4526
4527
4528

4529
4530
4531
4532
4533
4534
4535
4509
4510
4511
4512
4513
4514
4515

4516
4517
4518
4519
4520
4521
4522
4523







-
+







 32 41 l 25
 0 65 l 25
EndSplineSet
Validated: 1
EndChar

StartChar: uniEAA4
Encoding: 136 60068 136
Encoding: 135 60068 135
Width: 250
Flags: HMW
LayerCount: 2
Fore
SplineSet
0 270 m 0
 30 300 45 311 85 311 c 0
︙
4545
4546
4547
4548
4549
4550
4551
4552

4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573

4574
4575
4576
4577
4578
4579
4580
4533
4534
4535
4536
4537
4538
4539

4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560

4561
4562
4563
4564
4565
4566
4567
4568







-
+




















-
+







 -17 226 -24 227 -24 234 c 0
 -24 241 -17 253 0 270 c 0
EndSplineSet
Validated: 1
EndChar

StartChar: uniECA2
Encoding: 137 60578 137
Encoding: 136 60578 136
Width: 450
Flags: HMW
LayerCount: 2
Fore
SplineSet
337 -20 m 4
 337 50 264 111 193 111 c 4
 154 111 109 85 109 41 c 4
 109 -30 186 -87 257 -87 c 4
 298 -87 337 -65 337 -20 c 4
450 10 m 4
 450 -60 361 -119 225 -119 c 4
 89 -119 0 -60 0 10 c 4
 0 80 89 139 225 139 c 4
 361 139 450 80 450 10 c 4
EndSplineSet
Validated: 1
EndChar

StartChar: uniECA3
Encoding: 138 60579 138
Encoding: 137 60579 137
Width: 328
Flags: HMW
LayerCount: 2
Fore
SplineSet
292 68 m 0
 283 84 264 91 242 91 c 0
︙
4593
4594
4595
4596
4597
4598
4599
4600

4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619

4620
4621
4622
4623
4624
4625
4626
4581
4582
4583
4584
4585
4586
4587

4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606

4607
4608
4609
4610
4611
4612
4613
4614







-
+


















-
+







 237 148 273 134 298 103 c 1
 299 680 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniECA5
Encoding: 139 60581 139
Encoding: 138 60581 138
Width: 320
Flags: HMW
LayerCount: 2
Fore
SplineSet
290 680 m 1
 320 680 l 1
 320 40 l 2
 320 -51 231 -135 110 -135 c 0
 40 -135 0 -90 0 -40 c 0
 0 50 90 135 210 135 c 0
 244 135 271 124 290 107 c 1
 290 680 l 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniECA7
Encoding: 140 60583 140
Encoding: 139 60583 139
Width: 522
Flags: HMW
LayerCount: 2
Fore
SplineSet
320 441 m 1
 320 40 l 2
︙
4636
4637
4638
4639
4640
4641
4642
4643

4644
4645
4646
4647
4648
4649
4650
4624
4625
4626
4627
4628
4629
4630

4631
4632
4633
4634
4635
4636
4637
4638







-
+







 485 57 490 104 490 148 c 0
 490 258 462 396 320 441 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniECA9
Encoding: 141 60585 141
Encoding: 140 60585 140
Width: 522
Flags: HMW
LayerCount: 2
Fore
SplineSet
290 107 m 1
 290 337 l 1
︙
4666
4667
4668
4669
4670
4671
4672
4673

4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684

4685
4686
4687
4654
4655
4656
4657
4658
4659
4660

4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676







-
+











+



 494 242 495 248 495 255 c 0
 495 388 391 509 320 509 c 1
EndSplineSet
Validated: 1
EndChar

StartChar: uniECB7
Encoding: 142 60599 142
Encoding: 141 60599 141
Width: 100
Flags: HMW
LayerCount: 2
Fore
SplineSet
50 -50 m 3
 22 -50 0 -28 0 0 c 3
 0 28 22 50 50 50 c 3
 78 50 100 28 100 0 c 3
 100 -28 78 -50 50 -50 c 3
EndSplineSet
Validated: 1
EndChar
EndChars
EndSplineFont
Added jsmin.js.




























































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// jsmin.js
//
// Copyright (C) 2020 Jean-François Moine
//
// adapted from
/* jsmin.c
   2013-03-29

Copyright (c) 2002 Douglas Crockford  (www.crockford.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

The Software shall be used for Good, not Evil.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

    var	EOF = undefined,
	theA, theB,
	theLookahead = EOF,
	theX = EOF,
	theY = EOF

function error(s) {
	std.err.printf("JSMIN Error: " + s)
	std.exit(1)
}

/* isAlphanum -- return true if the character is a letter, digit, underscore,
		dollar sign, or non-ASCII character.
*/

function isAlphanum(c) {
	return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
		(c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' ||
		c > 126)
}


/* get -- return the next character from stdin. Watch out for lookahead. If
		the character is a control character, translate it to a space or
		linefeed.
*/

    var	fb = std.in.readAsString(), // file buffer
	fp = -1			// pointer to the file buffer
function get() {
    var	c = theLookahead

	theLookahead = EOF
	if (c == EOF) {
		c = fb[++fp]
		if (!c)
			return EOF
	}
	if (c >= ' ' || c == '\n')
		return c
	if (c == '\r')
		return '\n'
	return ' '
}


/* peek -- get the next character without getting it.
*/

function peek() {
	theLookahead = get()
	return theLookahead
}


/* next -- get the next character, excluding comments. peek() is used to see
		if a '/' is followed by a '/' or '*'.
*/

function next() {
   var	c = get()
	if  (c == '/') {
		switch (peek()) {
		case '/':
			while (1) {
				c = get()
				if (c <= '\n')
					break
			}
			break
		case '*':
			get()
			while (c != ' ') {
				switch (get()) {
				case '*':
					if (peek() == '/') {
						get()
						c = ' '
					}
					break
				case EOF:
					error("Unterminated comment.")
					break
				}
			}
			break
		}
	}
	theY = theX
	theX = c
	return c
}

    var line = ""
function put(c) {
	if (c == '\n') {
		print(line)
		line = ""
	} else {
		line += c
	}
}

/* action -- do something! What you do is determined by the argument:
		1   Output A. Copy B to A. Get the next B.
		2   Copy B to A. Get the next B. (Delete A).
		3   Get the next B. (Delete B).
   action treats a string as a single character. Wow!
   action recognizes a regular expression if it is preceded by ( or , or =.
*/

function action(d) {
	switch (d) {
	case 1:
		put(theA)
		if (
			(theY == '\n' || theY == ' ') &&
			(theA == '+' || theA == '-' || theA == '*' || theA == '/') &&
			(theB == '+' || theB == '-' || theB == '*' || theB == '/')
		) {
			put(theY)
		}
	case 2:
		theA = theB
		if (theA == '\'' || theA == '"' || theA == '`') {
			while (1) {
				put(theA)
				theA = get()
				if (theA == theB)
					break
				if (theA == '\\') {
					put(theA)
					theA = get()
				}
				if (theA == EOF)
					error("Unterminated string literal.")
			}
		}
	case 3:
		theB = next()
		if (theB == '/' && (
			theA == '(' || theA == ',' || theA == '=' || theA == ':' ||
			theA == '[' || theA == '!' || theA == '&' || theA == '|' ||
			theA == '?' || theA == '+' || theA == '-' || theA == '~' ||
			theA == '*' || theA == '/' || theA == '{' || theA == '\n'
		)) {
			put(theA)
			if (theA == '/' || theA == '*')
				put(' ')
			put(theB)
			while (1) {
				theA = get()
				if (theA == '[') {
					while (1) {
						put(theA)
						theA = get()
						if (theA == ']')
							break
						if (theA == '\\') {
							put(theA)
							theA = get()
						}
						if (theA == EOF)
							error("Unterminated set in Regular Expression literal.")
					}
//jfm
				} else if (theA == '\n') {
					break			// not a regex
				} else if (theA == '/') {
					switch (peek()) {
					case '/':
					case '*':
						error("Unterminated set in Regular Expression literal.")
					}
					break
				} else if (theA =='\\') {
					put(theA)
					theA = get()
				}
				if (theA == EOF)
					error("Unterminated Regular Expression literal.")
				put(theA)
			}
			theB = next()
		}
	}
}


/* jsmin -- Copy the input to the output, deleting the characters which are
		insignificant to JavaScript. Comments will be removed. Tabs will be
		replaced with spaces. Carriage returns will be replaced with linefeeds.
		Most spaces and linefeeds will be removed.
*/

function jsmin() {
//	if (peek() == 0xEF) {
//		get()
//		get()
//		get()
//	}
//jfm - keep the first comment
//	theA = '\n'
//	action(3)
	theA = get()
	theB = get()
	while (theA != EOF) {
		switch (theA) {
		case ' ':
			action(isAlphanum(theB) ? 1 : 2)
			break
		case '\n':
			switch (theB) {
			case '{':
			case '[':
			case '(':
			case '+':
			case '-':
			case '!':
			case '~':
				action(1)
				break
			case ' ':
				action(3)
				break
			default:
				action(isAlphanum(theB) ? 1 : 2)
				break
			}
			break
		default:
			switch (theB) {
			case ' ':
				action(isAlphanum(theA) ? 1 : 3)
				break
//jfm
			case '}':
				action(theA == ';' ? 2 : 1)
				break
			case '\n':
				switch (theA) {
				case '}':
				case ']':
				case ')':
				case '+':
				case '-':
				case '"':
				case '\'':
				case '`':
					action(1)
					break
				default:
					action(isAlphanum(theA) ? 1 : 3)
					break
				}
				break
			default:
				action(1)
				break
			}
		}
	}
}


/* main -- Output any command line arguments as comments
		and then minify the input.
*/
function comments() {
    var	arg,
	args = scriptArgs

	args.shift()		// skip the path of the script
	while (1) {
		arg = args.shift()
		if (!arg)
			break
		print("// " + arg)
	}
}

	comments()
	jsmin()
	if (line)
		print(line)
Changes to modules/MIDI.js.
1
2
3

4
5
6
7
8
9

10
11

12
13
14
15
16
17
18
1
2

3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19


-
+





-
+


+







// MIDI.js - module to handle the %%MIDI parameters
//
// Copyright (C) 2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2019-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%MIDI" appears in a ABC source.
//
// Parameters (see abcMIDI for details)
//	%%MIDI channel n
//	%%MIDI program n
//	%%MIDI program [channel] n
//	%%MIDI control k v
//	%%MIDI drummap ABC_note MIDI_pitch
//	%%MIDI temperamentequal nedo

// Using %%MIDI drummap creates a voicemap named "MIDIdrum".
// This name must be used if some print map is required:
//	%%MIDI drummap g 42
//	%%map MIDIdrum g heads=x
// A same effect may be done by
//	%%percmap g 42 x
︙
60
61
62
63
64
65
66
67
68
69
70



71
72
73
74
75



























76
77
78

79




80








81
































































82
83
84
85
86




















87
88
89
90
91

92
93

94
95
96

97
98
99
100
101
102


103
104
105


106
107

108

109
110
111
112


113
114
115


116
117
118
119

120
121
122
123
124
125
126


127
128
129
130
131


132
133
134


135
136
137
138
139

140





































































141
142
143
144
145
146

147
148
149
150
151



152
153

154
155
156
157
158

159
160
161
162
163
164

165
166
167

168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
61
62
63
64
65
66
67




68
69
70





71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179





180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205

206
207
208

209
210
211
212
213


214
215
216
217

218
219
220

221
222
223
224
225


226
227
228


229
230
231
232
233

234
235
236
237
238
239


240
241
242
243
244


245
246
247


248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339

340
341
342
343
344

345
346
347
348
349
350

351
352
353
354
355

356
357
358
359
360
361
362





363
364
365
366
367
368
369
370
371
372
373
374







-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+
-
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
+


-
+




-
-
+
+


-
+
+

-
+

+


-
-
+
+

-
-
+
+



-
+





-
-
+
+



-
-
+
+

-
-
+
+




-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+





+
+
+

-
+




-
+





-
+



+
-
+






-
-
-
-
-












	while (p[i] == ",") {
		pit -= 7
		i++
	}
	return abc2svg.pab40(pit, acc).toString()
    } // abc_b40()

    // convert a MIDI pitch to b40
    function mid_b40(p) {
    var	pit = Number(p)
	if (isNaN(pit))
	function mid_pit(p) {
	    var	b40,
		pit = p
		return
	p = (pit / 12) | 0		// octave
	pit = pit % 12;			// in octave
	return p * 40 + abc2svg.isb40[pit] + 2
    } // mid_b40()
		p = (pit / 12) | 0		// octave
		pit = pit % 12;			// in octave
		b40 = p * 40 + abc2svg.isb40[pit] + 2
		return {
			pit: abc2svg.b40p(b40),
			acc: abc2svg.b40a(b40)
		}
	}

    // build the equal temperament as a b40 float array
    function tb40(qs) {
// b40	  C  D   E   F   G   A   B
//	[ 2, 8, 14, 19, 25, 31, 37 ]
    var	i,
//	      C  G  D  A  E  B ^F ^C ^G ^D ^A ^E ^B^^F^^C^^G^^D^^A^^E^^B
	n1 = [2,25, 8,31,14,37,20, 3,26, 9,32,15,38,21, 4,27,10,33,16,39],
//	      C  F _B _E _A _D _G _C _F__B__E__A__D__G__C__F
	n2 = [0,19,36,13,30, 7,24, 1,18,35,12,29, 6,23, 0,17],
	da = 21 - 3 * qs		// 21 = 12 (octave) + 9 (A)
	b = new Float32Array(40)

	for (i = 0; i < n1.length; i++)
		b[n1[i]] = (qs * i + da) % 12
	for (i = 1; i <= n2.length; i++)
		b[n2[i]] = 12 - (qs * i - da) % 12
	return b
    } // tb40()

    // do_midi()
    var	n, v, s, maps,
	o, q, n, qs,
	a = parm.split(/\s+/)
	a = parm.split(/\s+/),
	abc = this,
	cfmt = abc.cfmt(),
	curvoice = abc.get_curvoice()

	if (curvoice) {
		if (curvoice.ignore)
			return
		if (curvoice.chn == undefined)
			curvoice.chn = curvoice.v < 9 ?
					curvoice.v :
					curvoice.v + 1
	}
	switch (a[1]) {
//	case "bassprog":	// %%MIDI bassprog <#MIDI program> [octave=<n>]
//		break
//	case "bassvol":		// %%MIDI bassvol <volume>
//		break
//	case "beatstring":	// %%MIDI beatstring <string of fmp>
//		break
	case "chordname":	// %%MIDI chordname <list of MIDI pitches>
				// example: %%MIDI chordname m 0 3 7
		if (!cfmt.chord)
			cfmt.chord = {}
		if (!cfmt.chord.names)
			cfmt.chord.names = {}
		cfmt.chord.names[a[2]] = a.slice(3)
		break
	case "chordprog":	// %%MIDI chordprog <#MIDI program> [octave=<n>]
		if (!cfmt.chord)
			cfmt.chord = {}
		cfmt.chord.prog = a[2]
		if (a[3] && a[3].slice(0, 7) == "octave=")
			cfmt.chord.trans = Number(a[3].slice(7))
		break
	case "chordvol":	// %%MIDI chordvol <volume>
		v = Number(a[2])
		if (isNaN(v) || v < 0 || v > 127) {
			abc.syntax(1, abc.errs.bad_val, "%%MIDI chordvol")
			break
		}
		if (!cfmt.chord)
			cfmt.chord = {}
		cfmt.chord.vol = v / 127
		break
//	case "drone":		// %%MIDI drone <#prog> <pit_1> <pit_2> <vol_1> <vol_2>
//				//	default: 70 45 33 80 80
//		break
//	case "droneon":		// %%MIDI droneon
//		break
//	case "droneoff":	// %%MIDI droneoff
//		break
//	case "gchord":		// %%MIDI gchord <list of letters and repeat numbers>
//				//	z rest
//				//	c chord
//				//	f fundamental
//				//	b fundamental + chord
//				// defaults:
//				//	M:2/4 or 4/4	fzczfzcz
//				//	M:3/4	fzczcz
//				//	M:6/8	fzcfzc
//				//	M:9/8	fzcfzcfzc
//		break
	case "gchordon":	// %%MIDI gchordon
	case "gchordoff":	// %%MIDI gchordoff
		if (!cfmt.chord)
			cfmt.chord = {}
		if (abc.parse.state == 2)
			abc.goto_tune()
		if (abc.parse.state >= 2
		 && abc.get_curvoice()) {
			s = abc.new_block("midigch")
			s.play = true
			s.on = a[1][7] == 'n'
		} else {
			cfmt.chord.gchon = a[1][7] == 'n'
		}
		break
	case "channel":				// channel 10 is bank 128
		if (a[2] != "10")
			break			// other channel values are ignored
		abc2svg.MIDI.do_midi.call(this, "MIDI control 0 1")	// MSB bank
		abc2svg.MIDI.do_midi.call(this, "MIDI control 32 0")	// LSB bank
	case "channel":
		v = parseInt(a[2])
		if (isNaN(v) || v <= 0 || v > 16) {
			abc.syntax(1, abc.errs.bad_val, "%%MIDI channel")
			break
		}
		if (--v != 9) {			// channel range 1..16 => 0..15
			if (abc.parse.state == 3) {
				s = abc.new_block("midichn");
				s.play = true
				s.chn = v
			} else {
				abc.set_v_param("channel", v)
			}
			break
		}

		// channel 10 is bank 128
		abc2svg.MIDI.do_midi.call(abc, "MIDI control 0 1")	// MSB bank
		abc2svg.MIDI.do_midi.call(abc, "MIDI control 32 0")	// LSB bank
		break
	case "drummap":
//fixme: should have a 'MIDIdrum' per voice?
		n = abc_b40(a[2])
		v = mid_b40(a[3])
		v = Number(a[3])
		if (!n || !v) {
			this.syntax(1, this.errs.bad_val, "%%MIDI drummap")
			abc.syntax(1, abc.errs.bad_val, "%%MIDI drummap")
			break
		}
		maps = this.get_maps()
		maps = abc.get_maps()
		if (!maps.MIDIdrum)
			maps.MIDIdrum = {}
		if (!maps.MIDIdrum[n])
			maps.MIDIdrum[n] = []
		maps.MIDIdrum[n][3] = v
		this.set_v_param("mididrum", "MIDIdrum")
		maps.MIDIdrum[n][3] = mid_pit(v)
		abc.set_v_param("mididrum", "MIDIdrum")
		break
	case "program":
		if (a[3] != undefined)	// the channel is unused
		if (a[3] != undefined) {	// with a channel
			abc2svg.MIDI.do_midi.call(abc, "MIDI channel " + a[2])
			v = a[3]
		else
		} else {
			v = a[2];
		}
		v = parseInt(v)
		if (isNaN(v) || v < 0 || v > 127) {
			this.syntax(1, "Bad program in %%MIDI")
			return
			abc.syntax(1, abc.errs.bad_val, "%%MIDI program")
			break
		}
		if (this.parse.state == 3) {
			s = this.new_block("midiprog");
		if (abc.parse.state == 3) {
			s = abc.new_block("midiprog");
			s.play = true
			s.instr = v
		} else {
			this.set_v_param("instr", v)
			abc.set_v_param("instr", v)
		}
		break
	case "control":
		n = parseInt(a[2])
		if (isNaN(n) || n < 0 || n > 127) {
			this.syntax(1, "Bad controller number in %%MIDI")
			return
			abc.syntax(1, "Bad controller number in %%MIDI")
			break
		}
		v = parseInt(a[3])
		if (isNaN(v) || v < 0 || v > 127) {
			this.syntax(1, "Bad controller value in %%MIDI")
			return
			abc.syntax(1, "Bad controller value in %%MIDI")
			break
		}
		if (this.parse.state == 3) {
			s = this.new_block("midictl");
		if (abc.parse.state == 3) {
			s = abc.new_block("midictl");
			s.play = true
			s.ctrl = n;
			s.val = v
		} else {
			this.set_v_param("midictl", a[2] + ' ' + a[3])
			abc.set_v_param("midictl", a[2] + ' ' + a[3])
		}
		break
	case "temperamentequal":
		n = parseInt(a[2])
		if (isNaN(n) || n < 5 || n > 255) {
			abc.syntax(1, abc.errs.bad_val, "%%MIDI " + a[1])
			return
		}

		// define the Turkish accidentals (53-TET)
		if (n == 53) {
			s = abc.get_glyphs()

// #1
			s.acc12_53 = '<text id="acc12_53" x="-1">&#xe282;</text>'

// #2
			s.acc24_53 = '<text id="acc24_53" x="-1">&#xe282;\
	<tspan x="0" y="-10" style="font-size:8px">2</tspan></text>'

// #3
			s.acc36_53 = '<text id="acc36_53" x="-1">&#xe262;\
	<tspan x="0" y="-10" style="font-size:8px">3</tspan></text>'

// #4
			s.acc48_53 = '<text id="acc48_53" x="-1">&#xe262;</text>'

// #5
			s.acc60_53 = '<g id="acc60_53">\n\
	<text style="font-size:1.2em" x="-1">&#xe282;</text>\n\
	<path class="stroke" stroke-width="1.6" d="M-2 1.5l7 -3"/>\n\
</g>'

// b5
			s["acc-60_53"] = '<text id="acc-60_53" x="-1">&#xe260;</text>'

// b4
			s["acc-48_53"] = '<g id="acc-48_53">\n\
	<text x="-1">&#xe260;</text>\n\
	<path class="stroke" stroke-width="1" d="M-3 -5.5l5 -2"/>\n\
</g>'

// b3
			s["acc-36_53"] = '<g id="acc-36_53">\n\
	<text x="-1">&#xe260;\
		<tspan x="0" y="-10" style="font-size:8px">3</tspan></text>\n\
	<path class="stroke" stroke-width="1" d="M-3 -5.5l5 -2"/>\n\
</g>'

// b2
			s["acc-24_53"] = '<text id="acc-24_53" x="-2">&#xe280;\
	<tspan x="0" y="-10" style="font-size:8px">2</tspan></text>'

// b1
			s["acc-12_53"] = '<text id="acc-12_53" x="-2">&#xe280;</text>'
		}

		// define the detune values
		q = 7.019550008653874,	//  Math.log(3/2)/Math.log(2) * 12
					// = just intonation fifth
		o = 12			// octave
		cfmt.nedo = n		// octave divider
		qs = ((n * q / o + .5) | 0) * o / n	// new fifth

		// warn on bad fifth values
		if (qs < 6.85 || qs > 7.2)
			abc.syntax(0, abc.errs.bad_val, "%%MIDI " + a[1])

		cfmt.temper = tb40(qs)	// pitches / A in 100th of cents

		break
	}
    }, // do_midi()

    // set the MIDI parameters in the current voice
    set_midi: function(a) {
    set_vp: function(of, a) {
    var	i, item,
	curvoice = this.get_curvoice()

	for (i = 0; i < a.length; i++) {
		switch (a[i]) {
		case "channel=":		// %%MIDI channel
			curvoice.chn = a[++i]
			break
		case "instr=":			// %%MIDI program
			curvoice.instr = a[i + 1]
			curvoice.instr = a[++i]
			break
		case "midictl=":		// %%MIDI control
			if (!curvoice.midictl)
				curvoice.midictl = []
			item = a[i + 1].split(' ');
			item = a[++i].split(' ');
			curvoice.midictl[item[0]] = Number(item[1])
			break
		case "mididrum=":		// %%MIDI drummap note midipitch
			if (!curvoice.map)
				curvoice.map = {}
			curvoice.map = a[i + 1]
			curvoice.map = a[++i]
			break
		}
	}
	of(a)
    }, // set_midi()
    }, // set_vp()

    do_pscom: function(of, text) {
	if (text.slice(0, 5) == "MIDI ")
		abc2svg.MIDI.do_midi.call(this, text)
	else
		of(text)
    },

    set_vp: function(of, a) {
	abc2svg.MIDI.set_midi.call(this, a);
	of(a)
    },

    set_hooks: function(abc) {
	abc.do_pscom = abc2svg.MIDI.do_pscom.bind(abc, abc.do_pscom);
	abc.set_vp = abc2svg.MIDI.set_vp.bind(abc, abc.set_vp)
    }
} // MIDI

abc2svg.modules.hooks.push(abc2svg.MIDI.set_hooks);

// the module is loaded
abc2svg.modules.MIDI.loaded = true
Changes to modules/break.js.
︙
79
80
81
82
83
84
85
86

87
88

89

90

91
92
93
94
95
96
97
79
80
81
82
83
84
85

86


87
88
89

90
91
92
93
94
95
96
97







-
+
-
-
+

+
-
+







			t = brk.t
			if (t) {
				t = s.time + t
				for ( ; s; s = s.next) {
					if (s.time >= t)
						break
				}
				if (!s)
			} else {
					continue
				s = s.prev
				s = s.next
			}
			if (s)
			s.eoln = true
				s.soln = true
		}
	}, // do_break()

    do_pscom: function (of, text) {
	if (text.slice(0, 6) == "break ")
		abc2svg.break.get_break.call(this, text)
	else
︙
Changes to modules/capo.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17









18
19
20
21
22
23
24
25
26
27
28
29
30
31
32














33

34
35


36
37
38


39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59


















60
61
62
63
64

65
66
67
68
69
70
71
1
2

3
4
5
6
7
8
9
10
11






12
13
14
15
16
17
18
19
20
21














22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


38
39
40


41
42


43




44





45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83


-
+








-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
+
+

-
-
+
+
-
-
+
-
-
-
-

-
-
-
-
-




-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-

+







// capo.js - module to add a capo chord line
//
// Copyright (C) 2018-2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2018-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%capo" appears in a ABC source.
//
// Parameters
//	%%capo n	'n' is the capo fret number

abc2svg.capo = {

// function called when setting a chord symbol on a music element
    gch_capo: function(a_gch) {
    var	gch, gch2, i2,
	cfmt = this.cfmt(),
	transp = cfmt.capo,
	i = 0
    gch_build: function(of, s) {
    var	t, i, gch, gch2, i2,
	abc = this,
	p_v = abc.get_curvoice(),
	a_gch = s.a_gch

	if (p_v.capo && a_gch) {
		t = p_v.capo
		i = 0

	while (1) {
		gch = a_gch[i++]
		if (!gch)
			return
		if (gch.type == 'g')
			break
	}
	gch2 = Object.create(gch);
	gch2.capo = false;		// (would be erased when setting gch)
	gch2.text = this.gch_tr1(gch2.text, -abc2svg.ifb40[transp % 12])
	if (!this.capo_first) {			// if new tune
		this.capo_first = true;
		gch2.text += "  (capo: " + transp.toString() + ")"
	}
		while (1) {
			gch = a_gch[i++]
			if (!gch)
				return
			if (gch.type == 'g')
				break
		}
		gch2 = Object.create(gch)
		gch2.capo = false	// (would be erased when setting gch)
		gch2.text = abc.gch_tr1(gch2.text, -abc2svg.ifb40[t % 12])
		if (!p_v.capo_first) {		// if new voice
			p_v.capo_first = true
			gch2.text += "  (capo: " + t.toString() + ")"
		}

		gch2.font = abc.get_font(abc.cfmt().capofont ?
	gch2.font = this.get_font(cfmt.capofont ? "capo" : "annotation");
	a_gch.splice(i, 0, gch2)
						"capo" : "annotation")
		a_gch.splice(i, 0, gch2)

	// set a mark in the first chord symbol for %%diagram
	gch.capo = true
		// set a mark in the first chord symbol for %%diagram
		gch.capo = true
    }, // gch_capo()

	}
    gch_build: function(of, s) {
    var	a_gch = this.get_a_gch()
	if (this.cfmt().capo && a_gch)
		abc2svg.capo.gch_capo.call(this, a_gch);
	of(s)
    },

    output_music: function(of) {
	this.capo_first = false;
	of()
    },

    set_fmt: function(of, cmd, param) {
	if (cmd == "capo") {
		this.cfmt().capo = param
		this.set_v_param("capo_", param)
		return
	}
	of(cmd, param)
    },

    // get the parameters of the current voice
    set_vp: function(of, a) {
    var	i, v,
	p_v = this.get_curvoice()

	for (i = 0; i < a.length; i++) {
		if (a[i] == "capo_=") {
			v = Number(a[++i])
			if (isNaN(v) || v <= 0)
				this.syntax(1, "Bad fret number in %%capo")
			else
				p_v.capo = v
			break
		}
	}
	of(a)
    }, // set_vp()

    set_hooks: function(abc) {
	abc.gch_build = abc2svg.capo.gch_build.bind(abc, abc.gch_build);
	abc.output_music = abc2svg.capo.output_music.bind(abc, abc.output_music);
	abc.set_format = abc2svg.capo.set_fmt.bind(abc, abc.set_format)
	abc.set_vp = abc2svg.capo.set_vp.bind(abc, abc.set_vp)
    }
} // capo

abc2svg.modules.hooks.push(abc2svg.capo.set_hooks);

// the module is loaded
abc2svg.modules.capo.loaded = true
Added modules/chordnames.js.






























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// abc2svg - chordnames.js - change the names of the chord symbols
//
// Copyright (C) 2020-2021 Jean-Francois Moine
// License GPL-3
//
// This module is loaded by %%chordnames.
//
// Parameters
//	%%chordnames <comma separated list of chord names>
// Each name replace one chord. The order is:
//	CDEFGAB<N.C.>

abc2svg.chordnames = {

    gch_build: function(of, s) {
    var	gch, ix, t,
	cfmt = this.cfmt()

	if (s.a_gch && cfmt.chordnames) {
		for (ix = 0; ix < s.a_gch.length; ix++) {
			gch = s.a_gch[ix]
			t = gch.text
			if (gch.type != 'g' || !t)
				continue
			if (t[0].toUpperCase() == "N") {
				if (cfmt.chordnames.N)
					gch.text = cfmt.chordnames.N
			} else {
				gch.text = t.replace(/[A-G]/g,
					function(c){return cfmt.chordnames[c] || c})
				if (cfmt.chordnames.B == 'H')	// if german 'H'
					gch.text = gch.text.replace(/Hb/g, 'Bb')
			}
		}
	}
	of(s)
    }, // gch_build()

    set_fmt: function(of, cmd, parm) {
    var	i,
	cfmt = this.cfmt()

	if (cmd == "chordnames") {
		parm = parm.split(',')
		cfmt.chordnames = {}
		for (i = 0; i < parm.length; i++) {
			if (parm[i])
				cfmt.chordnames['CDEFGABN'[i]] = parm[i]
		}
		return
	}
	of(cmd, parm)
    }, // set_fmt()

    set_hooks: function(abc) {
	abc.gch_build = abc2svg.chordnames.gch_build.bind(abc, abc.gch_build)
	abc.set_format = abc2svg.chordnames.set_fmt.bind(abc, abc.set_format)
    } // set_hooks()
} // chordnames

abc2svg.modules.hooks.push(abc2svg.chordnames.set_hooks)
abc2svg.modules.chordnames.loaded = true
Changes to modules/clair.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

















33
34
35
36

37
38
39
40
41
42
43
44





45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66















67
68
69
70

71
72

73
74
75
76

77

78
79
80
81
82
83
84

85
86
87
88
89
90
91
1
2

3
4
5
6
7
8
9
10
11
12
13

14
15

















16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39





40
41
42
43
44
45
46
47

48
49
50
51















52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71

72
73
74
75
76
77

78
79
80
81
82
83
84

85
86
87
88
89
90
91
92


-
+










-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+



-
-
-
-
-
+
+
+
+
+



-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+

-
+




+
-
+






-
+







// clair.js - module to output Clairnote sheets (https:clairnote.org)
//
// Copyright (C) 2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2019-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%clairnote" appears in a ABC source.
//
// Parameters (none)
//	%%clairnote 1

abc2svg.clair = {

// table for helper lines (from C, to c'')
// index = (note pitch + 16)
// value = array of staff offsets / null
// value = array of line numbers / null
    hl_tb: [
	new Int8Array([-20,-16,-12,-8,-4]), // _B,, -18
	new Int8Array([-20,-18,-16,-12,-8,-4]), // B,, -17
	new Int8Array([-16,-12,-8,-4]),	// C, -16
	new Int8Array([-16,-12,-8,-4]),	// ^C, -15
	new Int8Array([-16,-14,-12,-8,-4]), // D, -14
	new Int8Array([-12,-8,-4]),	// ^D, -13
	new Int8Array([-12,-8,-4]),	// E, -12
	new Int8Array([-12,-8,-4]),	// F, -11
	new Int8Array([-12,-10,-8,-4]),	// ^F, -10
	new Int8Array([-8,-4]),		// G, -9
	new Int8Array([-8,-4]),		// ^G, -8
	new Int8Array([-8,-4]),		// A, -7
	new Int8Array([-8,-6,-4]),	// _B, -6
	new Int8Array([-4]),		// B, -5
	new Int8Array([-4]),		// C -4
	new Int8Array([-4]),		// ^C -3
	new Int8Array([-4,-2]),		// D -2
	new Int8Array([-10,-8,-6,-4,-2]), // _B,, -18
	new Int8Array([-10,-9,-8,-6,-4,-2]), // B,, -17
	new Int8Array([-8,-6,-4,-2]),	// C, -16
	new Int8Array([-8,-6,-4,-2]),	// ^C, -15
	new Int8Array([-8,-7,-6,-4,-2]), // D, -14
	new Int8Array([-6,-4,-2]),	// ^D, -13
	new Int8Array([-6,-4,-2]),	// E, -12
	new Int8Array([-6,-4,-2]),	// F, -11
	new Int8Array([-6,-5,-4,-2]),	// ^F, -10
	new Int8Array([-4,-2]),		// G, -9
	new Int8Array([-4,-2]),		// ^G, -8
	new Int8Array([-4,-2]),		// A, -7
	new Int8Array([-4,-3,-2]),	// _B, -6
	new Int8Array([-2]),		// B, -5
	new Int8Array([-2]),		// C -4
	new Int8Array([-2]),		// ^C -3
	new Int8Array([-2,-1]),		// D -2
	null,				// ^D -1
	null,				// E 0
	null,				// F 1
	new Int8Array([2]),		// ^F 2
	new Int8Array([1]),		// ^F 2
	null,				// G 3
	null,				// ^G 4
	null,				// A 5
	new Int8Array([6,8]),		// _B 6
	new Int8Array([8]),		// B 7
	new Int8Array([8]),		// c 8
	new Int8Array([8]),		// ^c 9
	new Int8Array([8,10]),		// d 10
	new Int8Array([3,4]),		// _B 6
	new Int8Array([4]),		// B 7
	new Int8Array([4]),		// c 8
	new Int8Array([4]),		// ^c 9
	new Int8Array([4,5]),		// d 10
	null,				// _e 11
	null,				// e 12
	null,				// f 13
	new Int8Array([14]),		// ^f 14
	new Int8Array([7]),		// ^f 14
	null,				// g 15
	null,				// ^g 16
	null,				// a 17
	new Int8Array([18,20]),		// _b 18
	new Int8Array([20]),		// b 19
	new Int8Array([20]),		// c' 20
	new Int8Array([20]),		// ^c' 21
	new Int8Array([20,22]),		// d' 22
	new Int8Array([20,22]),		// _e' 23
	new Int8Array([20,24]),		// e' 24
	new Int8Array([20,24]),		// f' 25
	new Int8Array([20,24,26]),	// ^f' 26
	new Int8Array([20,24,26]),	// g' 27
	new Int8Array([20,24,28]),	// ^g' 28
	new Int8Array([20,24,28]),	// a' 29
	new Int8Array([20,24,28,30]),	// _b' 30
	new Int8Array([20,24,28,30]),	// b' 31
	new Int8Array([20,24,28,32])	// c'' 32
	new Int8Array([9,10]),		// _b 18
	new Int8Array([10]),		// b 19
	new Int8Array([10]),		// c' 20
	new Int8Array([10]),		// ^c' 21
	new Int8Array([10,11]),		// d' 22
	new Int8Array([10,11]),		// _e' 23
	new Int8Array([10,12]),		// e' 24
	new Int8Array([10,12]),		// f' 25
	new Int8Array([10,12,13]),	// ^f' 26
	new Int8Array([10,12,13]),	// g' 27
	new Int8Array([10,12,14]),	// ^g' 28
	new Int8Array([10,12,14]),	// a' 29
	new Int8Array([10,12,14,15]),	// _b' 30
	new Int8Array([10,12,14,15]),	// b' 31
	new Int8Array([10,12,14,16])	// c'' 32
    ],

// draw the helper lines
    draw_hl: function(of, x, s, hltype) {
    draw_hl: function(of, s) {
	if (!s.p_v.clair) {
		of(x, s, hltype)
		of(s)
		return
	}

    var	i, m, hl,
	dx = s.grace ? 4 : [4.7, 5, 6, 7.2, 7.5][s.head] * 1.4,
	staffb = this.get_staff_tb()[s.st].y
	p_st = this.get_staff_tb()[s.st]

	for (m = 0; m <= s.nhd; m++) {
		hl = abc2svg.clair.hl_tb[s.notes[m].pit]
		if (!hl)
			continue
		for (i = 0; i < hl.length; i++)
			this.xygl(x, staffb + hl[i] * 3, hltype)
			this.set_hl(p_st, hl[i], s.x, -dx, dx)
	}
    }, // draw_hl()

// draw the key signature
    draw_keysig: function(of, x, s) {
	if (!s.p_v.clair) {
		of(x, s)
︙
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
181
182
183
184
185
186
187

188



189
190
191
192
193
194
195







-
+
-
-
-







    }, // new_clef()

// function called before SVG generation
    output_music: function(of) {
    var	s, m, mp, p_v, v,
	cfmt = this.cfmt(),
	tsfirst = this.get_tsfirst(),
	voice_tb = this.get_voice_tb(),
	voice_tb = this.get_voice_tb()
	abcmidi = new AbcMIDI();

	abcmidi.add(tsfirst, voice_tb);		// get the MIDI pitches

	// define the new clefs and key signatures
	// (clefs converted from clairnote.ly)
	this.do_begin_end("svg", null, '<defs>\n\
<g id="cl2">\n\
<path transform="translate(-9,-27) scale(8)" d="m0.2656 -0.78107\n\
 C0.3775 -0.79547 0.4351 -0.84567 0.7003 -0.85587\n\
︙
Changes to modules/diag.js.
︙
454
455
456
457
458
459
460











461

462
463
464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481


482

483
484
485
486
487
488
489
490







+
+
+
+
+
+
+
+
+
+
+
-
+









-
-

-
+







<use xlink:href="#fb"/>\n\
<text x="-12,0,4" y="-36" class="diag">x34</text>\n\
<use x="6" y="-19" xlink:href="#ddot"/>\n\
<use x="2" y="-25" xlink:href="#ddot"/>\n\
</g>'
	}

	// convert the chord symbol to a "better known" one
	function ch_cnv(t) {
	    var	a = t.match(/[A-G][#♯b♭]?([^/]*)\/?/)	// a[1] = chord type
		if (a && a[1]) {
			a[2] = abc2svg.ch_alias[a[1]]
			if (a[2] != undefined)
				t = t.replace(a[1], a[2])
		}
		return t
	} // ch_cnv()

    var	s, i, gch, t
    var	s, i, gch

	for (s = voice_tb[0].sym; s; s = s.next) {
		if (!s.a_gch)
			continue
		for (i = 0; i < s.a_gch.length; i++) {
			gch = s.a_gch[i]
			if (!gch || gch.type != 'g' || gch.capo)
				continue

			t = gch.otext || gch.text

			// insert the diagram as a decoration
			this.deco_cnv(t.split(/[ \t/]/, 1), s, null)
			this.deco_cnv([ ch_cnv(gch.otext) ], s, null)
		}
	}
    }, // do_diag()

    output_music: function(of) {
	if (this.cfmt().diag)
		abc2svg.diag.do_diag.call(this)
︙
Added modules/gamelan.js.






























































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// gamelan.js - module to output Gamelan (indonesian) music sheets
//
// Copyright (C) 2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%gamelan" appears in a ABC source.
//
// Parameters (none)
//	%%gamelan 1
// scale:
// - sléndro - 5 equal tones
//	5-TET	C   D   E     G   A
//	detune	0 +40 +80 . +20 +60 .
// - pélog - 7 unequal tones
//		D _E+ F- ^G+ A _B c+ d
//		1  2  3   4  5  6 7  1
// (first note = ding)
//   Bali
//	selisir ^C D E ^G A	12356
//	tembung	E F A B c	45612
//	sunaren	F G B c d (?)	56723
//   Java
//	bem	D_E ^G A _B	12456
//	barang	_E F A _B c	23567
// numbers
//	??	E F G B c
//	??	C ^C _E G _A (or ^C D E ^G A)
// dot = continuation (not rest)

abc2svg.gamelan = {

  cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]),
  cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3,
			  0, -4, -1, -5, -2, -6, -3, 0]),
  acc2: new Int8Array([-2, -1, 3, 1, 2]),

// change %%staves and %%score
  do_pscom: function(of, p) {
	switch (p.match(/\w+/)[0]) {
	case 'staves':
	case 'score':
		p = p.replace(/\(|\)/g, '')
		break
	}
	of(p)
  },

// adjust some symbols before the generation
  output_music: function(of) {
    var	C = abc2svg.C,
	abc = this,
	cur_sy = abc.get_cur_sy(),
	voice_tb = abc.get_voice_tb()

	if (!abc.cfmt().gamelan) {
		of()
		return
	}

	// expand dots and long notes/rests
	function slice(s) {
	    var	m, n, s2, s3, d, d_orig

		if (s.dur <= C.BLEN * 3 / 8) {
			if ((s.dur_orig / 9 | 0) * 9 != s.dur_orig)
				return
			d = s.dur / 3
			d_orig = s.dur_orig / 3
			s.dur -= d
			s.dur_orig -= d_orig
			n = 1
		} else {
			if (s.dur >= C.BLEN)
				n = 3
			else if (s.dur == C.BLEN / 2)
				n = 1
			else
				n = 2
			d = d_orig = C.BLEN / 4
			s.dur = s.dur_orig = C.BLEN / 4
		}
		for (m = 0; m <= s.nhd; m++)
			s.notes[m].dur = s.dur
		s.beam_on = true
		while (--n >= 0) {
			s2 = {
				type: C.REST,
				v: s.v,
				p_v: s.p_v,
				st: s.st,
				dur: d,
				dur_orig: d_orig,
				stem: 1,
				multi: 0,
				nhd: 0,
				notes: [{
					pit: s.notes[0].pit,
					jn: 8
				}],
				xmx: 0,
				beam_on: true,
				noplay: true,
				time: s.time + s.dur,
				prev: s,
				next: s.next
			}
			s.next = s2
			if (s2.next)
				s2.next.prev = s2

			if (!s.ts_next) {
				s.ts_next = s2
				if (s.soln)
					s.soln = false
				s2.ts_prev = s
				s2.seqst = true
			} else {
			    for (s3 = s.ts_next; s3; s3 = s3.ts_next) {
				if (s3.time < s2.time)
					continue
				if (s3.time > s2.time) {
					s2.seqst = true
					s3 = s3.ts_prev
				}
				s2.ts_next = s3.ts_next
				s2.ts_prev = s3
				if (s2.ts_next)
					s2.ts_next.ts_prev = s2
				s3.ts_next = s2
				break
			    }
			}
			s = s2
		}
	} // slice()

	// replace the tied notes by a '.'
	function do_tie(s) {
	    var	end_time = s.time + s.dur
		while (1) {
			s = s.ts_next
			if (!s || s.time > end_time)
				return	// ?!
			if (s.type == C.NOTE
			 && s.time == end_time)
				break
		}
		s.notes[0].jn = 8
		s.notes[0].jo = 2
	} // do_tie()

	function set_sym(p_v) {
	    var s, s2, note, pit, nn, p, a, m, i,
		sf = p_v.key.k_sf
		delta = abc2svg.gamelan.cgd2cde[sf + 7] - 2

		p_v.key.k_a_acc = []	// no accidental

		// no (visible) clef
		p_v.clef.invis = true

		// scan the voice
		for (s = p_v.sym; s; s = s.next) {
			s.st = p_v.st
			switch (s.type) {
			case C.CLEF:
				s.invis = true
//				continue
			default:
				continue
			case C.KEY:
				delta = abc2svg.gamelan.cgd2cde[s.k_sf + 7] - 2
				continue
			case C.REST:
				if (s.notes[0].jn)
					continue
				s.notes[0].jn = 0
				s.notes[0].pit = 21
				slice(s)
				continue
			case C.NOTE:			// change the notes
				break
			}

			s.stem = 1
			s.stemless = true

			// set the slurs offset and direction
			if (s.sls) {
				for (i = 0; i < s.sls.length; i++)
					s.sls[i].ty = C.SL_BELOW
			}

			for (m = 0; m <= s.nhd; m++) {
				note = s.notes[m]

				// note head
				p = note.pit
				pit = p + delta
				if (note.jn == undefined) {	// if not tied
					note.jn = ((pit + 77) % 7) + 1	// note number
					note.jo = (pit / 7) | 0	// octave number
				}

				// set a fixed offset to the note
				// for the slurs and decorations
				note.pit = 21			// "A"

				// accidentals
				a = note.acc
				if (a) {
					nn = abc2svg.gamelan.cde2fcg[(p + 5 + 16 * 7) % 7] - sf
					if (a != 3)
						nn += a * 7
					nn = ((((nn + 1 + 21) / 7) | 0) + 2 - 3 + 32 * 5) % 5
					note.acc = abc2svg.gamelan.acc2[nn]
				}

				if (note.tie_ty) {
					do_tie(s)
					delete note.tie_ty
				}
			}

			// change the dots and the long notes
			slice(s)

			// replace the staccato dot
			if (s.a_dd) {
				for (i = 0; i < s.a_dd.length; i++) {
					if (s.a_dd[i].glyph == "stc") {
						abc.deco_cnv(["gstc"], s)
						s.a_dd[i] = s.a_dd.pop()
					}
				}
			}
		}
	} // set_sym()

	// -- output_music --

	for (v = 0; v < voice_tb.length; v++)
		set_sym(voice_tb[v])

	of()
  }, // output_music()

  draw_symbols: function(of, p_voice) {
    var	i, m, nl, note, s, s2, x, y,
	C = abc2svg.C,
	abc = this,
	dot = "\ue1e7",
	staff_tb = abc.get_staff_tb(),
	out_svg = abc.out_svg,
	out_sxsy = abc.out_sxsy,
	xypath = abc.xypath

	if (!abc.cfmt().gamelan) {
		of(p_voice)
		return
	}

	// draw the duration lines above the notes
	function draw_dur(s1, y, s2, n, nl) {
	    var s, s3

		xypath(s1.x - 3, y + 24)
		out_svg('h' + (s2.x - s1.x + 8).toFixed(1) + '"/>\n')	// "
		y -= 2.5
		while (++n <= nl) {
			s = s1
			while (1) {
				if (s.nflags && s.nflags >= n) {
					s3 = s
					while (s != s2) {
						if (s.next.beam_br1
						 || (s.next.beam_br2 && n > 2)
						 || (s.next.nflags
						  && s.next.nflags < n))
							break
						s = s.next
					}
					draw_dur(s3, y, s, n, nl)
				}
				if (s == s2)
					break
				s = s.next
			}
		}
	} // draw_dur()

	function out_mus(x, y, p) {
		out_svg('<text x="')
		out_sxsy(x, '" y="', y)
		out_svg('">' + p + '</text>\n')
	} // out_txt()

	function out_txt(x, y, p) {
		out_svg('<text class="bn" x="')
		out_sxsy(x, '" y="', y)
		out_svg('">' + p + '</text>\n')
	} // out_txt()

	function draw_hd(s, x, y) {
	    var	m, note, ym

		for (m = 0; m <= s.nhd; m++) {
			note = s.notes[m]
			out_txt(x - 3.5, y + 8, "01234567."[note.jn])
			if (note.acc) {
				out_svg('<path class="stroke" stroke-width="1.1" d="M')
				if (note.acc > 0) {
					out_sxsy(x - 6, ' ', y + 10)
					out_svg("l12 -6")
				} else {
					out_sxsy(x - 6, ' ', y + 16)
					out_svg("l12 6")
				}
				out_svg('"/>\n')
			}
			if (note.jo > 2) {
				out_mus(x - 1, y + 23, dot)
				if (note.jo > 3) {
					y += 3
					out_mus(x - 1, y + 23.4, dot)
				}
			} else if (note.jo < 2) {
				ym = y + 4
				out_mus(x - 1, ym, dot)
			}
			y += 20
		}
	} // draw_hd()

	// -- draw_symbols --

	for (s = p_voice.sym; s; s = s.next) {
		if (s.invis)
			continue
		switch (s.type) {
		case C.NOTE:
		case C.REST:
			x = s.x
			y = staff_tb[s.st].y
			draw_hd(s, x, y)

			if (s.nflags > 0) {
				if (s.beam_st) {
					nl = s.nflags
					s2 = s
					while (1) {
						if (s2.nflags && s2.nflags > nl)
							nl = s2.nflags
						if (s2.beam_end)
							break
						if (!s2.next
						 || !s2.next.nflags
						 || s2.next.nflags <= 0)
							break
						s2 = s2.next
					}
					draw_dur(s, y + 7, s2, 1, nl)
				}
			}
			break
		}
	}
  }, // draw_symbols()

// set some parameters
    set_fmt: function(of, cmd, param) {
	if (cmd == "gamelan") {
	    var	cfmt = this.cfmt()

		cfmt.gamelan = true
		cfmt.staffsep = 20
		cfmt.sysstaffsep = 14
		this.set_v_param("stafflines", "...")
		cfmt.tuplets = [0, 1, 0, 1]	// [auto, slur, number, above]
		return
	}
	of(cmd, param)
    }, // set_fmt()

// adjust some values
    set_pitch: function(of, last_s) {
	of(last_s)
	if (!last_s
	 || !this.cfmt().gamelan)
		return			// first time

    var	C = abc2svg.C
	
	for (var s = this.get_tsfirst(); s; s = s.ts_next) {
		switch (s.type) {

		// adjust the vertical spacing above the note heads
		case C.NOTE:
			s.ymx = 20 * s.nhd + (s.nflags > 0 ? 30 : 24)
			if (s.notes[s.nhd].jo > 2) {
				s.ymx += 3
				if (s.notes[s.nhd].jo > 3)
					s.ymx += 2
			}
			break
		}
	}
    }, // set_pitch()

// set the width of some symbols
    set_width: function(of, s) {
	of(s)
	if (!this.cfmt().gamelan)
		return

    var	w, m, note,
	C = abc2svg.C

	switch (s.type) {
	case C.CLEF:
	case C.KEY:
	case C.METER:
		s.wl = s.wr = 0
		break
	}
    }, // set_width()

    set_hooks: function(abc) {
	abc.do_pscom = abc2svg.gamelan.do_pscom.bind(abc, abc.do_pscom)
	abc.draw_symbols = abc2svg.gamelan.draw_symbols.bind(abc, abc.draw_symbols)
	abc.output_music = abc2svg.gamelan.output_music.bind(abc, abc.output_music)
	abc.set_format = abc2svg.gamelan.set_fmt.bind(abc, abc.set_format)
	abc.set_pitch = abc2svg.gamelan.set_pitch.bind(abc, abc.set_pitch)
	abc.set_width = abc2svg.gamelan.set_width.bind(abc, abc.set_width)

	// big staccato dot
	abc.get_glyphs().gstc = '<circle id="gstc" cx="0" cy="-3" r="2"/>'
	abc.get_decos().gstc = "0 gstc 5 1 1"

	abc.add_style("\n.bn {font-family:sans-serif; font-size:16px}")
    } // set_hooks()
} // gamelan

abc2svg.modules.hooks.push(abc2svg.gamelan.set_hooks)

// the module is loaded
abc2svg.modules.gamelan.loaded = true
Changes to modules/grid.js.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20


21
22
23
24



25
26
27

28
29
30
31
32
33
34
35
36
37
38




39
40
41
42

43
44
45

46
47
48
49
50
51
52
53
54
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


20
21




22
23
24



25


26








27
28
29
30
31
32
33

34
35
36

37


38
39
40
41
42
43
44


-
+














+

-
-
+
+
-
-
-
-
+
+
+
-
-
-
+
-
-

-
-
-
-
-
-
-
-
+
+
+
+



-
+


-
+
-
-







// grid.js - module to insert a chord grid before or after a tune
//
// Copyright (C) 2018-2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2018-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%grid" appears in a ABC source.
//
// Parameters
//	%%grid <n> [include=<list>] [nomusic] [norepeat] [repbrk]
//		<n> = number of columns (1: auto)
//			> 0: above the tune, < 0: under the tune
//		<list> = comma separated list of (continuous) measure numbers
//		'nomusic' displays only the grid
//		'norepeat' omits the ':' indications
//		'repbrk' starts a new grid line on start/stop repeat
//	%%gridfont font_name size (default: 'serif 16')

abc2svg.grid = {
    pl: '<path class="stroke" stroke-width="1" d="M',

// function called before tune generation
    do_grid: function() {
// generate the grid
    block_gen: function(of, s) {
    var	C = abc2svg.C,
	tsfirst = this.get_tsfirst(),
	voice_tb = this.get_voice_tb(),
	img, font_cl, cls,
	if (s.subtype != "grid") {
		of(s)
		return
	cfmt = this.cfmt(),
	grid = cfmt.grid

	}
function get_beat(s) {
    var	beat = C.BLEN / 4

	if (!s.a_meter[0] || s.a_meter[0].top[0] == 'C' || !s.a_meter[0].bot)
		return beat;
	beat = C.BLEN / s.a_meter[0].bot[0] |0
	if (s.a_meter[0].bot[0] == 8
	 && s.a_meter[0].top[0] % 3 == 0)
		beat = C.BLEN / 8 * 3
	return beat
} // get_beat()
    var	abc = this,
	img, cls,
	cfmt = abc.cfmt(),
	grid = cfmt.grid

// generate the grid
function build_grid(chords, bars, font, wmx) {
    var	i, k, l, nr, line, bar, w, hr, x0, x, y, yl,
    var	i, k, l, nr, bar, w, hr, x0, x, y, yl,
	lc = '',
	cells = [],
	nc = grid.n,
	nc = grid.n
	sf = '" style="font-size:' + (font.size * .72).toFixed(1)
						// small font

	// set some chord(s) in each cell
	function set_chords() {
	    var	i, ch,
		pch = '-'

		for (i = 0; i < chords.length; i++) {
︙
74
75
76
77
78
79
80
81
82
83
84
85



86
87

88
89
90
91



92
93

94
95


96
97
98
99
100
101

102
103
104


105
106
107
108
109
110
111
112



113
114
115


116
117
118

119
120

121
122
123
124
125


126
127
128
129
130
131
132
133


134
135
136
137
138

139
140
141
142
143
144
145
64
65
66
67
68
69
70

71



72
73
74
75

76
77



78
79
80
81

82


83
84






85
86


87
88


89
90
91



92
93
94
95


96
97



98


99


100


101
102


103
104
105



106
107
108

109
110

111
112
113
114
115
116
117
118







-

-
-
-
+
+
+

-
+

-
-
-
+
+
+

-
+
-
-
+
+
-
-
-
-
-
-
+

-
-
+
+
-
-



-
-
-
+
+
+

-
-
+
+
-
-
-
+
-
-
+
-
-

-
-
+
+
-
-



-
-
-
+
+

-


-
+







			if (!ch[2])
				ch[2] = ch[1] || ch[0];
			pch = ch[3]
		}
	} // set_chords()

	function build_cell(cell, x, y, yl, hr) {
	    var	line = ''
		if (cell.length > 1) {
			line += '<path class="stroke" stroke-width="1" d="M' +
				(x - wmx / 2).toFixed(1) + ' ' +
				yl.toFixed(1) + 'l' +
			abc.out_svg(abc2svg.grid.pl)		// / line
			abc.out_sxsy(x - wmx / 2, ' ', yl)
			abc.out_svg('l' +
				wmx.toFixed(1) + ' -' + hr.toFixed(1) +
				'"/>\n'
				'"/>\n')
			if (cell[1]) {
			    line += '<path class="stroke" stroke-width="1" d="M' +
				(x - wmx / 2).toFixed(1) + ' ' +
				(yl - hr).toFixed(1) + 'l' +
			    abc.out_svg(abc2svg.grid.pl)	// \ left line
			    abc.out_sxsy(x - wmx / 2, ' ', yl + hr)
			    abc.out_svg('l' +
				(wmx / 2).toFixed(1) + ' ' + (hr / 2).toFixed(1) +
				'"/>\n'
				'"/>\n')
			    line += '<text class="' + cls + sf + '" x="' +
				(x - wmx / 3).toFixed(1) + '" y="' +
			    abc.set_font('gs')			// small font
			    abc.xy_str(x - wmx / 3, y, cell[0])
				y.toFixed(1) + '">' +
				cell[0] + '</text>\n'
			    line += '<text class="' + cls + sf + '" x="' +
				x.toFixed(1) + '" y="' +
				(y - hr / 3).toFixed(1) + '">' +
				cell[1] + '</text>\n'
			    abc.xy_str(x, y + hr / 3, cell[1])
			} else {
			    line += '<text class="' + cls + sf + '" x="' +
				(x - wmx * .2).toFixed(1) + '" y="' +
			    abc.set_font('gs')
			    abc.xy_str(x - wmx * .2, y + hr / 4, cell[0])
				(y - hr / 4).toFixed(1) + '">' +
				cell[0] + '</text>\n'
			}
			if (cell.length >= 3) {
			  if (cell[3]) {
			    line += '<path class="stroke" stroke-width="1" d="M' +
				x.toFixed(1) + ' ' +
				(yl - hr / 2).toFixed(1) + 'l' +
			    abc.out_svg(abc2svg.grid.pl)	// \ right line
			    abc.out_sxsy(x, ' ', yl + hr / 2)
			    abc.out_svg('l' +
				(wmx / 2).toFixed(1) + ' ' + (hr / 2).toFixed(1) +
				'"/>\n'
			    line += '<text class="' + cls + sf + '" x="' +
				'"/>\n')
			    abc.set_font('gs')
				x.toFixed(1) + '" y="' +
				(y + hr / 3).toFixed(1) + '">' +
				cell[2] + '</text>\n'
			    abc.xy_str(x, y - hr / 3, cell[2])
			    line += '<text class="' + cls + sf + '" x="' +
				(x + wmx / 3).toFixed(1) + '" y="' +
			    abc.xy_str(x + wmx / 3, y, cell[3])
				y.toFixed(1) + '">' +
				cell[3] + '</text>\n'
			  } else {
			    line += '<text class="' + cls + sf + '" x="' +
				(x + wmx * .2).toFixed(1) + '" y="' +
			    abc.set_font('gs')
			    abc.xy_str(x + wmx * .2, y - hr / 4, cell[2])
				(y + hr / 4).toFixed(1) + '">' +
				cell[2] + '</text>\n'
			  }
			}
		} else {
			line += '<text class="' + cls + '" x="' +
				x.toFixed(1) + '" y="' + y.toFixed(1) + '">' +
				cell[0] + '</text>\n'
			abc.set_font('grid')
			abc.xy_str(x, y, cell[0])
		}
		return line
	} // build_cell()

	// build_grid()
	// ------- build_grid() -------

	// set some chords in each cell
	set_chords()

	// build the content of the cells
	if (!grid.ls) {
		cells = chords
︙
166
167
168
169
170
171
172
173
174


175

176
177

178
179
180
181
182
183
184


185
186

187
188
189
190
191
192
193


194
195
196
197
198
199

200
201
202
203

204
205
206

207
208
209


210
211
212
213

214
215

216
217
218
219



220
221
222
223
224
225




226
227
228
229
230

231
232
233

234
235
236
237
238
239

240
241
242
243
244


245
246
247
248




249



























250
251
252
253
254
255
256







257
258
259
260
261
262
263
264
265
266












267
268




269
270
271
272
273









274








275

276
277
278
279
280









281
282
283
284

285
286

287
288
289

290
291
292
293
294
295
296
297
298
299
300
301














302
303
304
305
306



307
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
































345
346
347
348
349
350
351






352









353
354
355
356
357
358
359
360
361
362
363














364
365

366
367

368
369
370
371
372
373
374
375
376
377
378
379
380
381























382
383
384
385
386
387
388
389







390
391

392
393
394
395
396

397
398
399
400
401
402
403
139
140
141
142
143
144
145


146
147
148
149
150

151
152
153
154
155
156


157
158
159

160
161
162
163
164
165


166
167
168
169
170
171
172

173
174
175
176

177



178



179
180




181


182




183
184
185






186
187
188
189





190
191
192

193
194



195

196
197
198
199


200
201




202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233







234
235
236
237
238
239
240










241
242
243
244
245
246
247
248
249
250
251
252


253
254
255
256
257




258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277




278
279
280
281
282
283
284
285
286




287


288

289

290












291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307


308
309
310
311

312

313
314

































315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346


347




348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363











364
365
366
367
368
369
370
371
372
373
374
375
376
377


378
379

380



381










382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404








405
406
407
408
409
410
411


412



413

414
415
416
417
418
419
420
421







-
-
+
+

+

-
+





-
-
+
+

-
+





-
-
+
+





-
+



-
+
-
-
-
+
-
-
-
+
+
-
-
-
-
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+


-
+

-
-
-

-
+



-
-
+
+
-
-
-
-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+

-
-
-
-
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
-
+

-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
+
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+
+

-
+
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-

-
-
-
-
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+

-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-

-
+







		nc = -nc
	if (nc < 3)				// auto
		nc = cells.length % 6 == 0 ? 6 : 8
	if (nc > cells.length)
		nc = cells.length;

	hr = font.size * 2
	if (wmx < hr * 1.4)
		wmx = hr * 1.4;				// cell width
	if (wmx < hr * 1.5)
		wmx = hr * 1.5				// cell width

	x0 = img.width - img.lm - img.rm		// staff width
	w = wmx * nc
	if (w > img.width) {
	if (w > x0) {
		nc /= 2;
		w /= 2
	}

	// generate the cells
	yl = 1
	y = 1 - hr / 2 + font.size * .3
	yl = -1
	y = -1 + font.size * .6
	nr = 0
	x0 = (img.width - w) / 2
	x0 = (x0 / cfmt.scale - w) / 2
	for (i = 0; i < cells.length; i++) {
		if (i == 0
		 || (grid.repbrk
		  && (bars[i].slice(-1) == ':' || bars[i][0] == ':'))
		 || k >= nc) {
			y += hr			// new row
			yl += hr
			y -= hr			// new row
			yl -= hr
			x = x0 + wmx / 2
			k = 0
			nr++
		}
		k++
		lc += build_cell(cells[i], x, y, yl, hr)
		build_cell(cells[i], x, y, yl, hr)
		x += wmx
	}

	// build the SVG image
	// draw the lines
	line = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	xmlns:xlink="http://www.w3.org/1999/xlink"\n\
	color="black" width="' + img.width.toFixed(0) +
	abc.out_svg('<path class="stroke" stroke-width="1" d="\n')
			'px" height="' + (hr * nr + 6).toFixed(0) + 'px"';
	i = cfmt.bgcolor
	if (i)
	y = -1
	for (i = 0; i <= nr; i++) {
		line += ' style="background-color: ' + i + '"';
	line += '>\n<style type="text/css">\n\
.mid {text-anchor:middle}\n'

		abc.out_svg('M')
	if (cfmt.fullsvg || grid.nomusic)
		line += '\
		abc.out_sxsy(x0, ' ', y)
.stroke {stroke: currentColor; fill: none}\n\
.' + font_cl + ' {' + this.style_font(font) +  '}\n';
	line += '</style>\n'

		abc.out_svg('h' + w.toFixed(1)+ '\n')
		y -= hr
	}
	// draw the lines
	line += '<path class="stroke" d="\n';
	y = 1
	for (i = 0; i <= nr; i++) {
		line += 'M' + x0.toFixed(1) + ' ' + y.toFixed(1) +
			'h' + w.toFixed(1)+ '\n';
	x = x0
	for (i = 0; i <= nc; i++) {
		abc.out_svg('M')
		abc.out_sxsy(x, ' ', -1)
		y += hr
	}
	x = x0
	for (i = 0; i <= nc; i++) {
		line += 'M' + x.toFixed(1) + ' 1v' + (hr * nr).toFixed(1) + '\n';
		abc.out_svg('v' + (hr * nr).toFixed(1) + '\n')
		x += wmx
	}
	line += '"/>\n';
	abc.out_svg('"/>\n')

	// insert the cells
	line += lc

	// show the repeat signs
	y = 1 - hr / 2 + font.size * .3;
	y = -1 + font.size * .7
	x = x0
	for (i = 0; i < bars.length; i++) {
		bar = bars[i]
		if (bar[0] == ':')
			line += '<text class="' + cls + '" x="' +
		if (bar[0] == ':') {
			abc.out_svg('<text class="' + cls + '" x="')
				(x - 5).toFixed(1) +
				'" y="' + y.toFixed(1) +
				'" style="font-weight:bold;font-size:' +
			(font.size + 2).toFixed(1) + '">:</text>\n'
			abc.out_sxsy(x - 5, '" y="', y)
			abc.out_svg('" style="font-weight:bold;font-size:' +
				(font.size * 1.5).toFixed(1) + 'px">:</text>\n')
		}
		if (i == 0
		 || (grid.repbrk
		  && (bars[i].slice(-1) == ':' || bars[i][0] == ':'))
		 || k >= nc) {
			y -= hr;			// new row
			x = x0
			k = 0
		}
		k++
		if (bar.slice(-1) == ':') {
			abc.out_svg('<text class="' + cls + '" x="')
			abc.out_sxsy(x + 5, '" y="', y)
			abc.out_svg('" style="font-weight:bold;font-size:' +
				(font.size * 1.5).toFixed(1) + 'px">:</text>\n')
		}
		x += wmx
	}
	abc.vskip(hr * nr + 6)
} // build_grid()

	// ----- block_gen() -----
    var	p_voice, n, font, f2

	img = abc.get_img()

	// set the text style
	if (!cfmt.gridfont)
		abc.param_set_font("gridfont", "serif 16")
		 || (grid.repbrk
		  && (bars[i].slice(-1) == ':' || bars[i][0] == ':'))
		 || k >= nc) {
			y += hr;			// new row
			x = x0
			k = 0
		}
	font = abc.get_font('grid')
	if (font.class)
		font.class += ' mid'
	else
		font.class = 'mid'
	cls = abc.font_class(font)

		k++
		if (bar.slice(-1) == ':')
			line += '<text class="' + cls + '" x="' +
				(x + 5).toFixed(1) +
				'" y="' + y.toFixed(1) +
				'" style="font-weight:bold;font-size:' +
			(font.size + 2).toFixed(1) + '">:</text>\n'
		x += wmx
	}

	// define a smaller font
	abc.param_set_font("gsfont",
		font.name + ' ' + (font.size * .7).toFixed(1))
	f2 = cfmt.gsfont
	if (font.weight)
		f2.weight = font.weight
	if (font.style)
		f2.style = font.style
	f2.class = font.class
	abc.add_style("\n.mid {text-anchor:middle}")

	// create the grid
	return line + '</svg>'
} // build_grid()
	abc.blk_flush()
	build_grid(s.chords, s.bars, font, s.wmx)
	abc.blk_flush()
    }, // block_gen()

    var	s, beat, cur_beat, i, beat_i, p_voice, n, font, wm, bt, w, wmx, rep,
	bars = [],
	chords = [],
	chord = [];
    output_music: function(of) {
    var	C = abc2svg.C,
	abc = this,
	tsfirst = abc.get_tsfirst(),
	voice_tb = abc.get_voice_tb(),
	grid = abc.cfmt().grid

	function get_beat(s) {
	    var	beat = C.BLEN / 4

		if (!s.a_meter[0] || s.a_meter[0].top[0] == 'C'
		 || !s.a_meter[0].bot)
			return beat
		beat = C.BLEN / s.a_meter[0].bot[0] |0
		if (s.a_meter[0].bot[0] == 8
		 && s.a_meter[0].top[0] % 3 == 0)
			beat = C.BLEN / 8 * 3
		return beat
	img = this.get_img();
	} // get_beat()

	// get the beat
	beat = get_beat(voice_tb[0].meter);
	wm = voice_tb[0].meter.wmeasure;

	// build the arrays of chords and bars
	function build_chords(sb) {		// block 'grid'
	    var	s, i, w, bt, rep,
		bars = [],
		chords = [],
		chord = [],
		beat = get_beat(voice_tb[0].meter),
		wm = voice_tb[0].meter.wmeasure,
		cur_beat = 0,
	// set the text style
	if (!cfmt.gridfont)
		this.param_set_font("gridfont", "serif 16");
	font = this.get_font('grid');
		beat_i = 0,
	font_cl = this.font_class(font)
	cls = font_cl + " mid";
		wmx = 0
	this.set_font('grid');		// (for strwh())

	// scan the first voice of the tune
		// scan the first voice of the tune
	cur_beat = beat_i = n = wmx = 0;
	bars.push('|')
	for (s = tsfirst; s; s = s.ts_next) {
		while (s.time > cur_beat) {
			if (beat_i < 3)		// only 2, 3 or 4 beats / measure...
				beat_i++;
			cur_beat += beat
		}
		switch (s.type) {
		case C.NOTE:
		case C.REST:
			if (s.a_gch) {		// search a chord symbol
		bars.push('|')
		for (s = tsfirst; s; s = s.ts_next) {
			while (s.time > cur_beat) {
				if (beat_i < 3)	// only 2, 3 or 4 beats / measure...
					beat_i++
				cur_beat += beat
			}
			switch (s.type) {
			case C.NOTE:
			case C.REST:
				if (!s.a_gch)
					break

				// search a chord symbol
				for (i = 0; i < s.a_gch.length; i++) {
					if (s.a_gch[i].type == 'g') {
						if (!chord[beat_i]) {
							chord[beat_i] = s.a_gch[i].text;
							w = this.strwh(chord[beat_i])[0]
							chord[beat_i] = s.a_gch[i].text
							abc.set_font(s.a_gch[i].font)
							w = abc.strwh(chord[beat_i])[0]
							if (w > wmx)
								wmx = w;
								wmx = w
							n++
						}
						break
					}
				}
			}
			break
		case C.BAR:
			bt = grid.norep ? '|' : s.bar_type
			if (s.time < wm) {		// if anacrusis
				if (chord.length) {
					chords.push(chord);
					bars.push(bt)
				} else {
					bars[0] = bt
				}
			} else {
				if (!s.bar_num)		// if not normal measure bar
					break
				chords.push(chord);
				bars.push(bt)
			}
			chord = [];
			cur_beat = s.time;	// synchronize in case of error
			beat_i = 0
			if (bt.indexOf(':') >= 0)
				rep = true	// some repeat
			while (s.ts_next && s.ts_next.type == C.BAR)
				s = s.ts_next
			break
		case C.METER:
			beat = get_beat(s)
			wm = s.wmeasure
			break
		}
	}
					}
				}
				break
			case C.BAR:
				bt = grid.norep ? '|' : s.bar_type
				if (s.time < wm) {		// if anacrusis
					if (chord.length) {
						chords.push(chord)
						bars.push(bt)
					} else {
						bars[0] = bt
					}
				} else {
					if (!s.bar_num)		// if not normal measure bar
						break
					chords.push(chord)
					bars.push(bt)
				}
				chord = []
				cur_beat = s.time	// synchronize in case of error
				beat_i = 0
				if (bt.indexOf(':') >= 0)
					rep = true	// some repeat
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
				break
			case C.METER:
				beat = get_beat(s)
				wm = s.wmeasure
				break
			}
		}
	if (n == 0)				// no chord in this tune
		return

	if (chord.length != 0) {
		bars.push('')
		chords.push(chord)
	}
		if (chord.length) {
			bars.push('')
			chords.push(chord)
		}
		if (!chords.length)
			return			// no chord in this tune

		wmx += abc.strwh(rep ? '    ' : '  ')[0]

		sb.chords = chords
		sb.bars = bars
		sb.wmx = wmx
	} // build_chords

	// -------- output_music --------

	// create the grid
	wmx += this.strwh(rep ? '    ' : '  ')[0];
	p_voice = voice_tb[this.get_top_v()]
	s = {
		type: C.BLOCK,
		subtype: 'ml',
		dur: 0,
		time: 0,
		p_v: p_voice,
		v: p_voice.v,
		st: p_voice.st,
	// create a specific block
	if (grid) {
	    var	C = abc2svg.C,
		tsfirst = this.get_tsfirst(),
		voice_tb = this.get_voice_tb(),
		p_v = voice_tb[this.get_top_v()],
		s = {
			type: C.BLOCK,
			subtype: 'grid',
			dur: 0,
			time: 0,
			p_v: p_v,
			v: p_v.v,
			st: p_v.st
		text: build_grid.call(this, chords, bars, font, wmx)
	}
		}

	if (grid.nomusic) {		// if no music
		build_chords(s)			// build the array of the chords
		this.set_tsfirst(s)
		return
	}

	// and insert it in the tune
	if (cfmt.grid.n < 0) {		// below
		for (var s2 = tsfirst; s2.ts_next; s2 = s2.ts_next)
			;
		s.time = s2.time;
		s.prev = p_voice.last_sym;
		s.ts_prev = s2;
		p_voice.last_sym.next = s;
		s2.ts_next = s
	} else {			// above
		// and insert it in the tune
		if (!s.chords) {		// if no chord
			;
		} else if (grid.nomusic) {	// if just the grid
			this.set_tsfirst(s)
		} else if (grid.n < 0) {	// below
			for (var s2 = tsfirst; s2.ts_next; s2 = s2.ts_next)
				;
			s.time = s2.time
			s.prev = p_v.last_sym.prev // before the last symbol
			s.prev.next = s
			s.next = p_v.last_sym
			p_v.last_sym.prev = s

			s.ts_prev = s2.ts_prev
			s.ts_prev.ts_next = s
			s.ts_next = s2
			s2.ts_prev = s
			if (s2.seqst) {
				s.seqst = true
				s2.seqst = false
			}
		} else {			// above
		s.time = 0;
		s.next = p_voice.sym;
		s.ts_next = tsfirst;
		tsfirst.ts_prev = s;
		this.set_tsfirst(s);
		p_voice.sym.prev = s;
		p_voice.sym = s
	}
			s.next = p_v.sym
			s.ts_next = tsfirst
			tsfirst.ts_prev = s
			this.set_tsfirst(s)
			p_v.sym.prev = s
			p_v.sym = s
		}
    }, // do_grid()

	}
    output_music: function(of) {
	if (this.cfmt().grid)
		abc2svg.grid.do_grid.call(this);
	of()
    },
    }, // output_music()

    set_fmt: function(of, cmd, parm) {
	if (cmd == "grid") {
		if (!parm)
			parm = "1";
		parm = parm.split(/\s+/)
		var grid = {n: Number(parm.shift())}
︙
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456







+









		this.cfmt().grid = grid
		return
	}
	of(cmd, parm)
    },

    set_hooks: function(abc) {
	abc.block_gen = abc2svg.grid.block_gen.bind(abc, abc.block_gen)
	abc.output_music = abc2svg.grid.output_music.bind(abc, abc.output_music);
	abc.set_format = abc2svg.grid.set_fmt.bind(abc, abc.set_format)
    }
} // grid

abc2svg.modules.hooks.push(abc2svg.grid.set_hooks);

// the module is loaded
abc2svg.modules.grid.loaded = true
Changes to modules/grid2.js.
︙
30
31
32
33
34
35
36


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




60
61
62


63
64
65
66
67
68
69








70
71
72
73
74
75
76
77
78
79
80
81
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57




58
59
60
61



62
63







64
65
66
67
68
69
70
71





72
73
74
75
76
77
78







+
+



















-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-







				continue
			}

			// set all notes
				s.invis = true;	//  as invisible
				delete s.sl1;	//  with no slur
				delete s.tie_s	//  and no tie
				for (ix = 0; ix <= s.nhd; ix++)
					delete s.notes[ix].tie_ty
				if (s.tf)	// don't show the tuplets
					s.tf[0] = 1
				if (!s.a_gch) {
					if (s.time == bt)
						s.a_gch = c_a_cs
					continue
				}
				for (ix = 0; ix < s.a_gch.length; ix++) {
					gch = s.a_gch[ix]
					if (gch.type == 'g') {
						c_a_cs = s.a_gch
						break
					}
				}
		}
	}
    }, // do_grid()

    // draw the chord symbol in the middle of the staff
    draw_chosym: function(s) {
    var	ix, gch;

	this.set_dscale(s.st)
    draw_gchord: function(of, i, s, x, y) {
    var	an
	if (s.p_v.grid2) {
		this.set_dscale(s.st)
	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		if (gch.type != 'g')
		an = s.a_gch[i]
		if (an.type == 'g') {
			continue
		this.use_font(gch.font);
		this.set_font(gch.font);
		this.xy_str(s.x + gch.x, gch.y + 6, gch.text)
	}
    }, // draw_chosym()

			this.use_font(an.font)
			this.set_font(an.font)
			this.xy_str(s.x + an.x, 12 - an.font.size * .5,
					an.text)
		}
	} else {
		of(i, s, x, y)
	}
    draw_gchord: function(of, s, gchy_min, gchy_max) {
	if (s.p_v.grid2)
		abc2svg.grid2.draw_chosym.call(this, s)
	else
		of(s, gchy_min, gchy_max)
    },

    output_music: function(of) {
	abc2svg.grid2.do_grid.call(this);
	of()
    },

︙
Added modules/grid3.js.



































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// grid3.js - module to insert a manual chords
//
// Copyright (C) 2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%begingrid" appears in a ABC source.
//
// Parameters
//	%%begingrid [ chord-define [ noprint ] ]
//	    list of chords, '-' or '.', measure bars ('|') and ':' for repeat
//	%%endgrid
//
//	%%gridfont font_name size (default: 'serif 16')
//
// When this command appears inside a tune and when 'chord-define' is present,
// the chords are used to define the chord symbols that are displayed
// above the staff system.
// When 'noprint' is also present, the grid itself is not displayed.

abc2svg.grid3 = {

// generate the grid
    block_gen: function(of, s) {
	if (s.subtype != "grid") {
		of(s)
		return
	}

    var	abc = this,
	cfmt = abc.cfmt(),
	img = abc.get_img(),
	txt = s.text,
	font, font_cl, cls, w,
	ln, i,
	lines = [],
	cl = [],
	bars = [],
	cells = [],
	nr = 0,			// number of rows
	nc = 0,			// number of columns
	wc = 0			// width of a cell

	// generate the grid
	function build_grid() {
	    var	i, k, l, line, bl, bar, w, hr, x0, x, y, yl, cl, cell,
		lc = '',
		path = '<path class="stroke" stroke-width="1" d="M',
		sf = '" style="font-size:' + (font.size * .72).toFixed(1) + 'px'
						// small font

		function build_ch(cl, x, y, n) {
			return '<text class="' + cl + '" x="' +
				x.toFixed(1) + '" y="' + y.toFixed(1) + '">' +
					cell[n] + '</text>\n'
		} // build_ch()

		function build_cell(cell, x, y, yl, hr) {
		    var	line

			if (cell.length > 1) {
				line = path +
					(x - wc / 2).toFixed(1) + ' ' +
					yl.toFixed(1) + 'l' +
					wc.toFixed(1) + ' -' + hr.toFixed(1) +
					'"/>\n'
				if (cell[1]) {
				    line += path +
					(x - wc / 2).toFixed(1) + ' ' +
					(yl - hr).toFixed(1) + 'l' +
					(wc / 2).toFixed(1) + ' ' + (hr / 2).toFixed(1) +
						'"/>\n' +
					build_ch(cls + sf, x - wc / 3, y, 0) +
					build_ch(cls + sf, x, y - hr * .32, 1)
				} else {
					line += build_ch(cls + sf,
						x - wc * .2, y - hr / 4, 0)
				}
				if (cell.length >= 3) {
				  if (cell[3]) {
				    line += path +
					x.toFixed(1) + ' ' +
					(yl - hr / 2).toFixed(1) + 'l' +
					(wc / 2).toFixed(1) + ' ' + (hr / 2).toFixed(1) +
						'"/>\n' +
					build_ch(cls + sf, x, y + hr * .3, 2) +
					build_ch(cls + sf, x + wc / 3, y, 3)
				  } else {
					line += build_ch(cls + sf,
						x + wc * .2, y + hr / 4, 2)
				  }
				}
			} else {
				line = build_ch(cls, x, y, 0)
			}
			return line
		} // build_cell()

		// -- build_grid() --

		// build the content of the cells
		hr = font.size * 2.1
		if (wc < hr * 1.4)
			wc = hr * 1.4			// cell width
		w = wc * nc				// grid width

		// generate the cells
		yl = 3
		y = 3 - font.size * .7
		x0 = (img.width / cfmt.scale - w) / 2
		while (1) {
			cl = cells.shift()
			if (!cl)
				break
			y += hr
			yl += hr
			x = x0 + wc / 2
			while (1) {
				cell = cl.shift()
				if (!cell)
					break
				lc += build_cell(cell, x, y, yl, hr)
				x += wc
			}
		}

		// draw the lines
		line = '<path class="stroke" d="\n'
		y = 3
		for (i = 0; i <= nr; i++) {
			line += 'M' + x0.toFixed(1) + ' ' + y.toFixed(1) +
				'h' + w.toFixed(1)+ '\n'
			y += hr
		}
		x = x0
		for (i = 0; i <= nc; i++) {
			line += 'M' + x.toFixed(1) + ' 3v' + (hr * nr).toFixed(1) + '\n'
			x += wc
		}
		line += '"/>\n'

		// insert the cells
		line += lc

		// show the repeat signs
		y = 3 - font.size * .7
		while (1) {
			bl = bars.shift()
			if (!bl)
				break
			x = x0
			y += hr
			while (1) {
				bar = bl.shift()
				if (!bar)
					break
				if (bar[0] == ':')
					line += '<text class="' + cls + '" x="' +
						(x - 5).toFixed(1) +
						'" y="' + y.toFixed(1) +
						'" style="font-weight:bold;font-size:' +
						(font.size * 1.6).toFixed(1) +
						'px">:</text>\n'
				if (bar.slice(-1) == ':')
					line += '<text class="' + cls + '" x="' +
						(x + 5).toFixed(1) +
						'" y="' + y.toFixed(1) +
						'" style="font-weight:bold;font-size:' +
						(font.size * 1.6).toFixed(1) +
						'px">:</text>\n'
				x += wc
			}
		}
		abc.out_svg(line)
		abc.vskip(hr * nr + 6)
	} // build_grid()

	// ----- block_gen ----

	// set the text style
	if (!cfmt.gridfont)
		abc.param_set_font("gridfont", "serif 16")
	font = abc.get_font('grid')
	font_cl = abc.font_class(font)
	cls = font_cl + " mid"
	abc.add_style("\n.mid {text-anchor:middle}")
	abc.set_font('grid')		// (for strwh())

	// scan the grid content
	txt = txt.split('\n')
	while (1) {
		ln = txt.shift()	// line
		if (!ln)
			break

		// extract the bars and the chords
		ln = ln.match(/[|:]+|[^|:\s]+/g)
		bars[nr] = []
		cells[nr] = []
		i = -1
		while (1) {
			cl = ln.shift()
			if (!cl)
				break
			if (cl.match(/[:|]+/)) {
				bars[nr][++i] = cl
				cells[nr][i] = []
			} else {
				if (!cells[nr][i]) {	// if starting '|' is missing
					bars[nr][++i] = '|'
					cells[nr][i] = []
				}
				if (cl == '.' || cl == '-')
					cl = ''
				cells[nr][i].push(cl)
			}
		}
		if (cells[nr][i].length)
			bars[nr][++i] = '|'	// missing ending bar
		else
			cells[nr][i] = null	// keep just the measure bar

		if (i > nc)
			nc = i

		i = 0
		while (1) {
			cl = cells[nr][i++]
			if (!cl)
				break
			if (cl.length == 2) {
				cl[2] = cl[1]	// "| A B |" => "|A - B|"
				cl[1] = ''
			}
			w = abc.strwh(cl.join(''))[0]
			if (w > wc)
				wc = w
		}
		nr++
	}
	wc += abc.strwh('  ')[0]

	// build the grid and insert it in the music
	abc.blk_flush()
	build_grid()
	abc.blk_flush()
    }, // block_gen()

// handle %%begingrid
    do_begin_end: function(of, type, opt, txt) {
    var	vt = this.get_voice_tb()

	if (type != "grid") {
		of(type, opt, txt)
		return
	}

	// replace the accidentals
	txt = txt.replace(/#|=|b/g,
		function(x) {
			switch (x) {
			case '#': return "\u266f"
			case '=': return "\u266e"
//			case 'b': return "\u266d"
			}
			return "\u266d"
		})

	if (opt.indexOf("chord-define") >= 0)
		this.cfmt().csdef = txt
	if (opt.indexOf("noprint") < 0) {
		if (this.parse.state >= 2) {
			s = this.new_block(type)
			s.text = txt
		} else {
			abc2svg.grid3.block_gen.call(this, null, {
						subtype: type,
						text: txt
						})
		}
	}
    }, // do_begin_end()

    output_music: function(of) {
    var	ln, i, dt, ss, ntim, p_vc, s3,
	C = abc2svg.C,
	abc = this,
	s = abc.get_tsfirst(),
	vt = abc.get_voice_tb(),
	t = abc.cfmt().csdef,
	cs = []

	// add a chord symbol
	function add_cs(ss, ch) {
	    var	s = {			// invisible rest in the voice "grid3"
			type: C.REST,
			fname: ss.fname,
			istart: ss.istart,
			iend: ss.iend,
			v: p_vc.v,
			p_v: p_vc,
			time: ntim,
			st: 0,
			dur: 0,
			dur_orig: 0,
			invis: true,
			seqst: true,
			nhd: 0,
			notes: [{
				pit: 18,
				dur: 0
			}]
		}

		if (ch != '.' && ch != '-') {
			abc.set_a_gch(s, [{	// define the chord symbol
				type: 'g',
				text: ch,
				otext: ch,
				istart: ss.istart,
				iend: ss.iend,
				font: abc.get_font("gchord")
			}])
		}

		// insert the rest
		if (!p_vc.last_sym) {
			p_vc.sym = s
		} else {
			s.prev = p_vc.last_sym
			s.prev.next = s
		}
		p_vc.last_sym = s
		s.ts_next = ss
		s.ts_prev = ss.ts_prev
		s.ts_prev.ts_next = s
		ss.ts_prev = s
		if (s.time == ss.time)
			delete ss.seqst
		return s
	} // add_cs()

	if (t) {				// if chord-define
		p_vc = {
			id: "grid3",
			v: vt.length,
			time: 0,
			pos: {
				gst: 0
			},
			scale: 1,
			st: 0,
			second: true,
			sls: []
		}
		vt.push(p_vc)	// add the voice supporting the chord symbols

		t = t.split('\n')
		while (1) {			// scan the grid content
			ln = t.shift()		// line
			if (!ln)
				break
			ln = ln.trimLeft()
			if (ln[0] == '|')
				ln = ln.slice(ln[1] == ':' ? 2 : 1)
			if (ln[ln.length - 1] != '|')
				ln = ln + '|'

			// extract the bars and the chords
			ln = ln.match(/[|:]+|[^|:\s]+/g)
			while (1) {
				cl = ln.shift()
				if (!cl)
					break
				if (cl[0] == '|' || cl[0] == ':') {
					while (s && !s.dur)
						s = s.ts_next
					if (!s)
						break
					ss = s			// first note/rest
					while (s && !s.bar_type)
						s = s.ts_next	// end of measure
					if (!cs.length)
						cs = ['.']
					ntim = ss.time
					dt = (s.time - ntim) / cs.length
					s3 = null
					for (i = 0; i < cs.length; i++) {
						if ((cs[i] != '.'
						  && cs[i] != '-')
						 || !s3) {
							while (ss.time < ntim)
								ss = ss.ts_next
							s3 = add_cs(ss, cs[i])
						}
						s3.dur += dt
						s3.dur_orig =
							s3.notes[0].dur = s3.dur
						ntim += dt
					}
					while (s && s.type != C.BAR)
						s = s.ts_next
					ss = {
						type: C.BAR,
						bar_type: "|",
						fname: s.fname,
						istart: s.istart,
						iend: s.iend,
						v: p_vc.v,
						p_v: p_vc,
						st: 0,
						time: s.time,
						dur: 0,
						nhd: 0,
						notes: [{
							pit: 18
						}],
						next: s,
						ts_next: s,
						prev: s.prev,
						ts_prev: s.ts_prev
					}
					if (!s)
						break
					if (s.seqst) {
						ss.seqst = true
						delete s.seqst
					}
					ss.prev.next =
						ss.ts_prev.ts_next =
						s.prev =
							s.ts_prev = ss
					cs = []
				} else {
					cs.push(cl)
				}
			}
		}
	}
	of()
    }, // output_music()

    set_hooks: function(abc) {
	abc.block_gen = abc2svg.grid3.block_gen.bind(abc, abc.block_gen)
	abc.do_begin_end = abc2svg.grid3.do_begin_end.bind(abc, abc.do_begin_end)
	abc.output_music = abc2svg.grid3.output_music.bind(abc, abc.output_music)
    }
} // grid3

abc2svg.modules.hooks.push(abc2svg.grid3.set_hooks)

// the module is loaded
abc2svg.modules.begingrid.loaded = true
Added modules/jazzchord.js.
























































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// abc2svg - jazzchord.js - Adds jazz chord styling to chord symbols
//
// Copyright (C) 2020 Jean-Francois Moine
// License GPL-3
// Code adapted from Chris Fargen.
//	https://gist.github.com/chrisfargen/4324c6cf6fed2c8f9a6eae1680e53169
//
// This module is loaded by %%jazzchord.
//
// Parameters
//	%%jazzchord [ string '=' replacement-string ]*

abc2svg.jazzchord = {

    gch_build: function(of, s) {
    var	gch, i, ix, t

	if (!this.cfmt().jazzchord) {
		of(s)
		return
	}

	for (ix = 0; ix < s.a_gch.length; ix++) {
		gch = s.a_gch[ix]
		t = gch.text
		if (gch.type != 'g'
		 || t.indexOf('$') >= 0)	// if some formatting already
			continue
		switch (t) {
		case "/": gch.text = "&#x1d10d;"; continue
		case "%": gch.text = "&#x1d10e;"; continue
		case "%%": gch.text = "&#x1d10e;"; continue
		}

		if (abc2svg.jazzchord.rep) {	// if replacement list
			t = t.replace(abc2svg.jazzchord.reg, function(x) {
				return abc2svg.jazzchord.rep[x]
			})
		}


		t = t.replace(/-|°|º|ᵒ|0|6\/9|\^/g, function(x) {
			switch (x) {
			case '-': return "–"
			case '0': return "ø"
			case '6/9': return "⁶⁄₉"
			case '^': return "∆"
			default: return "o"
			}
		})
		if (t[0] == '(')
			t = t.slice(1, -1)
		i = 1
		switch (t[1]) {
		case "\u266f":		// #
		case "\u266d":		// b
			i++
			break
		}
		a = t.match(/([A-G])([#♯b♭]?)([^/]*)\/?(.*)/)
		// a[1] = note, a[2] = acc, a[3] = type, a[4] = bass
		if (!a)
			continue
		if (!a[2])
			t = a[1]
		else
			t = "$6" + a[1] + "$7" + a[2] + "$0"
		if (a[3])
			t += "$8" + a[3] + "$0"
		if (a[4])
			t += "/$9" + a[4] + "$0"
		if (gch.text[0] == '(')
			gch.text = '(' + t + ')'
		else
			gch.text = t
	}
	of(s)				// build the chord symbols
    }, // gch_build()

    set_fmt: function(of, cmd, parm) {
    var	r, k

	if (cmd == "jazzchord") {
		this.cfmt().jazzchord = this.get_bool(parm)
		if (parm && parm.indexOf('=') > 0) {
			parm = parm.split(/[\s]+/)
			abc2svg.jazzchord.rep = {}
			r = []
			for (cmd = 0; cmd < parm.length; cmd++) {
				k = parm[cmd].split('=')
				if (k.length == 2) {
					abc2svg.jazzchord.rep[k[0]] = k[1]
					r.push(k[0])
				}
			}
			abc2svg.jazzchord.reg = new RegExp(r.join('|'))
		}
		return
	}
	of(cmd, parm)
    }, // set_fmt()

    set_hooks: function(abc) {
	abc.gch_build = abc2svg.jazzchord.gch_build.bind(abc, abc.gch_build)
	abc.set_format = abc2svg.jazzchord.set_fmt.bind(abc, abc.set_format)

	abc.add_style("\n.jc6{letter-spacing:-0.05em}\
\n.jc7{baseline-shift:30%;font-size:75%}\
\n.jc8{baseline-shift:25%;font-size:75%;letter-spacing:-0.05em}\
\n.jc9{font-size:75%;letter-spacing:-0.05em}\
")
	abc.param_set_font("setfont-6", "* * class=jc6")
	abc.param_set_font("setfont-7", "* * class=jc7")
	abc.param_set_font("setfont-8", "* * class=jc8")
	abc.param_set_font("setfont-9", "* * class=jc9")
    } // set_hooks()
} // jazzchord

abc2svg.modules.hooks.push(abc2svg.jazzchord.set_hooks)
abc2svg.modules.jazzchord.loaded = true
Added modules/jianpu.js.












































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// jianpu.js - module to output jiănpŭ (简谱) music sheets
//
// Copyright (C) 2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%jianpu" appears in a ABC source.
//
// Parameters (none)
//	%%jianpu 1

abc2svg.jianpu = {

  k_tb: [ "Cb", "Gb", "Db", "Ab", "Eb", "Bb", "F",
	  "C",
	  "G", "D", "A", "E", "B", "F#", "C#" ],
  cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]),
  cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3,
			  0, -4, -1, -5, -2, -6, -3, 0]),
  acc2: new Int8Array([-2, -1, 3, 1, 2]),
  acc_tb: ["\ue264", "\ue260", , "\ue262", "\ue263", "\ue261"],

// change %%staves and %%score
  do_pscom: function(of, p) {
	switch (p.match(/\w+/)[0]) {
	case 'staves':
	case 'score':
		p = p.replace(/\(|\)/g, '')
		break
	}
	of(p)
  },

// adjust some symbols before the generation
  output_music: function(of) {
    var	C = abc2svg.C,
	abc = this,
	cur_sy = abc.get_cur_sy(),
	voice_tb = abc.get_voice_tb()

	if (!abc.cfmt().jianpu) {
		of()
		return
	}

	// output the key and time signatures
	function set_head() {
	    var	tsfirst = abc.get_tsfirst(),
		p_v = voice_tb[0],
		mt = p_v.meter.a_meter[0],
		sk = p_v.key,
		s = {
			type: C.BLOCK,
			subtype: "text",
			dur: 0,
			v: 0,
			p_v: p_v,
			st: 0,
			seqst: true,
			text: (sk.k_mode + 1) + "=" +
				(abc2svg.jianpu.k_tb[sk.k_sf + 7 +
					abc2svg.jianpu.cde2fcg[sk.k_mode]])
		},
		s2 = voice_tb[0].sym

		if (mt)
			s.text += ' ' + (mt.bot ? (mt.top + '/' + mt.bot) : mt.top)

		s2.prev = s
		s.next = s2
		voice_tb[0].sym = s
		tsfirst.ts_prev = s
		s.ts_next = tsfirst
		abc.set_tsfirst(s)
	} // set head()

	// expand a long note/rest
	function slice(s) {
	    var	n, s2, s3

		if (s.dur >= C.BLEN)
			n = 3 
		else if (s.dur == C.BLEN / 2)
			n = 1
		else
			n = 2
		while (--n >= 0) {
			s2 = {
				type: C.REST,
				v: s.v,
				p_v: s.p_v,
				st: s.st,
				dur: C.BLEN / 4,
				dur_orig: C.BLEN / 4,
				stem: 0,
				multi: 0,
				nhd: 0,
				notes: [{
					pit: s.notes[0].pit,
					jn: 8
				}],
				xmx: 0,
				noplay: true,
				time: s.time + C.BLEN / 4,
				prev: s,
				next: s.next
			}
			s.next = s2
			if (s2.next)
				s2.next.prev = s2

			if (!s.ts_next) {
				s.ts_next = s2
				if (s.soln)
					s.soln = false
				s2.ts_prev = s
				s2.seqst = true
			} else {
			    for (s3 = s.ts_next; s3; s3 = s3.ts_next) {
				if (s3.time < s2.time)
					continue
				if (s3.time > s2.time) {
					s2.seqst = true
					s3 = s3.ts_prev
				}
				s2.ts_next = s3.ts_next
				s2.ts_prev = s3
				if (s2.ts_next)
					s2.ts_next.ts_prev = s2
				s3.ts_next = s2
				break
			    }
			}

			s = s2
		}
	} // slice()

	function set_sym(p_v) {
	    var s, s2, note, pit, nn, p, a, m, i,
		sf = p_v.key.k_sf
		delta = abc2svg.jianpu.cgd2cde[sf + 7] - 2

		p_v.key.k_a_acc = []	// no accidental

		// no (visible) clef
		p_v.clef.invis = true

		// scan the voice
		for (s = p_v.sym; s; s = s.next) {
			s.st = p_v.st
			switch (s.type) {
			case C.CLEF:
				s.invis = true
//				continue
			default:
				continue
			case C.KEY:
				delta = abc2svg.jianpu.cgd2cde[s.k_sf + 7] - 2
				s.a_gch = [{
					type: '@',
					font: abc.get_font("annotation"),
					wh: [10, 10],
					x: -5,
					y: 30,
					text: (s.k_mode + 1) + "=" +
						(abc2svg.jianpu.k_tb[s.k_sf + 7 +
							abc2svg.jianpu.cde2fcg[s.k_mode]])
				}]
				continue
			case C.REST:
				if (s.notes[0].jn)
					continue
				s.notes[0].jn = 0
				if (s.dur >= C.BLEN / 2)
					slice(s)
				continue
			case C.NOTE:			// change the notes
				break
			}

			s.stem = -1
			s.stemless = true

			if (s.sls) {
				for (i = 0; i < s.sls.length; i++)
					s.sls[i].ty = C.SL_ABOVE
			}

			for (m = 0; m <= s.nhd; m++) {
				note = s.notes[m]

				// note head
				p = note.pit
				pit = p + delta
				note.jn = ((pit + 77) % 7) + 1	// note number

				// set a fixed offset to the note for the decorations
				note.pit = 25			// "e"

				note.jo = (pit / 7) | 0	// octave number

				// accidentals
				a = note.acc
				if (a) {
					nn = abc2svg.jianpu.cde2fcg[(p + 5 + 16 * 7) % 7] - sf
					if (a != 3)
						nn += a * 7
					nn = ((((nn + 1 + 21) / 7) | 0) + 2 - 3 + 32 * 5) % 5
					note.acc = abc2svg.jianpu.acc2[nn]
				}

				// set the slurs and ties up
				if (note.sls) {
					for (i = 0; i < note.sls.length; i++)
						note.sls[i].ty = C.SL_ABOVE
				}
				if (note.tie_ty)
					note.tie_ty = C.SL_ABOVE
			}

			// change the long notes
			if (s.dur >= C.BLEN / 2)
				slice(s)

			// replace the staccato dot
			if (s.a_dd) {
				for (i = 0; i < s.a_dd.length; i++) {
					if (s.a_dd[i].glyph == "stc") {
						abc.deco_cnv(["gstc"], s)
						s.a_dd[i] = s.a_dd.pop()
					}
				}
			}
		}
	} // set_sym()

	// -- output_music --

	set_head()

	for (v = 0; v < voice_tb.length; v++)
		set_sym(voice_tb[v])

	of()
  }, // output_music()

  draw_symbols: function(of, p_voice) {
    var	i, m, nl, note, s, s2, x, y,
	C = abc2svg.C,
	abc = this,
	dot = "\ue1e7",
	staff_tb = abc.get_staff_tb(),
	out_svg = abc.out_svg,
	out_sxsy = abc.out_sxsy,
	xypath = abc.xypath

	if (!abc.cfmt().jianpu) {
		of(p_voice)
		return
	}

	// draw the duration lines under the notes
	function draw_dur(s1, y, s2, n, nl) {
	    var s, s3

		xypath(s1.x - 3, y + 5)
		out_svg('h' + (s2.x - s1.x + 8).toFixed(1) + '"/>\n')	// "
		y -= 2.5
		while (++n <= nl) {
			s = s1
			while (1) {
				if (s.nflags && s.nflags >= n) {
					s3 = s
					while (s != s2) {
						if (s.next.beam_br1
						 || (s.next.beam_br2 && n > 2)
						 || (s.next.nflags
						  && s.next.nflags < n))
							break
						s = s.next
					}
					draw_dur(s3, y, s, n, nl)
				}
				if (s == s2)
					break
				s = s.next
			}
		}
	} // draw_dur()

	function out_mus(x, y, p) {
		out_svg('<text x="')
		out_sxsy(x, '" y="', y)
		out_svg('">' + p + '</text>\n')
	} // out_txt()

	function out_txt(x, y, p) {
		out_svg('<text class="bn" x="')
		out_sxsy(x, '" y="', y)
		out_svg('">' + p + '</text>\n')
	} // out_txt()

	function draw_hd(s, x, y) {
	    var	m, note, ym

		for (m = 0; m <= s.nhd; m++) {
			note = s.notes[m]
			out_txt(x - 3.5, y + 8, "01234567-"[note.jn])
			if (note.acc)
				out_mus(x - 12, y + 12,
					abc2svg.jianpu.acc_tb[note.acc + 2])
			if (note.jo > 2) {
				out_mus(x - 1, y + 22, dot)
				if (note.jo > 3) {
					y += 3
					out_mus(x - 1, y + 22, dot)
				}
			} else if (note.jo < 2) {
				ym = y + 4
				if (m == 0 && s.nflags > 0)
					ym -= 2.5 * s.nflags
				out_mus(x - 1, ym, dot)
			}
			y += 20
		}
	} // draw_hd()

	// -- draw_symbols --

	for (s = p_voice.sym; s; s = s.next) {
		if (s.invis)
			continue
		switch (s.type) {
		case C.METER:
			abc.draw_meter(s)
			break
		case C.NOTE:
		case C.REST:
			x = s.x
			y = staff_tb[s.st].y
			draw_hd(s, x, y)

			if (s.nflags >= 0 && s.dots)
				out_mus(x + 8, y + 13, dot)
			if (s.nflags > 0) {
//fixme: ko with rests because no beam_st /_end
				if (s.beam_st || s.type == C.REST) {
					nl = s.nflags
					s2 = s
					while (1) {
						if (s2.nflags && s2.nflags > nl)
							nl = s2.nflags
						if (s2.beam_end)
							break
						if (!s2.next
						 || !s2.next.nflags
						 || s2.next.nflags <= 0)
							break
						s2 = s2.next
					}
					draw_dur(s, y, s2, 1, nl)
				}
			}
			break
		}
	}
  }, // draw_symbols()

// set some parameters
    set_fmt: function(of, cmd, param) {
	if (cmd == "jianpu") {
	    var	cfmt = this.cfmt()

		cfmt.jianpu = true
		cfmt.staffsep = 20
		cfmt.sysstaffsep = 14
		this.set_v_param("stafflines", "...")
		cfmt.tuplets = [0, 1, 0, 1]	// [auto, slur, number, above]
		return
	}
	of(cmd, param)
    }, // set_fmt()

// adjust some values
    set_pitch: function(of, last_s) {
	of(last_s)
	if (!last_s
	 || !this.cfmt().jianpu)
		return			// first time

    var	C = abc2svg.C
	
	for (var s = this.get_tsfirst(); s; s = s.ts_next) {
		switch (s.type) {

		// draw the key signature only in the first voice
		// and not at start of the staff
		case C.KEY:
			if (s.prev.type == C.CLEF
			 || s.v != 0)
				s.a_gch = null
			break

		// adjust the vertical spacing above the note heads
		case C.NOTE:
			s.ymx = 20 * s.nhd + 22
			if (s.notes[s.nhd].jo > 2) {
				s.ymx += 3
				if (s.notes[s.nhd].jo > 3)
					s.ymx += 2
			}
			break
		}
	}
    }, // set_pitch()

// set the width of some symbols
    set_width: function(of, s) {
	of(s)
	if (!this.cfmt().jianpu)
		return

    var	w, m, note,
	C = abc2svg.C

	switch (s.type) {
	case C.CLEF:
	case C.KEY:
//	case C.METER:
		s.wl = s.wr = 0
		break
	case C.NOTE:
		for (m = 0; m <= s.nhd; m++) {
			note = s.notes[m]
			if (note.acc && s.wl < 14)	// room for the accidental
				s.wl = 14
		}
		break
	}
    }, // set_width()

    set_hooks: function(abc) {
	abc.do_pscom = abc2svg.jianpu.do_pscom.bind(abc, abc.do_pscom)
	abc.draw_symbols = abc2svg.jianpu.draw_symbols.bind(abc, abc.draw_symbols)
	abc.output_music = abc2svg.jianpu.output_music.bind(abc, abc.output_music)
	abc.set_format = abc2svg.jianpu.set_fmt.bind(abc, abc.set_format)
	abc.set_pitch = abc2svg.jianpu.set_pitch.bind(abc, abc.set_pitch)
	abc.set_width = abc2svg.jianpu.set_width.bind(abc, abc.set_width)

	// big staccato dot
	abc.get_glyphs().gstc = '<circle id="gstc" cx="0" cy="-3" r="2"/>'
	abc.get_decos().gstc = "0 gstc 5 1 1"

	abc.add_style("\n.bn {font-family:sans-serif; font-size:15px}")
    } // set_hooks()
} // jianpu

abc2svg.modules.hooks.push(abc2svg.jianpu.set_hooks)

// the module is loaded
abc2svg.modules.jianpu.loaded = true
Added modules/mdnn.js.































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// mdnn.js - module to output Modernised Diatonic Numerical Notation
// (https://medium.com/@info_70544/the-case-for-numerical-music-notation-part-1-introduction-and-history-5f1543ca8a95)
//
// Copyright (C) 2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%mdnn" appears in a ABC source.
//
// Parameters
//	(none)
//
//fixme:nsk
// - Non Standard Key signature - other way to display the accidentals on key change

// polyfill
if (typeof Object.assign !== 'function') {
  // Must be writable: true, enumerable: false, configurable: true
  Object.defineProperty(Object, "assign", {
    value: function assign(target, varArgs) { // .length of function is 2
      'use strict';
      if (target === null || target === undefined) {
        throw new TypeError('Cannot convert undefined or null to object');
      }

      var to = Object(target);

      for (var index = 1; index < arguments.length; index++) {
        var nextSource = arguments[index];

        if (nextSource !== null && nextSource !== undefined) { 
          for (var nextKey in nextSource) {
            // Avoid bugs when hasOwnProperty is shadowed
            if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
              to[nextKey] = nextSource[nextKey];
            }
          }
        }
      }
      return to;
    },
    writable: true,
    configurable: true
  });
}

abc2svg.mdnn = {

  cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]),
  cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3,
			  0, -4, -1, -5, -2, -6, -3, 0]),
  acc_tb: ["aff", "af", "n", "s", "ss"],

  glyphs: {
	n1: '<text id="n1" class="bn" x="-1.5" y="16">1</text>',
	n2: '<text id="n2" class="bn" x="-1.5" y="16">2</text>',
	n3: '<text id="n3" class="bn" x="-1.5" y="16">3</text>',
	n4: '<text id="n4" class="bn" x="-1.5" y="16">4</text>',
	n5: '<text id="n5" class="bn" x="-1.5" y="16">5</text>',
	n6: '<text id="n6" class="bn" x="-1.5" y="16">6</text>',
	n7: '<text id="n7" class="bn" x="-1.5" y="16">7</text>',
	nq: '<text id="nq" class="bn" x="8" y="16">\'</text>',
	nc: '<text id="nc" class="bn" x="8" y="16">,</text>',
	nh: '<path id="nh" class="stroke" d="m3.5 0l-7.2 0 0 -6.2 7.2 0"/>',
	nw: '<path id="nw" class="stroke" d="m6 -5l-7.2 0 0 -6.2 7.2 0 0 6.2"/>',
	aff: '<text id="aff" class="music" x="-8" y="11">&#xe264;</text>',
	af: '<text id="af" class="music" x="-8" y="11">&#xe260;</text>',
	nn: '<text id="nn" class="music" x="-8" y="11">&#xe261;</text>',
	ns: '<text id="ns" class="music" x="-8" y="11">&#xe262;</text>',
	nss: '<text id="nss" class="music" x="-8" y="11">&#xe263;</text>'
  }, //glyphs

  decos: {
	n1: "9 n1 0 0 0",
	n2: "9 n2 0 0 0",
	n3: "9 n3 0 0 0",
	n4: "9 n4 0 0 0",
	n5: "9 n5 0 0 0",
	n6: "9 n6 0 0 0",
	n7: "9 n7 0 0 0",
	q: "0 nq 0 0 0",
	c: "0 nc 0 0 0",
	h: "0 nh 0 0 0",
	w: "0 nw 0 0 0",
	aff: "0 aff 0 0 0",
	af: "0 af 0 0 0",
	n: "0 nn 0 0 0",
	s: "0 ns 0 0 0",
	ss: "0 nss 0 0 0"
  }, // decos

  // change the voices into MDNN
//fixme: actually, one voice only
  output_music: function(of) {
    var	C = abc2svg.C,
	abc = this,
	cfmt = abc.cfmt(),
	cur_sy = abc.get_cur_sy(),
	voice_tb = abc.get_voice_tb(),
	sf = voice_tb[0].key.k_sf,
	delta = abc2svg.mdnn.cgd2cde[sf + 7] - 2
    var s, s2, note, pit, nn, p, a, i,
	prev_oct = -10

	if (!cfmt.mdnn) {
		of()
		return
	}

	voice_tb[0].key.k_a_acc = []	// no accidental
	voice_tb[0].clef.invis = true	// no (visible) clef
	cur_sy.staves[0].stafflines = "..." // empty staff

	// scan the first voice of the tune
	for (s = voice_tb[0].sym; s; s = s.next) {
		switch (s.type) {
		case C.CLEF:
			s.invis = true
			continue
		case C.KEY:
//fixme:nsk
//			s.k_a_acc = []		// don't display the accidentals
			sf = s.k_sf
			delta = abc2svg.mdnn.cgd2cde[sf + 7] - 2
			nn = sf - s.k_old_sf	// delta accidentals
//fixme:nsk
//			if (!nn) {
//				s.k_old_sf = s.k_sf = 0 // don't display the accidentals
//				continue
//			}

//fixme:comment if nsk
			// display normal accidentals
			s.k_old_sf = 0
			s.k_sf = nn
			continue

//fixme:nsk
//			// display '[' <accidentals ']'
//			s2 = s
//// other solution
////			s2 = {
////				type: C.SPACE,
////				v: s.v,
////				p_v: s.p_v,
////				st: s.st,
////				dur: 0,
////				seqst: true,
////				invis: true,
////				time: s.time,
////				prev: s,
////				ts_prev: s,
////				next: s.next,
////				ts_next: s.ts_next
////			}
////			s.next = s2
////			s.ts_next = s2
////			if (s2.next)
////				s2.next.prev = s2
////			if (s2.ts_next)
////				s2.ts_next.ts_prev = s2
//			abc.set_font("annotation")
//			s2.a_gch = []
//			s2.a_gch[0] = {
//				type: '@',
//				font: abc.get_font("annotation"),
//				wh: [10,10],
//				y: -6,
////				text: '[' + (nn > 0 ?
////		"\u266f\u266f\u266f\u266f\u266f\u266f".slice(0, nn) :
////		"\u266d\u266d\u266d\u266d\u266d\u266d".slice(0, -nn)) +
////					']'
//				text: '[' + (nn > 0 ?
//					nn + '\u266f' : (-nn) + '\u266d') +
//					']'
//			}
//			s2.width = abc.strwh(s2.a_gch[0].text + ' ')[0]
//			s2.a_gch[0].x = -s2.width / 2
//			s = s2
//			continue
		default:
			continue
		case C.NOTE:			// change the notes
			break
		}
		note = s.notes[0]

		// note head
		p = note.pit
		pit = p + delta
		nn = ((pit + 77) % 7) + 1	// note number
		if (!note.a_dcn)
			note.a_dcn = []
		note.a_dcn.push('n' + nn)

		// display the note as C5 with stem up
		note.pit = 23			// 'c'
		s.stem = 1

		// octave
		nn = (pit / 7) | 0
		if (nn > prev_oct) {
			if (prev_oct != -10) {
				if (!note.a_dcn)
					note.a_dcn = []
				note.a_dcn.push('q')
			}
			prev_oct = nn
		} else if (nn < prev_oct) {
			if (!note.a_dcn)
				note.a_dcn = []
			note.a_dcn.push('c')
			prev_oct = nn
		}

		// half and whole notes
		if (s.dur >= C.BLEN / 2) {
			if (!note.a_dcn)
				note.a_dcn = []
			note.a_dcn.push(s.dur >= C.BLEN ? 'w' : 'h')
		}

		// accidentals
		a = note.acc
		if (a) {
			note.acc = 0
			if (!note.a_dcn)
				note.a_dcn = []
			nn = abc2svg.mdnn.cde2fcg[(p + 5 + 16 * 7) % 7] - sf
			if (a != 3)
				nn += a * 7
			nn = ((((nn + 1 + 21) / 7) | 0) + 2 - 3 + 32 * 5) % 5
			note.a_dcn.push(abc2svg.mdnn.acc_tb[nn])
		}

		// set the slurs and ties up
		if (s.sls) {
			for (i = 0; i < s.sls.length; i++)
				s.sls[i].ty = C.SL_ABOVE
		}
		if (note.sls) {
			for (i = 0; i < note.sls.length; i++)
				note.sls[i].ty = C.SL_ABOVE
		}
		if (note.tie_ty != undefined)
			note.tie_ty = C.SL_ABOVE
	}

	of()
  }, // output_music()

  set_fmt: function(of, cmd, param) {
	if (cmd == "mdnn")
		this.cfmt().mdnn = true
	else
		of(cmd, param)
  }, // set_fmt()

// don't display the key signature at start of staff
    set_pitch: function(of, last_s) {
	of(last_s)
	if (!last_s				// first time
	 || !this.cfmt().mdnn)
		return

    var	C = abc2svg.C,
	s = this.get_tsfirst()

	if (s && s.next && s.next.type == C.KEY)
//fixme:nsk
		s.next.k_a_acc = []
//		s.next.a_gch = null
    }, // set_pitch()

    set_hooks: function(abc) {
	abc.output_music = abc2svg.mdnn.output_music.bind(abc, abc.output_music)
	abc.set_format = abc2svg.mdnn.set_fmt.bind(abc, abc.set_format)
	abc.set_pitch = abc2svg.mdnn.set_pitch.bind(abc, abc.set_pitch)

	Object.assign(abc.get_glyphs(), abc2svg.mdnn.glyphs)
	Object.assign(abc.get_decos(), abc2svg.mdnn.decos)
	abc.add_style("\n.bn {font-family:sans-serif; font-size:15px}")
    }
} // mdnn

abc2svg.modules.hooks.push(abc2svg.mdnn.set_hooks)

// the module is loaded
abc2svg.modules.mdnn.loaded = true
Changes to modules/page.js.
1

2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20

21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43


44
45
46
47
48
49
50

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19

20





21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
-
+

-
+














-
+

-
+
-
-
-
-
-
+
-















-
+

+
+







// page.js - module to generate one SVG image per page
// page.js - module to generate pages
//
// Copyright (C) 2018-2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2018-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%pageheight" appears in a ABC source.
//
// Parameters
//	%%pageheight <unit>

abc2svg.page = {

    // output a new block
    img_out: function(page, p) {
    var	cur_img_out = user.img_out;

	page.user_out(p)
	
	// user.img_out may have been changed ..
	// if user.img_out has been changed
	if (user.img_out != cur_img_out) {
		page.user_out = user.img_out;
		page.user_out = user.img_out	// save the new function
		if (cur_img_out == page.img_out_sav) {	// .. by the backend
			user.img_out = abc2svg.page.img_in.bind(page.abc);
			page.img_out_sav = user.img_out	// keep our reference
		} else {
			user.img_out = cur_img_out	// .. by an other extension
		user.img_out = cur_img_out	// and restore ours
		}
	}
    },

    // function called at end of generation
    abc_end: function(of) {
    var page = this.page
	if (page && page.in_page) {
		abc2svg.page.close_page(page)
		if (user.img_out == page.img_out_sav)
			user.img_out = page.user_out
	}
	of()
    }, // abc_end()

    // generate a header or a footer in page.hf and return its height
    gen_hf: function(page, up, font, str) {
    gen_hf: function(page, ty) {
    var	a, i, j, k, x, y, y0, s,
	font = page.abc.get_font(ty),
	str = page[ty],
	cfmt = page.abc.cfmt(),
	fh = font.size * 1.1,
	pos = [ '">',
		'" text-anchor="middle">',
		'" text-anchor="end">' ]

	// create the text of a header or a footer
︙
99
100
101
102
103
104
105
106
107
108


109




110

111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
96
97
98
99
100
101
102



103
104
105
106
107
108
109

110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125







-
-
-
+
+

+
+
+
+
-
+







-
+







				break
			}
			c = str[++i]
			switch (c) {
			case 'd':
				if (!abc2svg.get_mtime)
					break // cannot know the change time of the file
				r[j] += strftime(cfmt.dateformat,
						abc2svg.get_mtime(page.abc.parse.fname))
				break
				t = abc2svg.get_mtime(page.abc.parse.fname)
				// fall thru
			case 'D':
				if (c == 'D')
					t = new Date()
				if (cfmt.dateformat[0] == '"')
					cfmt.dateformat = cfmt.dateformat.slice(1, -1)
				r[j] += strftime(cfmt.dateformat)
				r[j] += strftime(cfmt.dateformat, t)
				break
			case 'F':
				r[j] += page.abc.parse.fname
				break
			case 'I':
				c = str[++i]
			case 'T':
				t = abc.info()[c]
				t = page.abc.info()[c]
				if (t)
					r[j] += t.split('\n', 1)[0]
				break
			case 'P':
			case 'Q':
				t = c == 'P' ? page.pn : page.pna
				switch (str[i + 1]) {
︙
218
219
220
221
222
223
224
225

226
227
228
229

230
231
232
233
234
235
236
237
238

239
240

241
242

243
244
245
246

247

248
249
250
251

252
253








254
255
256
257
258
259


260
261
262
263
264
265
266
267
268
269
270
271
272
273

274
275








276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294

295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315
316

317
318

319
320
321
322
323
324
325
326

327
328
329



330

331
332
333
334
335
336

337
338
339
340
341

342
343










344







345
346
347
348
349

350
351
352
353
354
355
356
218
219
220
221
222
223
224

225

226
227

228
229
230
231
232
233
234
235
236

237
238

239
240

241


242
243
244

245
246
247
248
249
250


251
252
253
254
255
256
257
258
259
260
261
262


263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279


280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316

317
318
319
320
321








322


323


324
325
326
327
328

329
330
331

332
333
334
335
336
337
338
339
340
341

342



343
344
345


346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375







-
+
-


-
+








-
+

-
+

-
+
-
-


+
-
+




+
-
-
+
+
+
+
+
+
+
+




-
-
+
+














+
-
-
+
+
+
+
+
+
+
+


















+
-
+









-
+




-
-
-
-
-
-
-
-
+
-
-
+
-
-





-
+


-
+
+
+

+





-
+
-
-
-


+
-
-
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+




-
+







	}
	return fh * a[4]
    }, // gen_hf()

    // start a new page
    open_page: function(page,
			ht) {	// spacing under the header
    var	h, o_font,
    var	h, l,
//	font_style,
	abc = page.abc,
	cfmt = abc.cfmt(),
	sty = ""
	sty = '<div style="line-height:0'

	page.pn++
	page.pna++

	// start a new page
	if (page.first)
		page.first = false
	else
		sty = "page-break-before:always"
		sty += ";page-break-before:always"
	if (page.gutter)
		sty += (sty ? ";" : "") + "margin-left:" +
		sty += ";margin-left:" +
			((page.pn & 1) ? page.gutter : -page.gutter).toFixed(1) + "px"
	abc2svg.page.img_out(page, sty ?
	abc2svg.page.img_out(page, sty + '">')
			'<div style="' + sty + '">' :
			'<div>')
	page.in_page = true

	ht += page.topmargin
	page.hmax = cfmt.pageheight - page.topmargin - page.botmargin - ht
	page.hmax = cfmt.pageheight - page.botmargin - ht

	// define the header/footer
	page.hf = ''
	if (page.header) {
		l = abc.get_font_style().length
		h = abc2svg.page.gen_hf(page, true,
					abc.get_font("header"), page.header)
		h = abc2svg.page.gen_hf(page, "header")
		sty = abc.get_font_style().slice(l)		// new style(s)
		if (cfmt.fullsvg || sty != page.hsty) {
			page.hsty = sty
			sty = '<style>' + sty + '\n</style>\n'
		} else {
			sty = ''
		}
		abc2svg.page.img_out(page,
			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	xmlns:xlink="http://www.w3.org/1999/xlink"\n\
	width="' + cfmt.pagewidth.toFixed(0) +
			'px" height="' + (page.topmargin + ht + h).toFixed(0) +
			'px">\n' +
			'px" height="' + (ht + h).toFixed(0) +
			'px">\n' + sty +
			'<g transform="translate(0,' +
				page.topmargin.toFixed(1) + ')">' +
				page.hf + '</g>\n</svg>')
		page.hmax -= h;
		page.hf = ''
	} else {
		abc2svg.page.img_out(page,
			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	xmlns:xlink="http://www.w3.org/1999/xlink"\n\
	width="' + cfmt.pagewidth.toFixed(0) +
			'px" height="' + ht.toFixed(0) +
			'px">\n</svg>')
	}
	if (page.footer) {
		l = abc.get_font_style().length
		page.fh = abc2svg.page.gen_hf(page, false,
					abc.get_font("footer"), page.footer)
		page.fh = abc2svg.page.gen_hf(page, "footer")
		sty = abc.get_font_style().slice(l)		// new style(s)
		if (cfmt.fullsvg || sty != page.fsty) {
			page.fsty = sty
			page.ffsty = '<style>' + sty + '\n</style>\n'
		} else {
			page.ffsty = ''
		}
		page.hmax -= page.fh
	}

	page.h = 0
    }, // open_page()

    close_page: function(page) {
    var	h,
	cfmt = page.abc.cfmt()

	page.in_page = false
	if (page.footer) {
		h = page.hmax + page.fh - page.h
		abc2svg.page.img_out(page,
			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
	xmlns:xlink="http://www.w3.org/1999/xlink"\n\
	width="' + cfmt.pagewidth.toFixed(0) +
			'px" height="' + h.toFixed(0) +
			'px">\n' + page.ffsty +
			'px">\n<g transform="translate(0,' +
			'<g transform="translate(0,' +
				(h - page.fh).toFixed(1) + ')">' +
			page.hf + '</g>\n</svg>')
	}
	abc2svg.page.img_out(page, '</div>')
	page.h = 0
    }, // close_page()

    // handle the output flow of the abc2svg generator
    img_in: function(p) {
    var h, ht,
    var h, ht, nh,
	page = this.page

	// copy a block
	function blkcpy(page) {
	    var b

		if (!page.blk.length) {
			page.blk = null
			return
		}
		page.h = page.hb
		while (page.blk.length) {
		while (page.blk.length)
			b = page.blk.shift()
			abc2svg.page.img_out(page, b.p)
			abc2svg.page.img_out(page, page.blk.shift())
			page.h += b.h
		}
		page.blk = null			// direct output
	} // blkcpy()

	// img_in()
	switch (p.slice(0, 4)) {
	case "<div":				// new block (tune / paragraph)
	case "<div":				// block of new tune
		if (p.indexOf('newpage') > 0
		 || (page.oneperpage && this.info().X)
		 || !page.h)			// empty page
		 || !page.h) {			// empty page
			if (page.in_page)
				abc2svg.page.close_page(page)
			abc2svg.page.open_page(page, 0)
		}
		page.blk = []			// in block
		page.hb = page.h		// keep the offset of the start of tune
		break
	case "<svg":				// SVG image
		h = Number(p.match(/height="(\d+)px"/)[1])
		if (h + page.h >= page.hmax) {	// if page overflow
		while (h + page.h >= page.hmax) { // if (still) page overflow
			if (page.blk)		// if inside a block
				blkcpy(page)	// output the beginning of the tune

			ht = page.blk ? 0 :
				this.cfmt().topspace // tune continuation

//			if (page.in_page)
				abc2svg.page.close_page(page)
			if (page.blk) {
				if (!page.hb) {	// overflow on the first page
					blkcpy(page)
					nh = 0
				} else {
					nh = page.h - page.hb
					page.h = page.hb
				}
			}
			abc2svg.page.close_page(page)
			abc2svg.page.open_page(page, ht)

			if (page.blk) {		// if inside a block
				blkcpy(page)	// output the beginning of the tune
				page.h = nh
			}
			if (h > page.hmax)
				break		// error
		}

		// if no overflow yet, keep the block
		if (page.blk)
			page.blk.push({p: p, h: h})
			page.blk.push(p)
		else
			abc2svg.page.img_out(page, p)
		page.h += h
		break
	case "</di":				// end of block
		if (page.blk)
			blkcpy(page)
︙
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399







-
+







    var	v,
	cfmt = this.cfmt(),
	page = this.page

	if (cmd == "pageheight") {
		v = this.get_unit(parm)
		if (isNaN(v)) {
			this.syntax(1, errs.bad_val, '%%' + cmd)
			this.syntax(1, this.errs.bad_val, '%%' + cmd)
			return
		}
		cfmt.pageheight = v

		// if first definition, install the hook
		if (!page && user.img_out && abc2svg.abc_end) {
			this.page = page = {
︙
396
397
398
399
400
401
402
403

404
405
406
407
408

409
410
411
412
413

414
415
416
417
418
419
420
415
416
417
418
419
420
421

422
423
424
425
426

427
428
429
430
431

432
433
434
435
436
437
438
439







-
+




-
+




-
+







			}
			if (cfmt.footer) {
				page.footer = cfmt.footer;
				cfmt.footer = null
			}

			// get the previously defined page parameters
			if (cfmt.botmargin) {
			if (cfmt.botmargin != undefined) {
				v = this.get_unit(cfmt.botmargin)
				if (!isNaN(v))
					page.botmargin = v
			}
			if (cfmt.topmargin) {
			if (cfmt.topmargin != undefined) {
				v = this.get_unit(cfmt.topmargin)
				if (!isNaN(v))
					page.topmargin = v
			}
			if (cfmt.gutter) {
			if (cfmt.gutter != undefined) {
				v = this.get_unit(cfmt.gutter)
				if (!isNaN(v))
					page.gutter = v
			}
			if (cfmt.oneperpage)
				page.oneperpage = this.get_bool(cfmt.oneperpage)
			if (!cfmt.dateformat)
︙
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466


467
468
469
470
471
472
473
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494







-
+









-
+














+
+







			page[cmd] = parm
			return
		case "newpage":
			if (!parm)
				break
			v = Number(parm)
			if (isNaN(v)) {
				this.syntax(1, errs.bad_val, '%%' + cmd)
				this.syntax(1, this.errs.bad_val, '%%' + cmd)
				return
			}
			page.pn = v - 1
			return
		case "gutter":
		case "botmargin":
		case "topmargin":
			v = this.get_unit(parm)
			if (isNaN(v)) {
				this.syntax(1, errs.bad_val, '%%' + cmd)
				this.syntax(1, this.errs.bad_val, '%%' + cmd)
				return
			}
			page[cmd] = v
			return
		case "oneperpage":
			page[cmd] = this.get_bool(parm)
			return
		}
	}
	of(cmd, parm)
    }, // set_fmt()

    set_hooks: function(abc) {
	abc.set_format = abc2svg.page.set_fmt.bind(abc, abc.set_format)
	user.page_format = true			// do page formatting
	abc.set_pagef()
    }
} // page

abc2svg.modules.hooks.push(abc2svg.page.set_hooks);

// the module is loaded
abc2svg.modules.pageheight.loaded = true
Added modules/pedline.js.

















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// pedline.js - module to draw pedal lines instead of 'Ped .. *'
//
// Copyright (C) 2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%pedline" appears in a ABC source.
//
// Parameters
//	%%pedline 1

abc2svg.pedline = {
    draw_all_deco: function(of) {
    var	de, i,
	a_de = this.a_de()

	if (!a_de.length)
		return			// no decoration in this music line
	if (this.cfmt().pedline) {
		for (i = 0; i < a_de.length; i++) {
			de = a_de[i]
			if (de.dd.name != "ped)")
				continue
			if (de.prev
			 && de.prev.dd.name == "ped)") {
// ( .. ) ( .. )
//		\ de
//	\ de.prev
// \ de.prev.start
// |_____/\____|
				de.defl.nost = true
				de.prev.defl.noen = true
				de.x = de.prev.s.x - 5
				de.val = de.s.x - de.x - 5
				if (!de.prev.prev)
					de.prev.val = de.x - de.prev.x
			} else {
				de.x -= 3
				de.val += 10
			}
		}
	}
	of()
    }, // draw_all_deco()

    out_lped: function(of, x, y, val, defl) {
	if (!this.cfmt().pedline) {
		of(x, y, val, defl)
		return
	}
	this.xypath(x, y + 16)
	if (defl.nost) {
		this.out_svg("l2.5 6")
		val -= 2.5
	} else {
		this.out_svg("v6")
	}
	if (defl.noen) {
		val -= 2.5
		this.out_svg("h" + val.toFixed(1) + 'l2.5 -6"/>\n')
	} else {
		this.out_svg("h" + val.toFixed(1) + 'v-6"/>\n')
	}
    }, // out_lped()

    set_fmt: function(of, cmd, param) {
	if (cmd == "pedline")
		this.cfmt().pedline = param
	else
		of(cmd, param)
    }, // set_fmt()

    set_hooks: function(abc) {
	abc.draw_all_deco = abc2svg.pedline.draw_all_deco.bind(abc, abc.draw_all_deco)
	abc.out_lped = abc2svg.pedline.out_lped.bind(abc, abc.out_lped)
	abc.set_format = abc2svg.pedline.set_fmt.bind(abc, abc.set_format)
    } // set_hooks()
} // pedline

abc2svg.modules.hooks.push(abc2svg.pedline.set_hooks)

// the module is loaded
abc2svg.modules.pedline.loaded = true
Changes to modules/perc.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// perc.js - module to handle %%percmap
//
// Copyright (C) 2018-2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2018-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%percmap" appears in a ABC source.
//
// Parameters (from W. Vree)
//	%%percmap ABC_note percussion [note_head]
// The percussion may be a number (MIDI percussion number range 35..81),
// a ABC note or a possibly abbreviated percussion name.
︙
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174



175
176
177
178
179


180
181
182
183
184
185
186
187
158
159
160
161
162
163
164










165
166
167
168
169
170


171
172

173
174
175
176
177
178
179







-
-
-
-
-
-
-
-
-
-
+
+
+



-
-
+
+
-







		i++
	}
	if (p[i])			// if some extra character
		return
	return abc2svg.pab40(pit, acc)
    } // abc_b40()

    // convert a MIDI pitch to b40
    function mid_b40(pit) {
    var	o = (pit / 12) | 0		// octave
	pit = pit % 12;			// in octave
	return o * 40 + abc2svg.isb40[pit] + 2
    } // mid_b40()

    // convert a drum instrument to b40
    function tob40(p) {
    var	i, j, s,
    // convert a drum instrument to a pitch
    function topit(p) {
    var	i, j, s, b40,
	pit = Number(p)

	if (isNaN(pit)) {		// not a MIDI pitch
		s = abc_b40(p)		// try a ABC note
		if (s)
	    b40 = abc_b40(p)		// try a ABC note
	    if (!b40) {
			return s

		// try a drum instrument name
		p = p.toLowerCase(p);
		s = p[0];		// get the 1st letters after '-'
		i = 0
		while (1) {
			j = p.indexOf('-', i)
︙
214
215
216
217
218
219
220
221
222











223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242



243
244
245
246
247
248
249
206
207
208
209
210
211
212


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241


242
243
244
245
246
247
248
249
250
251







-
-
+
+
+
+
+
+
+
+
+
+
+


















-
-
+
+
+







					break
				}
				break
			}
			if (!pit)
				return
		}
	}
	return mid_b40(pit)
	    }
	}
	if (!b40) {
		p = (pit / 12) | 0		// octave
		pit = pit % 12;			// in octave
		b40 = p * 40 + abc2svg.isb40[pit] + 2
	}
	return {
		pit: abc2svg.b40p(b40),
		acc: abc2svg.b40a(b40)
	}
    } // tob40()

    // do_perc()
    var	vpr, vpl,
	maps = this.get_maps(),
	a = parm.split(/\s+/),
	n = abc_b40(a[1])			// note as b40

	if (!n) {
		this.syntax(1, this.errs.bad_val, "%%percmap")
		return
	}

	vpr = {					// print
		pit: abc2svg.b40p(n),
		acc: 0
	}

	vpl = tob40(a[2])			// play
	if (!vpl) {
	vpl = topit(a[2])				// play

	if (!vpl.pit) {
		this.syntax(1, this.errs.bad_val, "%%percmap")
		return
	}
	a = a[3] ? [a[3]] : null		// head
	if (!maps.MIDIdrum)
		maps.MIDIdrum = {}
	n = n.toString()
︙
Changes to modules/psvg.js.
︙
463
464
465
466
467
468
469


470
471
472
473
474
475
476
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478







+
+







	x = gcur.cx;
	y = gcur.cy
	if (span) {
		svgbuf += "<tspan\n\t";
		output_font(true);
		svgbuf += ">"
	} else if (g != 2) {
		if (!g)
			defg1()
		svgbuf += '<text x="' + (x + gcur.xoffs).toFixed(1) + '" y="' +
				(gcur.yoffs - y).toFixed(1) + '">';
		g = 2
	}
	svgbuf += s.replace(/<|>|&|  /g, function(c){
			switch (c) {
			case '<': return "&lt;"
︙
Changes to modules/sth.js.
︙
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114







-


+







		curvoice.sth = null	// some stem widths in this voice
	}
	return s
    },

    set_fmt: function(of, cmd, param) {
	if (cmd == "sth") {
	    var	curvoice = this.get_curvoice()
		if (this.parse.state == 2)
			this.goto_tune()
	    var	curvoice = this.get_curvoice()
		if (curvoice)
			curvoice.sth = param.split(/[ \t;-]+/)
		return
	}
	of(cmd, param)
    },

︙
Added modules/strtab.js.






































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// abc2svg - strtab.js - tablature for string instruments
//
// Copyright (C) 2020 Jean-Francois Moine
// License GPL-3
//
// This module is loaded by %%strtab.
// The command %%strtab changes the display of the voice to a tablature.
// Syntax:
//	%%strtab <string list> [diafret]
// <string list> is the list of the strings as ABC notes
// diafret indicates the instrument has diatonic frets
// The fret may be forced by a decoration format
//	"!" digit "s!"
// where 'digit' is the string range in the string list (last string is '1')
//
// This module accepts Willem Vree's tablature syntax:
//	https://wim.vree.org/svgParse/abc2xml.html#tab

abc2svg.strtab = {

    // draw the tablature
    draw_symbols: function(of, p_v) {
    var	s, m, not, stb, x, y,
	C = abc2svg.C,
	abc = this

	if (!p_v.tab) {
		of(p_v)
		return
	}

	// define the 'bgx' filter if not done yet
	m = abc.cfmt().bgcolor || "white"
	if (abc.bgt != m) {
		if (!abc.bgn)
			abc.bgn = 1
		else
			abc.bgn++
		abc.bgt = m
		abc.defs_add('\
<filter x="-0.1" y="0.2" width="1.2" height=".8" id="bg' + abc.bgn + '">\n\
<feFlood flood-color="' + m + '"/>\n\
<feComposite in="SourceGraphic" operator="over"/>\n\
</filter>')
		abc.add_style('\n.bg' + abc.bgn + '{filter:url(#bg' + abc.bgn + ')}')
	}

	// adjust the symbol before generation
	for (s = p_v.sym; s; s = s.next) {
		switch (s.type) {
		case C.KEY:
		case C.METER:
		case C.REST:
			s.invis = true
			break
		case C.NOTE:
			if (!s.stemless)
				s.ys = -10
			break
		}
	}
	of(p_v)

	abc.glout()			// output the stems

	// draw the note heads
	stb = abc.get_staff_tb()[p_v.st].y
	abc.out_svg('<g class="bn">\n')
	for (s = p_v.sym; s; s = s.next) {
		if (s.type == C.NOTE) {
			for (m = 0; m <= s.nhd; m++) {
				not = s.notes[m]
				x = s.x - 3
				if (not.nb >= 10)
					x -= 3
				y = 3 * (not.pit - 18)
				abc.out_svg('<text class="bg' + abc.bgn +
					'" x="')
				abc.out_sxsy(x, '" y="', stb + y - 2.5)
				abc.out_svg('">' + not.nb + '</text>\n')
			}
		}
	}
	abc.out_svg('</g>\n')
    }, // draw_symbols()

    // set a format parameter
    set_fmt: function(of, cmd, parm) {
	if (cmd == "strtab") {
		if (!parm)
			return
		this.set_v_param("clef", "tab")
		if (parm.indexOf("diafret") >= 0) {
			this.set_v_param("diafret", true)
			parm = parm.replace(/\s*diafret\s*/, "")
		}
		this.set_v_param("strings", parm)
		return
	}
	of(cmd, parm)
    }, // set_fmt()

    // adjust the horizontal offset of the stems
    set_width: function(of, s) {
    var	m, not,
	abc = this,
	C = abc2svg.C,
	o = s.stem < 0 ? 3.5 : -2.5

	of(s)
	if (s.p_v && s.p_v.tab && s.type == C.NOTE && !s.stemless) {
		for (m = 0; m <= s.nhd; m++)
			s.notes[m].shhd = o
	}
    }, // set_width()

    // change the notes when the global generation settings are done
    set_stems: function(of) {
    var	p_v, i, m, nt, n, bi, bn, strss,
	C = abc2svg.C,
	abc = this,
	s = abc.get_tsfirst(),		// first symbol
	strs = [],			// notes per staff - index = staff
	lstr = []			// lowest string per staff - index staff

	// set a string (pitch) and a fret number
	function set_pit(p_v, s, nt, i) {
	    var	st = s.st,
		n = (p_v.diafret ? nt.pit : nt.midi) - p_v.tab[i]

		if (p_v.diafret && nt.acc)
			n += '+'
		nt.acc = 0
		nt.invis = true
		nt.pit = i * 2 + 18
		nt.nb = n
		strss[i] = s.time + s.dur
		if (s.nflags >= -1 && !s.stemless) {
			if (!lstr[st])
				lstr[st] = [ 10 ]
			if (lstr[st][0] > i) {
				lstr[st][0] = i
				lstr[st][1] = s
			}
			s.stemless = true
		}
	} // set_pit()

	// get the string number from the decoration
	// format is either !<n>s! or !<n>!
	function strnum(n) {
		n = n.match(/^([1-9])s?$/)
		return n ? p_v.tab.length - n[1] : -1
	} // strnum()

	// change the notes of the strings when a capo
	p_v = abc.get_voice_tb()
	for (n = 0; n < p_v.length; n++) {
		if (!p_v[n].tab)
			continue
		m = p_v[n].capo
		if (m) {
			for (i = 0; i < p_v[n].tab.length; i++)
				p_v[n].tab[i] += m
		}
	}

	// loop on the notes of the voices with a tablature
	for ( ; s; s = s.ts_next) {
		p_v = s.p_v
		if (!p_v.tab)
			continue
		strss = strs[s.st]
		if (!strss)
			strss = strs[s.st] = []
		switch (s.type) {
		case C.KEY:
		case C.REST:
		case C.TIME:
			s.invis = true
		default:
			continue
		case C.NOTE:
			break
		}

		// handle the fret numbers as chord decoration
		if (!s.nhd && s.a_dd) {
			i = s.a_dd.length
			while (--i >= 0) {
				bi = strnum(s.a_dd[i].name)
				if (bi >= 0) {
					nt = s.notes[0]
					set_pit(p_v, s, nt, bi)
					break
				}
			}
			delete s.a_dd
		}

	ls:	for (m = 0; m <= s.nhd; m++) {
			nt = s.notes[m]
			if (nt.nb != undefined)
				continue
			if (nt.a_dcn) {
				i = nt.a_dcn.length
				while (--i >= 0) {
					bi = strnum(nt.a_dcn[i])
					if (bi >= 0) {
						set_pit(p_v, s, nt, bi)
						delete nt.a_dcn
						continue ls
					}
				}
				delete nt.a_dcn
			}

			// search the best string
			bn = 100
			i = p_v.tab.length
			while (--i >= 0) {
				if (strss[i] && strss[i] > s.time)
					continue
				n = (p_v.diafret ?
					nt.pit : nt.midi) -
						p_v.tab[i]
				if (n >= 0 && n < bn) {
					bi = i
					bn = n
				}
			}
			set_pit(p_v, s, nt, bi)
		}

		// put the stems on the lowest strings
		if (!s.ts_next || s.ts_next.time != s.time) {
			for (i = 0; i < lstr.length; i++) {
				if (lstr[i]) {
					delete lstr[i][1].stemless
					lstr[i] = null
				}
			}
		}
	}
	of()
    }, // set_stems()

    // get the parameters of the current voice
    set_vp: function(of, a) {
    var	i, e, g, tab, strs, ok,
	p_v = this.get_curvoice()

	// convert a list of ABC notes into a list of MIDI pitches
	function abc2tab(p) {
	    var	i, c,
		t = []

		if (p_v.diafret) {
		    for (i = 0; i < p.length; i++) {
			c = p[i]
			c = "CDEFGABcdefgab".indexOf(c)
			if (c < 0)
				return // null
			c += 16
			while (1) {
				if (p[i + 1] == "'") {
					c += 7
					i++
				} else if (p[i + 1] == ",") {
					c -= 7
					i++
				} else {
					break
				}
			}
			t.push(c)
		    }
		} else {
		    for (i = 0; i < p.length; i++) {
			c = p[i]
			c = "CCDDEFFGGAABccddeffggaab".indexOf(c)
			if (c < 0)
				return // null
			c += 60
			while (1) {
				if (p[i + 1] == "'") {
					c += 12
					i++
				} else if (p[i + 1] == ",") {
					c -= 12
					i++
				} else {
					break
				}
			}
			t.push(c)
		    }
		}
		return t
	} // abc2tab

	// convert an array of <note name><octave> into a list of MIDI pitches
	function str2tab(a) {
	    var	str, p, o,
		t = []

		if (p_v.diafret) {
		    while (1) {
			str = a.shift()
			if (!str)
				break
			p = "CDEFGAB".indexOf(str[0])
			o = Number(str[1])
			if (p < 0 || isNaN(o))
				return // null
			t.push(o * 7 + p - 12)	// C4 = 16 (12 = 4 * 7 - 16)
		    }
		} else {
		    while (1) {
			str = a.shift()
			if (!str)
				break
			p = "CCDDEFFGGAAB".indexOf(str[0])
			o = Number(str[1])
			if (p < 0 || isNaN(o))
				return // null
			t.push((o + 1) * 12 + p)	// C4 = 60
		    }
		}
		return t
	} // str2tab()

	for (i = 0; i < a.length; i++) {
		switch (a[i]) {
		case "clef=":
			e = a[i + 1]
			if (e != "tab")
				break
			a.splice(i, 1)
			// fall thru
		case "tab":
			a.splice(i, 1)
			i--
			ok = true
			p_v.pos.stm = abc2svg.C.SL_BELOW
			break
		case "strings=":
			strs = a[++i]
			ok = true
			break
		case "nostems":
			p_v.pos.stm = abc2svg.C.SL_HIDDEN
			break
		case "capo=":
			p_v.capo = Number(a[++i])
			break
		case "diafret=":
			i++
		case "diafret":
			p_v.diafret = true
			break
		}
	}

	// define the elements of the tablature
	if (ok) {
		if (strs) {
			if (strs[1] >= '1' && strs[1] <= '9')
				tab = str2tab(strs.split(','))	// W.V.'s syntax
			else
				tab = abc2tab(strs)		// ABC syntax
			if (!tab) {
				this.syntax(1, "Bad strings in tablature")
				ok = false
			}
		} else if (!p_v.tab) {
			tab = p_v.diafret ?
				[10, 14, 17] :		// dulcimer
				[40, 45, 50, 55, 59, 64] // guitar strings
		}
	}
	if (ok) {
		if (p_v.capo) {
			p_v.tab = []
			for (i = 0; i < tab.length; i++)
				p_v.tab.push(tab[i] + p_v.capo)
		} else {
			p_v.tab = tab
		}

		a.push("clef=")				// set the clef
		g = this.get_glyphs()
		if (tab.length == 3) {
			a.push('"tab3"')
			if (!g.tab3)
// SMuFL: -none-
				g.tab3 = '<text id="tab3"\
 x="-4,-4,-4" y="-4,3,10"\
 style="font:bold 8px sans-serif">TAB</text>'
		} else if (tab.length == 4) {
			a.push('"tab4"')
			if (!g.tab4)
// SMuFL: \ue06e
				g.tab4 = '<text id="tab4"\
 x="-4,-4,-4" y="-8,1,10"\
 style="font:bold 12px sans-serif">TAB</text>'
		} else if (tab.length == 5) {
			a.push('"tab5"')
			if (!g.tab5)
// SMuFL: -none-
				g.tab5 = '<text id="tab5"\
 x="-4,-4,-4" y="-11,-2,7"\
 style="font:bold 12px sans-serif">TAB</text>'
		} else {
			a.push('"tab6"')
			if (!g.tab6)
// SMuFL: \ue06d
				g.tab6 = '<text id="tab6"\
 x="-4,-4,-4" y="-14.5,-4,5.5"\
 style="font:bold 13px sans-serif">TAB</text>'
		}
		a.push("stafflines=")
		a.push("|||||||||".slice(0, tab.length))
		p_v.staffscale = 1.6
//		p_v.scale = .6
//		p_v.straightflags = true
	}
	of(a)
    }, // set_vp()

    set_hooks: function(abc) {
	abc.draw_symbols = abc2svg.strtab.draw_symbols.bind(abc, abc.draw_symbols)
	abc.set_format = abc2svg.strtab.set_fmt.bind(abc, abc.set_format);
	abc.set_stems = abc2svg.strtab.set_stems.bind(abc, abc.set_stems)
	abc.set_width = abc2svg.strtab.set_width.bind(abc, abc.set_width)
	abc.set_vp = abc2svg.strtab.set_vp.bind(abc, abc.set_vp)

	// define specific decorations used to force the string number
    var	decos = abc.get_decos()
	decos["1s"] = "0 nul 0 0 0"
	decos["2s"] = "0 nul 0 0 0"
	decos["3s"] = "0 nul 0 0 0"
	decos["4s"] = "0 nul 0 0 0"
	decos["5s"] = "0 nul 0 0 0"
	decos["6s"] = "0 nul 0 0 0"
	if (!user.nul)
		user.nul = function() {}

	abc.add_style("\n.bn{font:bold 8px sans-serif}")
    } // set_hooks()
} // strtab

abc2svg.modules.hooks.push(abc2svg.strtab.set_hooks)
abc2svg.modules.strtab.loaded = true
Changes to modules/temper.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// temper.js - module to define the temperament
//
// Copyright (C) 2018-2019 Jean-Francois Moine - GPL3+
// Copyright (C) 2018-2020 Jean-Francois Moine - GPL3+
//
// This module is loaded when "%%temperament" appears in a ABC source.
//
// Parameters
//	%%temperament <list>
// The <list> must contain 12 integer values that are the detune values in cents
// of the 12 notes of the equal scale.
︙
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45

46
47
48

49
50
51
52
53
54
55
56


















57
58



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
23
24
25
26
27
28
29












30
31
32
33
34

35

36

37








38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73







-
-
-
-
-
-
-
-
-
-
-
-



+
+
-
+
-

-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+






-









// %%temperament +00 -04 +04 +00 -04 +04 +00 +02 -08 +00 +02 -02
//
// % well temperament (F.A. Vallotti 1754)
// %%temperament +00 -06 -04 -02 -08 +02 -08 -02 -04 -06 +00 -10

abc2svg.temper = {

    // move the temperament to the 1st voice
    set_bar_num: function(of) {
	of()
	if (this.cfmt().temper) {
	    var	v0 = this.get_voice_tb()[0];

		v0.temper = new Float32Array(12)
		for (var i = 0; i < 12; i++)
			v0.temper[i] = this.cfmt().temper[i] / 100
	}
    },

    // get the temperament
    set_fmt: function(of, cmd, param) {
	if (cmd == "temperament") {
	    var	i, tb,
		tb40 = new Float32Array(40),
	    var	ls = new Float32Array(param.split(/ +/)),
		ls = new Float32Array(param.split(/ +/))
		i = ls.length

		if (i == 12) {
		for (i = 0; i < ls.length; i++) {
			while (--i >= 0) {
				if (isNaN(parseInt(ls[i])))
					break
			}
			if (i < 0) {
				this.cfmt().temper = ls
				return
			}
			if (isNaN(ls[i]))
				break
			ls[i] = i + ls[i] / 100	// delta -> MIDI/octave
		}
		switch (i) {
		case 12:
			tb = [	10,11,0,1,2,0,	// C
				0,1,2,3,4,0,	// D
				2,3,4,5,6,	// E
				3,4,5,6,7,0,	// F
				5,6,7,8,9,0,	// G
				7,8,9,10,11,0,	// A
				9,10,11,0,1]	// B
			break
		default:
			this.syntax(1, this.errs.bad_val, "%%temperament")
			return
		}
		}
		this.syntax(1, this.errs.bad_val, "%%temperament")
		for (i = 0; i < 40; i++)
			tb40[i] = ls[tb[i]]
		this.cfmt().temper = tb40
		return
	}
	of(cmd, param)
    },

    set_hooks: function(abc) {
	abc.set_bar_num = abc2svg.temper.set_bar_num.bind(abc, abc.set_bar_num);
	abc.set_format = abc2svg.temper.set_fmt.bind(abc, abc.set_format)
    }
} // temper


abc2svg.modules.hooks.push(abc2svg.temper.set_hooks);

// the module is loaded
abc2svg.modules.temperament.loaded = true
Changes to modules/wps.js.
1
2

3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10


+







// wps.js
// (c) 2009 Tomas Hlavaty
// reference: http://logand.com/sw/wps/log.html

function isQuoted(V) {
  return V.q;
}

function quote(V) {
  V.q = true;
︙
Changes to package.json.
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48



49

50
51
52
53
54
55
56

57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91

92
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97



98



-
+


















+
+




+
+



















-


+

+
+
+

+



-



+




+









-
-
-
+
+
+















-
+
-
-
-
+
-
{
  "name": "abc2svg",
  "version": "1.20.7",
  "version": "1.20.17",
  "description": "ABC music notation translator",
  "devDependencies": {
    "uglify-js": "^2.5.0"
  },
  "files": [
    "COPYING",
    "COPYING.LESSER",
    "MIDI-1.js",
    "Scc1t2/",
    "abc2odt",
    "abc2svg",
    "abc2svg-1.js",
    "abc2svg.ttf",
    "abcdoc-1.js",
    "abcemb-1.js",
    "abcemb1-1.js",
    "abcemb2-1.js",
    "abctopdf",
    "abcweb-1.js",
    "abcweb1-1.js",
    "abcweb2-1.js",
    "ambitus-1.js",
    "break-1.js",
    "capo-1.js",
    "chord-1.js",
    "chordnames-1.js",
    "clair-1.js",
    "clip-1.js",
    "cmdline.js",
    "combine-1.js",
    "diag-1.js",
    "edit-1.css",
    "edit-1.js",
    "edit-1.xhtml",
    "edit-de.js",
    "edit-en.js",
    "edit-fr.js",
    "edit-it.js",
    "edit-pt_BR.js",
    "equalbars-1.js",
    "err-de.js",
    "err-en.js",
    "err-fr.js",
    "err-it.js",
    "err-pt_BR.js",
    "follow-1.js",
    "grid-1.js",
    "grid2-1.js",
    "grid3-1.js",
    "json-1.js",
    "jazzchorg-1.js",
    "jianpu-1.js",
    "mdnn-1.js",
    "page-1.js",
    "pedline-1.js",
    "perc-1.js",
    "play-1.js",
    "psvg-1.js",
    "setmidi-1.js",
    "snd-1.js",
    "soloffs-1.js",
    "sth-1.js",
    "strtab-1.js",
    "temper-1.js",
    "toabc.js",
    "toaudio-1.js",
    "toabw.js",
    "tohtml.js",
    "tomei.js",
    "toodt.js",
    "toparam.js",
    "toxhtml.js"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "bin": {
    "abc2odt": "./abc2odt",
    "abc2svg": "./abc2svg",
    "abctopdf": "./abctopdf"
    "abc2odt": "abc2odt",
    "abc2svg": "abc2svg",
    "abctopdf": "abctopdf"
  },
  "repository": {
    "type": "fossil",
    "url": "https://chiselapp.com/user/moinejf/repository/abc2svg"
  },
  "keywords": [
    "ABC",
    "music",
    "SVG"
  ],
  "author": "Jean-François Moine",
  "license": "LGPL-3.0",
  "bugs": {
    "url": "https://chiselapp.com/user/moinejf/repository/abc2svg/reportlist"
  },
  "homepage": "https://chiselapp.com/user/moinejf/repository/abc2svg",
  "homepage": "https://chiselapp.com/user/moinejf/repository/abc2svg"
  "dependencies": {
    "npm": "^6.10.1"
  }
}
}
Changes to toabc.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - toabc.js - convert ABC to ABC
//
// Copyright (C) 2016-2019 Jean-Francois Moine
// Copyright (C) 2016-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
52
53
54
55
56
57
58





59
60
61
62



63
64
65
66
67

68
69

70
71
72

73
74
75
76
77
78
79
80
81

82

83
84

85

86
87
88
89
90
91
92
93
94
95
96
97
98

99

100
101
102
103
104
105
106










107
108
109
110
111
112
113
114
115
116


























117
118
119
120
121

122
123

124
125
126


127
128
129
130
131
132














133
134
135
136
137
138
139
52
53
54
55
56
57
58
59
60
61
62
63
64
65


66
67
68
69
70
71
72
73
74
75

76
77
78

79
80
81
82
83



84

85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106

107





108
109
110
111
112
113
114
115
116
117










118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

148


149



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178







+
+
+
+
+


-
-
+
+
+





+

-
+


-
+




-
-
-

-
+

+


+
-
+













+
-
+
-

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+
-
-
+
-
-
-
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+







		[0, ""],
		[2, "dor"],
		[4, "phr"],
		[-1, "lyd"],
		[1, "mix"],
		[3, "m"],
		[5, "loc"]
	],
	k_tb = [			// key names
		"Cb", "Gb", "Db", "Ab", "Eb", "Bb", "F",
		"C",
		"G", "D", "A", "E", "B", "F#", "C#", "G#", "D#", "A#"
	]

function abc_dump(tsfirst, voice_tb, music_types, info) {
    var	i, v, s, g, line, ulen, tmp, tmp2, grace, bagpipe, eoln, curv,
function abc_dump(tsfirst, voice_tb, info) {
    var	i, v, s, g, line, ulen, tmp, tmp2, grace, bagpipe, curv,
	cfmt = abc.cfmt(),
	nv = voice_tb.length,
	vo = [],		// dump line per voice
	vold = [],		// false/true for voice name
	vti = []

	// dump an information field on voice 'v'
	function info_out(inf) {
		if (vo[s.v].length != 0)
		if (vo[v].length && vo[v].slice(-1) != '\n')
			line += '[' + inf + ']'
		else
			abc2svg.print(inf)
			line += inf + '\n'
	} // info_out()

	function voice_out() {
		function vi_out(v) {
			if (v == curv)		// (for one voice in %score)
				return
			curv = v
		    var	p_voice = voice_tb[v],
			ln = 'V:' + p_voice.id
			ln = voice_tb.length == 1 ? '' : 'V:' + p_voice.id

			curv = v
			if (!vold[v]) {
				vold[v] = true
				if (ln		// if not the only voice
				if (p_voice.clef
				 && p_voice.clef
				 && p_voice.clef.clef_type != 'a')
					ln += ' ' + clef_dump(p_voice.clef)
				if (p_voice.nm) {
					ln += ' nm="' + p_voice.nm + '"'
					font_def("voice", p_voice.nm)
				}
				if (p_voice.snm)
					ln += ' snm="' + p_voice.snm + '"';
				if (p_voice.scale != 1)
					ln += ' scale=' + p_voice.scale
				if (p_voice.uscale)
					ln += ' microscale=' + p_voice.uscale
			}
			if (ln)
			abc2svg.print(ln)
				abc2svg.print(ln)
		} // vi_out()

		if (nv == 1) {
			if (vo[0].length == 0)
				return
			if (!vold[0]
			 && (voice_tb[0].nm || voice_tb[0].snm
			if (p_voice.instr) {
				for (var s = p_voice.sym; s && s.time == 0; s = s.next) {
					if (s.subtype == "midiprog") {
						p_voice.instr = null
						break
					}
				}
//fixme: the MIDI program may be the one of the channel 10
				if (p_voice.clef.clef_type == "p")
					p_voice.instr = null
			  || voice_tb[0].scale != 1 || voice_tb[0].uscale))
				vi_out(0);
			if (eoln) {
				eoln = false
				vo[0][vo[0].length - 1] += "$"
			}
			abc2svg.print(vo[0].join(''));
			vo[0] = []
			return
		}
				if (p_voice.instr)
					abc2svg.print("%%MIDI program " + p_voice.instr)
				p_voice.instr = null
			}
			if (p_voice.midictl) {
				if (p_voice.midictl[0] == 1
				 && p_voice.midictl[32] == 0) {
					delete p_voice.midictl[0]
					delete p_voice.midictl[32]
					abc2svg.print("%%MIDI channel 10")
				}
				for (k in p_voice.midictl)
					abc2svg.print("%%MIDI control " +
						k + ' ' + p_voice.midictl[k])
				p_voice.midictl = null
			}
			if (p_voice.chn != undefined) {
				abc2svg.print("%%MIDI channel " + (p_voice.chn + 1))
				p_voice.chn = undefined
			}
//fixme: to do
//			if (p_voice.mididrum) {
//				p_voice.mididrum = null
//			}
		} // vi_out()

		for (var v = 0; v < nv; v++) {
			if (vo[v].length == 0)
				continue
			vi_out(v);
			if (eoln) {
			if (vo[v].slice(-1) == '\n')
				eoln = false
				vo[v][vo[v].length - 1] += "$"
				vo[v] = vo[v].slice(0, -1)
			}
			abc2svg.print(vo[v].join(''));
			vo[v] = []
			abc2svg.print(vo[v])
			vo[v] = ""
		}
	} // voice_out()

	function block_dump(s) {
	    var	ln = "%%" + s.subtype + ' '
		switch (s.subtype) {
		case "midichn":
			s.p_v.chn = s.chn
			s.time = -1	// force %%MIDI
			return
		case "midictl":
			if (!s.p_v.midictl)
				s.p_v.midictl = []
			s.p_v.midictl[s.ctrl] = s.val
			s.time = -1	// force %%MIDI
			return
		case "midiprog":
			s.p_v.instr = s.instr
			s.time = -1	// force %%MIDI
			return
		case "ml":
			ln += s.text
			break
		default:
			ln += s.param
			break
		case "sep":
︙
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283

284

285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320







-
+







-
+
-






-
+
+




















+








		abc.get_font(fn)		// used font
// fixme: one '$' only
		if (i >= 0) {
			c = p[i + 1]
			if (c >= '1' && c <= '9') {
				c = "u" + c
				f = abc.cfmt()[c + "font"]	// user font
				f = cfmt[c + "font"]		// user font
				f.fid = abc.get_font(c).fid	// dump it!
			}
		}
		font_dump()		// dump the new fonts
	} // font_def()

	function font_dump() {
	    var	k, f, def,
	    var	k, f, def
		cfmt = abc.cfmt()
//		fs = abc.get_font_style().split("\n").shift()

		for (k in cfmt) {
			if (k.slice(-4) != "font")
				continue
			f = cfmt[k]
			if (f.fid == undefined)
//			if (f.fid == undefined)
			if (!f.used)
				continue	// not used
			if (old_font[f.fid])
				continue	// already out
			old_font[f.fid] = true
			def = f.name || ""
			if (f.weight)
				def += f.weight
			if (f.style)
				def += f.style
			if (!def)
				def = "*"
			if (k[0] == "u")
				k = "setfont-" + k[1]
			abc2svg.print('%%' + k + ' ' +
				def + ' ' + (f.size || "*"))
		}
	} // font_dump()

	function gch_dump(a_gch) {
	    var i, j, gch

		for (i = 0; i < a_gch.length; i++) {
			gch = a_gch[i]
			font_def(gch.type == 'g' ? "gchord" : "annotation", gch.text)
			line += '"';
			switch (gch.type) {
			case 'g':
				for (j = 0; j < gch.text.length; j++) {
︙
302
303
304
305
306
307
308
309
310


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
342
343
344
345
346
347
348


349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

368
















369
370
371
372
373
374
375
376
377
378
379
380


381
382
383
384
385
386
387







-
-
+
+

















-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
-







				line += gch.type
			}
			line += gch.text + '"'
		}
	} // gch_dump()

	function header_dump(hl) {
	    var l
		for (var i = 0; i < hl.length; i++) {
	    var l, i
		for (i = 0; i < hl.length; i++) {
			l = hl[i]
			if (info[l])
				abc2svg.print(l + ':' + info[l].replace(/\n/g, '\n' + l + ':'))
		}
	} // header_dump()

	function key_dump(s, clef) {
	    var	ln
		if (s.k_bagpipe) {
			bagpipe = true			// for grace notes
			ln = "K:H" + s.k_bagpipe
		} else if (s.k_drum) {
			ln = "K:P"
		} else if (s.k_none) {
			ln = "K:none"
		} else {
			ln = "K:"
			switch (s.k_sf + mode_tb[s.k_mode][0]) {
			ln += k_tb[s.k_sf + 7 + mode_tb[s.k_mode][0]]
			case -7: ln += 'Cb'; break
			case -6: ln += 'Gb'; break
			case -5: ln += 'Db'; break
			case -4: ln += 'Ab'; break
			case -3: ln += 'Eb'; break
			case -2: ln += 'Bb'; break
			case -1: ln += 'F'; break
			case 1: ln += 'G'; break
			case 2: ln += 'D'; break
			case 3: ln += 'A'; break
			case 4: ln += 'E'; break
			case 5: ln += 'B'; break
			case 6: ln += 'F#'; break
			case 7: ln += 'C#'; break
			default: ln += 'C'; break
			}
			ln += mode_tb[s.k_mode][1]
		}

		if (clef && clef.clef_type != 'a')
			ln += ' ' + clef_dump(clef)
//fixme: to continue
		return ln
	} // key_dump()

	function lyric_dump() {
	    var	v, s, i, ly, nly, t, w

		font_def("vocal", "")

		for (v = 0; v < nv; v++) {
			nly = 0;
			w = []
			for (s = voice_tb[v].sym; s; s = s.next) {
				ly = s.a_ly
				if (ly)
					while (nly < ly.length)
︙
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
554
555
556
557
558
559
560

561
562
563
564
565
566
567
568







-
+







					if (staff.flags & CLOSE_BRACE)
						ln += '}'
					if (staff.flags & CLOSE_BRACKET2)
						ln += ']'
					if (staff.flags & CLOSE_BRACKET)
						ln += ']'
					if (!(staff.flags & STOP_BAR))
						ln += '|'
						ln += '| '
				}
				staff = sy.staves[++st]
				if (staff.flags & OPEN_BRACKET)
					ln += '['
				if (staff.flags & OPEN_BRACKET2)
					ln += '['
				if (staff.flags & OPEN_BRACE)
︙
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609







-
+







			if (s.type != C.BAR)
				break
			if (s.time != vti[s.v])
				continue
			sym_dump(s);
			s.del = true
			if (line) {
				vo[s.v].push(line);
				vo[s.v] += line
				line = ""
			}
		}
		voice_out();
		abc2svg.print(ln)
		for (v = 0; v < nv; v++)
			vti[v] = s.time
︙
680
681
682
683
684
685
686
687
688















689
690
691
692
693
694
695
696
697
698
699
700


701
702
703
704
705
706
707
702
703
704
705
706
707
708


709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744







-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












+
+







				}
			}
		}
		if (s.a_gch)
			gch_dump(s.a_gch)
		if (s.a_dd)
			deco_dump(s.a_dd)
		if (s.invis && s.type != C.REST && s.type != C.SPACE)
			line += "!invisible!"
		if (s.invis) {
			switch (s.type) {
			case C.REST:
			case C.SPACE:
			case C.TEMPO:
				break
			case C.BAR:
				if (s.bar_type == '[' || s.bar_type == ']')
					break
				// fall thru
			default:
				line += "!invisible!"
				break
			}
		}
		if (s.color)
			line += "!" + s.color + "!"
		if (s.feathered_beam)
			line += s.feathered_beam > 0 ? "!beam-accel!" : "!beam-rall!"
		switch (s.type) {
		case C.BAR:
			if (s.beam_on)
				line += "!beamon!"
			if (s.bar_dotted)
				line += '.';
			line += s.bar_type
			if (s.text) {
				if (!s.bar_type)
					line += '['
				if (s.text[0] >= '0' && s.text[0] <= '9')
					line += s.text + ' '
				else
					line += '"' + s.text + '"'
			}
			break
		case C.CLEF:
︙
793
794
795
796
797
798
799
800
801
802














803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835

836
837
838






















839
840
841
842
843
844
845
846
847
848
849
850
851


852
853

854
855
856
857

858


859

860
861
862
863
864
865



866
867
868
869
870
871
872














873






874

875
876

877
878

879
880

881
882

883
884
885
886

887
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910



911
912








913
914
915
916
917
918
919
830
831
832
833
834
835
836



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870



871
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922
923
924
925
926
927
928
929
930

931

932




933
934
935
936
937
938
939



940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963

964
965

966
967

968
969

970
971
972
973

974
975
976
977


978
979

980
981
982
983
984
985

986
987
988
989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
-
-









-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













+
+

-
+




+

+
+
-
+
-

-
-
-
-
+
+
+




-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+

+

-
+

-
+

-
+

-
+



-
+



-
-


-
+





-










+
+
+

-
+
+
+
+
+
+
+
+







				slti_dump(s.notes[0].tie_ty, '-');
			tmp = s.sl2
			while (tmp) {
				line += ')';
				tmp--
			}
			break
		case C.PART:
			font_def("parts", s.text)
			info_out('P:' + s.text)
		case C.TEMPO:
			if ((s.invis && cfmt.writefields.indexOf('Q') >= 0)
			 || (!s.invis && cfmt.writefields.indexOf('Q') < 0)) {
				voice_out()
				if (s.invis) {
					abc2svg.print("%%writefields Q 0")
					cfmt.writefields =
						cfmt.writefields.replace('Q', '')
				} else {
					abc2svg.print("%%writefields Q 1")
					cfmt.writefields += 'Q'
				}
			}
			tempo_dump(s)
			break
		case C.REST:
			line += s.invis ? 'x' : 'z';
			dur_dump(s.dur)
			break
		case C.SPACE:
			line += 'y'
			if (s.width != 10)
				line += s.width
			break
		case C.STAVES:
			if (nv == 1)
				break
			staves_dump(s)
			break
		case C.STBRK:
			voice_out();
			abc2svg.print('%%staffbreak ' + s.xmx.toString() +
				(s.stbrk_forced ? 'f' : ''))
			break
		case C.TEMPO:
			tempo_dump(s)
			break
		case C.BLOCK:
			voice_out();
			block_dump(s)
			break
		case C.REMARK:
			info_out('r:' + s.text)
			break
		default:
			voice_out();
			abc2svg.print('% ??sym: ' + music_types[s.type])
			abc2svg.print('% ??sym: ' + abc2svg.sym_name[s.type])
			break
		}
	} // sym_dump()

	function wf_dump() {
	    var i, a,
		wf = "CMOPQsTWw"	// default printed fields

		if (cfmt.writefields == wf)
			return
		a = ""
		for (i = 0; i < cfmt.writefields.length; i++) {
			if (wf.indexOf(cfmt.writefields[i]) < 0)
				a += cfmt.writefields[i]
		}
		if (a)
			abc2svg.print('%%writefields ' + a + " 1")
		a = ""
		for (i = 0; i < wf.length; i++) {
			if (cfmt.writefields.indexOf(wf[i]) < 0)
				a += wf[i]
		}
		if (a)
			abc2svg.print('%%writefields ' + a + " 0")
	} // wf_dump()

	font_dump()

	abc2svg.print('\nX:' + info['X'])
	header_dump("TC")

	abc2svg.print(meter_dump(voice_tb[0].meter));

	ulen = voice_tb[0].ulen < 0 ? C.BLEN / 4 : voice_tb[0].ulen;
	abc2svg.print('L:1/' + (C.BLEN / ulen).toString());

	header_dump("OABDFGRNPSZH")

	wf_dump()

	for (v = 0; v < nv; v++) {
		vo[v] = [];
		vo[v] = ""
		vti[v] = 0
	}

	if (info.Q) {
		abc2svg.print("Q: " + info.Q)
		for (s = tsfirst; s; s = s.ts_next) {
			if (s.time)
				break
			if (s.type == C.TEMPO) {
			if (s.type == C.TEMPO)
				tempo_dump(s);
				s.del = true
				break
			}
		}
	}
		}
	}

	abc2svg.print(key_dump(voice_tb[0].key, voice_tb[0].clef))

	// loop by time
	for (s = tsfirst; s; s = s.ts_next) {
		if (eoln && s.seqst)
			voice_out();
		if (s.del)
		if (s.type == C.PART) {		// new part
			voice_out()
			if (s.invis && cfmt.writefields.indexOf('P') >= 0) {
				abc2svg.print("%%writefields P 0")
				cfmt.writefields =
						cfmt.writefields.replace('P', '')
			} else if (!s.invis && cfmt.writefields.indexOf('P') < 0) {
				abc2svg.print("%%writefields P 1")
				cfmt.writefields += 'P'
			}
			font_def("parts", s.text)
			abc2svg.print('P:' + s.text)
			while (s.ts_next && s.ts_next.type == C.PART)
				s = s.ts_next
			continue
		}
		v = s.v
		if (s.soln && s.seqst) {
			vo[v] += '$'
			voice_out();
		}
		line = "";

		// (all voices are synchronized on %%score)
		if (s.type != C.STAVES && s.time > vti[s.v]) {
		if (s.type != C.STAVES && s.time > vti[v]) {
//fixme: put 'X' if more than one measure
			if (s.time > vti[s.v] + 2) {
			if (s.time > vti[v] + 2) {
				line += 'x';
				dur_dump(s.time - vti[s.v]);
				dur_dump(s.time - vti[v]);
			}
			vti[s.v] = s.time
			vti[v] = s.time
		}
		sym_dump(s)
		if (s.dur)
			vti[s.v] = s.time + s.dur
			vti[v] = s.time + s.dur
		if (s.next) {
			if (s.beam_end && !s.beam_st && !s.next.beam_end)
				line += ' '
			if (s.eoln)
				eoln = true
		}
		if (line)
			vo[s.v].push(line)
			vo[v] += line
	}
	voice_out();
	lyric_dump();
	header_dump("W")
} // abc_dump()
user.get_abcmodel = abc_dump

// -- local functions
abc2svg.abc_init = function(args) {
	abc2svg.print('%abc-2.2\n\
% generated by abc2svg toabc from\n\
%\t' + args.join(' ') + '\n\
%%linebreak $')
}

abc2svg.abc_end = function() {
    var	t,
	tunes = abc.tunes.slice(0)	// get a copy of the generated tunes

	if (user.errtxt)
		abc2svg.print("Errors:\n" + user.errtxt)
		abc2svg.print("\n--- Errors ---\n" + user.errtxt)

	while (1) {
		t = tunes.shift()
		if (!t)
			break
		abc_dump(t[0], t[1], t[2])
	}
}

abc2svg.abort = function(e) {
	abc2svg.print(e.message + "\n*** Abort ***\n" + e.stack);
	abc2svg.abc_end();
	abc2svg.quit()
}
Added tohtml.js.














































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// abc2svg - tohtml.js - HTML+SVG generation
//
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

    var	init_done, pw, ml, mr, pkf, lkf

// replace <>& by XML character references
function clean_txt(txt) {
	return txt.replace(/<|>|&.*?;|&/g, function(c) {
		switch (c) {
		case '<': return "&lt;"
		case '>': return "&gt;"
		case '&': return "&amp;"
		}
		return c
	})
}

abc2svg.abort = function(e) {
	if (!init_done)				// if empty document
		user.img_out('')
	abc.blk_flush()
	if (typeof abc2svg.printErr == 'function')
		abc2svg.printErr(e.message + "\n*** Abort ***\n" + e.stack)
	else
		abc2svg.print("<pre>" + e.message + "\n*** Abort ***\n" + e.stack + "</pre>")
	abc2svg.abc_end()
	abc2svg.quit()
}

function get_date() {
	return (new Date()).toUTCString()
} // get_date()

function header_footer(str) {
    var	c, i, t,
	j = 0,
	r = ["", "", ""]

	if (str[0] == '"')
		str = str.slice(1, -1)
	if (str.indexOf('\t') < 0)		// if no TAB
		str = '\t' + str		// center

	for (i = 0; i < str.length; i++) {
		c = str[i]
		switch (c) {
		case '\t':
			if (j < 2)
				j++		// next column
			continue
		case '\\':			// hope '\n'
			for (j = 0; j < 3; j++)
				r[j] += '<br/>'
			j = 0
			i++
			continue
		default:
			r[j] += c
			continue
		case '$':
			break
		}
		c = str[++i]
		switch (c) {
		case 'd':
			if (!abc2svg.get_mtime)
				break // cannot know the modification date of the file
			r[j] += abc2svg.get_mtime(abc.parse.fname)
			break
		case 'D':
			r[j] += get_date()
			break
		case 'F':
			r[j] += abc.parse.fname
			break
		case 'I':
			c = str[++i]
		case 'T':
			t = abc.info()[c]
			if (t)
				r[j] += t.split('\n', 1)[0]
			break
		case 'P':
			r[j] += '\x0c'	// form feed
			break
		case 'V':
			r[j] += "abc2svg-" + abc2svg.version
			break
		}
	}
	return r
} // header_footer()

// set a paragraph style
function set_pstyle() {
    var	nml, nmr, nlkf, npkf, npw,
	cfmt = abc.cfmt(),
	psty = ''

	nml = cfmt.leftmargin
	if (nml != ml) {
		if (ml == undefined)
			ml = nml
		psty += 'margin-left:' + nml.toFixed(1) + 'px;'
	}
	nmr = cfmt.rightmargin
	if (nmr != mr) {
		if (mr == undefined)
			mr = nmr
		psty += 'margin-right:' + nmr.toFixed(1) + 'px;'
	}
	nlkf = cfmt.lineskipfac
	if (nlkf != lkf) {
		if (lkf == undefined)
			lkf = nlkf
		psty += 'line-height:' + ((nlkf * 100) | 0).toString() + '%;'
	}
	npkf = cfmt.parskipfac
	if (npkf != pkf) {
		if (pkf == undefined)
			pkf = npkf
		psty += 'margin-bottom:' + npkf.toFixed(2) + 'em;'
	}
	npw = cfmt.pagewidth
	if (npw != pw || nml != ml || nmr != mr) {
		if (pw == undefined)
			pw = npw
		psty += 'width:' + (npw - nml - nmr).toFixed(1) + 'px;'
	}
	return psty
}

// entry point from cmdline
abc2svg.abc_init = function() {
    var cfmt = abc.cfmt()

	// output a header or footer
	function gen_hf(type, str) {
	    var	a, i, page,
		lcr = ["left", "center", "right"]

		a = header_footer(clean_txt(str))
		for (i = 0; i < 3; i++) {
			str = a[i]
			if (!str)
				continue
			if (str.indexOf('\x0c') >= 0) {
				str = str.replace('\x0c', '')
				page = " page"
			} else {
				page = ''
			}
			abc2svg.print('<div class="' + type + ' ' + lcr[i] + page +
				'">' +
				str + '</div>')
		}
	}

	user.page_format = true

	// output the xhtml header
	user.img_out = function(str) {
		var	header = cfmt.header,
			footer = cfmt.footer,
			topmargin = cfmt.topmargin || "1cm",
			botmargin = cfmt.botmargin || "1cm",
			media_s = '@media print {\n\
	body {margin:0; padding:0; border:0}\n\
	.newpage {page-break-before: always}\n\
	div.nobrk {page-break-inside: avoid}\n\
}',
			media_f ='@media screen {\n\
	div.header {display: none}\n\
	div.footer {display: none}\n\
}\n\
@media print {\n\
	body {margin:0; padding:0; border:0;\n\
		counter-reset: page;\n\
		counter-increment: page; }\n\
	.newpage {page-break-before: always}\n\
	div.nobrk {page-break-inside: avoid}\n\
	div.header {\n\
		position: fixed;\n\
		top: 0pt;\n\
		width: 100%;\n\
		' + abc.style_font(cfmt.headerfont) + '\n\
	}\n\
	div.footer {\n\
		position: fixed;\n\
		bottom: 0pt;\n\
		width: 100%;\n\
		' + abc.style_font(cfmt.footerfont) + '\n\
	}\n\
	div.page:after {\n\
		counter-increment: page;\n\
		content: counter(page);\n\
	}\n\
	div.left {text-align: left}\n\
	div.center {text-align: center}\n\
	div.right {text-align: right}\n\
}';

		// no margin / header / footer when SVG page formatting
		if (abc.page)
			topmargin = botmargin = header = footer = 0

		abc2svg.print('<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<meta charset="utf-8"/>\n\
<meta name="generator" content="abc2svg-' + abc2svg.version + '"/>\n\
<!-- CreationDate: ' + get_date() + '-->\n\
<style>\n\
body {width:' + cfmt.pagewidth.toFixed(0) +'px}\n\
p {' + set_pstyle() + 'margin-top:0}\n\
p span {line-height:' + ((cfmt.lineskipfac * 100) | 0).toString() + '%}\n' +
			((header || footer) ? media_f : media_s))
// works with chrome and --headless
		if (abc.page)
			abc2svg.print('@page{size:' +
				(cfmt.pagewidth / 96).toFixed(2) + 'in ' +
				(cfmt.pageheight / 96).toFixed(2) + 'in;margin:0}')
		else
			abc2svg.print('@page{margin:' + topmargin + ' 0 ' +
							botmargin + ' 0}')
		abc2svg.print('</style>\n\
<title> ' + abc.parse.fname.replace(/.*\//, '') + '</title>\n\
</head>\n\
<body>')
		if (header)
			gen_hf("header", header)
		if (footer)
			gen_hf("footer", footer)

		// output the first generated string
		abc2svg.print(str)
		init_done = true

		// change the output function
		user.img_out = abc2svg.print
	}
}

abc2svg.abc_end = function() {
    var	font_style = abc.get_font_style()

	if (!init_done)				// if empty document
		user.img_out('')
	if (user.errtxt)
		abc2svg.print("<pre>" + clean_txt(user.errtxt) + "</pre>")
	if (font_style)				// if some %%text at the end
		abc2svg.print('<style>' + font_style + '\n</style>')
	abc2svg.print("</body>\n</html>")
}
Changes to tolead.js.
︙
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28







-
+







// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

function lead(tsfirst, voice_tb, music_types, info) {
    var	C = abc2svg.C
    var	C = abc2svg.C,
	s, beat, cur_beat, i,
	line = '';

	function get_beat(s) {
		if (s.a_meter[0].top[0] == 'C' || !s.a_meter[0].bot) {
			beat = C.BLEN / 4
		} else {
︙
47
48
49
50
51
52
53


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73






74
75
76
77
78

79
80
81
82
83
84
85
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69






70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87







+
+














-
-
-
-
-
-
+
+
+
+
+
+




-
+







	// treat only the first voice
	cur_beat = 0
	for (s = voice_tb[0].sym; s; s = s.next) {
		while (s.time > cur_beat) {
			line += '/ ';
			cur_beat += beat
		}
		if (s.soln)
			line += '\n'
		switch (s.type) {
		case C.NOTE:
		case C.REST:
			if (s.a_gch) {		// search a chord symbol
				for (i = 0; i < s.a_gch.length; i++) {
					if (s.a_gch[i].type == 'g') {
						line += s.a_gch[i].text + ' ';
						cur_beat = s.time + beat
						break
					}
				}
			}
			break
		case C.BAR:
			if (s.eoln) {
				if (s.bar_type == '::')
					line += ':|\n|: '
				else
					line += s.bar_type +'\n'
			} else {
//			if (s.eoln) {
//				if (s.bar_type == '::')
//					line += ':|\n|: '
//				else
//					line += s.bar_type +'\n'
//			} else {
				if (s.bar_type == '::')
					line += ':|: '
				else
					line += s.bar_type + ' '
			}
//			}
			cur_beat = s.time	// re-synchronize
			break
		case C.METER:
			get_beat(s)
			break
		}
	}
︙
Changes to tomei.js.
︙
259
260
261
262
263
264
265













266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

282
283
284
285
286
287
288
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301







+
+
+
+
+
+
+
+
+
+
+
+
+















-
+







			}
			ln += ' clef.line="' + s.clef_line + '"'
			if (s.clef_octave)
				ln += ' clef.dis="8" clef.dis.place="' +
					(s.clef_octave > 0 ? 'above"' : 'below"')
			return ln
		} // clef_dump()

		// get the number of lines of the staff
		function nl(st) {
		    var	i,
			l = abc.get_staff_tb()[st].stafflines,
			n = 0

			for (i = 0; i < l.length; i++) {
				if (l[i] == '|' || l[i] == '[')
					n++
			}
			return n
		} // nl()

//		meas.sy = sy

		for (v = 0; v < sy.voices.length; v++) {
			p_v = sy.voices[v]
			if (p_v)
				vn[p_v.range] = v
		}

		for (v = 0; v < sy.voices.length; v++) {
			if (vn[v] == undefined)
				continue
			p_v = sy.voices[vn[v]]
			if (p_v.st == st)
				continue
			if (st >= 0) {
			if (st >= 0) {		// if a previous staff
				if (staff.flags & CLOSE_BRACE2)
					abc2svg.print('\t    </staffGrp>')
				if (staff.flags & CLOSE_BRACE)
					abc2svg.print('\t  </staffGrp>')
				if (staff.flags & CLOSE_BRACKET2)
					abc2svg.print('\t   </staffGrp>')
				if (staff.flags & CLOSE_BRACKET)
︙
302
303
304
305
306
307
308








309


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329





330
331
332
333
334
335
336
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363







+
+
+
+
+
+
+
+
-
+
+




















+
+
+
+
+







			if (staff.flags & OPEN_BRACE)
				abc2svg.print('\t  <staffGrp symbol="brace"' +
						stop + '>')
			if (staff.flags & OPEN_BRACE2)
				abc2svg.print('\t    <staffGrp symbol="brace"' +
						stop + '>')

			// must have a staff group
			if (v == 0
			 && !(staff.flags & (OPEN_BRACKET |
					OPEN_BRACKET2 |
					OPEN_BRACE |
					OPEN_BRACE2)))
				abc2svg.print('\t <staffGrp>')

			ln = '\t     <staffDef n="' + (st + 1).toString() + '"'
			ln = '\t     <staffDef n="' + (st + 1).toString() +
				'" lines="' + nl(st) + '"'
			for (s2 = voice_tb[vn[v]].sym; s2; s2 = s2.next) {
				if (s2.dur)
					break
				if (s2.type == C.CLEF) {
					if (!s2.invis)
						ln += clef_dump(s2)
					meas.clefs[st] = s2
					break
				}
			}
			abc2svg.print(ln + '/>')

		}
		if (staff.flags & CLOSE_BRACE2)
			abc2svg.print('\t    </staffGrp>')
		if (staff.flags & CLOSE_BRACE)
			abc2svg.print('\t  </staffGrp>')
		if (staff.flags & CLOSE_BRACKET2)
			abc2svg.print('\t   </staffGrp>')
		if (staff.flags & CLOSE_BRACKET)
			abc2svg.print('\t </staffGrp>')
		if (!(staff.flags & (CLOSE_BRACKET |
				CLOSE_BRACKET2 |
				CLOSE_BRACE |
				CLOSE_BRACE2)))
			abc2svg.print('\t </staffGrp>')
	} // staves_dump()

// dump the header
function head_dump() {
    var	i, v, s, g, line, ulen, tmp, tmp2, grace, bagpipe, eoln, curv,
	info = abc.info(),
︙
716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757







-
+







			}
		}
		while (--n >= 0)
			abc2svg.print('\t    </tuplet>')
	} // note_dump()

	function tempo_dump(s) {
		if (s.del)
		if (s.invis)
			return
	    var	v,
		t = '\t  <tempo place="above" startid="#a',
		s2 = s.ts_next

		while (!s2.dur && s2.type != C.SPACE)
			s2 = s2.ts_next
︙
Changes to toxhtml.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// abc2svg - toxhtml.js - SVG generation
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
240
241
242
243


244
245

246
247
248
249
250
251
252
223
224
225
226
227
228
229

230

231
232
233
234
235
236
237
238
239
240


241
242
243

244
245
246
247
248
249
250
251







-
+
-










-
-
+
+

-
+







		abc2svg.print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n\
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">\n\
<html xmlns="http://www.w3.org/1999/xhtml">\n\
<head>\n\
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n\
<meta name="generator" content="abc2svg-' + abc2svg.version + '"/>\n\
<!-- CreationDate: ' + get_date() + '-->\n\
<style type="text/css">\n\
<style>\n\
svg {display:block}\n\
body {width:' + cfmt.pagewidth.toFixed(0) +'px}\n\
p {' + set_pstyle() + 'margin-top:0}\n\
p span {line-height:' + ((cfmt.lineskipfac * 100) | 0).toString() + '%}\n' +
			((header || footer) ? media_f : media_s))
// works with chrome and --headless
		if (abc.page)
			abc2svg.print('@page{size:' +
				(cfmt.pagewidth / 96).toFixed(2) + 'in ' +
				(cfmt.pageheight / 96).toFixed(2) + 'in;margin:0}')
		else
			abc2svg.print('@page{margin:0' + topmargin + ' 0 ' +
							 botmargin + ' 0}')
			abc2svg.print('@page{margin:' + topmargin + ' 0 ' +
							botmargin + ' 0}')
		abc2svg.print('</style>\n\
<title>abc2svg document</title>\n\
<title> ' + abc.parse.fname.replace(/.*\//, '') + '</title>\n\
</head>\n\
<body>')
		if (header)
			gen_hf("header", header)
		if (footer)
			gen_hf("footer", footer);

︙
263
264
265
266
267
268
269
270

271
272
262
263
264
265
266
267
268

269
270
271







-
+


    var	font_style = abc.get_font_style()

	if (!init_done)				// if empty document
		user.img_out('')
	if (user.errtxt)
		abc2svg.print("<pre>" + clean_txt(user.errtxt) + "</pre>")
	if (font_style)				// if some %%text at the end
		abc2svg.print('<style type="text/css">' + font_style + '\n</style>');
		abc2svg.print('<style>' + font_style + '\n</style>');
	abc2svg.print("</body>\n</html>")
}
Changes to util/abcdoc.js.
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28



-
+















+
+







//#javascript
// abcdoc-1.js file to include in html pages with abc2svg-1.js
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

    var user

(function(){

window.onerror = function(msg, url, line) {
	if (typeof msg == 'string')
		alert("window error: " + msg +
			"\nURL: " + url +
︙
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
45
46
47
48
49
50
51

52
53
54
55
56
57
58


59
60
61
62
63
64
65
66







-
+






-
-
+







		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf('abcdoc-') >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??

	})(),
	})()
    user = {	// -- abc2svg init argument
	errmsg: function(msg, l, c) {	// get the errors
		errtxt += clean_txt(msg) + '\n'
	},
	img_out: function(str) {	// image output
		new_page += str
	},
	page_format: true		// define the non-page-breakable blocks
	}
    }

// replace <>& by XML character references
function clean_txt(txt) {
	return txt.replace(/<|>|&.*?;|&/g, function(c) {
		switch (c) {
		case '<': return "&lt;"
︙
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107






108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126



















127
128
129
130
131
132
133
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115


















116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141







-










-
-
+
+
+















+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







// function to load javascript files
	abc2svg.loadjs = function(fn, relay, onerror) {
		var s = document.createElement('script');
		if (/:\/\//.test(fn))
			s.src = fn		// absolute URL
		else
			s.src = jsdir + fn;
		s.type = 'text/javascript'
		if (relay)
			s.onload = relay;
		s.onerror = onerror || function() {
			alert('error loading ' + fn)
		}
		document.head.appendChild(s)
	}

    // search the ABC tunes and add their rendering as SVG images
    function render() {
	var	i = 0, j, k, res,
		re = /\n%abc|\nX:/g,		// start on "%abc" or "X:"
	var	i = 0, j, k, res, scr,
		re =				// start on "%abc" or "X:"
			 /\n%abc|\nX:|<script[^>]+vnd.abc/g,
		re_stop = /\n<|\n%.begin/g,	// stop on "<" and skip "%%begin"
	abc = new abc2svg.Abc(user);

	abc.tosvg('abcdoc', '%%bgcolor white\n\
%%rightmargin 0.8cm\n\
%%leftmargin 0.8cm\n\
%%topspace 0')
	for (;;) {

		// get the start of a ABC sequence
		res = re.exec(page)
		if (!res)
			break
		j = re.lastIndex - res[0].length;
		new_page += page.slice(i, j);
		if (page[j] == '<') {		// ABC start on <script .. vnd.abc ..>
			j = page.indexOf(">", re.lastIndex) + 2
			k = page.indexOf("</script>", j)
			tune = page.slice(j, k)
			k += 10
		} else {

		// get the end of the ABC sequence
		// including the %%beginxxx/%%endxxx sequences
		re_stop.lastIndex = ++j
		while (1) {
			res = re_stop.exec(page)
			if (!res || res[0] == "\n<")
				break
			k = page.indexOf(res[0].replace("begin", "end"),
					re_stop.lastIndex)
			if (k < 0)
				break
			re_stop.lastIndex = k
		}
		if (!res || k < 0)
			k = page.length
		else
			k = re_stop.lastIndex - 2;
		tune = page.slice(j, k);
			// get the end of the ABC sequence
			// including the %%beginxxx/%%endxxx sequences
			re_stop.lastIndex = ++j
			while (1) {
				res = re_stop.exec(page)
				if (!res || res[0] == "\n<")
					break
				k = page.indexOf(res[0].replace("begin", "end"),
						re_stop.lastIndex)
				if (k < 0)
					break
				re_stop.lastIndex = k
			}
			if (!res || k < 0)
				k = page.length
			else
				k = re_stop.lastIndex - 2
			tune = page.slice(j, k)
		}
		new_page += '<pre style="display:inline-block; vertical-align: top">' +
				clean_txt(tune) +
				'</pre>\n\
<div style="display:inline-block; vertical-align: top">\n'
// not "float:right"
		try {
			abc.tosvg('abcdoc', tune)
︙
Changes to util/abcemb.js.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







//#javascript
// abcemb-1.js file to include in html pages with abc2svg-1.js
//
// Copyright (C) 2014-2019 Jean-Francois Moine
// Copyright (C) 2014-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
26
27
28
29
30
31
32


33

34
35
36
37
38
39
40
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







+
+
-
+







	else if (typeof msg == 'object')
		alert("window error: " + msg.type + ' ' + msg.target.src)
	else
		alert("window error: " + msg)
	return false
}

    var user
if (typeof abc2svg == "undefined")
var abc2svg = {}
    var abc2svg = {}

// function called when abc2svg is fully loaded
function dom_loaded() {
var	errtxt = '',
	new_page = '',
	playing,
	abcplay,
︙
50
51
52
53
54
55
56







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75







76
77
78
79
80
81
82







+
+
+
+
+
+
+










-
-
-
-
-
-
-







		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf('abcemb-') >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??
	})(),

// play arguments
    playconf = {
	onend: function() {
		playing = false
	}
    }

// -- abc2svg init argument
    user = {
	errmsg: function(msg, l, c) {	// get the errors
		errtxt += clean_txt(msg) + '\n'
	},
	img_out: function(str) {	// image output
		new_page += str
	},
	page_format: true		// define the non-page-breakable blocks
    };

// play arguments
    playconf = {
	onend: function() {
		playing = false
	}
    }

// replace <>& by XML character references
function clean_txt(txt) {
	return txt.replace(/<|>|&.*?;|&/g, function(c) {
		switch (c) {
		case '<': return "&lt;"
︙
Changes to util/abcemb1.js.
︙
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







// When the tune is displayed, if playing is not enabled,
// scrolling the music may be done by clicking/taping
// on the 'start scrolling' button.
//
// The header of the tune list ("Tunes:") may be set in a global
// javascript variable 'list_head'.
//
// Copyright (C) 2019 Jean-Francois Moine
// Copyright (C) 2019-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
49
50
51
52
53
54
55


56

57
58
59
60
61
62
63
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







+
+
-
+







}
window.onafterprint = function() {
   var	e = document.getElementById("dd")
	if (e)
		e.style.display = "block"
}

    var user
if (typeof abc2svg == "undefined")
var abc2svg = {}
    var abc2svg = {}

// function called when abc2svg is fully loaded
function dom_loaded() {
var	errtxt = '',
	app = "abcemb",
	new_page,
	playing,
︙
76
77
78
79
80
81
82







83
84
85
86
87
88
89
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98







+
+
+
+
+
+
+







		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf('abcemb1-') >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??
	})(),

// play arguments
    playconf = {
	onend: function() {
		playing = false
	}
    }

// -- abc2svg init argument
    user = {
	errmsg: function(msg, l, c) {	// get the errors
		errtxt += clean_txt(msg) + '\n'
	},

︙
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
120
121
122
123
124
125
126


127






128
129
130
131
132
133
134







-
-
+
-
-
-
-
-
-







	},

	img_out: function(str) {	// image output
		new_page += str
	},

	page_format: true		// define the non-page-breakable blocks
    };

    } // user
// play arguments
    playconf = {
	onend: function() {
		playing = false
	}
    }

// replace <>& by XML character references
function clean_txt(txt) {
	return txt.replace(/<|>|&.*?;|&/g, function(c) {
		switch (c) {
		case '<': return "&lt;"
		case '>': return "&gt;"
︙
Added util/abcweb.js.


















































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
//#javascript
// abcweb-1.js file to include in html pages
//
// Copyright (C) 2014-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

// This script is used in HTML or XHTML files.
// It replaces the ABC sequences
// - contained in <script> elements with the type "text/vnd.abc", or
// - defined in HTML elements with the class "abc", or
// - starting with "%abc-n" or "X:n" at start of line up to a XML tag
// by music as SVG images.
// The other elements stay in place.
// The script abc2svg-1.js may be loaded before this script.
// It is automatically loaded when not present.
//
// When the file is .html, if the ABC sequence is contained inside
// elements <script type="text/vnd.abc">, there is no constraint
// about the ABC characters. Note that the <script> element is removed.
// With a container of class "abc", the characters '<', '>' and '&' may be
// replaced by their XML counterparts ('&lt;', '&gt;' and '&amp;').
// When the file is .xhtml, if the ABC sequence contains the characters
// '<', '>' or '&', this sequence must be enclosed in a XML comment
// (%<!-- .. %-->) or in a CDATA (%<![CDATA[ .. %]]>).
//
// ABC parameters may be defined in the query string of the URL.

window.onerror = function(msg, url, line) {
	if (typeof msg == 'string')
		alert("window error: " + msg +
			"\nURL: " + url +
			"\nLine: " + line)
	else if (typeof msg == 'object')
		alert("window error: " + msg.type + ' ' + msg.target.src)
	else
		alert("window error: " + msg)
	return false
}

    var user
if (typeof abc2svg == "undefined")
    var abc2svg = {}

// function called when abc2svg is fully loaded
function dom_loaded() {
var	abc, new_page, src,
	a_inc = {},
	errtxt = '',
	app = "abcweb",
	playing,
	abcplay,
	playconf = {
		onend: function() {
			playing = false
		}
	},
	page,				// document source
	tune_lst,		// array of [tsfirst, voice_tb, info, cfmt] per tune
	jsdir = document.currentScript ?
		    document.currentScript.src.match(/.*\//) :
		    (function() {
		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf(app) >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??
	})()

// -- abc2svg init argument
    user = {
	read_file: function(fn) {
		return a_inc[fn]
	}, // read_file()
	errmsg: function(msg, l, c) {	// get the errors
		errtxt += clean_txt(msg) + '\n'
	},
	img_out: function(str) {	// image output
		new_page += str
	}
    }

// replace <>& by XML character references
function clean_txt(txt) {
	return txt.replace(/<|>|&.*?;|&/g, function(c) {
		switch (c) {
		case '<': return "&lt;"
		case '>': return "&gt;"
		case '&': return "&amp;"
		}
		return c
	})
}

	// function called on click on the music
	abc2svg.playseq = function(evt) {
	    var	i, j,
		svg = evt.target,
		e = svg			// keep the clicked element

		// search if click in a SVG image
		while (svg.tagName != 'svg') {
			svg = svg.parentNode
			if (!svg)
				return
		}
		i = svg.getAttribute('class')
		if (!i)
			return
		i = i.match(/tune(\d+)/)
		if (!i)
			return
		i = i[1]		// tune number

		// initialize the play object
		if (!abcplay) {
			if (typeof AbcPlay == "undefined") { // as snd-1.js not loaded,
				abc2svg.playseq = function(){}	// don't come here anymore
				return
			}
			if (abc.cfmt().soundfont)
				playconf.sfu = abc.cfmt().soundfont
			abcplay = AbcPlay(playconf);
		}

		// if first time, get the tunes references
		// and generate the play data of all tunes
		if (!tune_lst) {
			tune_lst = abc.tunes
			for (j = 0; j < tune_lst.length; j++)
				abcplay.add(tune_lst[j][0],
					tune_lst[j][1],
					tune_lst[j][3])
		}

		// check if click on a music symbol
		// (this works when 'follow' is active)
		s = tune_lst[i][0]		// first symbol of the tune
		i = e.getAttribute('class')
		if (i)
			i = i.match(/abcr _(\d+)_/)
		if (playing) {
			abcplay.stop();
			if (!i)
				return
		}
		if (i) {
			i = i[1]		// symbol offset in the source
			while (s && s.istart != i)
				s = s.ts_next
			if (!s) {		// fixme: error ?!
				alert("play bug: no such symbol in the tune")
				return
			}
		}

		playing = true
		abcplay.play(s, null)
	} // playseq()

	// convert HTML to ABC
	function toabc(s) {
		return s.replace(/&gt;/g, '>')
			.replace(/&lt;/g, '<')
			.replace(/&amp;/g, '&')
			.replace(/[ \t]+(%%|.:)/g, '$1')
	} // toabc()

// function to load javascript files
	abc2svg.loadjs = function(fn, relay, onerror) {
		var s = document.createElement('script');
		if (/:\/\//.test(fn))
			s.src = fn		// absolute URL
		else
			s.src = jsdir + fn;
		if (relay)
			s.onload = relay;
		s.onerror = onerror || function() {
			alert('error loading ' + fn)
		}
		document.head.appendChild(s)
	}

function render() {

	// search the ABC tunes,
	// replace them by SVG images with play on click

//search in page
// 1- <script type="text/vnd.abc"> ..ABC.. <script>
// 2- <anytag .. class="abc" .. > ..ABC.. </anytag>
// 3- %abc-n ..ABC.. '<' with skip %%beginxxx .. %%endxxx
// 4- X:n ..ABC.. '<' with skip %%beginxxx .. %%endxxx

    var	i = 0, j, k, res,
	re = /<script type="text\/vnd.abc"|<[^>]* class="abc"|%abc-\d|X:\s*\d/g,
	re_stop = /\n<|\n%.begin[^\s]+/g

	// aweful hack: user.anno_stop must be defined before Abc creation
	// for being set later by follow() !
	if (typeof follow == "function")
		user.anno_stop = function(){};

	abc = new abc2svg.Abc(user)
	new_page = ''

	// initialize the play follow function
	if (typeof follow == "function")
		follow(abc, user, playconf)

	// handle MEI files
	j = page.indexOf("<mei ")
	if (j >= 0) {
		k = page.indexOf("</mei>") + 6
		abc.mei2mus(page.slice(j, k))
		document.body.innerHTML = new_page
		return
	}

	src = '%%beginml\n'
	for (;;) {

		// get the start of a ABC sequence
		res = re.exec(page)
		if (!res) {
			src += page.slice(i).replace(/\n%%/g,"\n%%%%") +
					"\n%%endml\n"
			break
		}
		j = re.lastIndex - res[0].length;

		// (the core removes '%%' at start of line)
		src += page.slice(i, j).replace(/\n%%/g,"\n%%%%")

		switch (res[0][0]) {
		default:
			res = res[0].match(/<([^\s]*)/)[1]	// tag
			if (res == 'script') {		// <script
				j = page.indexOf('>', j) + 2
				i = page.indexOf('</' + res, j)
				src += "%%endml\n" +
					page.slice(j, i) // keep the script content only
				i += 10
			} else {			// < .. class="abc"
				i = page.indexOf('>', j) + 1
				src += page.slice(j, i) + "\n%%endml\n"
				i = page.indexOf('\n', i)
				j = page.indexOf('</' + res, i)
				src += toabc(page.slice(i, j))	// keep the element
				i = j
			}
			break
		case '%':		// %abc
		case 'X':		// X:
			if (j != 0 && page[j - 1] != '\n') {
				src += res[0]		// not at start of line
				i = re.lastIndex
				continue
			}

			// get the end of the ABC sequence
			// including the %%beginxxx/%%endxxx sequences
			re_stop.lastIndex = j
			while (1) {
				res = re_stop.exec(page)
				if (!res || res[0] == "\n<")
					break
				k = page.indexOf(res[0].replace("begin", "end"),
						re_stop.lastIndex)
				if (k < 0)
					break
				re_stop.lastIndex = k
			}
			if (!res || k < 0)
				i = page.length
			else
				i = re_stop.lastIndex - 1
			src += "%%endml\n" + page.slice(j, i)
			break
		}
		if (i < 0)
			break			// problem!
		re.lastIndex = i
		src += '%%beginml\n'
	}

	// use the query string of URL for global parameters
	k = location.search.substr(1).split("&")
	for (i = 0; i < k.length; i++) {
		if (k[i]) {
			j = k[i].split('=')
			if (j[0])
				abc.tosvg(app, "%%" + j[0] + " " +
						decodeURIComponent(j[1]))
		}
	}

	// generate the new source
	try {
		abc.tosvg(app, src)
	} catch (e) {
		alert("abc2svg javascript error: " + e.message +
			"\nStack:\n" + e.stack)
	}
	abc2svg.abc_end()		// close the page if %%pageheight
	if (errtxt) {
		new_page += '<pre class="nop" style="background:#ff8080">' +
				errtxt + "</pre>\n"
		errtxt = ""
	}

	// change the page
	try {
		document.body.innerHTML = new_page
	} catch (e) {
		alert("abc2svg bad generated SVG: " + e.message +
			"\nStack:\n" + e.stack)
	}

	// prepare for play on click
	window.onclick = abc2svg.playseq
} // render()

	// load the %%abc-include files
	function include() {
	    var	i, j, fn, r,
		k = 0

		while (1) {
			i = page.indexOf('%%abc-include ', k)
			if (i < 0) {
				render()
				return
			}
			i += 14
			j = page.indexOf('\n', i)
			fn = page.slice(i, j).trim()
			if (!a_inc[fn])
				break
			k = j
		}

		// %%abc-include found: load the file
		r = new XMLHttpRequest()
		r.open('GET', fn, true)		// (async)
		r.onload = function() {
			if (r.status === 200) {
				a_inc[fn] = r.responseText
				if (abc2svg.modules.load(a_inc[fn], include))
					include()
			} else {
				a_inc[fn] = '%\n'
				alert('Error getting ' + fn + '\n' + r.statusText)
				include()
			}
		}
		r.onerror = function () {
			a_inc[fn] = '%\n'
			alert('Error getting ' + fn + '\n' + r.statusText)
			include()
		}
		r.send()
	} // include()

	// --- dom_loaded() main code ---

	// get the page content
	page = document.body.innerHTML

	// load the abc2svg core if not done by <script>
	if (!abc2svg.Abc) {
		abc2svg.loadjs(page.indexOf("<mei ") >= 0 ?
					"mei2svg-1.js" :
					"abc2svg-1.js",
						dom_loaded)
		return
	}

	// accept page formatting
	abc2svg.abc_end = function() {}

	// load the required modules, then render the music
	if (abc2svg.modules.load(page, include))
		include()
} // dom_loaded()

// wait for the scripts to be loaded
window.addEventListener("load", dom_loaded)
Added util/abcweb1.js.











































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
//#javascript
// abcweb1-1.js file to include in html pages with abc2svg-1.js
//
// This script either:
// - builds a list of the tunes when there is no selection or
// - displays the selected tune.
//
// When the tune is displayed, if playing is not enabled,
// scrolling the music may be done by clicking/taping
// on the 'start scrolling' button.
//
// The header of the tune list ("Tunes:") may be set in a global
// javascript variable 'list_head'.
// The tail of the tune list ("(all tunes)") may be set in a global
// javascript variable 'list_tail'.
//
// Copyright (C) 2019-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

window.onerror = function(msg, url, line) {
	if (typeof msg == 'string')
		alert("window error: " + msg +
			"\nURL: " + url +
			"\nLine: " + line)
	else if (typeof msg == 'object')
		alert("window error: " + msg.type + ' ' + msg.target.src)
	else
		alert("window error: " + msg)
	return false
}

// remove the menu button on print
window.onbeforeprint = function() {
   var	e = document.getElementById("dd")
	if (e)
		e.style.display = "none"
}
window.onafterprint = function() {
   var	e = document.getElementById("dd")
	if (e)
		e.style.display = "block"
}

    var user
if (typeof abc2svg == "undefined")
    var abc2svg = {}

// function called when abc2svg is fully loaded
function dom_loaded() {
    var	abc,
	new_page,
	playing,
	abcplay,

	tune_dur,			// scroll tune duration
	scroll_to,			// scroll timeout
	dt,				// scroll delta per timeout
	sY,				// current scroll Y

	page,				// document source
	a_inc = {},
	errtxt = '',
	app = "abcweb1",
	playconf = {			// play arguments
		onend: function() {
			playing = false
		}
	},
	tune_lst,		// array of [tsfirst, voice_tb, info, cfmt] per tune
	jsdir = document.currentScript ?
		    document.currentScript.src.match(/.*\//) :
		    (function() {
		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf(app) >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??
	})()
// end of the variables of dom_loaded()

// -- abc2svg init argument
	user = {
		read_file: function(fn) {
			return a_inc[fn]
		}, // read_file()
		errmsg: function(msg, l, c) {	// get the errors
			errtxt += clean_txt(msg) + '\n'
		},

		// function called before SVG generation
		get_abcmodel: function(tsfirst, voice_tb) {
		    var	d, i, n, pf,
			s = tsfirst

			while (1) {
				if (s.tempo && !pf) {
					d = 0
					n = s.tempo_notes.length
					for (i = 0; i < n; i++)
						d += s.tempo_notes[i]
					pf = d * s.tempo / 60
				}
				if (!s.ts_next)
					break
				s = s.ts_next
			}
			if (!pf)
				pf = abc2svg.C.BLEN / 8	// default: Q:1/4=120
//				     abc2svg.C.BLEN / 4 * 120 / 60
			tune_dur = s.time / pf
		},

		img_out: function(str) {	// image output
			new_page += str
		}
	} // user

	// extract the ABC code from the HTML body
	function fix_abc(s) {
	    var	j,
		i = s.indexOf('<script')

		if (i >= 0) {
			i = s.indexOf('type="text/vnd.abc"', i)
			if (i > 0) {
				i = s.indexOf('\n', i) + 1
				j = s.indexOf('</script', i)
				return s.slice(i, j)
			}
		}
		return s
	} // fix_abc()

	// replace <>& by XML character references
	function clean_txt(txt) {
		return txt.replace(/<|>|&.*?;|&/g, function(c) {
			switch (c) {
			case '<': return "&lt;"
			case '>': return "&gt;"
			case '&': return "&amp;"
			}
			return c
		})
	}

	// scroll the displayed music
	function do_scroll(old) {
	    var	d, ttop

		// if start, get the window parameters and delay the first scroll
		if (!old) {
			d = document.documentElement

			// time for scrolling one pixel
			dt = tune_dur / d.scrollHeight

			// start scrolling at this time (1/4 of the first screen)
			ttop = dt * d.clientHeight / 4
			document.getElementById("ss").style.display = "block"
			scroll_to = setTimeout(do_scroll, ttop * 1000, 1)

			// (in Android Browser, remove the address bar)
			window.scrollTo(0, 8)		// go to the top
			sY = 0
		} else {
			if (sY == window.pageYOffset) {	// no scroll -> finished
				document.getElementById("ss").style.display = "none"
				scroll_to = null
				return
			}
			sY = window.pageYOffset
			window.scrollTo(0, sY + 1)
			scroll_to = setTimeout(do_scroll, dt * 1000, 1)
		}
	} // do_scroll()

	// source edit
	abc2svg.src_upd = function() {
		page = document.getElementById('ta').value
		abc2svg.get_sel()
	} // src_upd()

	abc2svg.src_edit = function() {
		// offer a textarea with the ABC source and 2 buttons
		document.body.innerHTML = '\
<textarea id="ta" rows="50" cols="80">' + page + '</textarea>\
<br/>\
<a href="#" onclick="abc2svg.src_upd()"> Apply </a> - \
<a href="#" onclick="abc2svg.get_sel()"> Cancel </a>'
	} // src_edit()

	// start/stop scrolling when no play
	abc2svg.st_scroll = function() {
		if (scroll_to) {
			clearTimeout(scroll_to)
			document.getElementById("ss").style.display = "none"
			scroll_to = null
		} else {
			scroll_to = setTimeout(do_scroll, 500, 0)	// scroll start
		}
	} // st_scroll()

	// function to load javascript files
	abc2svg.loadjs = function(fn, relay, onerror) {
	    var	s = document.createElement('script')
		if (/:\/\//.test(fn))
			s.src = fn		// absolute URL
		else
			s.src = jsdir + fn
		if (relay)
			s.onload = relay
		s.onerror = onerror || function() {
			alert('error loading ' + fn)
		}
		document.head.appendChild(s)
	} // loadjs()

	// build a list of the tunes
	abc2svg.get_sel = function() {
	    var	j, k,
		n = 0,
		i = 0,
		t = (typeof list_head == "undefined" ? "Tunes:" : list_head) + '<ul>\n'
		tt = typeof list_tail == "undefined" ? "(all tunes)" : list_tail

//		window.onclick = null

		for (;;) {
			i = page.indexOf("\nX:", i)
			if (i < 0)
				break
			k = page.indexOf("\n", ++i)
			j = page.indexOf("\nT:", i)
			n++
//			t += '<li><a \
			t += '<li \
style="cursor:pointer;color:blue;text-decoration:underline" \
onclick="abc2svg.do_render(\'' + page.slice(i, k) + '$\')">' +
				page.slice(i + 2, k).replace(/%.*/,'')
			if (j > 0 && j < i + 20) {
				k = page.indexOf("\n", j + 1)
				t += " " + page.slice(j + 3, k).replace(/%.*/,'')
				if (page[k + 1] == 'T' && page[k + 2] == ':') {
					j = k + 3
					k = page.indexOf("\n", j)
					t += " - " + page.slice(j, k).replace(/%.*/,'')
				}
			}
//			t += '</a></li>\n'
			t += '</li>\n'
			i = k
		}
		if (n <= 1) {
			abc2svg.do_render()
			return
		}
//		t += '<li><a \
		t += '<li \
style="cursor:pointer;color:blue;text-decoration:underline" \
onclick="abc2svg.do_render(\'.*\')">' + tt +
//			'</li>\n\
			'</li>\n\
</ul>'

		document.body.innerHTML = t
		if (window.location.hash)
			window.location.hash = ''
	} // get_sel()

	// search/ask the tune to be rendered
	function render() {
	    var	select = window.location.hash.slice(1)		// after '#'

		// create styles for the menu
	   var	sty = document.createElement('style')
		sty.innerHTML = '\
.dd{position:fixed;top:0;bottom:0;right:0;height:40px;cursor:pointer;font-size:16px}\
#ss{display:none;background-color:red}\
.db{margin:5px;background-color:yellow}\
.db:hover,.db:focus{background-color:lightgreen}\
.dc{position:absolute;left:-70px;min-width:100px;display:none;background-color:yellow}\
.dc label{display:block;padding:0 5px 0 5px;margin:2px}\
.dc label:hover{outline:solid;outline-width:2px}\
.show{display:block}'
		document.head.appendChild(sty)

		// if no selection and many tunes, get the references of the tunes
		// and ask which one to display
		if (!select)
			abc2svg.get_sel()
		else
			abc2svg.do_render(decodeURIComponent(select))
	} // render()

	// replace the (previous) body by the music
	abc2svg.do_render = function(select) {

		// aweful hack: user.anno_stop must be defined before Abc creation
		// for being set later by follow() !
		if (typeof follow == "function")
			user.anno_stop = function(){}

		abc = new abc2svg.Abc(user)
		new_page = ""

		// initialize the play follow function
		if (typeof follow == "function")
			follow(abc, user, playconf)

		if (select) {
			abc.tosvg(app, "%%select " + select)
			window.location.hash = encodeURIComponent(select)
		}
		try {
			abc.tosvg(app, page)
		} catch (e) {
			alert("abc2svg javascript error: " + e.message +
				"\nStack:\n" + e.stack)
		}
		abc2svg.abc_end()	// close the page if %%pageheight
		if (errtxt) {
			new_page += '<pre class="nop" style="background:#ff8080">' +
					errtxt + "</pre>\n"
			errtxt = ""
		}

		// add the menu
		new_page += '\
<div id="dd" class="dd nop">\
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" class="db">\
<path d="M4 6h15v2.5H4zm0 5h15v2.5H4zm0 5h15v2.5H4z" fill=black/>\
</svg>\
<div id="dc" class="dc">\
<label id="edit" onclick="abc2svg.src_edit()">Source edit</label>\
<label id="list" onclick="abc2svg.get_sel()">Tune list</label>\
<label id="play" onclick="abc2svg.st_scroll()">Scroll</label>\
</div>\
</div>\
<label id="ss" class="dd nop" onclick="abc2svg.st_scroll()">Scroll<br/>stop</label>'

		// change the page
		try {
			document.body.innerHTML = new_page
		} catch (e) {
			alert("abc2svg bad generated SVG: " + e.message +
				"\nStack:\n" + e.stack)
			return
		}

		// update the menu
		setTimeout(function() {

			// remove scroll in menu if play or not a big tune
			if (typeof AbcPlay != "undefined"
			 || document.documentElement.scrollHeight <= window.innerHeight)
				document.getElementById("play").style.display = "none"
		}, 500)
	} // render()

	// load the %%abc-include files
	function include() {
	    var	i, j, fn, r,
		k = 0

		while (1) {
			i = page.indexOf('%%abc-include ', k)
			if (i < 0) {
				render()
				return
			}
			i += 14
			j = page.indexOf('\n', i)
			fn = page.slice(i, j).trim()
			if (!a_inc[fn])
				break
			k = j
		}

		// %%abc-include found: load the file
		r = new XMLHttpRequest()
		r.open('GET', fn, true)		// (async)
		r.onload = function() {
			if (r.status === 200) {
				a_inc[fn] = r.responseText
				if (abc2svg.modules.load(a_inc[fn], include))
					include()
			} else {
				a_inc[fn] = '%\n'
				alert('Error getting ' + fn + '\n' + r.statusText)
				include()
			}
		}
		r.onerror = function () {
			a_inc[fn] = '%\n'
			alert('Error getting ' + fn + '\n' + r.statusText)
			include()
		}
		r.send()
	} // include()

	// --- dom_loaded() main code ---

	// load the abc2svg core if not done by <script>
	if (!abc2svg.Abc) {
		abc2svg.loadjs("abc2svg-1.js", dom_loaded)
		return
	}

	// get the page content
	page = fix_abc(document.body.innerHTML)

	// mouse functions
	window.onmouseup = function(evt) {

		// stop playing
		if (playing) {
			abcplay.stop()
			return
		}

	    var	e, s, j,
		c = evt.target

		// search if click in a SVG image
		e = c				// keep the clicked element
		while (c && c.tagName != 'svg')
			c = c.parentNode
		if (c)
			c = c.getAttribute('class')

		// no, remove the menu if active
		if (!c) {
			e = document.getElementById("dc")
			if (e && e.classList.contains("show")) {
				evt.stopImmediatePropagation()
				evt.preventDefault()
				e.classList.remove("show")
			}
			return
		}

		// if click in the menu button, show the menu
		if (c == "db") {
			evt.stopImmediatePropagation()
			evt.preventDefault()
			e = document.getElementById("dc")
			e.classList.toggle("show")
			return
		}

		//play stuff

		// initialize the play object
		if (!abcplay) {
			if (typeof AbcPlay == "undefined")
				return		// no play support
			if (abc.cfmt().soundfont)
				playconf.sfu = abc.cfmt().soundfont
			abcplay = AbcPlay(playconf)
		}

		// get the clicked tune
		c = c.match(/tune(\d+)/)
		if (!c)
			return
		c = c[1]			// tune number

		// if a new generation, get the tunes references
		// and generate the play data of all tunes
		if (tune_lst != abc.tunes) {
			tune_lst = abc.tunes
			for (j = 0; j < tune_lst.length; j++)
				abcplay.add(tune_lst[j][0],
					tune_lst[j][1],
					tune_lst[j][3])
		}

		// start playing from the clicked symbol
		// (this works when 'follow' is active)
		// or from the start of the tune
		s = tune_lst[c][0]		// first symbol of the tune
		c = e.getAttribute('class')
		if (c)
			c = c.match(/abcr _(\d+)_/)
		if (c) {
			c = c[1]		// symbol offset in the source
			while (s && s.istart != c)
				s = s.ts_next
			if (!s) {		// fixme: error ?!
				alert("play bug: no such symbol in the tune")
				return
			}
		}

		playing = true
		abcplay.play(s, null)
	} // onmouseup()

	// accept page formatting
	abc2svg.abc_end = function() {}

	// load the required modules, then render the music
	if (abc2svg.modules.load(page, include))
		include()
} // dom_loaded()

// wait for the scripts to be loaded
window.addEventListener("load", dom_loaded)
Changes to util/abcweb2.js.
1
2

3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19




















20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38


39

40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64



65
66
67
68
69
70
71
72
73
74

75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95




96
97
98
99
100
101
102
103

104
105



106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


130
131























132
133
134
135
136

137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153


154
155
156



157
158




159
160
161





162
163
164
165

166
167
168
169

170

171

172
173
174
175
176

177
178
179
180

181
182



183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209





210
211
212
213
214
215














































216
217

218


219










220
221

222
223
224
225
226
227


228
229
230
231
1

2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94






95


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112



113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141




142
143
144
145
146
147


148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194

195
196
197


198
199
200


201
202
203
204
205


206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221

222
223
224
225
226

227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243

244

245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266






267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317

318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333


334
335
336
337
338
339

-
+

-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













+





-
+
+

+

+


-

















-
+



+
+
+




-
-
-
-
-
-
+
-
-
+
















-
-
-
+
+
+
+







-
+


+
+
+
-
+











-
-
-
-






-
-
+
+

-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+



-
+












-
+
+

-
-
+
+
+
-
-
+
+
+
+

-
-
+
+
+
+
+



-
+




+

+
-
+




-
+




+

-
+
+
+







-
+
-









-








+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

+
+
-
+
+
+
+
+
+
+
+
+
+

-
+




-
-
+
+




//#javascript
// abcemb2-1.js file to include in html pages with abc2svg-1.js
// abcweb2-1.js file to include in (x)html pages with abc2svg-1.js
//
// Copyright (C) 2018-2019 Jean-Francois Moine
// Copyright (C) 2018-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.
//
// This script is used in HTML or XHTML files.
// It replaces the ABC sequences defined
// - in <script> elements with the type "text/vnd.abc" or
// - in the HTML elements with the class "abc"
// by music as SVG images.
// The other elements stay in place.
// The script abc2svg-1.js may be loaded before this script.
// It is automatically loaded when not present.
//
// When the file is .html, if the ABC sequence is defined inside
// elements <script type="text/vnd.abc">, there is no constraint
// about the ABC characters. Outside a script vnd.abc, the characters
// '<', '>' and '&' must be replaced by their XML counterparts
// ('&lt;', '&gt;' and '&amp;').
// When the file is .xhtml, if the ABC sequence contains the characters
// '<', '>' or '&', this sequence must be enclosed in a XML comment
// (%<!-- .. %-->) or in a CDATA (%<![CDATA[ .. %]]>).
//
// Tune selection may be done by a 'hash' value in the URL of the page.

window.onerror = function(msg, url, line) {
	if (typeof msg == 'string')
		alert("window error: " + msg +
			"\nURL: " + url +
			"\nLine: " + line)
	else if (typeof msg == 'object')
		alert("window error: " + msg.type + ' ' + msg.target.src)
	else
		alert("window error: " + msg)
	return false
}

    var	user
if (typeof abc2svg == "undefined")
    var	abc2svg = {}

// function called when abc2svg is fully loaded
function dom_loaded() {
    var	abc, i, elt,
    var	abc, i,
	a_inc = {},
	errtxt = '',
	app = "abcweb2",
	elts,				// ABC HTML elements
	a,
	abcsrc = "",			// ABC source
	indx = [],			// indexes of the tunes in abcsrc
	select,
	playing,
	abcplay,
	playconf = {
		onend: function() {
			playing = false
		}
	},
	tune_lst,		// array of [tsfirst, voice_tb] per tune
	jsdir = document.currentScript ?
		    document.currentScript.src.match(/.*\//) :
		    (function() {
		     var s_a = document.getElementsByTagName('script')
			for (var k = 0; k < s_a.length; k++) {
				if (s_a[k].src.indexOf('abcweb2-') >= 0)
					return s_a[k].src.match(/.*\//) || ''
			}
			return ""	// ??
		})(),
		})()

	// abc2svg init argument
	user = {
		read_file: function(fn) {
			return a_inc[fn]
		}, // read_file()
		errmsg: function(msg, l, c) {	// get the errors
			errtxt += clean_txt(msg) + '\n'
		},
		img_out: function(str) {	// image output
			if (str.slice(0, 4) == "<svg")
				new_page += '<svg class="abc' +
					abc.tunes.length + '"' +
					str.slice(4)
			else
				new_page += str
			new_page += str
		},
		page_format: true	// define the non-page-breakable blocks
		}
	} // user

	// replace <>& by XML character references
	function clean_txt(txt) {
		return txt.replace(/<|>|&.*?;|&/g, function(c) {
			switch (c) {
			case '<': return "&lt;"
			case '>': return "&gt;"
			case '&': return "&amp;"
			}
			return c
		})
	} // clean_txt()

	// function called on click in the screen
	abc2svg.playseq = function(evt) {
	    var	outputs, e, i,
		tunes = abc.tunes,
		svg = evt.target
	    var	i, s, t,
		tunes = abc.tunes,	// list of the tunes created by the core
		svg = evt.target,
		e = svg			// keep the clicked element

		// search if click in a SVG image
		while (svg.tagName != 'svg') {
			svg = svg.parentNode
			if (!svg)
				return
		}
		i = svg.getAttribute('class').match(/abc(\d)/)
		i = svg.getAttribute('class')
		if (!i)
			return
		i = i.match(/tune(\d+)/)
		if (!i)
			return
		i = i[1] - 1			// tune number
		i = i[1]		// tune number

		// initialize the play object
		if (!abcplay) {

			// if play-1.js is not loaded, don't come here anymore
			if (typeof AbcPlay == "undefined") {
				abc2svg.playseq = function(){}
				return
			}
			abcplay = AbcPlay(playconf)
		}
		if (playing) {
			abcplay.stop()
			return
		}

		// if first time, get the tunes references
		// and generate the play data of all tunes
		if (tunes.length) {
			tune_lst = tunes.slice(0)	// (array copy)
			while (1) {
				e = tunes.shift()
				if (!e)
				t = tunes.shift()
				if (!t)
					break
				abcplay.add(e[0], e[1])
				abcplay.add(t[0], t[1])
			}
		}

		// check if click on a music symbol
		// (this works when 'follow' is active)
		s = tune_lst[i][0]		// first symbol of the tune
		i = e.getAttribute('class')
		if (i)
			i = i.match(/abcr _(\d+)_/)
		if (playing) {
			abcplay.stop()
			if (!i)
				return
		}

		if (i) {
			i = i[1]		// symbol offset in the source
			while (s && s.istart != i)
				s = s.ts_next
			if (!s) {		// fixme: error ?!
				alert("play bug: no such symbol in the tune")
				return
			}
		}

		playing = true
		abcplay.play(tune_lst[i][0], null)
		abcplay.play(s, null)
	} // playseq()

	function render() {
	    var	i, sel
	    var	i, sel, elt

		// aweful hack: user.anno_stop must be defined before Abc creation
		// for being set later by follow() !
		if (typeof follow == "function")
			user.anno_stop = function(){}

		abc = new abc2svg.Abc(user)

		// initialize the play follow function
		if (typeof follow == "function")
			follow(abc, user, playconf)

		// do the selection
		// do the selection if the hash permits some generation
		// (the hash may be used to identify an element in the HTML document)
		sel = window.location.hash.slice(1)
		if (sel) {
			select = '%%select ' + decodeURIComponent(sel)
		if (sel
		 && abcsrc.match(new RegExp(sel)))
			abc.tosvg(app, '%%select ' + decodeURIComponent(sel))
			abc.tosvg("abcemb2", select)
		}

		// generate and replace
		i = 0
		while (1) {

		// generate and replace
		for (i = 0; i < elts.length; i++) {
			// get the next ABC element
			elt = document.getElementsByClassName('abc')[0]
			if (!elt)
				break

			new_page = ""

			try {
				abc.tosvg('abcemb2', abcsrc, indx[i], indx[i + 1])
				abc.tosvg(app, abcsrc, indx[i], indx[i + 1])
			} catch (e) {
				alert("abc2svg javascript error: " + e.message +
					"\nStack:\n" + e.stack)
			}
			abc2svg.abc_end()	// close the page if %%pageheight
			if (errtxt) {
				new_page += 
				new_page += '<pre style="background:#ff8080">' +
					'<pre class="nop" style="background:#ff8080">' +
						errtxt + "</pre>\n"
				errtxt = ""
			}
			try {
				elts[i].innerHTML = new_page
				elt.outerHTML = new_page
			} catch (e) {
				alert("abc2svg bad generated SVG: " + e.message +
					"\nStack:\n" + e.stack)
			}
			i++
		}
		abc2svg.abc_end()		// close the page if %%pageheight

		// prepare for play on click
		window.onclick = abc2svg.playseq
	} // render()

	// convert HTML to ABC
	function toabc(s) {
		return s.replace(/&gt;/g, '>')
			.replace(/&lt;/g, '<')
			.replace(/&amp;/g, '&')
			.replace(/[ \t]+(%%)/g, '$1')
			.replace(/[ \t]+(%%|.:)/g, '$1')
			.replace(/[ \t]+(.:)/g, '$1')
	} // toabc()

	// function to load javascript files
	abc2svg.loadjs = function(fn, relay, onerror) {
	    var	s = document.createElement('script')
		if (/:\/\//.test(fn))
			s.src = fn		// absolute URL
		else
			s.src = jsdir + fn
		s.type = 'text/javascript'
		if (relay)
			s.onload = relay
		s.onerror = onerror || function() {
			alert('error loading ' + fn)
		}
		document.head.appendChild(s)
	}

	// load the %%abc-include files
	function include() {
	    var	i, j, fn, r,
		page = abcsrc,
		k = 0
	// accept page formatting
	abc2svg.abc_end = function() {}

	// prepare for play on click
	window.onclick = abc2svg.playseq


		while (1) {
			i = page.indexOf('%%abc-include ', k)
			if (i < 0) {
				render()
				return
			}
			i += 14
			j = page.indexOf('\n', i)
			fn = page.slice(i, j).trim()
			if (!a_inc[fn])
				break
			k = j
		}

		// %%abc-include found: load the file
		r = new XMLHttpRequest()
		r.open('GET', fn, true)		// (async)
		r.onload = function() {
			if (r.status === 200) {
				a_inc[fn] = r.responseText
			} else {
				a_inc[fn] = '%\n'
				alert('Error getting ' + fn + '\n' + r.statusText)
			}
			include()
		}
		r.onerror = function () {
			a_inc[fn] = '%\n'
			alert('Error getting ' + fn + '\n' + r.statusText)
			include()
		}
		r.send()
	} // include()

	// --- dom_loaded() main code ---

	// load the abc2svg core if not done by <script>
	if (!abc2svg.Abc) {
		abc2svg.loadjs("abc2svg-1.js", dom_loaded)
		return
	}

	// accept page formatting
	abc2svg.abc_end = function() {}

	// extract the ABC source
	elts = document.getElementsByClassName('abc')
	elts = document.getElementsByTagName('script')
	for (i = 0; i < elts.length; i++) {
		if (elts[i].type != "text/vnd.abc")
			continue
		elt = elts[i]
		a = elts[i].getAttribute('class')
		if (a) {
			if (a.indexOf('abc') < 0)
				elts[i].setAttribute('class', a + ' abc')
		} else {
			elts[i].setAttribute('class', 'abc')
		}
	}
	elts = document.getElementsByClassName('abc')
	for (i = 0; i < elts.length; i++) {
		indx[i] = abcsrc.length
		abcsrc += toabc(elt.innerHTML) + '\n'
		abcsrc += toabc(elts[i].innerHTML) + '\n'
	}
	indx[i] = abcsrc.length

	// load the required modules
	if (abc2svg.modules.load(abcsrc, render))
		render()
	if (abc2svg.modules.load(abcsrc, include))
		include()
} // dom_loaded()

// wait for the page to be loaded
window.addEventListener("load", dom_loaded)
Added util/chord.js.






























































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// chord.js - generation of accompaniment
//
// Copyright (C) 2020 Jean-Francois Moine and Seymour Shlien
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// -- chord table --
// index = chord symbol type
// value: array of strings
//	index = inversion
//	string = list of 2 characters
//		1st character = note (see abc2svg.letmid)
//		2nd character = octave ('+', ' ', '-')
abc2svg.chordnames = {
	'':	["C-E G C+", "E-C G C+", "G-C E G "],
	m:	["C-e G C+", "e-C G C+", "G-C e G "],
	'7':	["C-b-E G ", "E-C G b ", "G-E b C+", "b-E G C+"],
	m7:	["C-b-e G ", "e-C G b ", "G-e b C+", "b-e G C+"],
	m7b5:	["C-b-e g ", "e-C g b ", "g-e b C+", "b-e g C+"],
	M7:	["C-B-E G ", "E-C G B ", "G-E B C+", "B-E G C+"],
	'6':	["C-A-E G ", "E-C A B ", "A-E B C+", "B-E A C+"],
	m6:	["C-A-e G ", "e-C A B ", "A-e B C+", "B-e A C+"],
	aug:	["C-E a C+", "E-C a C+", "a-C E a "],
//	plus:	["C-E a C+", "E-C a C+", "a-C E a "],
	aug7:	["C-b-E a ", "E-C a b ", "a-E b C+", "b-E a C+"],
	dim:	["C-E g C+", "E-C g C+", "g-C E g "],
	dim7:	["C-e g A ", "e-C g A ", "g-e A C+", "A-C e G "],
	'9':	["C-b-E G D+", "E-C G b D+", "G-E b C+D+", "b-E G C+D+", "D-G-C E b "],
	m9:	["C-b-e G D+", "e-C G b D+", "G-e b C+D+", "b-e G C+D+", "D-G-C e b "],
	maj9:	["C-B-E G D+", "E-C G B D+", "G-E B C+D+", "B-E G C+D+", "D-G-C E B "],
	M9:	["C-B-E G D+", "E-C G B D+", "G-C E B D+", "B-E G C+D+", "D-G-C E B "],
	'11':	["C-b-E G D+F+", "E-C G b D+F+", "G-E b C+D+F+", "b-E G C+D+F+",
						"D-G-C E b F+", "F-D-G-C E b D+"],
	dim9:	["C-A-e g d+", "e-C g A d+", "g-C e A d+", "A-C e g d+", "D-g-C e A "],
	sus4:	["C-F G C+", "F-C G C+", "G-C F G "],
	sus9:	["C-D G C+", "D-C G C+", "G-C D G "],
	'7sus4': ["C-b-F G ", "F-C G b ", "G-F b C+", "b-C F G "],
	'7sus9': ["C-b-D G ", "D-C G b ", "G-D b C+", "b-C D G "],
	'5':	["C-G C+", "G-G C+"]
} // chordnames

abc2svg.midlet = "CdDeEFgGaAbB"		// MIDI pitch -> letter
abc2svg.letmid = {			// letter -> MIDI pitch
	C: 0,
	d: 1,
	D: 2,
	e: 3,
	E: 4,
	F: 5,
	g: 6,
	G: 7,
	a: 8,
	A: 9,
	b: 10,
	B: 11
} // midsca

abc2svg.chord = function(first,		// first symbol in time
			 voice_tb,	// table of the voices
			 cfmt) {	// tune parameters
    var	chnm, i, k, vch, s, gchon,
	C = abc2svg.C,
	trans = 48 + (cfmt.chord.trans ? cfmt.chord.trans * 12 : 0)

	// create a chord according to the bass note
	function chcr(b, ch) {
	    var	i, v,
		r = []

		b = abc2svg.midlet[b]
		i = ch.length
		while (--i > 0) {
			if (ch[i][0] == b)	// search the bass in the chord
				break
		}
		ch = ch[i]
		for (i = 0; i < ch.length; i += 2) {
			v = abc2svg.letmid[ch[i]]
			switch (ch[i + 1]) {
			case '+': v += 12; break
			case '-': v -= 12; break
			}
			r.push(v)
		}
		return r
	} // chcr()

	// generate a chord
	function gench(sb, gch) {
	    var	r, ch, b, m, n, not,
		a = gch.otext.
//			replace(/\$./,'').
			match(/([A-G])([#♯b♭]?)([^/]*)\/?(.*)/),
			// a[1] = note, a[2] = acc, a[3] = type, a[4] = bass
		s = {
			v: vch.v,
			p_v: vch,
			type: C.NOTE,
			time: sb.time,
			notes: []
		}

		if (a)
			r = abc2svg.letmid[a[1]]	// root
		if (r == undefined) {
			if (a[1] != "N")
				return
			s.type = C.REST			// ("N") = no chord
			ch = [0]
			r = 0
		} else {
			switch (a[2]) {
			case "#":
			case "♯": r++; break
			case "b":
			case "♭": r--; break
			}
			if (!a[3]) {
				ch = chnm[""]
			} else {
				ch = abc2svg.ch_alias[a[3]]
				if (ch == undefined)
					ch = a[3]
				ch = chnm[ch]
				if (!ch)
					ch = a[3][0] == 'm' ? chnm.m : chnm[""]
			}
			if (a[4]) {			// bass
				b = a[4][0].toUpperCase()
				b = abc2svg.letmid[b]
				if (b != undefined) {
					switch (a[4][1]) {
					case "#":
					case "♯": b++; if (b >= 12) b = 0; break
					case "b":
					case "♭": b--;  if (b < 0) b = 11; break
					}
				}
			}
		}
		if (b == undefined)
			b = 0
		ch = chcr(b, ch)

		// generate the notes of the chord
		n = ch.length
		r += trans
		for (m = 0; m < n; m++) {
			not = {
				midi: r + ch[m]
			}
			s.notes.push(not)
		}
		s.nhd = n - 1

		// insert the chord in the chord voice and in the tune
		s.prev = vch.last_sym
		vch.last_sym.next = s
		s.ts_next = sb.ts_next
		sb.ts_next = s
		s.ts_prev = sb
		if (s.ts_next)
			s.ts_next.ts_prev = s
		vch.last_sym = s
	} // gench()

	// -- chord() --

	// set the chordnames defined by %%MIDI chordname
	if (cfmt.chord.names) {
		chnm = Object.create(abc2svg.chordnames)
		for (k in cfmt.chord.names) {
			vch = ""
			for (i = 0; i < cfmt.chord.names[k].length; i++) {
				s = cfmt.chord.names[k][i]
				vch += abc2svg.midlet[s % 12]
				vch += i == 0 ? "-" :
					(s >= 12 ? "+" : " ")
			}
//fixme: no inversion
			chnm[k] = [ vch ]
		}
	} else {
		chnm = abc2svg.chordnames
	}

	// create the chord voice
	vch = {
		v: voice_tb.length,
		id: "_chord",
		time: 0,
		sym: {			// dummy symbol to simplify chord insersion
			type: C.REST,
			time: 0
		},
		instr: cfmt.chord.prog || 0,
		vol: cfmt.chord.vol || .8
	}
	vch.last_sym = vch.sym
	voice_tb.push(vch)

	// define the MIDI channel
	k = 0
	for (i = 0; i < vch.v; i++) {
		if (k < voice_tb[i].chn)
			k = voice_tb[i].chn
	}
	if (k == 8)
		k++			// skip the channel 10
	vch.chn = k + 1

	// loop on the symbols and add the accompaniment chords
	gchon = cfmt.chord.gchon
	s = first
	while (1) {
		if (!s.ts_next) {
			if (gchon)
				vch.last_sym.dur = s.time - vch.last_sym.time
			break
		}
		s = s.ts_next
		if (!s.a_gch) {
			if (s.subtype == "midigch") {
				if (gchon && !s.on)
					vch.last_sym.dur = s.time - vch.last_sym.time
				gchon = s.on
			}
			continue
		}
		if (!gchon)
			continue
		for (i = 0; i < s.a_gch.length; i++) {
			gch = s.a_gch[i]
			if (gch.type != 'g')
				continue
			vch.last_sym.dur = s.time - vch.last_sym.time
			gench(s, gch)
			break
		}
	}
} // chord()
Changes to util/follow.js.
1
2
3




4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27



28
29
30
31
32

33
34
35
36
37
38
39
40

41
42
43

44
45


46
47




48






















49
50
51




52
53




1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25



26
27
28

29
30
31

32
33
34
35
36
37
38
39

40
41
42
43
44


45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74



75
76
77
78
79

80
-
-
-
+
+
+
+

-
+



















-
-
-
+
+
+
-



-
+







-
+



+
-
-
+
+

-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+

-
+
// follow-1.js - file to include in html pages after
//	abc2svg-1.js, abcemb[2]-1.js and play-1.js.
//	This script permits to follow the notes while playing.
// follow-1.js - file included in snd-1.js
//
// This script permits to follow the notes while playing.
// Scrolling the music may be disabled setting 'no_scroll' in the window object.
//
// Copyright (C) 2015-2019 Jean-Francois Moine
// Copyright (C) 2015-2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

// init
function follow(abc, user, playconf) {
var	ref = [],
	ignore_types = {
		beam:true,
		slur:true,
	keep_types = {
		note: true,
		rest: true
		tuplet:true
	}

user.anno_stop = function(type, start, stop, x, y, w, h) {
	if (ignore_types[type])
	if (!keep_types[type])
		return
	ref[start] = stop;		// keep the source reference

	// create a rectangle
	abc.out_svg('<rect class="abcr _' + start + '_" x="');
	abc.out_sxsy(x, '" y="', y);
	abc.out_svg('" width="' + w.toFixed(2) +
		'" height="' + h.toFixed(2) + '"/>\n')
		'" height="' + abc.sh(h).toFixed(2) + '"/>\n')
}

	playconf.onnote = function(i, on) {
	    var	b, x, y,
		var elts = document.getElementsByClassName('_' + i + '_')
		if (elts && elts[0])
		elts = document.getElementsByClassName('_' + i + '_')
		if (elts && elts[0]) {
			elts[0].style.fillOpacity = on ? 0.4 : 0
	}

			// scroll for the element to be in the screen
			if (on && !window.no_scroll) {	
				b = elts[0].getBoundingClientRect()

				// normal
				if (b.top < 0)
					y = window.scrollY + b.top -
							window.innerHeight / 2
				else if (b.bottom > window.innerHeight)
					y = window.scrollY + b.bottom +
							window.innerHeight / 2

				// single line
				if (b.left < 0)
					x = window.scrollX + b.left -
							window.innerWidth / 2
				else if (b.right > window.innerWidth)
					x = window.scrollX + b.right +
							window.innerWidth / 2
				if (x != undefined || y != undefined)
					window.scrollTo(x || 0, y || 0)
			}
		}
	}
} // follow()

	// create the style of the rectangles
	var sty = document.createElement("style");
	sty.innerHTML = ".abcr {fill: #d00000; fill-opacity: 0; z-index: 15}";
// create the style of the rectangles
(function () {
    var	sty = document.createElement("style")
	sty.innerHTML = ".abcr {fill: #d00000; fill-opacity: 0; z-index: 15}"
	document.head.appendChild(sty)
} // follow()
})()
Changes to util/json.js.
1
2
3
4


5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11
12



-
+
+







//#javascript
// Generate a JSON representation of ABC
//
// Copyright (C) 2016 Jean-Francois Moine
// Copyright (C) 2016-2020 Jean-Francois Moine
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.

// Usage:
//	// Define a get_abcmodel() callback function
//	// This one is called by abc2svg after ABC parsing 
︙
35
36
37
38
39
40
41

42
43
44
45
46
47












48
49
50

51
52
53

54

55
56
57
58
59




60
61
62
63
64
65
66
67
68
69
70
71
72
73
74





75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
36
37
38
39
40
41
42
43
44
45
46
47


48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121







+




-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
+



+
-
+





+
+
+
+















+
+
+
+
+

















+







		ind4 = ind3 + inb,
		links = {
			next: true,
			prev: true,
			ts_next: true,
			ts_prev: true,
			extra: true,
			note: true,
			p_v: true,
			s: true,
			sn: true,
			tie_s: true,
			dd_st: true
		}
			dd_st: true,
		        sym: true,
			last_sym: true,
			last_note: true,
			lyric_restart: true,
			sym_restart: true,
			rep_p: true,
			rep_v: true,
		        rep_s: true
		},
		objstk = []

	// generate an attribute
	function attr_gen(ind, attr, val) {
		var	i, e,
		var	i, e, l,
			indn = ind + inb	// next indentation

		if (links[attr]) {
			switch (attr) {
			if (attr == "extra") {
			case "extra":
				json += h + ind + '"extra": [';
				h = '\n'
				for (e = val ; e; e = e.next)
					attr_gen(indn, null, e);
				json += '\n' + ind + ']'
				break
			case "tie_s":
				json += h + ind + '"ti1": true'
				break
			}
			return
		}
		json += h + ind
		if (attr)
			 json += '"' + attr.toString() + '": ';
		switch (typeof(val)) {
		case "undefined":
			json += "null"
			break
		case "object":
			if (!val) {
				json += "null"
				break
			}
			if (objstk.indexOf(val) >= 0) {
				json += "!!! to_json: loop in '" + attr + "' !!!"
				break
			}
			objstk.push(val)
			if (Array.isArray(val)) {
				if (val.length == 0) {
					json += "[]"
					break
				}
				h = '[\n';
				l = val.length
				for (i = 0; i < l; i++)
					attr_gen(indn, null, val[i]);
				json += '\n' + ind + ']'
			} else {
				h = '{\n'
				for (i in val)
				    if (val.hasOwnProperty(i))
					attr_gen(indn, i, val[i]);
				json += '\n' + ind + '}'
			}
			objstk.pop()
			break
		default:
			json += JSON.stringify(val)
			break
		}
		h = ',\n'
	} // attr_gen()
︙
Deleted util/midi.js.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117





















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
//#javascript
// Set the MIDI pitches in the notes
//
// Copyright (C) 2015-2019 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg-core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg-core.  If not, see <http://www.gnu.org/licenses/>.

// Usage:
//	// Create a AbcMIDI object
//	var abcmidi = AbcMIDI()
//
//	// Define a get_abcmodel() callback function
//	// This one is called by abc2svg after ABC parsing 
//	user.get_abcmodel = my_midi_callback
//
//	// In this function
//	function my_midi_callback(tsfirst, voice_tb, music_types, info) {
//
//		// set the MIDI pitches
//		abcmidi.add(tsfirst, voice_tb);
//
//		// The MIDI pitches are stored in the notes
//		//	s.notes[i].midi
//	}

// AbcMIDI creation
function AbcMIDI() {
    var	C = abc2svg.C

	return {					// returned object
	  // add MIDI pitches
	  add: function(s,				// starting symbol
			voice_tb) {			// voice table
	    var p_v, s,
		temper = voice_tb[0].temper,		// (set by the module temper.js)
		v = voice_tb.length

		// initialize the clefs and keys
		while (--v >= 0) {
			p_v = voice_tb[v]
			if (!p_v.sym)
				continue
			if (p_v.key.k_bagpipe)
	// detune in cents for just intonation in A
	//  C    ^C     D    _E     E     F    ^F     G    _A     A    _B     B
	// 15.3 -14.0  -2.0 -10.0   1.9  13.3 -16.0 -31.8 -12.0   0.0  11.4   3.8
	// (C is ^C,			F is ^F and G is =G)
	// 86				 84
	// temp = [100-14, -14, -2, -10, 2, 100-16, -16, -32, -12, 0, 11, 4]
	// but 'A' bagpipe = 480Hz => raise Math.log2(480/440)*1200 = 151
				temper = new Float32Array([
	2.37, 1.37, 1.49, 1.41, 1.53, 2.35, 1.35, 1.19, 1.39, 1.51, 1.62, 1.55
				])

			s = p_v.clef
			vloop(p_v.sym,
				p_v.key.k_sndtran || 0,
				s.clef_octave && !s.clef_oct_transp ?
					(s.clef_octave / 7 * 40) : 0)
		}

	    function vloop(s, sndtran, ctrans) {
		var	i, g, note,
			transp = sndtran + ctrans

		function midi_set(note) {
		    var m = abc2svg.b40m(note.b40 + transp)
			if (temper		// if not equal temperament
			 && (!note.acc
			  || note.acc | 0 == note.acc)) // and not micro-tone
				m += temper[m % 12]
			note.midi = m
		}

		while (s) {
			switch (s.type) {
			case C.CLEF:
				ctrans = (s.clef_octave && !s.clef_oct_transp) ?
						(s.clef_octave / 7 * 40) : 0
				transp = ctrans + sndtran
				break
			case C.KEY:
				if (s.k_sndtran != undefined) {
					sndtran = s.k_sndtran
					transp = ctrans + sndtran
				}
				break
			case C.GRACE:
				for (g = s.extra; g; g = g.next) {
					for (i = 0; i <= g.nhd; i++)
						midi_set(g.notes[i])
				}
				break
			case C.NOTE:
				for (i = 0; i <= s.nhd; i++)
					midi_set(s.notes[i])
				break
			}
			s = s.next
		}
	    } // vloop()
	  } // add()
	} // returned object
} // end AbcMidi
Changes to util/play.js.
1

2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20




21
22
23
24
25
26
27

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-
+

-
+

















+
+
+
+







// play-1.js - file to include in html pages with abc2svg-1.js for playing
// snd-1.js - file to include in html pages with abc2svg-1.js for playing
//
// Copyright (C) 2015-2019 Jean-Francois Moine
// Copyright (C) 2015-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

// This file is a wrapper around
// - ToAudio (sndgen.js): generate the play data
// - Audio5 (sndaud.js): play with HTML5 audio API and SF2
// - Midi5 (sndmid.js): play with HTML5 MIDI api
// old version:
// - ToAudio (toaudio.js - convert ABC to audio sequences)
// - Audio5 (toaudio5.js - play the audio sequences with webaudio and SF2)
// - Midi5 (tomidi5.js - play the audio sequences with webmidi)

// AbcPlay methods:
//
// set_sfu() - get/set the soundfont URL
︙
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
41
42
43
44
45
46
47

48
49
50
51
52
53
54







-







    var	conf = i_conf,
	init = {},
	audio = ToAudio(),
	audio5, midi5, current,
	abcplay = {				// returned object (only instance)
		clear: audio.clear,
		add: audio.add,
		set_sft: vf,
		set_sfu: function(v) {
			if (v == undefined)
				return conf.sfu
			conf.sfu = v
		},
		set_speed: function(v) {
			if (v == undefined)
︙
112
113
114
115
116
117
118



119
120







121
122
123
124
125
126
127
128


129
130
131
132
133
134

135

136
137

138
139
140
141
142
143
144
115
116
117
118
119
120
121
122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158







+
+
+
-
-
+
+
+
+
+
+
+







-
+
+






+
-
+


+








		// set the current output changing the play functions
		current = out[o] == 'sf2' ? audio5 : midi5;
		abcplay.play = current.play;
		abcplay.stop = current.stop
		if (current.set_output)
			current.set_output(out[o]);
		if (abc2svg.pwait) {
			if (typeof abc2svg.pwait == "boolean") {
				abc2svg.pwait = function() {
		abcplay.play(init.istart, init.i_iend, init.a_e);
		init = {}
					abcplay.play(init.istart,
							init.i_iend, init.a_e)
				}
			}
			return
		}
		abcplay.play(init.istart, init.i_iend, init.a_e);
	} // play2()

	// set default configuration values
	conf.gain = 0.7;
	conf.speed = 1;

	// get the play parameters from localStorage
	(function get_param() {
	(function() {
	    var	v
		try {
			if (!localStorage)
				return
		} catch (e) {
			return
		}
	    if (!conf.sfu) {
	    var	v = localStorage.getItem("sfu")
		v = localStorage.getItem("sfu")
		if (v)
			conf.sfu = v;
	    }
		v = localStorage.getItem("volume")
		if (v)
			conf.gain = Number(v)
	})()

	// initialize the playing engines
	if (typeof Midi5 == "function")
︙
Changes to util/sf2-parser.js.
1
2

3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1

2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20

-
+










-
+







/*! JavaScript SoundFont 2 Parser. Copyright 2013-2015 imaya/GREE Inc and Colin Clark. Licensed under the MIT License. */

// https://github.com/colinbdclark/sf2-parser
/*
 * JavaScript SoundFont 2 Parser
 *
 * Copyright 2013 imaya/GREE Inc
 * Copyright 2015 Colin Clark
 *
 * Based on code from the "SoundFont Synthesizer for WebMidiLink"
 *   https://github.com/gree/sf2synth.js
 *
 * Adapted to abc2svg
 * Copyright (C) 2018-2019 Jean-Francois Moine
 * Copyright (C) 2018-2021 Jean-Francois Moine
 *
 * Licensed under the MIT License.
 */

/*global require*/

(function (root, factory) {
︙
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
29
30
31
32
33
34
35

36
37
38


39
40
41
42
43
44
45







-
+


-
-







            return (root.sf2, factory(exports));
        });
    } else {
        // Plain old browser.
        root.sf2 = {};
        factory(root.sf2);
    }
}(this, function (exports) {
}(this, function (sf2) {		// exports
    "use strict";

    var sf2 = exports;

    sf2.Parser = function (input, options) {
      options = options || {};
      /** @type {ByteArray} */
      this.input = input;
      /** @type {(Object|undefined)} */
      this.parserOptions = options.parserOptions;

︙
632
633
634
635
636
637
638
639
640
641
642
643

























































644
645
646
647
648
649
650
651


652
653

654
655

656
657
658
659
660
661
662
663

664
665
666
667
668






669
670
671
672
673
674





675
676
677
678




679







680
681
682
683
684




685
686
687
688
689
690
691
630
631
632
633
634
635
636





637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706

707
708
709
710
711
712
713
714

715
716




717
718
719
720
721
722
723
724




725
726
727
728
729
730
731


732
733
734
735
736
737
738
739
740
741
742
743
744
745
746


747
748
749
750
751
752
753
754
755
756
757







-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








+
+

-
+

-
+







-
+

-
-
-
-
+
+
+
+
+
+


-
-
-
-
+
+
+
+
+


-
-
+
+
+
+

+
+
+
+
+
+
+



-
-
+
+
+
+







            break;
        }
      }

      return output;
    };

    sf2.Parser.prototype.getInstruments = function () {
      /** @type {Array.<Object>} */
      var instrument = this.instrument,
      /** @type {Array.<Object>} */
	  zone = this.instrumentZone,
//    sf2.Parser.prototype.getInstruments = function () {
//      /** @type {Array.<Object>} */
//      var instrument = this.instrument,
//      /** @type {Array.<Object>} */
//	  zone = this.instrumentZone,
//      /** @type {Array.<Object>} */
//	  output = [],
//      /** @type {number} */
//	  bagIndex,
//      /** @type {number} */
//	  bagIndexEnd,
//      /** @type {Array.<Object>} */
//	  zoneInfo,
//      /** @type {{generator: Object, generatorInfo: Array.<Object>}} */
//	  instrumentGenerator,
//      /** @type {{modulator: Object, modulatorInfo: Array.<Object>}} */
//	  instrumentModulator,
//      /** @type {number} */
//	  i,
//      /** @type {number} */
//	  il,
//      /** @type {number} */
//	  j,
//      /** @type {number} */
//	  jl;
//
//      // instrument -> instrument bag -> generator / modulator
//      for (i = 0, il = instrument.length; i < il; ++i) {
//        bagIndex    = instrument[i].instrumentBagIndex;
//        bagIndexEnd = instrument[i+1] ? instrument[i+1].instrumentBagIndex : zone.length;
//        zoneInfo = [];
//
//        // instrument bag
//        for (j = bagIndex, jl = bagIndexEnd; j < jl; ++j) {
//          instrumentGenerator = this.createInstrumentGenerator_(zone, j);
//          instrumentModulator = this.createInstrumentModulator_(zone, j);
//
//          zoneInfo.push({
//            generator: instrumentGenerator.generator,
//            modulator: instrumentModulator.modulator,
//          });
//        }
//
//        output.push({
//          name: instrument[i].instrumentName,
//          info: zoneInfo
//        });
//      }
//
//      return output;
//    };

    sf2.Parser.prototype.getPresets = function () {
      /** @type {Array.<Object>} */
      var preset   = this.presetHeader,
      /** @type {Array.<Object>} */
	  zone = this.presetZone,
      /** @type {Array.<Object>} */
	  output = [],
      /** @type {number} */
	  bagIndex,
      /** @type {number} */
	  bagIndexEnd,
      /** @type {Array.<Object>} */
	  zoneInfo,
      /** @type {number} */
//	  instrument,
      /** @type {{generator: Object, generatorInfo: Array.<Object>}} */
	  instrumentGenerator,
	  presetGenerator,
      /** @type {{modulator: Object, modulatorInfo: Array.<Object>}} */
	  instrumentModulator,
	  presetModulator,
      /** @type {number} */
	  i,
      /** @type {number} */
	  il,
      /** @type {number} */
	  j,
      /** @type {number} */
	  jl;
	  jl

      // instrument -> instrument bag -> generator / modulator
      for (i = 0, il = instrument.length; i < il; ++i) {
        bagIndex    = instrument[i].instrumentBagIndex;
        bagIndexEnd = instrument[i+1] ? instrument[i+1].instrumentBagIndex : zone.length;
      // preset -> preset bag -> generator / modulator
      for (i = 0, il = preset.length; i < il; ++i) {
//        bagIndex    = preset[i].presetBagIndex;
	j = preset[i].presetBagIndex
//        bagIndexEnd = preset[i+1] ? preset[i+1].presetBagIndex : zone.length;
	jl = preset[i+1] ? preset[i+1].presetBagIndex : zone.length
        zoneInfo = [];

        // instrument bag
        for (j = bagIndex, jl = bagIndexEnd; j < jl; ++j) {
          instrumentGenerator = this.createInstrumentGenerator_(zone, j);
          instrumentModulator = this.createInstrumentModulator_(zone, j);
        // preset bag
//        for (j = bagIndex, jl = bagIndexEnd; j < jl; ++j) {
        for ( ; j < jl; ++j) {
          presetGenerator = this.createPresetGenerator_(zone, j);
          presetModulator = this.createPresetModulator_(zone, j);

          zoneInfo.push({
            generator: instrumentGenerator.generator,
            modulator: instrumentModulator.modulator,
            generator: presetGenerator.generator,
//            generatorSequence: presetGenerator.generatorInfo,
            modulator: presetModulator.modulator,
//            modulatorSequence: presetModulator.modulatorInfo
          });

//          instrument =
//            presetGenerator.generator.instrument !== undefined ?
//              presetGenerator.generator.instrument.amount :
//            presetModulator.modulator.instrument !== undefined ?
//              presetModulator.modulator.instrument.amount :
//            null;
        }

        output.push({
          name: instrument[i].instrumentName,
          info: zoneInfo
//          name: preset[i].presetName,
          info: zoneInfo,
          header: preset[i],
//          instrument: instrument
        });
      }

      return output;
    };

    /**
︙
721
722
723
724
725
726
727









































728
729
730
731
732
733
734
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        this.instrumentZoneModulator
      );

      return {
        modulator: modgen.modgen
      };
    };

    /**
     * @param {Array.<Object>} zone
     * @param {number} index
     * @returns {{generator: Object, generatorInfo: Array.<Object>}}
     * @private
     */
    sf2.Parser.prototype.createPresetGenerator_ = function (zone, index) {
      var modgen = this.createBagModGen_(
        zone,
        zone[index].presetGeneratorIndex,
        zone[index+1] ? zone[index+1].presetGeneratorIndex : this.presetZoneGenerator.length,
        this.presetZoneGenerator
      );

      return {
        generator: modgen.modgen,
//        generatorInfo: modgen.modgenInfo
      };
    };

      /**
       * @param {Array.<Object>} zone
       * @param {number} index
       * @returns {{modulator: Object, modulatorInfo: Array.<Object>}}
       * @private
       */
    sf2.Parser.prototype.createPresetModulator_ = function (zone, index) {
      /** @type {{modgen: Object, modgenInfo: Array.<Object>}} */
      var modgen = this.createBagModGen_(
        zone,
        zone[index].presetModulatorIndex,
        zone[index+1] ? zone[index+1].presetModulatorIndex : this.presetZoneModulator.length,
        this.presetZoneModulator
      );

      return {
        modulator: modgen.modgen,
//        modulatorInfo: modgen.modgenInfo
      };
    };

    /**
     * @param {Array.<Object>} zone
     * @param {number} indexStart
     * @param {number} indexEnd
     * @param zoneModGen
     * @returns {{modgen: Object, modgenInfo: Array.<Object>}}
︙
894
895
896
897
898
899
900
901

902
903
904
905
906
907
908
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
1015







-
+







        ),
        ip
      ));

      ip += size;

      // padding
      if ((this.padding && (ip - this.offset) & 1) === 1)
      if (this.padding && ((ip - this.offset) & 1) === 1)
        ip++;

      this.ip = ip;
    };

    /**
     * @param {number} index chunk index.
︙
Changes to util/sndaud.js.
1

2
3

4
5
6
7
8
9
10

1
2

3
4
5
6
7
8
9
10
-
+

-
+







// sndaud5.js - audio output using HTML5 audio
// sndaud.js - audio output using HTML5 audio
//
// Copyright (C) 2019 Jean-Francois Moine
// Copyright (C) 2019-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
25
26
27
28
29
30
31

32

33





34

35
36
37
38
39
40
41







-
+
-

-
-
-
-
-
+
-







//	onend: callback function called at end of playing
//		Argument:
//			repv: last repeat variant number
//	onnote: callback function called on note start/stop playing
//		Arguments:
//			i: start index of the note in the ABC source
//			on: true on note start, false on note stop
//	instr_load: function to load the sound font of an instrument
//	errmsg: function called on error (default: alert)
//			(optional)
//		Arguments:
//			instr: MIDI instrument number
//			done: callback function in case of success
//				Arguments: soundfont in binary format
//			fail: callback function in case of error
//				no argument
//			error message
//	errmsg: function called on error (default: alert)
//
//  When playing, the following items must/may be set:
//	gain: (mandatory) volume, must be set to [0..1]
//	speed: (mandatory) must be set to 1
//	new_speed: (optional) new speed value

// Audio5 methods
︙
58
59
60
61
62
63
64
65

66
67

68
69

70
71
72
73


74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
52
53
54
55
56
57
58

59
60

61


62
63
64
65
66
67
68
69
70
71

72





















73
74
75
76
77
78
79







-
+

-
+
-
-
+




+
+



-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







//
// set_vol() - set the current sound volume
// @volume: range [0..1] - undefined = return current value

    var	abcsf2 = []			// SF2 instruments

function Audio5(i_conf) {
    var	C = abc2svg.C,
    var	po,			// play object
	conf = i_conf,		// configuration
	onend = function() {},
	empty = function() {},
	onnote = function() {},
	errmsg = alert,
	errmsg,
	ac,			// audio context
	gain,			// global gain

	// instruments/notes
	parser,			// SF2 parser
	presets,		// array of presets
	instr = [],		// [voice] bank + instrument
	params = [],		// [instr][key] note parameters per instrument
	rates = [],		// [instr][key] playback rates
	w_instr = 0,		// number of instruments being loaded
	w_instr = 0		// number of instruments being loaded

	// -- play the memorized events --
	s_cur,			// current music symbol
	s_end,			// last music symbol / null
	stop,			// stop playing
	repn,			// don't repeat when true
	repv,			// repeat level (variant number)
	stime,			// start playing time
	timouts = []		// note start events

	// default sound font load function
	if (!conf.instr_load) {
		conf.instr_load = function(instr, done, fail) {
			abc2svg.loadjs(conf.sfu + '/' + instr + '.js',
				function() {
					 done(b64dcod(abcsf2[instr]))
				},
				fail
			)
		}
	}

	// base64 stuff
    var b64d = []
	function init_b64d() {
	    var	b64l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
		l = b64l.length
		for (var i = 0; i < l; i++)
︙
148
149
150
151
152
153
154
155
156
157












158


























159





























160

161




















162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181




182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223



224

225

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

































































243
244

245
246

247
248
249
250


251


252











253

254
255
256
257
258

259
260

261
262



263

264

265
266
267
268
269
270
271
272
273
274
275
276
277
278

279
280

281
282

283
284
285

286
287
288

289
290

291
292
293

294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475


476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
122
123
124
125
126
127
128



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224















225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268



269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286





287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

382
383
384
385


386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406

407
408

409
410
411

412
413
414

415
416

417
418
419

420
421
422
423

424
425
426
427
428
429
430








































































































































































431
432


433
434
435
436
437
438
439



440
441
442
443
444
445
446
447







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+











-
+







-
+













+






-
-
-
+
+
+

+
-
+












-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
+




+
+
-
+
+

+
+
+
+
+
+
+
+
+
+
+

+




-
+


+
-
-
+
+
+

+
-
+













-
+

-
+

-
+


-
+


-
+

-
+


-
+



-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+





-
-
-
+







		a = b.getChannelData(0)		// destination = array of float32

		for (i = 0; i < s.length; i++)
			a[i] = s[i] / 196608	// volume divided by 6
	}

	// create all notes of an instrument
	function sf2_create(parser, instr) {
	    var i, sid, gen, parm, sampleRate, sample,
		infos = parser.getInstruments()[0].info
	function sf2_create(instr) {

		// get the instrument parameters
		// adapted from getInstruments() in sf2-parser.js
		function get_instr(i) {
		    var	instrument = parser.instrument,
			zone = parser.instrumentZone,
			j = instrument[i].instrumentBagIndex,
			jl = instrument[i + 1]
				? instrument[i + 1].instrumentBagIndex
				: zone.length,
			info = []

			while (j < jl) {
				instrumentGenerator =
					parser.createInstrumentGenerator_(zone, j)
//				instrumentModulator =
//					parser.createInstrumentModulator_(zone, j)

				info.push({
					generator: instrumentGenerator.generator,
//					modulator: instrumentModulator.modulator
				})
				j++
			}
//console.log('instr: '+instrument[i].instrumentName)
		return {
//			name: instrument[i].instrumentName,
			info: info
		}
	} // get_instr()

	// sf2_create
	    var i, j, k, sid, gen, parm, oparm, sample, infos,
		sampleRate, scale, sm,
		b = instr >> 7,			// bank
		p = instr % 0x7f,		// preset
		pr = presets

		rates[instr] = []

		// search the bank:preset
		for (i = 0; i < pr.length; i++) {
			gen = pr[i].header
			if (gen.preset == p
			 && gen.bank == b)
				break
		}
		pr = pr[i]
		if (!pr) {
			errmsg('unknown instrument ' + b + ':' + p)
			return			// unknown preset!
		}
		pr = pr.info			// list of gen/mod
		for (k = 0; k < pr.length; k++) {
		    if (!pr[k].generator.instrument)
			continue
		    oparm = {			// default parameters
			attack: .001,
			hold: .001,
			decay: .001,
			sustain: 0
//			release: .001
		    }
		    sm = 0			// sampleModes

//		    infos = is[pr[k].generator.instrument.amount].info
		    infos = get_instr(pr[k].generator.instrument.amount).info
//console.log('infos '+infos.length)
		for (i = 0; i < infos.length; i++) {
		    for (i = 0; i < infos.length; i++) {
			gen = infos[i].generator

			if (gen.attackVolEnv)
				oparm.attack = Math.pow(2,
						gen.attackVolEnv.amount / 1200)
			if (gen.holdVolEnv)
				oparm.hold = Math.pow(2,
						gen.holdVolEnv.amount / 1200)
			if (gen.decayVolEnv)
				oparm.decay = Math.pow(2,
						gen.decayVolEnv.amount / 1200) / 3
			if (gen.sustainVolEnv)
				oparm.sustain = gen.sustainVolEnv.amount / 1000
//			if (gen.releaseVolEnv)
//				oparm.release = Math.pow(2,
//						gen.releaseVolEnv.amount / 1200)

			parm = Object.create(oparm)	// new parameters
			if (gen.sampleModes)
				sm = gen.sampleModes.amount

			if (!gen.sampleID)	// (empty generator!)
				continue
			sid = gen.sampleID.amount
			sampleRate = parser.sampleHeader[sid].sampleRate
			sample = parser.sample[sid]
			parm = {
				attack: Math.pow(2, (gen.attackVolEnv ?
					gen.attackVolEnv.amount : -12000) / 1200),
				hold: Math.pow(2, (gen.holdVolEnv ?
					gen.holdVolEnv.amount : -12000) / 1200),
				decay: Math.pow(2, (gen.decayVolEnv ?
					gen.decayVolEnv.amount : -12000) / 1200) / 3,
				sustain: gen.sustainVolEnv ?
					(gen.sustainVolEnv.amount / 1000) : 0,
//				release: Math.pow(2, (gen.releaseVolEnv ?
//					gen.releaseVolEnv.amount : -12000) / 1200),
				buffer: ac.createBuffer(1,
							sample.length,
							sampleRate)
			}
			parm.buffer = ac.createBuffer(1,
						sample.length,
						sampleRate)

			parm.hold += parm.attack
			parm.decay += parm.hold

			// sustain > 40dB is not audible
			if (parm.sustain >= .4)
				parm.sustain = 0.01	// must not be null
			else
				parm.sustain = 1 - parm.sustain / .4

			sample_cp(parm.buffer, sample)

			if (gen.sampleModes && (gen.sampleModes.amount & 1)) {
			if (sm & 1) {
				parm.loopStart = parser.sampleHeader[sid].startLoop /
					sampleRate
				parm.loopEnd = parser.sampleHeader[sid].endLoop /
					sampleRate
			}

			// define the notes
		    var scale = (gen.scaleTuning ?
			scale = (gen.scaleTuning ?
					gen.scaleTuning.amount : 100) / 100,
			tune = (gen.coarseTune ? gen.coarseTune.amount : 0) +
				(gen.fineTune ? gen.fineTune.amount : 0) / 100 +
				parser.sampleHeader[sid].pitchCorrection / 100 -
				(gen.overridingRootKey ?
					gen.overridingRootKey.amount :
					parser.sampleHeader[sid].originalPitch)

			for (j = gen.keyRange.lo; j <= gen.keyRange.hi; j++) {
				rates[instr][j] = Math.pow(Math.pow(2, 1 / 12),
							(j + tune) * scale)
				params[instr][j] = parm
			}
		    }
		}
	} // sf2_create()

	// load an instrument (.js file)
	function load_instr(instr) {
		w_instr++
		conf.instr_load(instr,
			function(sf2_bin) {
			    var	parser = new sf2.Parser(sf2_bin)
		abc2svg.loadjs(conf.sfu + '/' + instr + '.js',
			function() {
				parser = new sf2.Parser(b64dcod(abcsf2[instr]))
				parser.parse()
				presets = parser.getPresets()
				sf2_create(parser, instr)
				sf2_create(instr)
				if (--w_instr == 0)
					play_start()
			},
			function() {
				errmsg('could not find the instrument ' +
					((instr / 128) | 0).toString() + '-' +
					(instr % 128).toString())
				if (--w_instr == 0)
					play_start()
			})
	} // load_instr()

	// start loading the instruments
	function load_res() {
	    var i,
		s = s_cur

	// load the needed instruments
	function load_res(s) {
	    if (abc2svg.sf2
	     || conf.sfu.slice(-4) == ".sf2"
	     || conf.sfu.slice(-3) == ".js") {

		// if the soundfont is loaded as .js
		if (abc2svg.sf2) {
			if (!parser) {
				parser = new sf2.Parser(b64dcod(abc2svg.sf2))
				parser.parse()
				presets = parser.getPresets()
			}

		// load the soundfont if no done yet
		} else if (!parser) {
		    if (conf.sfu.slice(-3) == ".js") {
			abc2svg.loadjs(conf.sfu,
				function() {
					load_res(s)	// load the instruments
				},
				function() {
					errmsg('could not load the sound file '
						+ conf.sfu)
				})
			return
		    }
		    var	r = new XMLHttpRequest()	// .sf2
			r.open('GET', conf.sfu, true)
			r.responseType = "arraybuffer"
			r.onload = function() {
				if (r.status === 200) {
					parser = new sf2.Parser(
							new Uint8Array(r.response))
					parser.parse()
					presets = parser.getPresets()
					load_res(s)	// load the instruments
				} else {
					errmsg('could not load the sound file '
						+ conf.sfu)
				}
			}
			r.onerror = function() {
					errmsg('could not load the sound file '
						+ conf.sfu)
			}
			r.send()
			return
		}

		// create the instruments
		while (s) {
		    var	i = s.instr
			if (i != undefined && !params[i]) {
				params[i] = []	// instrument being loaded
				sf2_create(i)
			}
			s = s.ts_next
		}
		play_start()
	   } else {

	// (case instruments as base64 encoded js file,
	//  one file per instrument)
		w_instr++			// play lock
		while (s) {
			i = s.instr
		    var	i = s.instr
			if (i != undefined && !params[i]) {
				params[i] = []
				params[i] = []	// instrument being loaded
				load_instr(i)
			}
			s = s.ts_next
		}
		if (--w_instr == 0)		// all resources were there already
			play_start()
	}
	    }
	} // load_res()

	// return the play real time in seconds
	function get_time(po) {
		return po.ac.currentTime
	} // get_time()

	// MIDI control
	function midi_ctrl(po, s, t) {
		if (s.ctrl == 7)		// if volume
			s.p_v.vol = s.val / 127
	} // midi_ctrl()

	// create a note
	// @po = play object
	// @s = symbol
	// @key = MIDI key + detune
	// @t = audio start time
	// @d = duration adjusted for speed
	function note_run(s, key, t, d) {
	function note_run(po, s, key, t, d) {
	    var	g, st,
		instr = s.instr,
		k = key | 0
		parm = params[instr][key | 0],
		o = ac.createBufferSource()
		parm = po.params[instr][k],
		o = po.ac.createBufferSource(),
		v = s.p_v.vol == undefined ? 1 : s.p_v.vol	// volume (gain)

		if (!v			// mute voice
		if (!parm)		// if the instrument could not be loaded
		 || !parm)		// if the instrument could not be loaded
			return		// or if it has not this key
		o.buffer = parm.buffer
		if (parm.loopStart) {
			o.loop = true
			o.loopStart = parm.loopStart
			o.loopEnd = parm.loopEnd
		}
		if (o.detune) {
		    var	dt = (key * 100) % 100
			if (dt)			// if micro-tone
				 o.detune.value = dt
		}
//		o.playbackRate.setValueAtTime(parm.rate, ac.currentTime)
		o.playbackRate.value = rates[instr][key]
		o.playbackRate.value = po.rates[instr][k]

		g = ac.createGain()
		g = po.ac.createGain()
		if (parm.hold < 0.002) {
			g.gain.setValueAtTime(1, t)
			g.gain.setValueAtTime(v, t)
		} else {
			if (parm.attack < 0.002) {
				g.gain.setValueAtTime(1, t)
				g.gain.setValueAtTime(v, t)
			} else {
				g.gain.setValueAtTime(0, t)
				g.gain.linearRampToValueAtTime(1, t + parm.attack)
				g.gain.linearRampToValueAtTime(v, t + parm.attack)
			}
			g.gain.setValueAtTime(1, t + parm.hold)
			g.gain.setValueAtTime(v, t + parm.hold)
		}

		g.gain.exponentialRampToValueAtTime(parm.sustain,
		g.gain.exponentialRampToValueAtTime(parm.sustain * v,
					t + parm.decay)

		o.connect(g)
		g.connect(gain)
		g.connect(po.gain)

		// start the note
		o.start(t)
		o.stop(t + d)
	} // note_run()

	// handle a tie
	function do_tie(s, b40, d) {
	    var	i, note,
		v = s.v,
		end_time = s.time + s.dur

		// search the end of the tie
		while (1) {
			s = s.ts_next
			if (!s)
				return d
			switch (s.type) {
			case C.BAR:
				if (s.rep_p) {
					if (!repn) {
						s = s.rep_p
						end_time = s.time
					}
				}
				if (s.rep_s) {
					if (!s.rep_s[repv + 1])
						return d
					s = s.rep_s[repv + 1]
					end_time = s.time
				}
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
			}
			if (s.time > end_time)
				return d
			if (s.type == C.NOTE && s.v == v)
				break
		}
		i = s.notes.length
		while (--i >= 0) {
			note = s.notes[i]
			if (note.b40 == b40) {
				note.ti2 = true		// the sound is generated
				d += s.pdur / conf.speed
				return note.tie_ty ? do_tie(s, b40, d) : d
			}
		}

		return d
	} // do_tie()

	// generate 2 seconds of music
	function play_next() {
	    var	d, i, st, m, note, g, s2, t, maxt,
		s = s_cur

		if (stop) {			// stop
			onend(repv)
			return
		}

		while (s.noplay) {
			s = s.ts_next
			if (!s || s == s_end) {
				onend(repv)
				return
			}
		}
		t = stime + s.ptim / conf.speed		// start time

		// if speed change, shift the start time
		if (conf.new_speed) {
			stime = ac.currentTime -
					(ac.currentTime - stime) *
						conf.speed / conf.new_speed
			conf.speed = conf.new_speed
			conf.new_speed = 0
			t = stime + s.ptim / conf.speed
		}

		maxt = t + 2			// max time = now + 2 seconds
		timouts = []
		while (1) {
			switch (s.type) {
			case C.BAR:
				if (s.bar_type.slice(-1) == ':') // left repeat
					repv = 0
				if (s.rep_p) {			// right repeat
					if (!repn) {
						stime += (s.ptim - s.rep_p.ptim) /
								conf.speed
						s = s.rep_p	// left repeat
						t = stime + s.ptim / conf.speed
						repn = true
						break
					}
					repn = false
				}
				if (s.rep_s) {			// first variant
					s2 = s.rep_s[++repv]	// next variant
					if (s2) {
						stime += (s.ptim - s2.ptim) /
								conf.speed
						s = s2
						t = stime + s.ptim / conf.speed
						repn = false
					} else {		// end of tune
						s = s_end
						break
					}
				}
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
				break
			case C.GRACE:
				for (g = s.extra; g; g = g.next) {
					d = g.pdur / conf.speed
					for (m = 0; m <= g.nhd; m++) {
						note = g.notes[m]
						note_run(g,
							note.midi,
							t + g.ptim - s.ptim,
//fixme: there may be a tie...
							d)
					}
				}
				break
			case C.NOTE:
				d = s.pdur / conf.speed
				for (m = 0; m <= s.nhd; m++) {
					note = s.notes[m]
					if (note.ti2)
						continue
					note_run(s,
						note.midi,
						t,
						note.tie_ty ? 
							do_tie(s, note.b40, d) : d)
				}
				// fall thru
			case C.REST:
				d = s.pdur / conf.speed

				// follow the notes/rests while playing
				i = s.istart
				st = (t - ac.currentTime) * 1000
				timouts.push(setTimeout(onnote, st, i, true))
				setTimeout(onnote, st + d * 1000, i, false)
				break
			}
			while (1) {
				if (s == s_end || !s.ts_next) {
					setTimeout(onend,
						(t - ac.currentTime + d) * 1000,
						repv)
					s_cur = s
					return
				}
				s = s.ts_next
				if (!s.noplay)
					break
			}
			t = stime + s.ptim / conf.speed	// next time
			if (t > maxt)
				break
		}
		s_cur = s

		// delay before next sound generation
		timouts.push(setTimeout(play_next, (t - ac.currentTime)
			* 1000 - 300))		// wake before end of playing
	} // play_next()

	// wait for all resources, then start playing
	function play_start() {
		if (stop) {			// stop playing
			onend(repv)
		if (po.stop) {			// stop playing
			po.onend(repv)
			return
		}

		// all resources are there
		gain.connect(ac.destination)
		stime = ac.currentTime + .2		// start time + 0.2s
			- s_cur.ptim * conf.speed
		play_next()
		abc2svg.play_next(po)
	} // play_start()

	// Audio5 function

	init_b64d()			// initialize base64 decoding

	if (!conf.sfu)
︙
499
500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
456
457
458
459
460
461
462






463
464
465
466
467
468
469
470







-
-
-
-
-
-
+







				['sf2'] : null
	}, // get_outputs()

	// play the symbols
	play: function(i_start, i_end, i_lvl) {

		// get the callback functions
		if (conf.onend)
			onend = conf.onend
		if (conf.onnote)
			onnote = conf.onnote
		if (conf.errmsg)
			errmsg = conf.errmsg
		errmsg = conf.errmsg || alert

		// play a null file to unlock the iOS audio
		// This is needed for iPhone/iPad/...
		function play_unlock() {
		    var buf = ac.createBuffer(1, 1, 22050),
			src = ac.createBufferSource()

︙
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544






















545
546
547
548
549
550
551
552


553
554
555

556
557
558
559
560
561
562
563
564
565
566
567
568
482
483
484
485
486
487
488


489
490




491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512


513
514
515
516


517
518
519
520

521
522
523
524
525
526
527
528
529
530
531
532
533
534







-
-


-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-




-
-
+
+


-
+













				if (/iPad|iPhone|iPod/.test(navigator.userAgent))
					play_unlock()
			}
			gain = ac.createGain()
			gain.gain.value = conf.gain
		}

		s_end = i_end
		stop = false
		while (i_start.noplay)
			i_start = i_start.ts_next
		s_cur = i_start
		repv = i_lvl || 0
		w_instr++
		load_res()
		po = {
			conf: conf,	// configuration
			onend: conf.onend || empty,
			onnote: conf.onnote || empty,
//			stop: false,	// stop playing
			s_end: i_end,	// last music symbol / null
			s_cur: i_start,	// current music symbol
//			repn: false,	// don't repeat
			repv: i_lvl || 0, // repeat variant number
			tgen: 2,	// // generate by 2 seconds
			get_time: get_time,
			midi_ctrl: midi_ctrl,
			note_run: note_run,
			timouts: [],

			// audio specific
			ac: ac,
			gain: gain,
			params: params,
			rates: rates
		}
		load_res(i_start)
		if (--w_instr == 0)		// all resources are there
			play_start()
	}, // play()

	// stop playing
	stop: function() {
		stop = true
		timouts.forEach(function(id) {
		po.stop = true
		po.timouts.forEach(function(id) {
					clearTimeout(id)
				})
		play_next()
		abc2svg.play_next(po)
		if (gain) {
			gain.disconnect()
			gain = null
		}
	}, // stop()

	// set volume
	set_vol: function(v) {
		if (gain)
			gain.gain.value = v
	} // set_vol()
    } // returned object
} // Audio5()
Changes to util/sndgen.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// sndgen.js - sound generation
//
// Copyright (C) 2019 Jean-Francois Moine
// Copyright (C) 2019-2020 Jean-Francois Moine
//
// This file is part of abc2svg-core.
//
// abc2svg-core is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
23
24
25
26
27
28
29

30
31
32



33
34
35
36
37
38
39
40
41





42
43
44
45


46
47
48
49















































































































































50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82

83
84
85
86




























87
88




89
90
91
92
93





















94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109

110
111
112
113
114
115
116
117
118
119
120













121
122
123



124
125
126
127
128
129
130
131
132




133
134

135
136
137
138
139
140





141
142
143



144
145



146
147
148

149
150
151


152
153

154
155










156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


39
40



41
42
43
44
45
46
47
48

49
50
51
52


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267





268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294







295

296

297
298
299
300
301




302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324








325
326
327
328


329






330
331
332
333
334



335
336
337


338
339
340



341



342
343

344
345


346
347
348
349
350
351
352
353
354
355
356

357





358
359










360










361
362
363
364
365
366
367







+



+
+
+


-
-


-
-
-
+
+
+
+
+



-
+
+


-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
















-
+






-
+








+
-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
-
-
-
-
-
-
+
-

-
+




-
-
-
-



+
+
+
+
+
+
+
+
+
+
+
+
+



+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
+
+
+
-
-
-
+
-
-
-
+
+
-

+
-
-
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-







// - in BAR
//	rep_p = on a right repeat bar, pointer to the left repeat symbol
//	rep_s = on the first repeat variant, array of pointers to the next symbols,
//						indexed by the repeat number
// - in NOTE and REST
//	s.pdur = play duration
//	s.instr = bank + instrument
//	s.chn = MIDI channel
// - in the notes[] of NOTE
//	s.notes[i].midi

if (!abc2svg)
    var	abc2svg = {}

function ToAudio() {
 return {
   clear: function() {		// useless - for compatibility
   },

   // generate the play data of a tune
   add: function(s,		// starting symbol
		voice_tb) {	// voice table
    var	C = abc2svg.C,
   add: function(first,		// starting symbol
		voice_tb,	// voice table
		cfmt) {		// tune parameters
    var	toaud = this,
	C = abc2svg.C,
	p_time = 0,		// last playing time
	abc_time = 0,		// last ABC time
	play_fac = C.BLEN / 4 * 120 / 60, // play time factor - default: Q:1/4=120
	i, n, dt, d, v,
	i, n, dt, d, v, c,
	s = first,
	rst = s,		// left repeat (repeat restart)
	rst_fac,		// play factor on repeat restart
	rsk,			// repeat variant (repeat skip)
	instr = []		// [voice] bank + instrument
	rsk,			// repeat variant array (repeat skip)
	b_tim,			// time of last measure bar
	b_typ,			// type of last measure bar
	instr = [],		// [voice] bank + instrument
	chn = []		// [voice] MIDI channel

	// build the information about the parts (P:)
	function build_parts(first) {
	    var	i, j, c, n, v,
		s = first,
		p = s.parts,
		st = [],
		r = ""

		// build a linear string of the parts
		for (i = 0; i < p.length; i++) {
			c = p[i]
			switch (c) {
			case '.':
				continue
			case '(':
				st.push(r.length)
				continue
			case ')':
				j = st.pop()
				if (j == undefined)
					j = r.length
				continue
			}
			if (c >= 'A' && c <= 'Z') {
				j = r.length
				r += c
				continue
			}
			n = Number(c)
//fixme:one digit is enough!
//			while (1) {
//				c = p[i + 1]
//				if (c < '0' || c > '9')
//					break
//				n = n * 10 + Number(c)
//				i++
//			}
			if (isNaN(n))
				break
			v = r.slice(j)
			if (r.length + v.length * n > 128)
				continue
			while (--n > 0)
				r += v
		}
		s.parts = r

		// build the part table in the first symbol
		// and put the reverse pointers in the P: symbols
		s.p_s = []			// pointers to the parts
		while (1) {
			if (!s.ts_next) {
				s.part = first	// end of tune = end of part
				break
			}
			s = s.ts_next
			if (s.type == C.PART) {
				s.part = first		// reverse pointer
				v = s.text[0]		// 1st letter only
				for (i = 0; i < first.parts.length; i++) {
					if (first.parts[i] == v)
						first.p_s[i] = s
				}
			}
		}
	} // build_parts()

	// set the starting MIDI instruments and channels
	function midi_start() {
	    var	v, p_v, c, i, ii

		for (v = 0; v < voice_tb.length; v++) {
			p_v = voice_tb[v]
			ii = p_v.instr || 0		// instrument
			c = p_v.chn			// channel
			if (c == undefined)
				c = p_v.v < 9 ? p_v.v : p_v.v + 1
			else if (c == 9)		// percussion
				ii = (ii & ~0x7f) | 16384

			if (p_v.midictl) {		// if MIDI controls
				for (i in p_v.midictl) {
					switch (Number(i)) {
					case 0:		// MSB bank
						ii = (ii & 0x3fff) |
							(p_v.midictl[i] << 14)
						break
					case 32:	// LSB bank
						ii = (ii & 0x1fc07f) |
							(p_v.midictl[i] << 7)
						break
					}
				}
			}

			if ((ii & ~0x7f) == 16384) // if bank 128 (percussion)
				c = 9			// channel '10'
			chn[v] = c
			instr[c] = ii
		}
	} // midi_start()

	// handle a block symbol
	function do_block(s) {
	    var	v = s.v,
		c = chn[v]

		switch (s.subtype) {
		case "midichn":
			chn[v] = s.chn
			break
		case "midictl":
			switch (s.ctrl) {
			case 0:			// MSB bank
				instr[c] = (instr[c] & 0x3fff) |
					(s.val << 14)
				break
			case 32:		// LSB bank
				instr[c] = (instr[c] & 0x1fc07f) |
					(s.val << 7)
				break
//			case 121:		// reset all controllers
//				instr = []
//				break
			}
			if ((instr[c] & ~0x7f) == 16384) { // if percussion
				instr[9] = instr[c]	// force the channel 10
				chn[v] = c = 9
			}
			s.chn = c
			break
		case "midiprog":
			instr[c] = (instr[c] & ~0x7f) | s.instr
			s.chn = c
			break
		}
	} // do_block()

	// generate the grace notes
	function gen_grace(s) {
	    var	g, i, n, t, d, s2,
		next = s.next

		// before beat
		if (s.sappo) {
			d = C.BLEN / 16
		} else if ((!next || next.type != C.NOTE)
			&& s.prev && s.prev.type == C.NOTE) {
			d = s.prev.dur / 2

		// on beat
		} else {
			d = next.dur / 12
			if (d & (d - 1) == 0)
			if (!(d & (d - 1)))
				d = next.dur / 2	// no dot
			else
				d = next.dur / 3
			next.time += d
			next.dur -= d
		}
//fixme: assume the grace notes have the same duration
//fixme: assume the grace notes in the sequence have the same duration
		n = 0
		for (g = s.extra; g; g = g.next)
			n++
		d /= n * play_fac
		t = p_time
		for (g = s.extra; g; g = g.next) {
			g.ptim = t
			g.pdur = d
			g.chn = chn[s.v]
			g.instr = instr[s.v]
			g.instr = instr[g.chn]
			t += d
		}
	} // gen_grace()

	// change the tempo
	function set_tempo(s) {
	    var	i,
		d = 0,
		n = s.tempo_notes.length

		for (i = 0; i < n; i++)
			d += s.tempo_notes[i]
		return d * s.tempo / 60
	} // set_tempo()

	function set_variant(rsk, n, s) {
	    var	d
		n = n.match(/[1-8]-[2-9]|[1-9,.]|[^\s]+$/g)
		while (1) {
			d = n.shift()
			if (!d)
				break
			if (d[1] == '-')
				for (i = d[0]; i <= d[2]; i++)
					rsk[i] = s
			else if (d >= '1' && d <= '9')
				rsk[Number(d)] = s
			else if (d != ',')
				rsk.push(s)	// last
		}
	} // set_variant()

	// add() main

	// if some MIDI stuff, load the associated module
	if (cfmt.chord) {
		if (!abc2svg.chord) {
			abc2svg.pwait = true	// don't start playing now
	// set the MIDI pitches
	AbcMIDI().add(s, voice_tb)

	// loop on the symbols
	rst = s

			abc2svg.loadjs("chord-1.js",
					function(){	// ok
						toaud.add(first, voice_tb, cfmt)
					},
					function(){	// KO
						cfmt.chord = null
						toaud.add(first, voice_tb, cfmt)
					})
			return
		}
		abc2svg.chord(first, voice_tb, cfmt)
	}

	if (s.parts)
		build_parts(s)

	// get the starting MIDI parameters
	midi_start()

	// set the time parameters
	rst_fac = play_fac
	while (s) {
		if (s.noplay) {			// in display macro sequence
			s = s.ts_next
			continue
		}
		if (s.tempo) {				// tempo change
			d = 0
			n = s.tempo_notes.length
			for (i = 0; i < n; i++)
				d += s.tempo_notes[i]
			play_fac = d * s.tempo / 60
		}


		dt = s.time - abc_time
		if (dt > 0) {
		if (dt != 0) {		// may go backwards after grace notes
			p_time += dt / play_fac
			abc_time = s.time
		}
		s.ptim = p_time
		v = s.v

		if (instr[v] == undefined)
			instr[v] = voice_tb[v].instr || 0

		switch (s.type) {
		case C.BAR:
			if (s.time != b_tim) {
				b_tim = s.time
				b_typ = 0
			}
			if (s.text && rsk		// if new variant
			 && s.text[0] != '1') {
				if (b_typ & 1)
					break
				b_typ |= 1
				set_variant(rsk, s.text, s)
				play_fac = rst_fac
				rst = rsk[0]		// reinit the restart
			}

			// right repeat
			if (s.bar_type[0] == ':') {
				if (b_typ & 2)
					break
				b_typ |= 2
				s.rep_p = rst		// :| to |:
				n = s.text		// variants
				while (s.ts_next && s.ts_next.type == C.BAR) {
					s = s.ts_next
					s.ptim = p_time
					if (!n && s.text)
						n = s.text
				}
				if (rsk) {		// if in a variant
				if (rsk && rst == rsk[0])
					s.rep_v = rsk	// to know the number of variants
			}

					if (!n)
						n = "a"		// last time
			// 1st time repeat
					n = n.match(/[1-8]-[2-9]|[1-9,.]|[^\s]+$/g)
					while (1) {
						d = n.shift()
						if (!d)
							break
						if (d[1] == '-')
			if (s.text) {
			    if (s.text[0] == '1') {
				if (b_typ & 1)
					break
				b_typ |= 1
							for (i = d[0]; i <= d[2]; i++)
								rsk.rep_s[i] = s
						else if (d >= '1' && d <= '9')
				s.rep_s = rsk = [rst]	// repeat skip
							// and memorize the restart
				if (rst.bar_type
							rsk.rep_s[Number(d)] = s
						else
				 && rst.bar_type.slice(-1) != ':')
					rst.bar_type += ':' // restart confirmed
				set_variant(rsk, s.text, s)
							rsk.rep_s.push(s)
					}
					play_fac = rst_fac
				rst_fac = play_fac
				    break
				}
			}
			    }


			// left repeat
			} else if (s.rbstop) {
			if (s.bar_type.slice(-1) == ':') {
				rst = s
				if (s.bar_type.slice(-1) == ':') {
					if (b_typ & 4)
						break
					b_typ |= 4
				} else {
					if (b_typ & 8)
						break
					b_typ |= 8
				}
				rst = s			// new possible restart
				rst_fac = play_fac

			}
			// 1st time repeat
			} else if (s.text && s.text[0] == '1') {
				rsk = s
				s.rep_s = [null, s]	// repeat skip
			}
			break
		case C.BLOCK:
			switch (s.subtype) {
			case "midictl":
				switch (s.ctrl) {
				case 0:			// MSB bank
					instr[v] = (instr[v] & 0x3fff) |
						(s.val << 14)
					break
				case 32:		// LSB bank
					instr[v] = (instr[v] & 0x1fc07f) |
						(s.val << 7)
			do_block(s)
					break
//				case 121:		// reset all controllers
//					instr = []
//					break
				}
				break
			case "midiprog":
				instr[v] = (instr[v] & ~0x7f) | s.instr
				break
			}
			break
		case C.GRACE:
			if (s.time == 0		// if before beat at start time
			 && abc_time == 0) {
				dt = 0
				if (s.sappo)
					dt = C.BLEN / 16
︙
205
206
207
208
209
210
211



212









213
214
215
216








217
218
219







































































































































































































































































































220
221
222
223
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713







+
+
+
-
+
+
+
+
+
+
+
+
+




+
+
+
+
+
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




				else if (!s.next.next || s.next.next.type != C.NOTE)
					dt = d / 2
				s.next.time -= dt
				d -= dt
			}
			d /= play_fac
			s.pdur = d
			v = s.v
			c = chn[v]			// channel
			s.chn = c
			s.instr = instr[v]
			s.instr = instr[c]
			break
		case C.PART:
			rst = s			// new possible restart
			rst_fac = play_fac
			break
		case C.TEMPO:
			if (s.tempo)
				play_fac = set_tempo(s)
			break
		}
		s = s.ts_next
	} // loop

	// if playing was waiting for a resource, start it now
	if (abc2svg.pwait) {
		i = abc2svg.pwait
		delete abc2svg.pwait
		if (typeof i == "function")
			i()
	}
   } // add()
 } // return
} // ToAudio()

// play some next symbols
//
// This function is called to start playing.
// Playing is stopped on either
// - reaching the 'end' symbol (not played) or
// - reaching the end of tune or
// - seeing the 'stop' flag (user request).
//
// The po object (Play Object) contains the following items:
// - variables
//  - stop: stop flag
//		set by the user to stop playing
//  - s_cur: current symbol (next to play)
//		must be set to the first symbol to be played at startup time
//  - s_end: stop playing on this symbol
//		this symbol is not played. It may be null.
//  - conf
//    - speed: current speed factor
//		must be set to 1 at startup time
//    - new_conf: new speed factor
//		set by the user
// - internal variables
//  - stim: start time
//  - repn: don't repeat
//  - repv: variant number
//  - timouts: array of the current timeouts
//		this array may be used by the upper function in case of hard stop
//  - p_v: voice table used for MIDI control
// - methods
//  - onend: (optional)
//  - onnote: (optional)
//  - note_run: start playing a note
//  - get_time: return the time of the underlaying sound system
abc2svg.play_next = function(po) {

	// handle a tie
	function do_tie(s, midi, d) {
	    var	i, note,
		C = abc2svg.C,
		v = s.v,
		end_time = s.time + s.dur

		// search the end of the tie
		while (1) {
			s = s.ts_next
			if (!s)
				return d
			switch (s.type) {
			case C.BAR:
				if (s.rep_p) {
					if (!po.repn) {
						s = s.rep_p
						end_time = s.time
					}
				}
				if (s.rep_s) {
					if (!s.rep_s[po.repv + 1])
						return d
					s = s.rep_s[po.repv + 1]
					end_time = s.time
				}
				while (s.ts_next && !s.ts_next.dur)
					s = s.ts_next
			}
			if (s.time > end_time)
				return d
			if (s.type == C.NOTE && s.v == v)
				break
		}
		i = s.notes.length
		while (--i >= 0) {
			note = s.notes[i]
			if (note.midi == midi) {
				note.ti2 = true		// the sound is generated
				d += s.pdur / po.conf.speed
				return note.tie_ty ? do_tie(s, midi, d) : d
			}
		}

		return d
	} // do_tie()

	// set the MIDI controls up to now
	function set_ctrl(po, s2, t) {
	    var	i,
		p_v = s2.p_v,
		tim = s2.time,
		s = {
			subtype: "midictl",
			p_v: p_v,
			v: p_v.v,
			chn: p_v.chn
		}

		for (i in p_v.midictl) { // MIDI controls at voice start time
			s.ctrl = Number(i)
			s.val = p_v.midictl[i]
			po.midi_ctrl(po, s, t)
		}
		for (s = p_v.sym; s && s.time <= tim; s = s.next) {
			if (s.subtype == "midictl")
				po.midi_ctrl(po, s, t)
		}
		po.p_v[s2.v] = true	// synchronization done
	} // set_ctrl()

    // start and continue to play
    function play_cont(po) {
    var	d, i, st, m, note, g, s2, t, maxt,
	C = abc2svg.C,
	s = po.s_cur

	if (po.stop) {
		if (po.onend)
			po.onend(po.repv)
		return
	}

	while (s.noplay) {
		s = s.ts_next
		if (!s || s == po.s_end) {
			if (po.onend)
				po.onend(po.repv)
			return
		}
	}
	t = po.stim + s.ptim / po.conf.speed	// start time

	// if speed change, shift the start time
	if (po.conf.new_speed) {
		d = po.get_time(po)
		po.stim = d - (d - po.stim) *
					po.conf.speed / po.conf.new_speed
		po.conf.speed = po.conf.new_speed
		po.conf.new_speed = 0
		t = po.stim + s.ptim / po.conf.speed
	}

	maxt = t + po.tgen		// max time = now + 'tgen' seconds
	po.timouts = []
	while (1) {
		if (!po.p_v[s.v])		// if new voice
			set_ctrl(po, s, t)	// set the MIDI controls
		switch (s.type) {
		case C.BAR:
			if (s.rep_p) {		// right repeat
				po.repv++
				if (!po.repn	// if repeat a first time
				 && (!s.rep_v	// and no variant (anymore)
				  || po.repv < s.rep_v.length)) {
					po.stim += (s.ptim - s.rep_p.ptim) /
							po.conf.speed
					s = s.rep_p	// left repeat
					while (s.ts_next
					 && !s.ts_next.dur)
						s = s.ts_next
					t = po.stim + s.ptim / po.conf.speed
					po.repn = true
					break
				}
				po.repn = false
			}
			if (s.rep_s) {			// first variant
				s2 = s.rep_s[po.repv]	// next variant
				if (s2) {
					po.stim += (s.ptim - s2.ptim) /
							po.conf.speed
					s = s2
					t = po.stim + s.ptim / po.conf.speed
					po.repn = false
				} else {		// end of tune
					s = po.s_end
					break
				}
			}
			if (s.bar_type.slice(-1) == ':') // left repeat
				po.repv = 1
			while (s.ts_next && !s.ts_next.seqst)
				s = s.ts_next
			if (!s.part)
				break
			// fall thru
		case C.PART:
			if (s.part				// if end of part
			 && po.i_p != undefined) {
				s2 = s.part.p_s[++po.i_p]	// next part
				if (s2) {
					po.stim += (s.ptim - s2.ptim) / po.conf.speed
					s = s2
					t = po.stim + s.ptim / po.conf.speed
				} else {
					s = po.s_end
				}
			}
			break
		case C.BLOCK:
			if (s.subtype == "midictl")
				po.midi_ctrl(po, s, t)
			break
		case C.GRACE:
			for (g = s.extra; g; g = g.next) {
				d = g.pdur / po.conf.speed
				for (m = 0; m <= g.nhd; m++) {
					note = g.notes[m]
					po.note_run(po, g,
						note.midi,
						t + g.ptim - s.ptim,
//fixme: there may be a tie...
						d)
				}
			}
			break
		case C.NOTE:
			d = s.pdur / po.conf.speed
			for (m = 0; m <= s.nhd; m++) {
				note = s.notes[m]
				if (note.ti2)
					continue
				po.note_run(po, s,
					note.midi,
					t,
					note.tie_ty ?
						do_tie(s, note.midi, d) : d)
			}
			// fall thru
		case C.REST:
			d = s.pdur / po.conf.speed

			// follow the notes/rests while playing
			if (po.onnote && s.istart) {
				i = s.istart
				st = (t - po.get_time(po)) * 1000
				po.timouts.push(setTimeout(po.onnote, st, i, true))
				setTimeout(po.onnote, st + d * 1000, i, false)
			}
			break
		}
		while (1) {
			if (s == po.s_end || !s.ts_next) {
				if (po.onend)
					setTimeout(po.onend,
						(t - po.get_time(po) + d) * 1000,
						po.repv)
				po.s_cur = s
				return
			}
			s = s.ts_next
			if (!s.noplay)
				break
		}
		t = po.stim + s.ptim / po.conf.speed // next time
		if (t > maxt)
			break
	}
	po.s_cur = s

	// delay before next sound generation
	po.timouts.push(setTimeout(play_cont,
				(t - po.get_time(po)) * 1000
					- 300,	// wake before end of playing
				po))
    } // play_cont()

    // search the index in the parts
    function get_part(po) {
    var	s, i, s_p
	for (s = po.s_cur; s; s = s.ts_prev) {
		if (s.parts) {
			po.i_p = -1
			return
		}
		s_p = s.part
		if (!s_p || !s_p.p_s)
			continue
		for (i = 0; i < s_p.p_s.length; i++) {
			if (s_p.p_s[i] == s) {
				po.i_p = i	// index in the parts
				return
			}
		}
	}
    } // get_part()

    // --- play_next ---
	get_part(po)

	po.stim = po.get_time(po) + .3	// start time + 0.3s
			- po.s_cur.ptim * po.conf.speed
	po.p_v = []			// voice table for the MIDI controls
	if (!po.repv)
		po.repv = 1

	play_cont(po)			// start playing
} // play_next()

// nodejs
if (typeof module == 'object' && typeof exports == 'object')
	exports.ToAudio = ToAudio
Added util/sndmem.js.






































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// sndmem.js - generate play events for use with toaudio5 or tomidi5
//
// Copyright (C) 2020 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.

// The function abc2svg.sndmem() must be called after the abc2svg generation
// and after the play data have been defined (by the function audio.add
// in util/sndgen.js).
//
// It returns an array of Float32Array:
//	[0]: index of the note in the ABC source
//	[1]: time in seconds
//	[2]: if >= 0: MIDI instrument (MIDI GM number - 1)
//		else: MIDI control message
//	[3]: MIDI note pitch (with cents) / controller
//	[4]: duration			  / controller value
//	[5]: volume (0..1)
//	[6]: voice number

abc2svg.sndmem = function(abc) {
    var	po, i, tune

	// create a note
	// @po = play object
	// @s = symbol
	// @k = MIDI key + detune
	// @t = audio start time (ms)
	// @d = duration adjusted for speed (ms)
	function note_run(po, s, k, t, d) {
		po.a_e.push(new Float32Array([
				s.istart,
				t,
				s.instr,
				k,
				d,
				1,
				s.v]))
	} // note_run()

	// return the play real time in seconds
	function get_time(po) {
		return 0
	} // get_time()

	// MIDI control
	function midi_ctrl(po, s, t) {
		po.a_e.push(new Float32Array([
				s.istart,
				0,	// (time - unused)
				-1,	// MIDI control
				s.ctrl,
				s.val,
				1,
				s.v]))
	} // midi_ctrl()

	// define the play object
	po = {
		conf: {		// configuration
			speed: 1
		},
		tgen: 3600, 	// generate by (for) 1 hour
		get_time: get_time,
		midi_ctrl: midi_ctrl,
		note_run: note_run,

		// sndmem specific
		a_e: []
	}

	// loop on the tunes
	while (1) {

		// get the [first symbol, voice table] of the next tune
		tune = abc.tunes.shift()
		if (!tune)
			break

		po.stop = false
		po.s_end = null
		po.s_cur = tune[0]	// first music symbol
		po.repn = false
		po.repv = 0

		abc2svg.play_next(po)
	}
	return po.a_e
} //sndmem()
Changes to util/sndmid.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// sndmid.js - audio output using HTML5 MIDI
//
// Copyright (C) 2019 Jean-Francois Moine
// Copyright (C) 2019-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
42
43
44
45
46
47
48
49

50
51

52
53
54
55
56

57
58
59
60
61
62
63
64
65




66
67

68
69
70
71
72



73
74
75
76
77

78
79
80
81
82
83
84




85
86
87

88
89

90
91
92

93
94
95
96
97
98
99


100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228


229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
42
43
44
45
46
47
48

49
50

51

52



53

54







55
56
57
58
59
60
61
62
63



64
65
66
67
68
69


70
71
72
73




74
75
76
77
78
79

80
81

82
83
84

85
86
87
88
89
90


91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109


110
111
112
113






114










































115




























































116
117






118


























119


























120
121
122
123
124
125
126







-
+

-
+
-

-
-
-
+
-

-
-
-
-
-
-
-
+
+
+
+


+


-
-
-
+
+
+



-
-
+



-
-
-
-
+
+
+
+


-
+

-
+


-
+





-
-
+
+



-
+













-
-
+
+


-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







// @start -
// @stop: start and stop music symbols
// @level: repeat variant (optional, default = 0)
//
// stop() - stop playing

function Midi5(i_conf) {
    var	C = abc2svg.C,
    var	po,
	conf = i_conf,		// configuration
	onend = function() {},
	empty = function() {},
	onnote = function() {},
	rf,			// get_outputs result function

// MIDI variables
	op,			// output port
	op			// output MIDI port
	v_i = [],		// voice (channel) to instrument

	s_cur,			// current music symbol
	s_end,			// last music symbol / null
	stop,			// stop playing
	repn,			// don't repeat when true
	repv = 0,		// repeat variant number
	stime,			// start playing time in ms
	timouts = []		// note start events
	// return the play real time in seconds
	function get_time(po) {
		return window.performance.now() / 1000
	} // get_time()

	// create a note
	// @po = play object
	// @s = symbol
	// @k = MIDI key + detune
	// @t = audio start time (ms)
	// @d = duration adjusted for speed (ms)
	function note_run(s, k, t, d) {
	// @t = audio start time (s)
	// @d = duration adjusted for speed (s)
	function note_run(po, s, k, t, d) {
	    var	j,
		a = (k * 100) % 100,	// detune in cents
		i = s.instr,
//fixme: problem when more than 16 voices
		c = s.v & 0x0f		// channel
		c = s.chn

		k |= 0			// remove the detune value

		if ((s.instr & ~0x7f) == 16384)	// if bank 128 (percussion)
//fixme: may conflict with the voice 9
			c = 9			// force the channel 10
		if (i != v_i[c]) {		// if program change
		t *= 1000		// convert to ms
		d *= 1000		

		if (i != po.c_i[c]) {		// if program change

			// at channel start, reset and initialize the controllers
			if (v_i[c] == undefined) {
			if (po.c_i[c] == undefined) {
//fixme: does not work with fluidsynth
				op.send(new Uint8Array([0xb0 + c, 121, 0]))
				po.op.send(new Uint8Array([0xb0 + c, 121, 0]))
				if (s.p_v.midictl) {
				    for (j in s.p_v.midictl)
					op.send(new Uint8Array([0xb0 + c,
					po.op.send(new Uint8Array([0xb0 + c,
								j,
								s.p_v.midictl[j]]))
				}
			}

			v_i[c] = i
			op.send(new Uint8Array([0xc0 + c, i & 0x7f]))	// program
			po.c_i[c] = i
			po.op.send(new Uint8Array([0xc0 + c, i & 0x7f])) // program
		}
		if (a && Midi5.ma.sysexEnabled) {	// if microtone
// fixme: should cache the current microtone values
			op.send(new Uint8Array([
			po.op.send(new Uint8Array([
				0xf0, 0x7f,	// realtime SysEx
				0x7f,		// all devices
				0x08,		// MIDI tuning standard
				0x02,		// note change
				i & 0x7f,		// tuning prog number
				0x01,		// number of notes
					k,		// key
					k,		// note
					a / .78125,	// MSB fract
					0,		// LSB fract
				0xf7		// SysEx end
				]), t)
		}
		op.send(new Uint8Array([0x90 + c, k, 127]), t)		// note on
		op.send(new Uint8Array([0x80 + c, k, 0]), t + d - 20)	// note off
		po.op.send(new Uint8Array([0x90 + c, k, 127]), t)	// note on
		po.op.send(new Uint8Array([0x80 + c, k, 0]), t + d - 20) // note off
	} // note_run()

	// handle a tie
	function do_tie(s, b40, d) {
	    var	i, note,
		v = s.v,
		end_time = s.time + s.dur

	// send a MIDI control
		// search the end of the tie
		while (1) {
			s = s.ts_next
			if (!s)
				return d
			switch (s.type) {
			case C.BAR:
				if (s.rep_p) {
					if (!repn) {
						s = s.rep_p
						end_time = s.time
					}
				}
				if (s.rep_s) {
					if (!s.rep_s[repv + 1])
						return d
					s = s.rep_s[repv + 1]
					end_time = s.time
				}
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
			}
			if (s.time > end_time)
				return d
			if (s.type == C.NOTE && s.v == v)
				break
		}
		i = s.notes.length
		while (--i >= 0) {
			note = s.notes[i]
			if (note.b40 == b40) {
				note.ti2 = true		// the sound is generated
				d += s.pdur / conf.speed * 1000
				return note.tie_ty ? do_tie(s, b40, d) : d
			}
		}

		return d
	} // do_tie()

	// generate 2 seconds of music
	function play_next() {
	function midi_ctrl(po, s, t) {
	    var	d, i, st, m, note, g, s2,
		s = s_cur,
		t = stime + s.ptim / conf.speed * 1000,	// start time
		maxt = t + 2000			// max time = now + 2 seconds

		if (stop) {
			onend(repv)
			return
		}

		// if speed change, shift the start time
		if (conf.new_speed) {
			stime = window-performance.now() -
					(window.performance.now() - stime) *
						conf.speed / conf.new_speed
			conf.speed = conf.new_speed
			conf.new_speed = 0
			t = stime + s.ptim / conf.speed * 1000
		}

		timouts = []
		while (1) {
			switch (s.type) {
			case C.BAR:
				if (s.bar_type.slice(-1) == ':') // left repeat
					repv = 0
				if (s.rep_p) {			// right repeat
					if (!repn) {
						stime += (s.ptim - s.rep_p.ptim) /
								conf.speed * 1000
						s = s.rep_p	// left repeat
						t = stime + s.ptim / conf.speed * 1000
						repn = true
						break
					}
					repn = false
				}
				if (s.rep_s) {			// first variant
					s2 = s.rep_s[++repv]	// next variant
					if (s2) {
						stime += (s.ptim - s2.ptim) /
								conf.speed * 1000
						s = s2
						t = stime + s.ptim / conf.speed * 1000
						repn = false
					} else {		// end of tune
						s = s_end
						break
					}
				}
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
				break
			case C.BLOCK:
				if (s.subtype == "midictl") {
					i = s.v & 0x0f		// voice = channel
					if ((s.instr & ~0x7f) == 16384) // if percussion
						i = 9		// force the channel 10
					op.send(new Uint8Array([0xb0 + i,
								s.ctrl, s.val]),
		po.op.send(new Uint8Array([0xb0 + s.chn,
					s.ctrl, s.val]),
						t)
				}
				break
			case C.GRACE:
				for (g = s.extra; g; g = g.next) {
					d = g.pdur / conf.speed * 1000
			t * 1000)
					for (m = 0; m <= g.nhd; m++) {
						note = g.notes[m]
						note_run(g,
							note.midi,
							t,
//fixme: there may be a tie...
							d)
					}
				}
				break
			case C.NOTE:
				d = s.pdur / conf.speed * 1000
				for (m = 0; m <= s.nhd; m++) {
					note = s.notes[m]
					if (note.ti2)
						continue
					note_run(s,
						note.midi,
						t,
						note.tie_ty ?
							do_tie(s, note.b40, d) : d)
				}
				// fall thru
			case C.REST:
				d = s.pdur / conf.speed * 1000

	} // midi_ctrl()
				// follow the notes/rests while playing
				i = s.istart
				st = t - window.performance.now()
				timouts.push(setTimeout(onnote, st, i, true))
				setTimeout(onnote, st + d, i, false)
				break
			}
			if (s == s_end || !s.ts_next) {
				setTimeout(onend,
					t - window.performance.now() + d,
					repv)
				s_cur = s
				return
			}
			s = s.ts_next
			t = stime + s.ptim / conf.speed * 1000 // next time
			if (t > maxt)
				break
		}
		s_cur = s

		// delay before next sound generation
		timouts.push(setTimeout(play_next,
					t - window.performance.now()
						- 300))	// wake before end of playing
	} // play_next()

	// MIDI output is possible,
	// return the possible ports in return to get_outputs()
	function send_outputs(access) {
	    var	o, os,
		out = []

︙
347
348
349
350
351
352
353
354

355
356
357
358
359
360


















361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

384
385
386
387
388
389


390
391

392

393
394
395
396
397
398
180
181
182
183
184
185
186

187






188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222



223
224
225
226
227


228
229
230
231
232

233
234
235
236
237
238
239







-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-

















-
-
-
+




-
-
+
+


+
-
+






					break
				}
			}
		},

		// play the symbols
		play: function(i_start, i_end, i_lvl) {

			po = {
			// get the callback functions
			if (conf.onend)
				onend = conf.onend
			if (conf.onnote)
				onnote = conf.onnote

				conf: conf,	// configuration
				onend: conf.onend || empty,
				onnote: conf.onnote || empty,
//				stop: false,	// stop playing
				s_end: i_end,	// last music symbol / null
				s_cur: i_start,	// current music symbol
//				repn: false,	// don't repeat
				repv: i_lvl || 0, // repeat variant number
				tgen: 2, 	// generate by 2 seconds
				get_time: get_time,
				midi_ctrl: midi_ctrl,
				note_run: note_run,
				timouts: [],

				// MIDI specific
				op: op,		// output port
				c_i: []		// channel to instrument
			}
			s_end = i_end
			s_cur = i_start
			repv = i_lvl || 0
if (0) {
// temperament
			op.send(new Uint8Array([
				0xf0, 0x7f,	// realtime SysEx
				0x7f,		// all devices
				0x08,		// MIDI tuning standard
				0x02,		// note change
				0x00,		// tuning prog number
				0x01,		// number of notes
					0x69,		// key
					0x69,		// note
					0x00,		// MSB fract
					0,		// LSB fract
				0xf7		// SysEx end
				]), t)
}

			v_i = []		// must do a reset of all channels
			stime = window.performance.now() + 200	// start time + 0.2s
			play_next()
			abc2svg.play_next(po)
		}, // play()

		// stop playing
		stop: function() {
			stop = true
			timouts.forEach(function(id) {
			po.stop = true
			po.timouts.forEach(function(id) {
						clearTimeout(id)
					})
			abc2svg.play_next(po)
			onend(repv)
//			po.onend(repv)
//fixme: op.clear() should exist...
			if (op && op.clear)
				op.clear()
		} // stop()
	} // returned object
} // end Midi5
Changes to util/toaudio.js.
︙
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
22
23
24
25
26
27
28

29

30
31
32
33
34
35
36







-
+
-








  var	C = abc2svg.C,

	a_e,				// event array

	p_time,				// last playing time
	abc_time,			// last ABC time
	play_factor,			// play time factor
	play_factor			// play time factor
	abcmidi = AbcMIDI()

// ToAudio
  return {

// clear the playing events and
// return the old ones as an array of Float32Array:
//	[0]: index of the note in the ABC source
︙
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
206
207
208
209
210
211
212



213
214
215
216
217
218
219







-
-
-







				1,
				s.v]))
		}
	} // gen_note()

	// add() main

	// set the MIDI pitches
	abcmidi.add(start, voice_tb)

	if (!a_e) {			// if first call
		a_e = []
		abc_time = p_time = 0;
		play_factor = C.BLEN / 4 * 120 / 60	// default: Q:1/4=120
	} else if (s.time < abc_time) {
		abc_time = s.time
	}
︙
Changes to util/toaudio5.js.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







// toaudio5.js - audio output using HTML5 audio
//
// Copyright (C) 2015-2019 Jean-Francois Moine
// Copyright (C) 2015-2021 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
︙
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82







-
+








    var	abcsf2 = []			// SF2 instruments

function Audio5(i_conf) {
	var	conf = i_conf,		// configuration
		onend = function() {},
		onnote = function() {},
		errmsg = alert,
		errmsg,
		ac,			// audio context
		gain,			// global gain

	// instruments/notes
		params = [],		// [instr][key] note parameters per instrument
		rates = [],		// [instr][key] playback rates
		w_instr = 0,		// number of instruments being loaded
︙
152
153
154
155
156
157
158
159

















160
161
162
163
164
165
166
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		for (i = 0; i < s.length; i++)
			a[i] = s[i] / 196608	// volume divided by 6
	}

	// create all notes of an instrument
	function sf2_create(parser, instr) {
	    var i, sid, gen, parm, sampleRate, sample,
		infos = parser.getInstruments()[0].info;
//		infos = parser.getInstruments()[0].info;
		j,
		infos = [],
		instrument = parser.instrument,
		zone = parser.instrumentZone

		i = instrument[0].instrumentBagIndex
		j = instrument[1] ? instrument[1].instrumentBagIndex
				  : zone.length
		while (i < j) {
			infos.push({
				generator: parser.
						createInstrumentGenerator_(zone, i)
							.generator
			})
			i++
		}

		rates[instr] = []
		for (i = 0; i < infos.length; i++) {
			gen = infos[i].generator;
			if (!gen.sampleID)	// (empty generator!)
				continue
			sid = gen.sampleID.amount;
︙
425
426
427
428
429
430
431
432
433

434
435
436
437
438
439
440
441
442
443
444
445
446
447


448
449
450
451
452
453
454
455







-
-
+







		}

		// get the callback functions
		if (conf.onend)
			onend = conf.onend
		if (conf.onnote)
			onnote = conf.onnote
		if (conf.errmsg)
			errmsg = conf.errmsg
		errmsg = conf.errmsg || alert

		// play a null file to unlock the iOS audio
		// This is needed for iPhone/iPad/...
		function play_unlock() {
		    var buf = ac.createBuffer(1, 1, 22050),
			src = ac.createBufferSource();
			src.buffer = buf;
︙