Category: Java MidiReference

With just a little trepidation I have checked in the code for all of my free software goodies into GitHub. I was getting several requests to provide access to the source for several of my old projects, so rather than emailing code around on a case by case basis, I have simply checked everything in to GitHub for posterity. Who knows, maybe someone will jump in there and fix all the bugs.

I have written some other tools for my personal use that I will likely check in there as well, so check back if you’re interested in that kind of thing.

Several months ago I started working on a series of classes to make my life easier when programming for music. I’d started several projects and realized that trying to refer back and forth between MIDI Numbers and Notation by hand was tedious, so I created a library of functions to do it all for me.

I finally got around to formalizing this into one library, and released it here. I’ve put this into action already with the Game Of Life Sequencer Bank and HarmonicTable projects, and its really made it easy to pull scales, chords, drum maps, you name it quickly from a preset library

If this kind of thing is useful for anyone other than me, feel free to use it

Lately I have been doing some work with Processing to create visuals from music. One of the concepts I’m working with is live visuals based on video feeds from cameras that are tracking the show, or band, or whatever. This alone would be enormously boring, so to heighten the experience, I thought of using the audio output of the show to control features of the video feeds, like playback speed, positions, color and hue, etc. This turned out to be way too processor intensive, and given the properties of sound, would be impossible to synchronize with a live show.

The solution was to use MIDI to trigger these events, rather than having to perform audio analysis first. Using rwmidi and Processing, I started an experiment to see what I can do to video, using MIDI messages as triggers, NoteOn’s as ellipses with alpha masks, or Pitch Bend controllers tracking hue logarithmically. So far these experiments have been successful, but I found myself referring to a MIDI reference constantly.

The problem is most musicians don’t think in MIDI numbers. Even though the messages I’m using have no musical information, they’re derived from the world of music. So Note names like C4 (The note C in the 4th position) have a MIDI number (60). When I’m creating a drum beat in Ableton for instance, I don’t look for note number 60, I look for C4. This means that every time I wanted to map this information to an event in Processing, I had to first look up the note number. After a while you memorize them, but that’s lame, and if I leave the project for a while and come back, I’ll have to go back to looking them up again.

I couldn’t find any solution for this in code, so I created a simple Java class to handle MIDI Reference Data:

Which you can download from the link above. Right now it only handle Notes and their associated midi numbers. The crux of the code consists of two loops:

//Loop through all of the note numbers
for (int noteNumber=0; noteNumber&lt;127;){
//loop through the ranges (-1 through 9)
for (Integer range=-1; range&lt;10; range++){
//loop through all of the note names
for (String nextNote : noteNames){
//if the note name contains a "flat" then it has the identical note number
//as the previous flat, decrement the total note number count and insert into
//the map so that note numbers can be translated from either sharps or flats
if (nextNote.contains("b")) noteNumber--;
noteNameMap.put(nextNote + range.toString(), noteNumber);
noteNumber++;
}
}
}

and

//Loop through all of the note numbers
for (int noteNumber=0; noteNumber&lt;128;){
//loop through the ranges (-1 through 9)
for (Integer range=-1; range&lt;10; range++){
//loop through all of the note names
for (String nextNote : noteNames){
String noteName;
//if the note name contains a "flat" then it has the identical note number
//as the previous flat, decrement the total note number count and insert into
//the array a string made up of both the previous notes name and the current one
if (nextNote.contains("b")){
noteNumber--;
String previous = noteNumberArray[noteNumber];
noteName = previous + "/" + nextNote + range.toString();
} else {
noteName = nextNote + range.toString();
}
noteNumberArray[noteNumber] = noteName;
noteNumber++;
}
}
}

The first loop rolls through all of the potential note names and maps them to a number, in order from 0-127 (all of the MIDI notes). The second does the opposite, so that you can quickly refer to the note name by number (which is something that Processing will find easier to do).

If you find this kind of thing useful, feel free to use it. I will expand it from time to time as I add new reference data for myself.