Recent direction of ScoreRender

April 5th, 2009

Looks like another half year has passed without any significant improvement on ScoreRender… actually not really. There is some work behind the scene, but not announcement yet.

  1. A certain user has been facing problem with hosted web sites, so it looks like there IS need to make it work with web hosts — to be specific, ScoreRender needs to cope with the case when PHP functionas are disabled due to security reasons. It shouldn’t be hard. The hardest part is how it can work with older ImageMagick and other related software. I don’t see any solution yet.
  2. IE6 PNG image transparency seems not as dead-end as I thought. With the image filter published by TwinHelix, it looks trivial to add the support for IE6. At least way better than the big fat warning with current releases.

My most admired instrument

October 2nd, 2008

Though I used to play piano during old days (that’s why most of the demo pieces are from piano :) ), pianist aren’t the kind of music player I admire most. At least, not as strong as towards drummer. I never said pianist is no good; their virtuosity for difficult (sometimes terrific) pieces keeps me still addicted to concertos like Rachmaninoff’s and Prokofiev’s ones; but there are entirely different challenges for drummers, at least viewed from outsider’s angle. Example?

Music fragment in "mup" notation

(no midi download)

Sounds familiar? How about this one:

Music fragment in "abc" notation

(no midi download)

Probably even starters can learn these rhythms very soon, as they are easy ones. Even people who haven’t played drum in their live can tap these rhythms with finger in no time (hey, drum games on game consoles don’t count!). But I haven’t finished: what if one need to:

  • Beat these rhythms non-stop for more than 10 minutes
  • Make absolutely no single error
  • Play at constant speed thoughout the whole passage, without anybody noticing any tempo change

That is not so easy. This is the case for first rhythm, which comes from Ravel’s Boléro. Think about beating the same rhythm again and again and again for 12+ minutes without any error, and controlling tempo / loudness at the same time! Probably even professional drummers can’t do that at single pass. It needs undivided attention and dedication in order to achieve the result.

For 2nd rhythm, which comes from Shostakovich’s 7th Symphony, it’s not so demanding for drummer — just about 7-8 minutes instead of 12+ minutes (in Ravel’s own interpretation probably around 17 minutes). But every other element is the same: repeat the same thing over and over, non-stop, no mistake, very gradual crescendo like Boléro. And again, it’s snare drum’s call.

No, I don’t think I can devote such concentration, that’s why I give my thumbs up to these drummers.

Support on Windows

September 19th, 2008

After several nights of hair pulling, Windows support is there, as well as support for yet another notation: Philip’s Music Writer.

Let me talk about Windows support first. It took me way too much time to finish it than I anticipated. There are a couple of scaring problems for using PHP on Windows.

Command execution on Windows

Under PHP documentation of system() function, people have been talking about PHP incapable of executing any command line with more than 2 double quotes, since PHP 4.3.x. So the following command line:

"C:\Program Files\ImageMagick\convert.exe" "C:\Temp Folder\1.gif" C:\1.png

Produces an instant failure (because there are 4 double quotes). And adding insult to injury: it’s not limited to system(), any other program execution functions like exec(), popen() are affected as well. Now the newest stable version is 5.2.6, guess what? Nothing changed. And people simply invented schemes to circumvent the bug, the most obvious one being using batch file, and that’s what I end up doing as well.

tempnam() stupidity on Windows

So this is an undocumented feature: tempnam() on Windows only uses 3 letter prefix and a sequentially increasing counter as suffix! Now compare with the Unix counterpart — people have been complaining how this temp file creation is a security problem on Unix, but it’s suddenly not a security problem anymore on Windows! Fantastic!

Other people have been bragging programmers not to invent their own schemes, and use native functions instead. But no way, I won’t listen to such “recommendations”!


For Philip’s Music Writer support, it is also not as straight forward as it should be, the main problem being on image conversion. No matter how I indicated sheet size in PMW source, ImageMagick invariably insists image size is 612×792 (which translates to 8.5" × 11" under 72 DPI)! And the final resulting PNG file is a 1×1 pixel dot.

Probably the problem is on PMW’s side. Normally within PostScript preamble part there is at least a declaration of %%BoundingBox, specifying its size (some even go as far as specifying %%DocumentPaperSizes and %%HiResBoundingBox); yet nothing like that exists in PostScripts produced by PMW. Anyway, that problem is temporarily fixed by forcing paper size using ImageMagick -page option.

0.2.0 debutted

August 27th, 2008

The much delayed release is out now. Download it by clicking on download icon!

Here is the list of more prominent changes since 0.1.x version:

  1. Remove markup configuration, and adds lots more config options
  2. Show statistics in dashboard
  3. Clickable image showing music source
  4. Start to migrate to PHP5-style classes
  5. Image conversion routine redone
  6. Allow clearing cache within admin page

However, to be sincere, some of the changes do make me worried, namely:

  1. Requirement of PHP5: though PHP5 growth is a bit stronger after PHP4 end of life, we are still seeing 41% adoption of PHP5 only (statistics by nexen). That means half of potential users can’t upgrade…
  2. Requirement of newer ImageMagick: I can’t stop cursing ImageMagick maintainers for this one. All packagers and software developers used to curse them, now I can feel the hatred in the guts too. ImageMagick can change API, compatilibility and even command line options between any minor, or even patch level releases! Damn it. Software versioning is completely meaningless for ImageMagick. As I have said before, -channel alpha no more creates alpha channel, causing all transparency rendering broken with previous release. However, not that many web servers have newest ImageMagick installed. I’d say the restriction is even more serious than PHP one. Perhaps I may need to think of another way to circumvent the problem in the coming releases.
  3. Potential of XSS on showcode.php: right now showcode.php reads music fragment from POST request and dumps them only after minimal content filtering. I’m a bit worried it can be susceptible to XSS. Perhaps there is need to fire up XSS scanners in short future.

All notations side by side

August 26th, 2008

Upon a time I have had compared the results of various notations side by side in my own blog, split into several posts. But comparing them within one single post is cooler, and easier for comparison purpose. So here presents the beginning 2 bars of Prokofiev Piano Sonata No. 8, second movement:

ABC:

Music fragment in "abc" notation

(midi download)

Guido:

Music fragment in "guido" notation

(no midi download)

Mup

Music fragment in "mup" notation

(no midi download)

Lilypond

Music fragment in "lilypond" notation

(no midi download)

PMW:

Music fragment in "pmw" notation

(midi download)

Among all notations, Lilypond takes me the most time to get positions of various dynamics and texts right. Much time is spent on Guido one too, but documentation on Guido is considerably easier to read than Lilypond’s, and much manual layout simply can’t be done by Guido :( .

I have been saying that ABC notation shows promise; now I want to take back to word. It doesn’t even allow specifying text marks in arbitrary position! This is 2008, not 1988, but still. Though ABC standard version 2.0 has it, but (1) it’s a draft, and (2) which software is implementing 2.0 standard?

The above paragraph partially reflects my lack of understanding of ABC format and abcm2ps, which already tries to implement 2.0 draft standard.


2008-09-28 Edit: Add Philip’s Music Writer counterpart since it is recently supported.

2010-02-21 Edit: Recently upgraded PMW to version 4.21, now adjusting staff spacing is not allowed for staff 0 (Tempo). Besides, ABC fragment is adjusted a bit, so slurs and expressive marks are correctly placed above/below notes. One problem remains: position of dynamics still can’t be adjusted.

Resuming development

August 22nd, 2008

ScoreRender have been put aside for some time, but right now I think it’s time for momentum again. The code still needs some scrutiny, but mostly works, as this site has been using development code for more than a year and there are no obvious breakage (yet).

The most problematic part is interaction of ImageMagick and various PostScript files generated by the programs. They constantly change, that’s the reason development is more difficult.

  • Only recently did I discover ImageMagick no more creates alpha channel with -channel alpha or -channel rgba options; it must be explictly created with -alpha activate. Yet this change is only added to ImageMagick 1 year ago. What about compatibility with older web servers? Probably I need to sacrifice something this time. No wonder some web apps supports GraphicsMagick too, though IMO that’s more like a failure than success.
  • And abcm2ps changed too. Old testing score fragments no more work on development version of abcm2ps. Urgh.
  • I decided I was fed up with PHP 4.x. Specifically it’s about the incompatibility between PHP 4.x and 5.x, it is no more beneficial to support classes used in 4.x. Thus next version will be PHP 5 only. During the old days PHP 4 end of life still haven’t been declared, but right now it makes more sense. Not to mention I don’t have any machine with PHP 4 now, so testing will be difficult.

That’s about it. Hopefully there will be a new release in these few days, when typhoon is storming here.

Guess this melody?

July 14th, 2008

Hint: it comes from main theme of a certain game, a classics within its genre. Few player would ever forget the melody, it’s so simple, so crystal clear, and so touching.

Music fragment in "mup" notation

(no midi download)

2008-10-02 edit: Time to disclose the answer. It’s the opening theme of Final Fantasy X, played with acoustic piano. And no, the music on main FFX website is just midi, it can’t represent the quality of the real game music.

PMX / M-Tx / MusixTex support delayed

June 12th, 2007

With the upcoming version (0.2), it should be possible to set image width so that the image may not overflow blog content area width, thus content layout would not be ‘broken’. However, since TeX does not provide any control for arbitrary page width, any TeX-using music rendering applications (the most prominent one being PMX, M-Tx and MusixTex) inherits such problem, and images rendered by them can’t perform any control on image width. So I’m temporarily postponing the support until 0.3.x.

Right now I can think of several solutions, of which none is perfect:

  1. Resize image: the simplest and most obvious method. But won’t work if people change theme frequently — after each theme change images have to be regenerated or images might overflow again. Not to mention tall images may not be very visible again after resizing.
  2. Clipped to fit width: again, what happens after each theme change?
  3. Installing extra TeX package: I’m told that Vmargin TeX package allows arbitrary page size. I’m also told that package is exotic and not included in most TeX systems by default; but it looks like Vmargin is more widespread than I’ve thought. At least on Linux — Vmargin belongs to default LaTeX package for RPM-based distributions, and belongs to some LaTeX extra package for Debian-based ones. I’ll give it some more thinking later.
  4. Use CSS overflow property: looks like the best solution so far, but still has its own problem, namely old browser compatibility. Though I wouldn’t care too much about browsers without proper CSS support…

Please leave message here if anybody has good solution!

Lilypond with international characters

June 11th, 2007

Music fragment in "lilypond" notation

(no midi download)

Neat, isn’t it? This example is taken from the one contained in Debian package, albeit the package itself is terribly outdated and unmaintained until Debian Etch comes. Even though the example was supposed to be usable during Lilypond 2.2.x days only (!), with some changes (specifically, filtered with convert-ly to remove obsolete constructs), it runs happily with newest Lilypond.

But — this absolutely isn’t for the faint of heart.

  • It took 35+ minute to render! Yes, 35+ minute 100% CPU time on Celeron 2.4GHz. Very likely due to embedding chinese font glyph outline into postscript file.
  • One has to tweak fontconfig configuration file under Linux. Fontconfig has been notoriously bad at choosing CJK fonts. Default config prefers Japanese fonts, and imagine what it looks like when a mixture of Japanese fonts and Chinese fonts are used in lyrics.
  • Installing Chinese fonts — actually this is the easy part. The score fragment in this post is rendered with Kai face (楷書) from CJKUnifonts, which is readily available in all major Linux distributions if Chinese support is enabled. Rendering Japanese and Korean requires fonts for corresponding language, of course.

Writing document for PHP code

June 1st, 2007

Since last night I start to consider writing more complete documentation inside the plugin itself. Of course it’s just API documentation, which is NOT a replacement of how to use the plugin. (Hey, I know, I know, this plugin has no public API, it is just for converting posts and comments, and not intended to be used for themes and templates)

The immediate solution found by googling is phpDocumentor. Not a very brilliant solution, but enough to get the job done, especially good because it parses PHP files quickly and is easy to learn. For example:


/**
 * Error constant used when content is known to be invalid or dangerous.
 *
 * Dangerous content means special constructs causing
 * inclusion of another file or command execution, etc.
 */
define('ERR_INVALID_INPUT', -1);

/**
 * Generate HTML content from error message or rendered image
 * @param string $input Music fragment to be rendered
 * @param object $render PHP object created for rendering relevant music fragment
 * @return string $html The HTML content
 */
function scorerender_process_content ($input, $render)
{

phpDocumentor has a quick start guide on how to install itself through Pear. After getting the doc done, the hardest part is over; generating document is relatively easy. Just a single command:

phpdoc -o HTML:frames:earthli -f *.php -t docs

ScoreRender inside phpdoc

And voila! Documents are readily available under docs/ directory for your browsing pleasure. Generally this step just takes a few seconds for small project with several small PHP files. What does it look like? See the pic on the right.