An Audio Visualizer With Quicktime And SZG
While the overview of code organization is elegant, making it work is another matter.
Two C-derived languages are at work here. The Syzygy code is C++ while the Quicktime/OS X code is Objective-C. C++ and Objective-C are both supersets of C, but outside of C itself, they do not overlap.
While it is slightly tricky to call C++ code from Objective-C code, the fact that they overlap makes it easier than it might otherwise be. First, a little on the physical organization of my code.
The code is split neatly along the lines of the diagram in the organization section. The Objective-C files are main.m, MyController.m, and MyController.h. main() naturally lives in main.m. MyController refers to the object (as in OOP) behind the OS X portion of the application which contains the interrupt routines. The C++ code is in visual.cpp and visual.h. These contain the syzygy initialization and update functions.
Each .m and .cpp can be compiled along with its .h and an object file will be created. Thus, after compilation, I have visual.o, MyController.o, and main.o. There is only one main() function, so we should be good to take the next step of linking the object files together and to libraries.
Here's where the difference between the languages comes in. The ways in which C, C++, and Objective-C represent functions in their object files are all slightly different. Luckily, Apple's GCC supports the "extern" command which basically allows me to create additional function headers encoded in the C fashion. For example, in visual.cpp, when I define the function visual_init(), I use the extern command just before to indicate that I want the function to be accessible like a C function. In MyController.m, I use the extern function to specify that visual_init() will be accessible as a C function. Voila--I now have cross language function calling.
The final step is to link the object files with each other and with libraries. These include the Apple application frameworks, the standard Objective-C libraries, and the standard C++ libraries. If all went according to plan, I now have an Apple application bundle that can be run from within the EZSZG shell.
David Stolarsky . Math 198 . Spring 2006