[erlang-questions] help: Erlang MIDI driver for MAC OS X

Joe Armstrong <>
Mon Jan 21 15:29:37 CET 2008


Thanks - I'd discovered this :-)

I have actually made great progress after about 9 hours of searching
and messing around suddenly things
bust into life.

I have now made a primitive OS-X midi driver - so now I can both send
and receive real-time midi events
and make horrible noises.

The interesting thing is that this really does bring home to me how
appallingly difficult it is to write even simple
code today.

According to the midi spec I can play a middle C (midi8 note number
60) by sending three bytes to
my midi device - I just send something like 144,60,75 (144 means "note
on channel 1", 60 is a pitch (middle C) and
75 a "velocity" - how loud to play the note)

Easy you might think:

    1) open /dev/midi
    2) write three bytes

A trivial exercise in any programming language - but NO - there is no
/dev/midi - instead there is an incredible
mess of API routines to open a midi first open a midi client - then
create a midi input and output port and
connect it to the client then get a midi device ref (for the correct
device) then setup a callback routine
for reading midi events - connect the sources the devices and
generally mess around.

The documents to aim in my understanding of this are 1) an API
definition that defines the types of the function
arguments (but without any *definitions* of what things *mean*) and a
number of example programs - which don't
do what I want - fortunately there is Google - a lot of Googling and
some inspired guess work saves the day.

Now all of this mess with APIs strikes me as a total waste of time -
the old unix way of opening a device and
writing three bytes to it is a) easy to understand b) language neutral
(ie does not favor a particular programming language) and c) easy to
use - so why why why^10 is this not the standard way of interfacing
things together?

In the last twenty years all we seem to have done is make simple
problems almost impossibly difficult -
the Unix model (everything is a file) and to do things you just read
and write bytes to these files is
simple, beautiful and easy to understand - the Erlang model is even
better - everything is a process -

To connect things you pipe the outputs of one program into the inputs
of the next - no messing around.

Once I'd made my simple driver things fell into place - no more
idiotic callback routines, type casts and memory
allocations.

When I play notes the midi synthesiser sends me Erlang messages {note,
on|off, Pitch, Velcoity}
to make it play things I sent it noteon and noteoff messages.

This seems very natural to me -

If anybody else is interested in real-time midi control and Erlang
programming please contact me.

Cheers

/Joe Armstrong




On Jan 21, 2008 2:52 PM, G Bulmer <> wrote:
>
> > Date: Fri, 18 Jan 2008 17:35:46 +0100
> > From: "Joe Armstrong" <>
> > Subject: [erlang-questions] help: Erlang MIDI driver for MAC OS X
> ...
>
> > Hello,
> >
> > I'm trying to write an Erlang midi driver to connect an external
> > Roland Synthesizer (SH-201) to
> > a MacBook.
> >
> > So far I can receive MIDI events from the synt but not send events.
> >
> > Does anybody have any experience with the Mac OS X CoreAudio Framework
> >  in particular with the CoreMIDI routines?
> >
>
> I have no experience, but I have been subscribing to Apple Developer
> for years, and I found some old (2004) links which led to these:
> (I assume you have them, but better to be safe than sorry !-)
> http://developer.apple.com/audio/
> http://developer.apple.com/audio/pdf/coreaudio.pdf
> http://developer.apple.com/qa/qa2004/qa1374.html
> http://www.audiosynth.com/sinewavedemo.html
>
> HTH
> G Bulmer
>
> PS: I thought Apples mailing list UI was unbelievably unfriendly. I
> clicked on "Mailing List Archives" and it looked empty! I had to
> really dig. UI guidelines? Horrid!
> PPS: I couldn't find the coreaudio swiki, but this may be why: http://
> lists.apple.com/archives/coreaudio-api/2006/Jan/msg00223.html
>
>
>



More information about the erlang-questions mailing list