MIDI stands for Musical Instrument Digital Interface. MIDI technology was standardized in 1983. Think of it as a way to encode sheet music in a format that can be read and played by a computer, musical keyboard, or synthesizer. Unlike other audio formats, such as WAV or MP3, MIDI cannot encode any arbitrary sound (such as people singing or speaking). Rather, MIDI can only encode the notes, volumes, and rhythms, as would be played by a musical instrument (piano, brass, strings, percussion, etc.). As a result, MIDI files are significantly smaller than WAV or MP3 formats. Whereas the WAV file for a 3-minute song might be around 30 MB, and the same song in MP3 format would be about 3 MB, an instrumental-only recording of this song in MIDI format would be only 15 KB (that is, 1/200th the size of the MP3 file).
MIDI files are comprised of Chunks, Tracks, and Events. Each note in a MIDI file is an event. There are other events for Tempo, Time Signature, Key Signature, Text, Lyrics, etc. Each event has a time, which is the number of ticks to wait from the previous event. Note events also have a channel, which sometimes corresponds to the instrument. For details on the MIDI file format, refer to one of the numerous references on the Internet.
MIDI files are the magic that allow the xylophone to play the songs that you like. Instead of programming each note individually, you simply need to find the MIDI file for the song that you want, and let the software do its work. The only events that are needed from the MIDI file are Note On and Tempo events. The Note Off event is not needed because the xylophone has no means to sustain a tone. It can only strike the key at the beginning of each note. The channel/instrument of the note has no meaning for a song played on the xylophone, because there is only one instrument to be played. (I have occasionally thought of building a whole mechanical orchestra to play different instruments from a MIDI file, but I don’t anticipate having the time or resources for this anytime soon.)
In versions 1.0 and 2.0 of the robotic xylophone, a PC-based program is used to read the MIDI files, decompile them, and translate them into a proprietary format that is loaded into I2C EEPROM or SPI Flash. In version 2.1, MIDI files are copied directly from a computer onto an SD card, and the Arduino reads the MIDI files directly, and plays the notes from MIDI events in real time.
Considerations for Choosing MIDI Files
Actually, putting songs on the robotic xylophone is not quite so simple as just finding any MIDI file on the Internet, and then copying it to an SD Card. Yes, any MIDI file can be played on the xylophone. But not every MIDI file will sound good.
Often MIDI files will have many different instruments. Sometimes, it will sound OK if the parts of all instruments are played together on the xylophone. But more often than not, this is just too much. The background tracks may hide the melody, and then you can’t even tell what song is being played on the xylophone. Many MIDI files have drums or other percussion, and these will never sound good on the xylophone.
So often it is necessary to use a MIDI editor to remove tracks or instruments that you do not want to play on the xylophone. At a minimum, the drums/percussion need to be removed. One free program that I like using to edit MIDI files is MidiEditor.
Some MIDI files are piano only. These often will play directly very well on the xylophone. If you are just starting, I would recommend that you try piano songs for your first songs on the xylophone.
Another consideration is length of the song. The MIDI files that you find on the Internet might be anywhere from 3-4 minutes long (typical for most pop songs), to as long as 15-20 minutes for some classical works. However, I have noticed that when demonstrating the xylophone to people, typically the longest that anyone wants to listen to a song is 30-60 seconds. Thus, it most effective to cut the original MIDI file to this length, where a song might play for just one verse, or maybe just the most recognizable part of the song. Use the MIDI editor to cut the song down to the desired length.
A third consideration is that some styles of music sound better on the xylophone than others do. Generally, songs that have a lot of rhythm or syncopation play very well on the xylophone because these same rhythms will always stand out. For example, most Scott Joplin, George Gershwin, or Irving Berlin compositions have this type of style, and play well on the xylophone as is. Songs that are fairly slow, or have a lot of long, sustained notes generally do not come out on the xylophone very well because the xylophone has no way to sustain notes. So while the sustained notes in the original song might sound pleasant and relaxing, on the xylophone, this will come out as dead space, and in listening to it, you will feel that there needs to be something to fill in the gaps.
Even among contemporary/pop songs, some styles tend to sound good, and others don’t. Songs with clear vocals, with maybe a piano, or acoustic or bass guitar in the background do very well. Rap or styles heavy in percussion don’t work.
I’ve also noticed that if a song does not have a very recognizable melody, it will be really hard to tell what song is playing. When the melody is in the higher notes, and the harmony or background is in the lower notes, the melody will usually be very easy to hear when played on the xylophone. But I have found some songs where there are background parts with higher notes than the melody, and when I try to play this on the xylophone, all I can hear is the background. Sometimes, I have been able to get around this problem by using the MIDI editor to transpose the melody track one or two octaves higher.
Some of today’s hit songs, I have searched for a MIDI file, and the only one that I can find is a karaoke version. So at first I am excited, thinking I have found a song that people will think is really cool on the xylophone. Then when I listen to it, and hear only the background, I’m disappointed. If you can’t find a good MIDI file for your favorite song, don’t despair. Just move on, to one of the thousands of other MIDI songs out there on the Internet.
That brings me to my final point regarding playing MIDI files on the xylophone. If you are musically inclined, you will realize that a piano has 88 keys (a little more than 7 octaves) while the xylophone has only 25 notes or 2 octaves. Many other instruments also play in a range of much more than 2 octaves. So how can one squeeze a piece that spans a range of 4-6 octaves down into an instrument with only a 2-octave range? The answer is simple. The software has a setting that will octave-transpose any notes higher or lower than the xylophone range onto notes that are within the xylophone range. So for example, if the xylophone is G3 to G5, and the MIDI file has a C6 note, the software will transpose that note to a C5, so that it can be played on the xylophone. Depending upon the song, this octave-transpose might sound slightly abnormal, or you might not even be able to tell the difference. I have found that for the majority of songs, the octave transpose sounds just fine. See the MIDI Transpose page for more details.
If you build your own robotic xylophone, and find your own MIDI files, you will probably discover your own techniques to make your music sound the best it can be. If you have any questions, or if you have succeeded in building your own music, I would love to hear from you. Please let me know via the Contact page.