Introduction
MidiReference is a Java library created to make using midi with Java (and Processing) more musical. The library can be added any project and used to to translate back in forth between MIDI and musical terms. This class does not provide access to the MIDI I/O of the machine, but is rather a way for the developer to act on and create MIDI events based on musical language.
MidiReference is made up of the following classes:
- MidiReference - Contains methods to translate midi note numbers and events into scales, chords, and other meaningful musical data.
- NoteReference - Enum class providing access to base note numbers and string names
- ChordReference - Enum class providing access to integer arrays of various types of chords
- ScaleReference - Enum class providing access to integer arrays of various types of scales
- TimeBase - Enum class providing access to rhythm values based on a 24PPQ Midi Clock. Useful when syncing MIDI to and external device
Please report any problems, suggestions, feedback here.
Documentation
Javadocs can be found here
Download
Older Posts
Java Midi Reference Class
Last modified on 2010-07-24 15:37:27 GMT. 3 comments. Top.
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<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.
Pingback: Java MidiReference 1.0 | Grant Muller
Pingback: week 5 + mid sem break: Project Pitch at z3249369’s blog
Pingback: z3249369’s blog » week 6: Project (no) development