|
About Andrew Choi
MIDI Programs
MIDI File Player (External Device)
MIDI Destination Pop-Up Button
Other Programs Cocoa Sample Programs Syntax Coloring Using Flex Algorithms Jazz Chord Analysis as Optimization
|
A blog where I will write mostly about programming in Cocoa and CoreMIDI, and experiences from my ports of Emacs and XEmacs to the Mac OS.
A Python extension module for sending and receiving sysex messages like the one I posted in the last few days is quite useful and a lot of fun to play with. But that would be too easy :-). My goal is to write MIDI applications that are extendible and customizable. I want to use Python as a scripting language and let my users write plugins in it to extend my applications.
The new code in the FCM project demonstrates how MIDI name doc utility can import Python plugins and call functions in them. The code below is that of a Python plugin that fetches patch names from a E-mu Morpheus. Its a bit more compact than the corresponding Objective-C code. The nice thing about such a design is users can write their own plugins for their synths (I cant possibly write all of them) and manufacturers can write plugins for new devices (this ensure future usefulness of an application). Its strangely satisfying to be able to implement a tool so quickly that harnesses the power of the Python language for solving the extendibility problem. The Opcode PatchTalk language, for those who know what it is, must have been much harder to implement, yet much less powerful. I believe many types of applications can benefit from a similar design. import FCM
Just added a bit more error and exception checking in this slightly improved version of the FCM Python extension module. When a library is called from an interpreter and not from compiled code, it should behave more gracefully when calls are made in sequences it doesnt expect. At least it shouldnt crash the interpreter!
I spent most of the day writing a Python extension module that wraps around the C/CoreFoundation code in FCM. As a result FCM can now be called from Python! Its really a lot of fun to play with. The following is a transcript of the use of the extension module in the Python interpreter to send a preset list request sysex to a E-mu Morpheus and then receive the preset list data from it.
~/Documents/Programming/FCM-Python$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import FCM
>>> FCM.initializeClient()
>>> FCM.sysexDeviceNames()
['Morpheus']
>>> d = FCM.SysexDevice('Morpheus')
>>> d.send('\xf0\x18\x0c\x00\x12\xf7')
>>> d.bytesReceived()
3336
>>> b = d.receive()
>>> b
"\xf0\x18\x0c\x00\x13\x00\x02Mph:Z-Synth \x00Real:PnoVibe\x00Cmp:ElecPno \x00Pad
:Strings \x00Bass:UpRight\x00Gtr:Trippy \x00Ld:Grunge \x00Atm:RaveGruv\x00Voc
:Why? \x00Drum:Sweep \x00Mph:KlavKlip\x00Mph:FluteToo\x00Mph:AirStrg \x00Mph
:Voices \x00Mph:Whisper \x00Mph:RhyOfLfe\x00Mph:MetalMlt\x00Mph:Phazbraz\x00Mph
:RezzSlth\x00Mph:SteinChl\x00Real:Piano \x00Real:E.Piano\x00Real:StnBass\x00Rea
l:Flute \x00Real:Mute Me\x00Real:MstyVib\x00Real:ExAcGtr\x00Real:Str<Chr\x00Rea
l:BrasStr\x00Real:StnTine\x00Cmp:ChikWill\x00Cmp:2 Pianos\x00Cmp:RingFire\x00Cmp
[...]
>>>
The document Extending and Embedding the Python Interpreter provides much of the information needed to write the extension module. Whatever information is lacking there can be found by reading the source code of Python modules and objects.Figuring out how to use put the source of the extension module in an Xcode project requires a bit of experimentation. I ended up using a shell script build phase that invokes the Python distutils. Once the input and output dependences in the information panel of the shell script build phase have been set up properly, building the target behaves very much as one would expect. Note that to add items to it, hit the return key when the inputs or outputs box is selected. This isnt obvious because add and delete buttons are missing from the information panel. Of course one can still build from the command line by typing
python setup.py build
The Fish Creek MIDI framework (FCM) has evolved again. This version implements everything, including send and receive requests, MIDI client, and sysex devices, in C/Core Foundation code. It currently handles only sysex messages. The handling of note messages will be implemented after completion of the ensemble interface.
Its interesting that Mac users are willing to pay for pre-built/slightly enhanced free software. On the Mac I suppose it started as early as the many ports of TeX on Mac OS classic. Im not thinking of Textures either, which I thought was a legitimate product; Im thinking of the simpler ports. I was looking at MacGIMP and I wondered whether the developers had posted the source for building their distribution: I wasnt able to find any on their web site. config.guess and config.sub in the root directory with ones in /usr/share/libtool/, and replace the files ltconfig and ltmain.sh in the root directory with ltconfig13 and ltmain13, respectively.Heres how each package is configured. After that run make and sudo make install.
/usr/local/bin/gimp from an xterm. Easy, isnt it? Just saved you $25 :-).
|
Lists
Less-Known Facts About Emacs
Chinese Restaurants in Calgary
Calgary/Banff Tourist Attractions
Top-10 Reason I Stopped Working on Emacs
Misc
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 2003, 2004, 2005 Andrew Choi (Contact Information). | Created with FCBlog |