Grant Muller

Java Midi Reference Class

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:

MidiReference

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<127;){
    //loop through the ranges (-1 through 9)
    for (Integer range=-1; range<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<128;){
    //loop through the ranges (-1 through 9)
    for (Integer range=-1; range<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.

3 comments

  1. Sure, Let me look around on OSI and find one that’s appropriate for this kind of thing. I’m working on extending this with ChordRefs, ModeRefs, and some other music/midi translations that will make my life easier…detecting which mode the music is in is proving to be very difficult.

Leave a Reply