Index: README.md
==================================================================
--- README.md
+++ README.md
@@ -1,259 +1,537 @@
+
## abc2svg
-**abc2svg** is a set of tools written in Javascript and based on
-[abcm2ps](https://github.com/leesavide/abcm2ps).
-
-It permits to edit, display, print and play music from files written in
-[ABC](http://abcnotation.com/).
-
-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).
-
-### Web usage
-
-**abc2svg** may be used in any web browser.
-The needed files are available in my site
-[http://moinejf.free.fr/js/](http://moinejf.free.fr/js).
-They are updated on release change.
-
-These files are:
-
-- `abc2svg-1.js`
- 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 `
+
+
+in the HTML <head> and put the music as
+ABC sequences in the <body>.
+
+[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"
+
+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].
+
+[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`).
+
+[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"
+
+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].
+
+[7]: https://en.wikibooks.org/wiki/Regular_Expressions "Regular expressions"
+[8]: http://moinejf.free.fr/abc/boyvin-2-2.html#T:Duo "Duo"
+
+In the first example ("J'ai du bon tabac"), you saw that care
+should be taken with regard to the special XML characters
+'<', '>' and '&' 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.
+
+#### 1.4 Installing abc2svg on your system or on your server
+
+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:
+
+- [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).
+
+- 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
+ ` fossil pull`
+ ` fossil update`
+ Building the scripts is done in the same way as with a tarball.
+ The repository is presently over 23Mb.
+
+ For those unfamiliar with [fossil][14], it is an integrated
+ software management system similar to [git](https://git-scm.com/).
+ Chisel acts like a repository similar to [github](https://github.com/).
+
+[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.
+
+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:
+
+` `
+
+This allows the generation of the music to run either locally
+or remotely.
+
+### 2. Automatic creation of music sheets
+
+#### 2.1 abc2svg shell scripts
+
+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][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)
-- `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:
-
-- `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:
+immediately following the name of the shell script.
+They are:
+
+- `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 the program `rsvg-convert`.
-As a constraint, the used music font must be installed and defined by
-`%%musicfont `.
-Example:
+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
+the program `rsvg-convert`.
+
+With `rsvg-convert`, the used music font must be installed and defined by
+`%%musicfont `.
+
+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`
-### MEI support
+### 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 <script> 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 <script> and when it contains
+ the characters '<', '>' or '&',
+ it must be enclosed in a XML comment or in a CDATA
+ (%<![CDATA[ .. %]]> - 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.
+
+### 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.
-
-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,
-`
+
+- JavaScript SoundFont 2 Parser by imaya/GREE Inc and Colin Clark
+
+
+- Scc1t2
+
+
+- strftime by T. H. Doan
+
+
+[Jean-François Moine](http://moinejf.free.fr)
Index: abc2odt
==================================================================
--- abc2odt
+++ abc2odt
@@ -7,15 +7,14 @@
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
Index: abc2svg
==================================================================
--- abc2svg
+++ abc2svg
@@ -1,25 +1,12 @@
-#! /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;
@@ -53,11 +40,11 @@
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");
@@ -64,23 +51,9 @@
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")
Index: abc2svg.ttf
==================================================================
--- abc2svg.ttf
+++ abc2svg.ttf
cannot compute difference between binary files
Index: abcjs24
==================================================================
--- abcjs24
+++ abcjs24
@@ -1,26 +1,24 @@
#!/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
-abc2svg.print = function(str) {
+var abc2svg = {
+ 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) {
@@ -27,31 +25,14 @@
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)")
Index: abcjs52
==================================================================
--- abcjs52
+++ abcjs52
@@ -1,26 +1,24 @@
#!/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
-abc2svg.print = function(str) {
+var abc2svg = {
+ 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) {
@@ -27,31 +25,14 @@
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)")
Index: abcjs60
==================================================================
--- abcjs60
+++ abcjs60
@@ -1,26 +1,24 @@
#!/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
-abc2svg.print = function(str) {
+var abc2svg = {
+ 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) {
@@ -27,31 +25,14 @@
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)")
Index: abcjsc
==================================================================
--- abcjsc
+++ abcjsc
@@ -30,66 +30,49 @@
// } 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
-abc2svg.print = function(str) {
+var abc2svg = {
+ 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 = ''
Index: abcnode
==================================================================
--- abcnode
+++ abcnode
@@ -1,18 +1,20 @@
-#!/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 <> /tmp/toto.js
var progdir='${progdir}/'
@@ -53,31 +55,15 @@
}
// (this file is wrapped)
global.Abc = Abc
global.abc2svg = abc2svg
-EOF
-cat ${progdir}/cmdline.js >> /tmp/toto.js
-
-cat <> /tmp/toto.js
// main
- 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)
- }
+ var args = process.argv
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 "$@"
Index: abcqjs
==================================================================
--- abcqjs
+++ abcqjs
@@ -1,116 +1,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 "$@"
-
-cat > /tmp/abcqjs.js << EOF
-//javascript
+exec qjs --std -e '
var i,
- args = scriptArgs
- args.shift() // remove '/tmp/abcqjs.js'
- var core = "abc2svg-1.js",
+ args = scriptArgs,
+ 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)
-
-// 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")
-
-// 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)
-EOF
-exec qjs --std /tmp/abcqjs.js $0 "$@"
+ load(path + core)
+ load(path + "cmdline.js")
+
+ abc_cmd("abcqjs", args, "QuickJS")
+' $0 "$@"
The previous solution with the shebang line as
#!/usr/bin/env -S qjs --std
did not work with non-GNU versions of env
Index: abctopdf
==================================================================
--- abctopdf
+++ abctopdf
@@ -1,20 +1,33 @@
-#!/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)
#
-# abctopdf - converts ABC to PDF using abc2svg
+# 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
+# '%%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
@@ -73,21 +86,72 @@
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
+n=0
+command $abcscr --pageheight 29.7cm --fullsvg 1 --musicfont abc2svg "$@" | while read v; do
+ case "$v" in
+ "> $fn
+ fn=
+ ;;
+ "> $fn
+ else
+ echo $v >> /tmp/abc.html
+ fi
+ ;;
+ esac
+done
+ echo '