David Welton: Concurrency
We've been having some interesting discussions on the Hecl mailing list about how to do concurrency:
http://sourceforge.net/mailarchive/message.php?msg_id=19566676
(although it seems SF has managed to lose a portion of the conversation!)
When all things are said and done, we have a couple of options:
- Try and immitate Tcl's select-based event loop. Not really concurrency, but it does a good job of "faking it" for things like GUI's, if done correctly. For the right kind of code, it makes life very easy for the programmer, as you don't have to think too much about concurrency issues, and you don't have to deal with threads. The downside for J2ME is that we don't have the equivalent of select, so we'd have to do the system with threads, which would probably be costly in terms of the resources required to set it up.
- Tcl style threads, where each thread gets its own interpreter, and data is mostly shared by message passing between the threads. Conceptually, I think this is a cleaner way of doing threads, compared with 'sharing everything and using mutexes', and it's a little closer to how Erlang handles concurrency, which is very nice indeed. For J2ME, I'm a little bit worried that this might be too resource intensive, and potentially slow to launch new threads.
- A low-level interface to threads that just exposes the Java API. This would be nice, and lightweight, but potentially quite complex to program if we attempt to make the interpreter reentrant. There are a lot of issues with things like stack frames - for instance, say one subroutine (proc) adds a stack frame, then a second thread kicks in and exits a proc, tearing down the stack frame again. If you put a big lock around procs, that just leads to blockage if a proc is doing some sort of long running calculation, defeating the whole point of the exersize.
- Deal with concurrency on a case-by-case basis, building it into each command that needs it. Not very elegant, and probably requires just as much work, if not more, than other options.

They represent exactly the same thing, yet someone who knows music
needs a split second to decode the below but a few seconds for the above
(if they understand lilypond's syntaxis). In fact, at first I thought
that I had done something wrong in invoking lilypond-book to
produce that snippet, because I had misparsed the code above (which,
incidentally, is one bar of some actual music that I have in my
~/data/audio/lilypond directory)
The plain text interface certainly does have some
advantages, but IMO the downsides by far outweigh the benefits. In
general, lilypond is not well suited as a way to actually write
music, as opposed to simply typesetting already existing music. I did
actually follow a course on harmonics (although I never finished it due
to lack of time); when writing some new piece, I find that it often far
easier to do the actual writing on a piece of paper and then enter that
in lilypond syntaxis, rather than getting distracted over the lilypond
syntaxis while trying to concentrate on what chords I can and/or want to
use. It is unnatural, and would look like a Japanese person being forced
to read and write texts like 'gaka ga e o kaita' which then get
postprocesssed into something like ' ' (look ma,
Unicode!). Or, in other words: why isn't there just an input method to
write music? There are unicode characters for musical notes,
you know...
When comparing lilypond to finale, it is not hard to understand that
entering music in a graphical environment is just so much easier. When I
last used it, Finale had four input methods: one with keyboard and mouse
(use the numeric keys on the keyboard to enter the desired note length
and the mouse to enter the pitch); one with keyboard only (use abcdefg
etc. to choose the pitch, and the same numeric keys to enter the desired
length); one with keyboard and MIDI keyboard (use the numeric keys to
enter a desired note length, and just press a note on the MIDI keyboard
to choose it); and finally, it can also quantisise music as you play it
(which is the fastest, but least accurate, method to enter music).
Lilypond only allows entering music with the keyboard directly, and then
only displays notes after 'compiling' them, so that you cannot see your
mistakes and typos until much later. I'm disregarding midi2ly, which
converts MIDI files to lilypond input files in a reasonably good way;
but Finale has MIDI import functionality as well, I do not consider that
to be an 'Input Method' as such.
After having entered the music, a musician will want to do something
with it. Have the computer play it, for instance, or print it out so
that he or she can rehearse it and eventually play it themselves.
Lilypond will do neither by itself; however, it can produce postscript,
PDF, and DVI files which one can use to print, and/or MIDI files which
one can have the computer play. The printouts are great, as I've said
before; but playing the MIDI files is another matter entirely.
As I've explained earlier, playing MIDI used to be done through
hardware. When I still had a working SB16-compatible card, I could play
MIDI files on my computer perfectly fine by just using the driver for
that sound card. Since I currently depend mostly on ESS1371-compatible
cards, that do not havve any hardware MIDI synthesizer, however, that
doesn't work. So I have to use software sequencing instead. On Windows,
software sequencing is done by the sound card's driver. On Linux, there
is no software sequencing being done by any driver, so it all has to be
done in userland. In theory, that's just fine. Unfortunately, the
implementation sucks.
The only software MIDI synthesizer available on Debian is