Among the great questions of programming is the connection between programming, mathematics, and music. Although it is only anecdotal evidence, many brilliant programmers also have an aptitude for music. Listening to classical or rock music is said to temporarily improve your test scores (the Mozart effect). Eric Raymond even suggests an analytical ear for music -- along with reading science fiction and studying Zen -- is a common style point among hackers, something you might want to develop if you want to become a hacker.
As in other areas of life, Python is here to help you with your hacking ambitions. Python developer and musician Tom Cato Amundsen has created Solfege, ear training software written in Python and using Python bindings to the gtk++ and GNOME libraries. While Solfege can be built without GNOME libs, it is really best built with it. Without GNOME, you lose the HTML support and some functionality like the guitar module which allows you to provide answers using a graphic fretboard..
The program isn't a replacement for a teacher, but it can help with some of the drills for which you might otherwise need a partner. It also keeps statistics on your performance so you can monitor your progress as you practice. Solfege can use your sound card's sequencer, or pipe its MIDI information through a program, like Timidity. Since I have a fairly weak soundcard, an old SB16, I opted for the Timidity support. It works great.
In addition to its user-level charms, you should also check
out Amundsen's soundcard support libraries, particularly his Python
bindings to Open Sound System's
/dev/music API, and how
he wraps the
/dev/sequencer API so he can use it just
/dev/music. You might find the PyGnome code is
interesting too, particularly his alternative piano and guitar input
Perhaps your interest in music leans more towards the mathematics of the signals themselves. If you are more interested in digital signal processing (DSP), you should take a look at Kåre Sjölander's Snack toolkit. Developed for TCL and Python, the Snack toolkit is a sound processing toolkit with a Tk interface. Whether your project is a simple recorder and player for WAV files, a spectrum analyzer, or a sound effect filter, Snack has a widget for it. Snack can be a springboard for the rapid development of your graphical sound application. Snack even supports the open Ogg Vorbis music compression format as well as MP3, granting you both freedom and versatility.
The Stanford sound toolkit with Python bindings, MusicKit, was originally written for NeXT. These Objective-C tools are made available to Python using the PyObjC Obective-C bridge. MusicKit's DSP tools are only available on the OpenStep platform, either for m68k or Intel systems, but its MIDI and sound streaming capabalities are available on both MacOS X and MS Windows. Work continues on porting the kit to GnuStep for Linux. They have sound support, but need help getting the MIDI support to work. This toolkit, however, might be of greatest interest to the MacOS X crowd.
If you are just thinking about making your Python program noisy you shouldn't overlook PyGame which will give you a cross-platform way to handle playing sound effects and music using the Pygame.mixer module. Pygame.mixer is great for giving your application a background sound track or event driven sounds, easily handling the playing of multiple sounds simultaneously.
There are many toolkits and sound applications I haven't mentioned that have either been written for or with Python. This is just the tip of the Python multimedia iceberg. Whether you want to get noisy, tune your musical ear, or boost your programming prowess through the power of classical sounds, Python is there to help.
Stephen Figgins administrates Linux servers for Sunflower Broadband, a cable company.
Read more Python News columns.
Return to the Python DevCenter.