The script parses an .xhtml file produced with abcm2ps with the -X option. The output is an html5 page
which plays an ogg/mp3 audio file (or webm/mp4 video) and, at the same time, shows the score synchronized
to the music with a moving vertical line cursor. One can also click in the score and playing will resume
precisely at that point.
During play back pages are turned and conversely one can browse to a certain page and playing resumes from
that page. For a couple of abc files the html5 output of svgParse has been tested with Firefox, Opera,
Chrome and IE9. It is may fail for other browsers and/or other abc-files.
You can download mscweb.py and mscweb.exe from:
svgParse.py-v13.zip (10kB Python script)
(the change log)
svgParse.exe-v13.zip (3 Mb stand alone win32 executable for those
who do not have Python)
> python svgParse.py [-v] [-n] [-s margin] [-z height] [-d OUTDIR] name.xhtml
> svgParse.exe [-v] [-n] [-s margin] [-z height] [-d OUTDIR] name.xhtml (stand alone win32 executable)
The script reads a formatted abc-score from name.xhtml and writes an html5 file name_play.html in the same dir as the inputfile. Normally the script reads tempo information from the tempo markings in the .xhtml score file. But when a file named name_beats.txt is present in the same dir as the input file, timing information will be read from name_beats.txt instead and the tempo markings in the score will be ignored. (see below: Syncing)
-v: When the -v option is used name_play.html will contain a visible html video element above the score.
Otherwise an invisible audio element is generated. The video element will play name.webm or
name.mp4. The audio element searches for name.ogg or name.mp3. These media files should
reside in the same directory as name_play.html.
-n: Hide the checkbox that enables synchronization. (in name_play.html)
-s margin: Set the scroll margin to margin pixels. (default width 100px)
When scrolling the score this margin remains visible below and above the current staff. If it is too large
compared to the visible part of the score you won't see the whole staff.
-z height: Set the height percentage of the video element (default 40%). The vertical layout of the page
is proportional: buttons/video/score = 5%/40%/55%. Use this option to make the video element larger or smaller.
-d: When option -d OUTDIR is given name_play.html will be written to directory OUTDIR. Otherwise it is
written to the same directory where name.xhtml resides. For example:
> python svgParse.py /path/to/foo.xhtml
generates the output file /path/to/foo_play.html
> python svgParse.py -d . /path/to/foo.xhtml
generates the output file ./foo_play.html
When the program reads tempo markings from the score (no beat file present) it assumes those tempo markings are in the units implied by the time signature. In, for example, a 7/8 measure the tempo should be given in eights per minute (Q:1/8=...). In a 12/16 measure the tempo should be given in sixteenths (Q:1/16=...).
The javascript code in file name_play.html looks for two optional parameters: the keyword "start"
and a measure number. The keyword "start" causes the playback to start immediately without user interaction.
The measure number places the playback cursor at that measure. Both parameters can be used independently.
For example:
url/to/foo_play.html?start&12 will open the score at measure 12 and start playing automatically.
url/to/foo_play.html?start will open the score at measure 1 and start playing automatically.
url/to/foo_play.html?12 will present the score at measure 12 and wait for user interaction.
url/to/foo_play.html will present the score at measure 1 and wait for user interaction.
The optional file name_beats.txt should contain one line for each measure in the score. Each line starts with a floating point number representing the end time of the corresponding measure in seconds. The program just reads this number and skips the rest of the line. The first line is an exeption; it specifies the start time of the first measure. This allows for a preamble in the media file. The end time of the first measure is specified in line 2 of name_beats.txt and all other measures follow, one on each subsequent line.
While the music is playing you can use the following keys:
p : pause/continue
] or c : jump to begin of next measure
[ or x : jump to begin of previous measure
The name_beats.txt file can be most easily made by opening name_play.html in a browser an checking
the "enable sync" chechbox in the upper right corner. While the audio/video is playing you van now click on the note
that happens to sound at that moment. Only one synchroniztion point per measure is remembered. Once you click on a
note, playback jumps 2 measures backwards and resumes playing, so you can check the result and, when nescesary, click
again on a note in the same measure to improve the timing. A repeated click in the same measure just replaces the
synchronization point in that measure.
When you add a synchronization point, the tempo in all measures before and after that point are updated by interpolation.
That means you do not have to synchronize each measure. If the tempo of a piece is relatively constant it may be
sufficient to synchronize a note at the very beginning and another one somewhere near the end.
When you are satisfied with the synchronization you can save the timing data to a text file by clicking the save button
in the top right corner below the synchronization checkbox. The file should be saved in the same directory where the xhtml
file of the score resides. The file name should be the same as the xhtml file but should end with _beats.txt.
In addition to clicking with the mouse you can also use keyboard shortcuts that become active when synchronization is
enabled. The following actions may allow a more precise synchronization than is possible with the mouse:
, : shorten the duration of the current measure
. : lengthen the duration of the current measure
shift-, : shorten the current and all following measures
shift-. : lengthen the current measure and all following measures
Shortening the duration of a measure means that the cursor traverses the measure faster. Lengthening makes the
cursor move slower. When all measures from the current point onwards are changed (holding the shift key while
pressing comma or dot) the tempo of the cursor changes for the rest of the music. One has to do that only a couple
of times in the beginning of the synchronization process to adjust the cursor approximately to the real audio/video
speed. Thereafter, fine tuning can be done by only changing one measure at a time (comma and dot without holding the shift).
[ or x : go one measure to the left
] or c : go one measure to the right
Before an adjustment is made one should stop play back and move the cursor to the measure where the tempo needs
correction. After the adjustment one moves the cursor at least one more measure to the left and then play back can
be started to check if the correction had the desired effect. If not, stop play back again and repeat the process.
ctrl-, : shorten the initial offset (idle time before cursor starts moving).
ctrl-. : lengthen the initial offset.
In audio and video files the music does not start right away. There is a so called preamble. The display of the
music cursor also has a preamble (called initial offset). With the comma and dot keys while holding the control key
one can adjust this initial offset. This is the first action one should undertake when synchronizing a new media file.
Once cursor and music start simultaneously one can move on to the adjustment of the global tempo of the cursor
with shift-dot and shift-comma. Finally, single measure durations can be changed to correct small deviations or
occasional slow passages in the music.
w : save the timings to a text file: name_beats.txt (when name.xhtml is the input file).
Take care to save the page as a pure text file (.txt) and not as an html file (.html)!
Clicking the save button has the same effect as pressing the w-key.
You can use the p-key to stop or continue playback. When using the keyboard corrections are most easily made when paused. When a measure is changed using the keys, playback jumps to and resumes from the start of that measure. When the initial offset is changed playback jumps to the very beginning.