| 1 | <style> |
| 2 | p{margin-left:.5cm;max-width:21cm} |
| 3 | li{margin-left:.5cm;max-width:20cm} |
| 4 | li p{margin-left:0} |
| 5 | </style> |
| 6 | ## abc2svg |
| 7 | |
| 8 | **abc2svg** is a set of ECMAscript files that handle the |
| 9 | [ABC music notation](http://abcnotation.com/). This includes |
| 10 | editing, displaying, printing, playing the music files and |
| 11 | converting them to other formats such as ABC and MEI notations. |
| 12 | |
| 13 | The **abc2svg** core is based on the |
| 14 | [abcm2ps](https://chiselapp.com/user/moinejf/repository/abcm2ps) C code |
| 15 | which requires compilation on every operating system. |
| 16 | The **abc2svg** scripts can run in any system with no compilation on |
| 17 | any platform that contains an internet browser. This includes MS-Windows, |
| 18 | Apple, and Unix-like systems (Linux, BSD...) as well as portable devices |
| 19 | such as cell phones and tablets. |
| 20 | |
| 21 | A description of the ABC parameters that relate to both abcm2ps |
| 22 | and abc2svg can be found [here][1]. |
| 23 | |
| 24 | [1]: http://moinejf.free.fr/abcm2ps-doc/index.html "abc2svg documentation" |
| 25 | |
| 26 | ### 1. Web browser usage |
| 27 | |
| 28 | #### 1.1 Rendering ABC files from a local or remote source |
| 29 | |
| 30 | After accessing ABC files with a web browser either from a local or web |
| 31 | source, you can render or play the music without much preparation. |
| 32 | One approach uses [bookmarklets](https://en.wikipedia.org/wiki/Bookmarklet). |
| 33 | |
| 34 | A bookmarklet is the same as a normal bookmark in a web browser. |
| 35 | Its title (or name) is anything you want to use to identify it and its URL |
| 36 | (or location or address) is javascript code starting by `javascript:`. |
| 37 | First, create a bookmark from this page adding it to your library of |
| 38 | bookmarks. Next, edit this mark changing the title and the URL. (Details |
| 39 | for editing a bookmark are specific for each browser. To get instructions, |
| 40 | search on the internet the name of the browser and keywords such as |
| 41 | 'bookmarklet' and 'javascript in url'). To edit the URL, extract |
| 42 | the javascript code |
| 43 | by right clicking on one of the bookmarklets below and selecting |
| 44 | copy url. Then, paste this code into the URL of your new bookmark |
| 45 | in your library. |
| 46 | |
| 47 | To use a abc2svg bookmarklet, first, load an ABC file into your |
| 48 | browser either from a web site of from a file on your system. |
| 49 | Once you see the textual abc code, click on the bookmarklet |
| 50 | that you created. After a slight delay depending upon the |
| 51 | complexity of the abc code, it should be replaced by a music |
| 52 | representation or a list of the contents of the ABC file. Here |
| 53 | are two bookmarklets that you can try. |
| 54 | |
| 55 | This |
| 56 | <a href="javascript:(function(){var%20s,n=2,d=document,b=d.body;d.head.innerHTML='%3cstyle%3esvg{display:block};@media print{body{margin:0;padding:0;border:0};.nop{display:none}}%3c/style%3e\n';b.innerHTML='%3cscript type=%22text/vnd.abc%22%3e\n'+b.textContent+'%3c/script%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')})()" |
| 57 | title="Copy me">first abc2svg bookmarklet</a> |
| 58 | renders all the music it finds in the page currently displayed. |
| 59 | Once the music is displayed, clicking inside a tune starts playing it |
| 60 | from the beginning. |
| 61 | Clicking on a particular note or rest starts playing from that point. |
| 62 | To print or convert the music to a PDF file, |
| 63 | simply click on the 'Print' button of the web browser. |
| 64 | (If the 'Print' button does not appear on your browser menu, |
| 65 | try right clicking on the web page.) |
| 66 | |
| 67 | Alternatively, if your source contains many tunes, you can |
| 68 | use this |
| 69 | <a href="javascript:(function(){var%20s,n=2,d=document,b=d.body;d.head.innerHTML='%3cstyle%3esvg{display:block};@media print{body{margin:0;padding:0;border:0};.nop{display:none}}%3c/style%3e\n';b.innerHTML='%3cscript type=%22text/vnd.abc%22%3e\n'+b.textContent+'%3c/script%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')})()" |
| 70 | title="Copy me">second bookmarklet</a>. |
| 71 | The browser will list the titles of the tunes. |
| 72 | Clicking on a title displays the tune. |
| 73 | Playing and printing work in the same manner as above. |
| 74 | The generated pages contain a yellow menu in the top right corner which permits |
| 75 | you to return to the tune list or to modify the music. With this last option, |
| 76 | you can adjust the page size before printing, correct the ABC syntax or |
| 77 | do some transposition. |
| 78 | Note that these changes stay only with the browser and are not saved |
| 79 | to your system. |
| 80 | |
| 81 | If you want to experiment with these bookmarklets, here are some raw ABC files: |
| 82 | |
| 83 | - [from my site](http://moinejf.free.fr/abc/agora.abc "agora.abc") |
| 84 | - [from Cranford Publications][2] |
| 85 | |
| 86 | [2]: http://www.cranfordpub.com/tunes/abcs/NatalieBlueprint.txt "Blueprint" |
| 87 | |
| 88 | #### 1.2 Writing, playing and printing music with the abc2svg editor |
| 89 | |
| 90 | The [abc2svg editor][3] |
| 91 | is another example of what can be done with **abc2svg**. |
| 92 | |
| 93 | [3]: http://moinejf.free.fr/js/edit-1.xhtml "ABC editor based on abc2svg" |
| 94 | |
| 95 | If you are unfamiliar with ABC music notation, just copy this ABC sequence below |
| 96 | and paste it into the text area of the editor. |
| 97 | |
| 98 | X:1 |
| 99 | T:C scale |
| 100 | M:C |
| 101 | L:1/4 |
| 102 | K:C |
| 103 | CDEF|GABc| |
| 104 | |
| 105 | If your ABC files contain `%%abc-include`, then you must: |
| 106 | |
| 107 | - load the ABC file using the browse button, |
| 108 | - click the include file name button, |
| 109 | - and load the include file using the same previous browse button. |
| 110 | |
| 111 | Only one included file is allowed. |
| 112 | |
| 113 | If you have installed abc2svg in a site of yours, you may put a file |
| 114 | **pref.js** with the abc2svg scripts. This file may contain various |
| 115 | javascript functions and also ABC parameters. |
| 116 | These parameters must be defined inside the following sequence: |
| 117 | |
| 118 | if (typeof abc2svg == "undefined") |
| 119 | var abc2svg = {} |
| 120 | if (!abc2svg.a_inc) |
| 121 | abc2svg.a_inc = {} |
| 122 | abc2svg.a_inc["default.abc"] = ` |
| 123 | .. put here the ABC parameters .. |
| 124 | ` |
| 125 | |
| 126 | If you have a US keyboard, its behaviour can be changed for easier music |
| 127 | entering by one of these bookmarklets: |
| 128 | <a href="javascript:(function(){if(typeof%20abc2svg.loadjs=='function'){abc2svg.loadjs('abckbd-1.js')}else{alert('use%20with%20abc2svg%20editor')}})()" |
| 129 | title="Copy me">keyboard 1</a> |
| 130 | and |
| 131 | <a href="javascript:(function(){if(typeof%20abc2svg.loadjs=='function'){abc2svg.loadjs('abckbd2-1.js')}else{alert('use%20with%20abc2svg%20editor')}})()" |
| 132 | title="Copy me">keyboard 2</a>. |
| 133 | |
| 134 | #### 1.3 Publishing music on your web pages |
| 135 | |
| 136 | To insert music in your web pages, you just have to insert the lines |
| 137 | |
| 138 | <script src="http://moinejf.free.fr/js/abc2svg-1.js" defer></script> |
| 139 | <script src="http://moinejf.free.fr/js/abcweb-1.js" defer></script> |
| 140 | <script src="http://moinejf.free.fr/js/snd-1.js" defer></script> |
| 141 | |
| 142 | in the HTML <head> and put the music as |
| 143 | ABC sequences in the <body>. |
| 144 | |
| 145 | [This example][4] demonstrates how to do it. |
| 146 | (Note that, in the example, the paths are relative - see why below.) |
| 147 | |
| 148 | [4]: http://moinejf.free.fr/abcm2ps-doc/tabac.html "J'ai du bon tabac" |
| 149 | |
| 150 | As it is apparent, HTML and ABC can be mixed in the same html file. |
| 151 | Both are rendered in the order you defined them. |
| 152 | |
| 153 | You may also have noticed this style about SVG elements: |
| 154 | ` svg { display: block }` |
| 155 | |
| 156 | It puts the lines of music on vertical areas. |
| 157 | Without this style, the music is in-lined as in [this other example][5]. |
| 158 | |
| 159 | [5]: http://moinejf.free.fr/abcm2ps-doc/dansou-i.html "Tune index example" |
| 160 | |
| 161 | Global ABC parameters may be added as `parameter=value` in the query string |
| 162 | of the URL of the page. The [following example][9] calls the same |
| 163 | "J'ai du bon tabac" with `pagescale=1.2` (giving `%%pagescale 1.2`). |
| 164 | |
| 165 | [9]: http://moinejf.free.fr/abcm2ps-doc/tabac.html?pagescale=1.2 "J'ai du bon tabac" |
| 166 | |
| 167 | In the above examples, all the ABC music is generated (displayed |
| 168 | and ready to be played) by means of the script **abcweb-1.js**. |
| 169 | If there is a large collection of tunes, it may be preferable to |
| 170 | link to the other script, **abcweb1-1.js**, which offers a tune selection. |
| 171 | Without an explicit |
| 172 | selection (see below), a list of the tunes is displayed, and, |
| 173 | after a tune has been selected, the whole page is replaced by the music. |
| 174 | (The HTML code, if any, is not displayed.) |
| 175 | You can go back to the list of the tunes thanks to the menu |
| 176 | on the top right corner of the screen. Here is [a real example][6]. |
| 177 | |
| 178 | [6]: http://moinejf.free.fr/abc/boyvin-2-2.html "J. Boyvin organ tunes" |
| 179 | |
| 180 | As you may notice in the menu, the edition of the ABC content is proposed. |
| 181 | This permits you, for example, to transpose the tunes. |
| 182 | This edition is done inside the browser, so, your changes will be lost |
| 183 | after leaving the page. |
| 184 | |
| 185 | When accessing such pages, an external selection of the tunes |
| 186 | can be accomplished by ending the URL with the character '`#`' |
| 187 | followed by a [regular expression][7] |
| 188 | to be applied to the tune headers. |
| 189 | For instance, here is the ['Duo' de J. Boyvin][8]. |
| 190 | |
| 191 | [7]: https://en.wikibooks.org/wiki/Regular_Expressions "Regular expressions" |
| 192 | [8]: http://moinejf.free.fr/abc/boyvin-2-2.html#T:Duo "Duo" |
| 193 | |
| 194 | With any of the above scripts the music may be printed using |
| 195 | the 'Print' button of the browser. You should add a style as: |
| 196 | ` @media print{body{margin:0;padding:0;border:0}.nop{display:none}}` |
| 197 | |
| 198 | to remove the margins, the error messages and the menus from the |
| 199 | printed pages. |
| 200 | |
| 201 | #### 1.4 Installing abc2svg on your system or on your server |
| 202 | |
| 203 | The **abc2svg** package on my server is still being tuned |
| 204 | which could change its behaviour at any unknown time; so you may |
| 205 | prefer to install and run it from your own system. |
| 206 | |
| 207 | There are many ways to install abc2svg: |
| 208 | |
| 209 | - [tarball][16] or [.zip archive][17] from my site |
| 210 | Both files contain the scripts that are generated from the source |
| 211 | when abc2svg is stable enough. The scripts are ready |
| 212 | to be used from the root directory. |
| 213 | |
| 214 | [16]: http://moinejf.free.fr/abc2svg.tar.bz2 "tarball" |
| 215 | [17]: http://moinejf.free.fr/abc2svg.zip "ZIP file" |
| 216 | |
| 217 | - [Guido Gonzato's page](http://abcplus.sourceforge.net/#abc2svg) |
| 218 | Guido maintains a ZIP archive of the abc2vg scripts after |
| 219 | each release of a new version (many thanks, Guido!). |
| 220 | You can just download and unzip this archive. **abc2svg** should |
| 221 | run immediately in your machine without connecting to my site. |
| 222 | In the same page, you can also find some binaries of QuickJS, |
| 223 | a fast javascript interpreter (see below). |
| 224 | |
| 225 | - tarball |
| 226 | From the timeline in the [chisel repository][13], you can get a tarball |
| 227 | of any version of the abc2svg source and install it in your system. |
| 228 | The abc2svg scripts must then be built from the raw source files |
| 229 | described in the section 'Build' below. |
| 230 | The disadvantage of this approach is that if you want |
| 231 | to use an other or newer version you need to download a new tarball. |
| 232 | |
| 233 | [13]: https://chiselapp.com/user/moinejf/repository/abc2svg/timeline |
| 234 | |
| 235 | - fossil clone |
| 236 | If you can get the fossil program (one binary) for your system, |
| 237 | you may clone the chisel repository by |
| 238 | ` fossil clone https://chiselapp.com/user/moinejf/repository/abc2svg abc2svg.fossil` |
| 239 | ` fossil open abc2svg.fossil` |
| 240 | and get the abc2svg source files containing the last changes |
| 241 | between the official versions. Updating your files is done by |
| 242 | ` fossil pull` |
| 243 | ` fossil update` |
| 244 | Building the scripts is done in the same way as with a tarball. |
| 245 | The repository is presently over 50Mb. |
| 246 | |
| 247 | For those unfamiliar with [fossil][14], it is an integrated |
| 248 | software management system similar to [git](https://git-scm.com/). |
| 249 | Chisel acts like a repository similar to [github](https://github.com/). |
| 250 | |
| 251 | [14]: https://fossil-scm.org/home/doc/trunk/www/index.wiki |
| 252 | |
| 253 | Using bookmarklets with a local installation does not work directly |
| 254 | because of a cross-domain security hole, but this is possible by running |
| 255 | a local HTTP server (you will also have to change the location |
| 256 | of the scripts in the bookmarklet code). |
| 257 | |
| 258 | If you have write access on a remote server, you may put there |
| 259 | the abc2svg scripts. There is no automatic process to do that. |
| 260 | You will have to |
| 261 | [look at my site](http://moinejf.free.fr/js/ "all abc2svg scripts") |
| 262 | to determine the files that need to be copied. |
| 263 | |
| 264 | In addition, you have to set the correct location of the abc2svg scripts |
| 265 | in your pages. As a trick, I put the abc2svg scripts in a folder |
| 266 | at the same level as the HTML files: |
| 267 | |
| 268 | ` <script src="../js/abcweb-1.js" defer></script>` |
| 269 | |
| 270 | This allows the generation of the music to run either locally |
| 271 | or remotely. |
| 272 | |
| 273 | ### 2. Automatic creation of music sheets |
| 274 | |
| 275 | #### 2.1 abc2svg shell scripts |
| 276 | |
| 277 | As you have seen, printing the music can be done easily with any web browser. |
| 278 | You can automate the process of creating music sheets |
| 279 | with **abc2svg** using shell scripts running a Javascript interpreter. |
| 280 | |
| 281 | The interfaces to the various interpreters are different. Below you will |
| 282 | find the scripts I had to built. |
| 283 | |
| 284 | - `abcqjs` with `qjs` [QuickJS by Fabrice Bellard and Charlie Gordon][10] |
| 285 | - `abcmjs` with `js78`, `js60`, `js52` or `js24` (Mozilla JavaScript shell) |
| 286 | - `abcjsc` with `jsc` (webkit2gtk) |
| 287 | - `abcnode` with `node` (nodeJS without module) |
| 288 | |
| 289 | [10]: https://bellard.org/quickjs/ |
| 290 | |
| 291 | Each script gets the abc2svg options and ABC files from the command line |
| 292 | and sends the generated file to `stdout` and possible errors to `stderr`. |
| 293 | The general syntax of the command line is: |
| 294 | ` script [script.js] [options] ABC_file [[options] ABC_file]* [options]` |
| 295 | with: |
| 296 | |
| 297 | - `script.js` is an optional backend script. |
| 298 | It defaults to `tohtml.js` (HTML+SVG) |
| 299 | - `options` are the ABC options. |
| 300 | For compatibility, the last options are moved before the last ABC file. |
| 301 | |
| 302 | These scripts try to read a file `default.abc` at startup time. |
| 303 | This file and also the files included by `%%abc-include` are searched |
| 304 | in the current directory or in the colon separated list of directories |
| 305 | contained in the environment variable `ABCPATH`. |
| 306 | |
| 307 | #### 2.2 Backend scripts |
| 308 | |
| 309 | By default, the shell scripts generate (HTML+SVG) files. |
| 310 | This output may be modified by backend scripts. These ones must appear |
| 311 | immediately following the name of the shell script. |
| 312 | They are: |
| 313 | |
| 314 | - `toabc.js` |
| 315 | This script returns the (selected) ABC tunes from the ABC source file |
| 316 | applying transposition. |
| 317 | The resulting file does not contain the formatting parameters. |
| 318 | Example: |
| 319 | ` abcqjs toabc.js my_file.abc --select X:2 > tune_2.abc` |
| 320 | |
| 321 | - `toabw.js` |
| 322 | This script outputs an Abiword file (ABW+SVG) that can be read by some |
| 323 | word processors (abiword, libreoffice...). The word processor allows |
| 324 | you to convert the file to many other formats from a command line. |
| 325 | The abc2svg music font (`abc2svf.woff` or `abc2svg.ttf`) must be installed |
| 326 | in the local system for displaying and/or converting the .abw file. |
| 327 | Example: |
| 328 | ` abcmjs toabw.js my_file.abc > my_file.abw` |
| 329 | |
| 330 | - `tomei.js` |
| 331 | This script outputs the music as a [MEI](https://music-encoding.org/) file. |
| 332 | Note, only one tune may be translated from ABC to MEI (multi-tunes ABC files |
| 333 | generate bad MEI files). |
| 334 | |
| 335 | - `tonotes.js` |
| 336 | This script outputs a list of the MIDI events. |
| 337 | |
| 338 | - `toodt.js` |
| 339 | This script creates an Open Document (ODT+SVG) which can be read by most |
| 340 | word processors (abiword, libreoffice...). |
| 341 | When runs with the shell script `abc2svg`, it asks for the npm module |
| 342 | `jszip` to be installed. |
| 343 | When run with `abcqjs` on unix-like systems, it creates a temporary |
| 344 | directory tree in `/tmp`. |
| 345 | The output ODT document may be specified in the command line argument |
| 346 | after `-o` (default `abc.odt`). |
| 347 | Example: |
| 348 | ` abcqjs toodt.js my_file.abc -o my_file.odt` |
| 349 | |
| 350 | - `toparam.js` |
| 351 | This script just outputs the abc2svg parameters. |
| 352 | |
| 353 | - `tosvg.js` |
| 354 | This script creates a SVG file that includes all the SVGs of the generation. |
| 355 | |
| 356 | The included SVG images are updated for being correctly rendered by tools |
| 357 | that use librsvg, the SVG library for GNOME (feh, viewnior, swayimg...). |
| 358 | |
| 359 | #### 2.3 PDF generation |
| 360 | |
| 361 | `abctopdf` is a shell script which converts ABC to PDF using one of the |
| 362 | previous shell scripts and, either a chrome/chromium compatible web browser |
| 363 | (settable by the environment variable 'BROWSER'), |
| 364 | or the program [weasyprint](https://weasyprint.org/). |
| 365 | |
| 366 | Note also that, with `weasyprint`, the paper size is forced to A4. |
| 367 | Instructions for changing this size may be found in the script source. |
| 368 | |
| 369 | The output PDF document may be specified by the command line argument `-o` |
| 370 | (default `abc.pdf`). |
| 371 | |
| 372 | Example: |
| 373 | ` abctopdf my_file.abc -o my_file.pdf` |
| 374 | |
| 375 | ### 3. Build |
| 376 | |
| 377 | The abc2svg scripts which are used to render the music |
| 378 | either by a web browser or by a shell script must be built from |
| 379 | the source files you got by tarball or fossil clone. |
| 380 | |
| 381 | Quoting [Douglas Crockford](https://www.crockford.com/jsmin.html), |
| 382 | minification is a process that removes comments and unnecessary whitespace from |
| 383 | JavaScript files. It typically reduces file size by half, resulting in |
| 384 | faster downloads. |
| 385 | |
| 386 | If you can run one of the tools [ninja](https://ninja-build.org/) |
| 387 | or [samurai](https://github.com/michaelforney/samurai), you can build |
| 388 | the scripts |
| 389 | |
| 390 | - without minification |
| 391 | This is useful for debugging purposes and the scripts are more human friendly. |
| 392 | |
| 393 | ` NOMIN=1 samu -v` |
| 394 | |
| 395 | or |
| 396 | |
| 397 | ` NOMIN=1` |
| 398 | ` export NOMIN` |
| 399 | ` ninja -v` |
| 400 | |
| 401 | - in a standard way with minification |
| 402 | In this case, you need one of the tools |
| 403 | [JSMin](https://www.crockford.com/jsmin.html) or |
| 404 | `uglifyjs` which comes with nodeJS. |
| 405 | |
| 406 | ` samu -v` |
| 407 | |
| 408 | If you also want to change or add music glyphs, you may edit the source |
| 409 | file `font/abc2svg.sfd`. |
| 410 | In this case, you will need both `base64` and `fontforge`, and run |
| 411 | |
| 412 | ` samu -v font.js` |
| 413 | |
| 414 | If you cannot or don't want to install `ninja` or `samurai`, you may build |
| 415 | the abc2svg files by the shell script `./build`. |
| 416 | (This script must be run by a Posix compatible shell.) |
| 417 | |
| 418 | ### 4. Inside the code of abc2svg |
| 419 | |
| 420 | #### 4.1 Core and modules |
| 421 | |
| 422 | `abc2svg-1.js` is the **abc2svg** core. |
| 423 | It contains the ABC parser and the SVG generation engine. |
| 424 | It is needed for all music rendering. It is automatically loaded |
| 425 | by the web scripts and the shell scripts. |
| 426 | If you want to use the core with your own scripts, |
| 427 | its API is described in the [wiki][11]. |
| 428 | |
| 429 | [11]: https://chiselapp.com/user/moinejf/repository/abc2svg/wiki?name=interface-1 |
| 430 | |
| 431 | The core does not handle all the abc2svg commands/parameters. |
| 432 | Some of them are treated by modules. |
| 433 | A module is a script which is loaded in the browser or in the JS interpreter |
| 434 | when the command it treats is seen in the ABC flow. |
| 435 | Detailed information about the modules may be found in the [wiki][12]. |
| 436 | |
| 437 | [12]: https://chiselapp.com/user/moinejf/repository/abc2svg/wiki?name=modules |
| 438 | |
| 439 | #### 4.2 Internal information |
| 440 | |
| 441 | - The music is displayed as SVG images. There is one image per |
| 442 | music line / text block. |
| 443 | If you want to move these images to some other files, |
| 444 | each one must contain the full CSS and defs. For that, insert |
| 445 | ` %%fullsvg x` |
| 446 | in the ABC file before rendering (see the |
| 447 | [fullsvg documentation](http://moinejf.free.fr/abcm2ps-doc/fullsvg.html) |
| 448 | for more information). |
| 449 | |
| 450 | - Playing uses the HTML5 audio and/or the midi APIs. |
| 451 | For audio, by default, abc2svg uses a sound font (format SF2) |
| 452 | which is split into one file |
| 453 | per instrument. This sound font is stored in the subdirectory `Scc1t2/`. |
| 454 | Each instrument file is a base64 encoded javascript array. |
| 455 | |
| 456 | Other sound fonts may be used. Some of them are stored in the subdirectory |
| 457 | `sf2/` (`AWE_ROM_gm` and `2MBGMGS`). Two formats are supported: raw SF2 and |
| 458 | SF2 wrapped into javascript (the raw SF2 files can be loaded |
| 459 | only when they are in the same HTTP domain). |
| 460 | The shell script `sf.sh` (in `sf2/`) may be used to create the javacript files |
| 461 | from raw SF2 files. |
| 462 | |
| 463 | The sound font to be used for playing may be defined in the ABC code |
| 464 | by the command `%%soundfont`. E.g.: |
| 465 | ` %%soundfont http://moinejf.free.fr/js/sf2/AWE_ROM_gm.js` |
| 466 | |
| 467 | - The names of the abc2svg scripts have a suffix which is the version of |
| 468 | the core interface (actually '`-1`'). |
| 469 | |
| 470 | #### 4.3 More about the web scripts |
| 471 | |
| 472 | Here are the scripts which are used in a web context: |
| 473 | |
| 474 | - `abcweb-1.js` |
| 475 | This script replaces the ABC sequences found in the (X)HTML file |
| 476 | by SVG images of the music. |
| 477 | The ABC sequences are searched: |
| 478 | - first inside <script> elements with a type |
| 479 | ["text/vnd.abc"](https://www.iana.org/assignments/media-types/text/vnd.abc) |
| 480 | (the script tag is replaced by a <div>), |
| 481 | - or inside (X)HTML elements with a class `abc` (lower case letters), |
| 482 | - otherwise on `X:` or `%abc-` at start of line up to a XML tag at start of line. |
| 483 | |
| 484 | When a ABC sequence is not included in a <script> and when it contains |
| 485 | the characters '<', '>' or '&', |
| 486 | it must be enclosed in a XML comment or in a CDATA |
| 487 | (%<![CDATA[ .. %]]> - the comment or CDATA must be in a ABC comment). |
| 488 | |
| 489 | When using <script>, it is possible to set abc2svg parameters via CSS. |
| 490 | For that, the <style> in the HTML <head> may contain custom |
| 491 | properties (properties starting with '--') and these properties are converted |
| 492 | to abc2svg parameters (starting with '%%') before the ABC sequence. |
| 493 | For instance, in the (<head>) <style> element, you can put: |
| 494 | ` .parm {--pagewidth:30cm; --bgcolor : yellow}` |
| 495 | |
| 496 | and in some <script ..vnd.abc..>, you set the class: |
| 497 | ` <script class="parm" type="text/vnd.abc">` |
| 498 | |
| 499 | This defines the page width and the background color of the generated music. |
| 500 | |
| 501 | See the |
| 502 | [%%beginml documentation](http://moinejf.free.fr/abcm2ps-doc/beginml.html) |
| 503 | for an example, and here is [how to put inline music in HTML][15]. |
| 504 | Playing and highlighting the played notes may be offered loading |
| 505 | the script `snd-1.js` (see below). |
| 506 | |
| 507 | [15]: http://moinejf.free.fr/abcm2ps-doc/inline.html "abc2svg - inline music" |
| 508 | |
| 509 | This script also accepts a parameter `with_source`. |
| 510 | When this parameter is set, the music source is included before the |
| 511 | SVG images of the music. The music source is displayed |
| 512 | in a <pre> element of class `source`. The SVG's are included |
| 513 | in a <div> of the same class `source`. |
| 514 | The source may be displayed either above (default) or |
| 515 | at the left side of the music (using a style as |
| 516 | `.source{display: inline-block; vertical-align: top}`). |
| 517 | See the source of |
| 518 | [abcm2ps/abc2svg features](http://moinejf.free.fr/abcm2ps-doc/features.html) |
| 519 | for an example. |
| 520 | |
| 521 | The music source may be editable. |
| 522 | To change it, the script contains two functions: |
| 523 | - `abc2svg.get_music` returns the source of the music sequence |
| 524 | (in <script> type "text/vnd.abc", class="abc" or inlined ABC). |
| 525 | Its argument is the HTML <div> element that contains the music. |
| 526 | - `abc2svg.set_music` has two arguments, the HTML <div> element |
| 527 | and the new source of the music. |
| 528 | It generates and replaces the music in the <div>. |
| 529 | |
| 530 | - `abcweb1-1.js` |
| 531 | The page body is analyzed as a ABC file and its content is |
| 532 | replaced by music as SVG images. |
| 533 | If the page contains reserved XML characters ('<', '>' and '&'), |
| 534 | the ABC code must be enclosed in a |
| 535 | ` <script type="text/vnd.abc"> .. </script>` |
| 536 | sequence. |
| 537 | |
| 538 | When there are many tunes in the file, the script displays a list |
| 539 | of the tunes. The list step may be bypassed when the URL of the file |
| 540 | contains a regular expression in the 'hash' value ('#' followed by |
| 541 | a string at the end of the URL). |
| 542 | This string does a |
| 543 | [%%select](http://moinejf.free.fr/abcm2ps-doc/select.xhtml). |
| 544 | |
| 545 | When one or many tunes are displayed, a menu in the top/right corner |
| 546 | offers to go back to the tune list or to modify the ABC source. |
| 547 | |
| 548 | - `snd-1.js` |
| 549 | This script may be used with `abcweb-1.js` or `abcweb1-1.js` |
| 550 | to play the rendered ABC music. |
| 551 | |
| 552 | ### 6. Credit |
| 553 | |
| 554 | **abc2svg** includes the following packages: |
| 555 | |
| 556 | - wps by Tomas Hlavaty |
| 557 | <http://logand.com/sw/wps/log.html> |
| 558 | |
| 559 | - JavaScript SoundFont 2 Parser by imaya/GREE Inc and Colin Clark |
| 560 | <https://github.com/colinbdclark/sf2-parser> |
| 561 | |
| 562 | - Scc1t2 |
| 563 | <http://www.ibiblio.org/thammer/HammerSound/localfiles/soundfonts/> |
| 564 | |
| 565 | - strftime by T. H. Doan |
| 566 | <https://thdoan.github.io/strftime/> |
| 567 | |
| 568 | [Jean-François Moine](http://moinejf.free.fr) |