Real time event accuracy

John O'Hagan research at johnohagan.com
Thu May 10 05:16:36 EDT 2012


On Wed, 09 May 2012 08:52:59 -0700
Tobiah <toby at tobiah.org> wrote:

> I'd like to send MIDI events from python to another
> program.  I'd like advice as to how to accurately
> time the events.  I'll have a list of floating point
> start times in seconds for the events, and I'd like to send them
> off as close to the correct time as possible.

I've done something similar using Fluidsynth (which  I think is cross
platform) to play the midi. It has the advantage that you can send it midi
commands as simple human-readable strings over a socket, like: 

   fluidsynth_socket.send("noteon 0 0 64 \n") 

making it easy to do things on the fly withoutwriting/reading midi files. On
Linux I've found just using: 

    time.sleep(correct_time - time.time())

before sending is accurate to the millisecond, but I understand you have to
specify a (hardware) timer to achieve this for Windows. 

> I'd also appreciate suggestions and pointers to a 
> suitable python MIDI library, and maybe an outline
> of what must be done to get the MIDI events to 
> the other program's MIDI in.
> 

I haven't used it but python-pypm looks about right:

"pyPortMidi is a Python wrapper for PortMidi. PortMidi is a cross-platform C
library for realtime MIDI control. Using pyPortMidi, you can send and receive
MIDI data in realtime from Python.

"Besides using pyPortMidi to communicate to synthesizers and the like, it is
possible to use pyPortMidi as a way to send MIDI messages between software
packages on the same computer."

HTH,

John



More information about the Python-list mailing list