[gsharp-devel] Connecting portmidi with gsharp...

Robert Strandh strandh at labri.fr
Thu Feb 2 01:37:16 UTC 2006


Thanassis Zervopoulos writes:
 > I'd like to connect my midi keyboard with gsharp so that i'll be able to
 > write a song with midi and not with the keyboard of my computer.

Sounds like a good idea to me. 

 > With wich files should i mess to create that? I know that there are a lot of
 > problems yet, but i'd like to work on this feature and add it on gsharp, if
 > it doesn't exist yet.

It does not exist yet.  There are several problems that need to be
solved:

  * You need to inject the MIDI events into the CLIM event queue.
    Alternatively, you could start a separate thread to read from the
    MIDI device, but then you get potential synchronization problems.
    I would think the easiest thing to do is to use the X server to
    resolve such synchronization problem.  You might have to define a
    new subclass of `event' (midi-event) in CLIM, but that's easy. 

  * You need to create a command table that can handle midi events
    (easy). 

The hard part is to know what to do with the events.  Specifically, do
you take into account things like duration.  I suggest that you don't
and that you use only pitch information.  There are still some things
to consider though:

  * If you receive an event that has the same pitch as one of the
    notes in the scale which is current at the cursor (which we know
    from the key signature), then insert the corresponding note.

  * If you receive an event that does not have the same pitch as one
    of the notes in the scale which is current at the cursor, then
    what to do?  I think the answer is that you should search the key
    signatures in both directions (more flats, more sharps) from the
    current one, until you reach a scale that has a note with the
    pitch of the event, and insert that note.

To obtain chords, you would create a new cluster only when you receive
the first note-on MIDI message.  When receiving a note-on message and
there are already keys for which you have received a note-on message
but no corresponding note-off message, you would instead add the note
to the previous cluster.  

If you want to avoid having to use both the MIDI keyboard and the
computer keyboard (which you would have to use (sometimes with both
hands) for things like changing the note head, the duration, the
flags, the dots, etc., you could map some other keys on the MIDI
keyboard to the Gsharp commands that accomplish this.

It is probably not terribly important what files you put things in at
the moment, but you probably need a bunch of commands and a command
table that you might put either in gui.lisp or in a new file
midi-input.lisp.  The modes.lisp file contains key bindings, but you
might as well put the new bindings in midi-input.lisp as well.  

Feel free to ask some more questions on this list if you get stuck,
and feel free to comment on my suggestions above. 
-- 
Robert Strandh

---------------------------------------------------------------------
Greenspun's Tenth Rule of Programming: any sufficiently complicated C
or Fortran program contains an ad hoc informally-specified bug-ridden
slow implementation of half of Common Lisp.
---------------------------------------------------------------------



More information about the gsharp-devel mailing list