MIDI Programs

Other Programs

Cocoa Sample Programs

Algorithms

A blog where I will write mostly about programming in Cocoa, Carbon, and CoreMIDI, and experiences from my ports of Emacs and XEmacs to Mac OS X.

➼ Visit My New OS X Programming Blog

MagicButton - another TOE Sample Program

Monday January 23, 2006

I came back from my vacation in Hong Kong about two weeks ago. I have yet to go through and organize all the photographs I took. But here’s one of a few flowers on a Bauhinia blakeana. They bloom during the “winter” there, which has daytime temperatures of 15 to 20 degrees Celsius.


I’ve been waiting to get a Core Duo iMac so I can start writing this blog using iWeb. Well, things happen a little slower here and they will probably arrived in computer stores some time this week.

In the mean time, I was asked on a few occasions whether there is a way to send short MIDI control messages to MIDI devices. With TOE, that’s quite easy to do if one can write a few lines of Python or Scheme. The result is of course a command-line application. TOE also has a C API which can be used in a Cocoa application, as demonstrated in my Program Panel project.

One way to implement a Cocoa application and still keep it customizable with Python or Scheme is to embed the Python or Scheme interepreter in the application. I wrote a new sample project MagicButton to illustrate how to do this (here’s the application). To build it, first build the Python extension target in the TOE project included in the archive. The action invoked when the button is clicked can be customized by modifying the definition of the function button in the file action.py in the Resources folder of the application bundle. For example, the contents of that file in the sample project is:
import TOE

def button(): d = TOE.Destination('Morpheus') d.Send('\xb0\x07\x64') d.Send('\xc0\x7f')

That sends a volume change of 100 and program change of 127 to channel 1 on the Morpheus. Note that all the power of the Python language and the TOE extension is at your disposal for implementing the function button. So you can pretty much do anything you like. Instead of a button, you can use a slider, stepper, or textbox and pass a value to the Python function, which can be sent to the MIDI device. That, as they say, is left as an exercise.

January 2006
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Nov  Feb

xml

Forums

My Projects

Lists