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.

Band-in-a-Box Format File Reader Source Code

Friday November 4, 2005

I have released my code for extracting chord sequences from Band-in-a-Box format files today. Partly I do this as “advertisement” for TOE. And to be honest, partly because I’m a little tired of being asked for it (if only I get a penny everytime ... :-). As you can see, the code is very simple and most of it was worked out in a day. Due to its origin (it is part of MyJazzBand), I’m only allowing non-commercial use of the code. Additional restrictions on it are the same as the original BSD license (attribution, advertising clause, etc.).

This is part of the software licensing model for my “business”. The next version of MyJazzBand will support user-defined styles, which will be specified in scripting languages such as Python and Scheme. I will open the source code that implements this, which will include new versions of the jazz theory classes and MIDI note generators that I have written about. I’d like people to learn from it, use it for personal purposes, use it to teach classes, and conduct research with it. But I can’t complete with commercial applications based on my own library: I’ll have to both maintain it and develop and sell the applications!

So here’s the model. Low-level TOE code (such as the current Sysex and Destination classes) will be released under the original BSD license. High-level TOE code (for supporting user-defined styles, for example) will be released under a “non-commerical use” software license (such as the one for BiaBReader). The applications I will sell will of course still be close source.

More TOE Sample Code - Bank and Program Panel

Wednesday November 2, 2005

A while ago I wrote some code to display a panel for browsing banks and programs on MIDI devices. That code used Cocoa bindings which made most of it quite clean. A big portion of that code, however, was for accessing CoreMIDI and parsing XML to construct the bank and program lists. Now that I have written TOE, I can just call it to get the banks and programs. The program will also get the additional functionality of sending bank selects and program changes to the MIDI devices by using the class methods BankSelect, ProgramChange, and Send. So this new sample project will be a good test of the support provided by TOE’s Destination class.

The archive containing the sample project also contains a new version of TOE that allows it to be built as a framework. The latter is referenced by relative path in the sample project. So if both its project folder and that of TOE are in the same folder, Xcode will correctly locate the framework. If things need to be moved, read Apple’s documentation Creating a Framework.

Here’s a screenshot of the sample project in action:


When one of the programs in the last column is selected and the Select button is clicked, the corresponding bank select and program change MIDI messages are sent to that MIDI device. So this panel serves as a “control center” of all the devices in the MIDI setup. Of course the user interface will need to be improved for this to be put to practical use. Right now, it’s a neat little sample program that would need a lot more effort to write if one must do so without TOE.

[DISCUSS THIS ENTRY]

TOE Sample Code - E-mu Morpheus MIDI Name Document Utility

Tuesday November 1, 2005

I wrote two versions of a sample program today using TOE. The program requests sysex bulk dumps containing patch names from a E-mu Morpheus, extracts them, then generates a MIDI name document that contains these patch names. The MIDI name document can then be used as the master name document or one of the overriding name documents and can be associated with the Morpheus using my NameConfigSetup utility.

I’ve written a similar program called MidnamUtility a while ago. The one today tests the use of TOE. It also shows how the use of SWIG in building TOE allows the sample program to be written in either Python or Scheme. The code has been structured for reuse, which I hope will encourage people to build their own MIDI name document utility for their MIDI device models. It’s really very simple once you’ve figured out the sysex requests to send and where the names are in the sysex replies.

Here’s the main line of the Python version:
TOE.Initialize()

d = TOE.Sysex('Morpheus')
ramRomSysex = GetSysexBulkDump(d, '\xf0\x18\x0c\x00x12\xf7', 3336) ramPresets = ExtractNameList(ramRomSysex, 128, 7, 13, 12) romPresets = ExtractNameList(ramRomSysex, 128, 7 + 13 * 128, 13, 12)
hyperSysex = GetSysexBulkDump(d, '\xf0\x18\x0c\x00\x50\xf7', 1672) hyperPresets = ExtractNameList(hyperSysex, 128, 7, 13, 12)
print template % (PatchNameList("RAM Presets", ramPresets) + \ PatchNameList("ROM Presets", romPresets) + \ PatchNameList("HyperPresets", hyperPresets))
TOE.Terminate()
The function GetSysexBulkDump(d, requestSysex, lengthExpected) sends sysex data requestSysex to device d and receives and returns lengthExpected bytes of bulk dump data.

The function ExtractNameList(sysexData, numNames, startOffset, interval, nameLen) extracts and returns a list of numNames patch names from the bulk dump data sysexData. Each name is of length nameLen. The first name starts at byte offest startOffset. The next names start at startOffset + interval, startOffset + 2 * interval, and so on.

The function PatchNameList(nameListName, nameList) converts a list of patch names into the <PatchNameList> XML element to be inserted into the MIDI name document.

The variable template contains the string representation of the MIDI name document, except for the patch name lists. The latter are inserted using the Python string formatting operator.

Here’s the Scheme (Chicken) version of the same program.

[DISCUSS THIS ENTRY]

October 2005
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

November 2005
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
Sep  Dec

xml

Forums

My Projects

Lists