Implementing real time MIDI playback
After some thought, I decided to give it a try and implement real time playback using the MIDI Streams API. I installed ctypes, an outstanding Python library to support native DLL calls from Python. After hacking with it a little bit, I managed to implement the basic midiStreamOpen and midiStreamClose calls. The library is actually fairly easy to use, but there were a few gotchas:
In the end, everything ran fine. I'm now working on the hardest part - the midiStreamOut call. The call itself is easy, bu I have first to set up the MIDIHDR and MIDIEVENT buffers. Both structures form simple linked lists with real C pointers, and that's something that I haven't done for a long time (being first a Pascal/Delphi nut, and now a Python lover). I fear that a few segfaults expect me there.
There is another thing that I absolutely have to do, that is to understand better the MIDI tempo stuff. Some of the information on the MIDI header is tempo related. My current model for the guitar is time-based -- the argument for the right hand movement defines how long does it take for each beat, in seconds. Now I have to change everything to expressed in terms of quarter notes and beats per minute. It's a small paradigm change, but clearly for better, and I'm still on the early stages of design so it's welcome.
- I mistakenly assumed that I would have to load the mmsystem.dll library. In fact, I had to load winmm.dll. What made this problem worse is that the error message when trying to load mmsystem.dll is totally misleading, and I had to count on the help of the ctypes-users mailing list to solve it.
- The winmm.dll library is 16 bit - weird, but understandable, given Microsoft tradition. This was not an issue up to this point, but I'm better be prepared for surprises.
- It takes some time to get to speed to translate C protoype definitions (with all those ugly hungary notation names) in the correspondent ctypes for Python. It's not hard, but a few mistakes were met with segfaults and stuff like that.
In the end, everything ran fine. I'm now working on the hardest part - the midiStreamOut call. The call itself is easy, bu I have first to set up the MIDIHDR and MIDIEVENT buffers. Both structures form simple linked lists with real C pointers, and that's something that I haven't done for a long time (being first a Pascal/Delphi nut, and now a Python lover). I fear that a few segfaults expect me there.
There is another thing that I absolutely have to do, that is to understand better the MIDI tempo stuff. Some of the information on the MIDI header is tempo related. My current model for the guitar is time-based -- the argument for the right hand movement defines how long does it take for each beat, in seconds. Now I have to change everything to expressed in terms of quarter notes and beats per minute. It's a small paradigm change, but clearly for better, and I'm still on the early stages of design so it's welcome.
3 Comments:
At April 4, 2006 at 2:28 PM, Anonymous said…
I've been looking for a Python MIDI module.
Is yours available for download (or a tutorial on what you did with ctypes?). I've done a couple simple things with ctypes but I'm not familiar with the original .dll so I doubt it would be fast for me to go that route.
Is your module documented at all?
Any other recommendations appreciated. ;>
At March 4, 2016 at 7:55 PM, Anonymous said…
ninest123 16.03
prada outlet, nike outlet, longchamp outlet, burberry outlet, gucci handbags, ralph lauren polo, cheap jordans, louis vuitton outlet, louis vuitton outlet online, oakley sunglasses, uggs on sale, louis vuitton outlet, tiffany jewelry, replica watches, ralph lauren outlet, michael kors outlet, longchamp outlet, cheap oakley sunglasses, ray ban sunglasses, michael kors handbags, replica watches, michael kors outlet online, oakley sunglasses, uggs on sale, louboutin shoes, christian louboutin, ray ban sunglasses, uggs outlet, nike free, christian louboutin, uggs outlet, tiffany jewelry, nike air max, oakley sunglasses, longchamp bags, uggs on sale, michael kors outlet online, michael kors outlet online, nike air max, louis vuitton handbags, oakley sunglasses, louis vuitton, ray ban sunglasses, louboutin uk, michael kors, tory burch outlet, burberry factory outlet, prada handbags
At March 4, 2016 at 8:01 PM, Anonymous said…
swarovski jewelry, coach outlet, links of london uk, canada goose, canada goose pas cher, moncler, barbour, ugg pas cher, louis vuitton, supra shoes, converse, wedding dresses uk, pandora charms, canada goose uk, karen millen uk, ugg,uggs,uggs canada, canada goose outlet, louis vuitton uk, pandora uk, replica watches, moncler, moncler pas cher, ugg,ugg australia,ugg italia, moncler, swarovski uk, canada goose outlet, canada goose jackets, moncler, converse shoes outlet, bottes ugg pas cher, barbour jackets uk, canada goose jackets, hollister, marc jacobs, thomas sabo uk, ugg uk, toms shoes, moncler uk, sac louis vuitton, sac louis vuitton, gucci, pandora jewelry, moncler jackets, juicy couture outlet, pandora jewelry, montre pas cher, juicy couture outlet, canada goose, louis vuitton, moncler outlet, ray ban, lancel
ninest123 16.03
Post a Comment
<< Home