Squeak MIDI output with Linux / ALSA
Florian Hars
florian at hars.de
Sun Mar 11 19:33:34 UTC 2007
I spent the sunday reading some ALSA documentation and produced a replacement
for sqUnixMIDI.c (which I compiled into Squeak by hacking the generated
Makefiles, yuck), which compiles, and the three or so functions Scratch uses
actually do something useful (I ignored MIDI input, the drumkit and other
things). Maybe somebody with a better (read: any) understanding of the squeak
internals can use this as a basis to create something that actually works and
is integrated into the build environment.
Some observations that should be adressed in a final version:
midiInit is only ever called when a note is played. So the MIDI output port
will only come into existence when the first note has been sent, and only then
can you connect the port to the input port of a sythesizer. This connection
will be destroyed if you stop the script in Scratch (in sqMIDIClosePort), so
you have to reconnect before starting the next script. There *must* be
something better than that.
There is a slight mismatch between Squeaks sqMIDIGetPortCount and the ability
to create as many ports as you want in ALSA.
The ALSA sequencer can schedule events, but the return type of
snd_seq_queue_status_get_tick_time is (typedefed to) unsigned int, so I do not
know if the assumption "The MIDI clock is assumed to wrap at or before half the
maximum positive SmallInteger value. This allows events to be scheduled
into the future without overflowing into LargePositiveIntegers." holds. As far
as I understand the ALSA documentation, the client shouldn't make these
assumtion at all and refrain from guessing at future clock values: "As each
sequencer queue has it's own clock the only way to deliver events at the right
time is by using the relative timestamp format. When the event arrives at the
queue it is normalised to absolute format."
(http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html)
My code is probably broken in this regard (Scratch produces only immediate events).
If you route the Squeak MIDI output to a sequencer that outputs to jack, Squeak
may no longer be able to open the normal ALSA audio device, so you should
either use a synth that does not require jack like timidity -iA -oS, or
implement jack output for Squeak. The latter could be difficult, the former has
the disadvantage of high latency (at least on my machine I have a noticable
delay if I send events from an external keyboard to timidity).
Yours, Florian Hars.
PS: http://www.squeakvm.org/unix/ mentions something like "svn export
http://squeakvm.org/svn/squeak/tags/unix-3.9-8", but that doesn't exist, there
is no tag past unix-3.9-4 there.
--
But our moral language is fragmented; our contemporaries reject the Kantian
hunch that choosing those things most admirable and plausible as ends in
themselves is the best practice; autonomous sources of the good are everywhere
brown and broken. Thus we have PHP. http://lambda-the-ultimate.org/node/1463
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqALSAMIDI.c
Type: text/x-csrc
Size: 18299 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070311/14707831/sqALSAMIDI.c
More information about the Squeak-dev
mailing list
|