« The Post slips up while reviewing Michael Nyman's latest | Main | Quote of the day: From LWN »

Beginning to produce results

For a personal project, I'm working on a translator from the ABC music format into SVG. The code will be free software, of course, and available from my Bazaar repository.

My first code turned into a horrible mess; for example, the NoteToken class was returned from the regex-based parsing code. This class ended up with attributes for the note's pitch and duration, and also had an as_svg() method. Yuck!

In the past two weeks I've cleaned things up and resumed making progress. After rewriting the parser using PLY, there are now separate Note and NoteGlyph classes, and the parser tokens are no longer also responsible for rendering. This week I've implemented a few symbols, accidentals, and chords.

Here's an SVG example; it should appear in Firefox, Opera, and probably in Safari. If you're using Internet Explorer, sorry; I'll eventually set up an SVG to PNG conversion, but not right now. The music isn't anything in particular, just random things that exercise various parts of the code. The blue border is added for debugging purposes, eventually I'll take it out. The bass clef symbol appears in Opera, but not in Firefox 3.0 or Safari; I'll worry about that later (and maybe Firefox 3.1 will fix it!).

[Music staff bearing a number of notes]

ABC is a complicated format and only a very small subset of it is implemented, but I'm getting close to being able to typeset the beginner- or intermedate-level cello music that I play. The two big missing things are drawing the beams between notes, and drawing slurs across a set of notes; those two features are a little frightening. My plan is to introduce BeamedNote and SlurredNote, turning the flat list of note glyphs into a tree. We'll see how that goes.

About

This page contains a single entry from the blog posted on September 13, 2008 8:30 AM.

The previous post in this blog was The Post slips up while reviewing Michael Nyman's latest.

The next post in this blog is Quote of the day: From LWN.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31