bodhidharma.midi_parsing
Class MIDIIntermediateRepresentations

java.lang.Object
  extended by bodhidharma.midi_parsing.MIDIIntermediateRepresentations

public class MIDIIntermediateRepresentations
extends java.lang.Object

Part of the Bodhidharma automatic music classification project. Objects of this class take in the path of a MIDI file when they are constructed and automatically parse the file. The fields are then filled with a number of different representations of the MIDI file and statistics about it. These fields can then be accessed by Feature objects in order to derive their values, so they don't have to access the MIDI file itself.

Important Notes:

- Patches are numbered one unit lower here than in their General MIDI patch names, so remember to raise by one when processing.

- Channesl are numbered 1 lower here than in real MIDI, so check for channel 9 when actually looking for channel 10.

- The data starts at tick 0.

- MIDI files that use SMPTE time encoding are not compatible with this software.

See Also:
Feature, Sequence, Track, MidiEvent, MidiMessage, MetaMessage, ShortMessage
Author:
Cory McKay

Field Summary
 double[] basic_pitch_histogram
          A normalized histogram with bins corresponding to MIDI pitches (0 to 127).
 int[][] channel_statistics
          A table with rows (first indice) corresponding to channels and the following column designations:
 boolean[][] channel_tick_map
          A table with rows (first indice) corresponding to MIDI ticks in the MIDI file.
 double[] fifths_pitch_histogram
          A normalized histogram with bins corresponding to MIDI pitch classes (0 to 11).
 double[] melodic_histogram
          A normalized histogram with bins corresponding to melodic intervals measured in number of semi-tones.
 java.util.LinkedList[] melody_list
          An array of lists of all melodic intervals occuring in each channel.
 java.lang.Object[] meta_data
          A listing of meta information.
 int[] non_pitched_instrumentation_frequencies
          An array whose indice corresponds to patches from the MIDI Percussion Key Map.
 boolean[][] note_beginnings_map
          A table with rows corresponding to MIDI ticks and columns corresponding to MIDI channels.
 java.util.LinkedList note_durations
          A list of the durations of all notes in seconds.
 int[][] note_loudnesses
          Gives the loudnesses of all notes.
 java.util.LinkedList pitch_bends_list
          A list of lists of pitch bends associated with notes.
 double[] pitch_class_histogram
          A normalized histogram with bins corresponding to MIDI pitch classes (0 to 11).
 int[][] pitched_instrumentation_frequencies
          A table with rows (first indice) corresponding to General MIDI pitched patch numbers.
 boolean[][] pitched_instrumentation_tick_map
          A table with rows (first indice) corresponding to MIDI ticks in the MIDI file.
 int recording_length
          The length in seconds of the recording
 double[] rhythmic_histogram
          A normalized histogram with bins corresponding to beats per minute.
 double[][] rhythmic_histogram_table
          Table with rows (first indice) corresponding to the bins of rhythmic_histogram.
 double[] seconds_per_tick
          An array with an entry for each tick.
 int total_number_notes
          The total number of Note Ons in the recording.
 int total_number_pitched_notes
          The total number of Note Ons in the recording that were played using a General MIDI pitched instrument.
 int total_number_unpitched_notes
          The total number of Note Ons in the recording that were played using a General MIDI Percussion Key Map instrument.
 double[][] volumes
          A table with rows (first indice) corresponding to MIDI ticks in the MIDI file.
 
Constructor Summary
MIDIIntermediateRepresentations(java.lang.String midi_file_path)
          Parses the given MIDI file and fills the fields with the appropriate values extracted from this file.
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

meta_data

public java.lang.Object[] meta_data
A listing of meta information. Indices correspond to the following:

Indice 0: Quality stored as an Integer. 0 indicates major, 1 indicates minor and 0 indicates that no key signature is given. NOTE: assumes only one key signature metamessage and considers only the first.

Indice 1: LinkedList of all time signature numerators in the order that they appeared (as Integers).

Indice 2: LinkedList of all time signature denominators in the order that they appeared (as Integers).

Indice 3: Integer storing the initial tempo in beats per minute.


pitched_instrumentation_frequencies

public int[][] pitched_instrumentation_frequencies
A table with rows (first indice) corresponding to General MIDI pitched patch numbers. The first column gives the total number of Note Ons played using each patch. The second column gives the total time in seconds (rounded) that at least one note was being held by each patch.


pitched_instrumentation_tick_map

public boolean[][] pitched_instrumentation_tick_map
A table with rows (first indice) corresponding to MIDI ticks in the MIDI file. The columns (second indice) correspond to the pitched General MIDI patches. An entry is set to true if a particular patch is playing at least one note during a particular MIDI tick.


non_pitched_instrumentation_frequencies

public int[] non_pitched_instrumentation_frequencies
An array whose indice corresponds to patches from the MIDI Percussion Key Map. Each entry indicates the number of Note Ons played by the specified patch.

NOTE: values for all 128 note values were collected here, although perhaps only notes 35 to 81 should be used. This is because some recordings actually use these other values, even though they should not. These other values simply duplicate the allowed values.


total_number_notes

public int total_number_notes
The total number of Note Ons in the recording.


total_number_pitched_notes

public int total_number_pitched_notes
The total number of Note Ons in the recording that were played using a General MIDI pitched instrument.


total_number_unpitched_notes

public int total_number_unpitched_notes
The total number of Note Ons in the recording that were played using a General MIDI Percussion Key Map instrument.

NOTE: values for all 128 note values were collected here, although perhaps only notes 35 to 81 should be used. This is because some recordings actually use these other values, even though they should not. These other values simply duplicate the allowed values.


recording_length

public int recording_length
The length in seconds of the recording


channel_tick_map

public boolean[][] channel_tick_map
A table with rows (first indice) corresponding to MIDI ticks in the MIDI file. The columns (second indice) correspond to the MIDI channels. An entry is set to true if one or more notes was sounding on the given channel during the given MIDI tick.

NOTE: this includes channel 10, even though it is understood that channel 10 notes are played using percussion patches, not pitch patches.


channel_statistics

public int[][] channel_statistics
A table with rows (first indice) corresponding to channels and the following column designations:

Column 0: total number of Note Ons on given channel

Column 1: total amount of time in seconds that one or more notes were sounding on given channel

Column 2: average loudness (velocity scaled by channel volume (still falls between 0 and 127)) of notes on given channel

Column 3: average melodic leap on given channel in semitones (includes accross rests and ignores direction) (will give erroneous values if there is more than one melody per channel or if a channel is polyphonic)

Column 4: lowest MIDI pitch on given channel (value of 1000 means no pithces on given channel)

Column 5: highest MIDI pitch on given channel (value of -1000 means no pithces on given channel)

Column 6: average MIDI pitch on given channel (value of 0 means no pithces on given channel)

NOTE: this includes channel 10, even though it is understood that channel 10 notes are played using percussion patches, not pitch patches.


rhythmic_histogram

public double[] rhythmic_histogram
A normalized histogram with bins corresponding to beats per minute. The frequency of each bin is proportional to the loudnesses of the notes that occur at the bin's rhythmic interval.

All bins below 40 BPM are set to 0 because autocorrelation was not performed at these lags. This omission is because the results are too noisy. These measurements were taken without consideration of tempo change messages, in order to emphasize the metrical notation of the recording.


rhythmic_histogram_table

public double[][] rhythmic_histogram_table
Table with rows (first indice) corresponding to the bins of rhythmic_histogram. Column 0 is related to bins that have a normalized frequency of over 0.1, column 1 corresponds to bins that have a normalized frequency of over 0.01 and column 2 corresponds to bins that have frequencies at least 30% as high as the frequency of the highest bin.

Entries are set to the frequency of the corresponding bin of rhythmic_histogram if the frequency is high enough to meet the column's requirements and to 0 otherwise.

This table was processed so that only peaks were included, which is to say that entries for bins that are adjacent to bins with higher frequencies are set to 0.


note_durations

public java.util.LinkedList note_durations
A list of the durations of all notes in seconds. Durations stored as doubles.


note_beginnings_map

public boolean[][] note_beginnings_map
A table with rows corresponding to MIDI ticks and columns corresponding to MIDI channels. Entries are set to true whenever a Note On event occurred on a given channel, and to false otherwise.

A final column (column 16) was added whose entry was set to true if at least one Note On occurred on any channel at the corresponding MIDI tick, and to false otherwise.


note_loudnesses

public int[][] note_loudnesses
Gives the loudnesses of all notes. The first indice corresponds to channel number and the second indice corresponds to individual notes (they are numbered in the order that they occured on each channel). Each entry gives the velocity of the note scaled by channel volume. Entry values range from 0 to 127.


basic_pitch_histogram

public double[] basic_pitch_histogram
A normalized histogram with bins corresponding to MIDI pitches (0 to 127). The frequency of each bin corresponds to the number of Note Ons in the recording at the pitch of the bin. Any notes on Channel 10 (percussion) are ignored.


pitch_class_histogram

public double[] pitch_class_histogram
A normalized histogram with bins corresponding to MIDI pitch classes (0 to 11). The frequency of each bin corresponds to the number of Note Ons in the recording at the pitch class of the bin. Any notes on Channel 10 (percussion) are ignored. Enharmonic equivalents are assigned the same pitch class number.


fifths_pitch_histogram

public double[] fifths_pitch_histogram
A normalized histogram with bins corresponding to MIDI pitch classes (0 to 11). The bins are ordered such that adjacent bins are separated by a perfect fifth rather than a semi-tone, as is the case with the pitch_class_histogram. The frequency of each bin corresponds to the number of Note Ons in the recording at the pitch class of the bin. Any notes on Channel 10 (percussion) are ignored. Enharmonic equivalents are assigned the same pitch class number.


pitch_bends_list

public java.util.LinkedList pitch_bends_list
A list of lists of pitch bends associated with notes. Each entry of the root list corresponds to a note that has at least one pitch bend message associated with it. Each such entry contains a list of all pitchbend messages (second MIDI data byte stored as an Integer) associated with the note, in the order that they occured.


melodic_histogram

public double[] melodic_histogram
A normalized histogram with bins corresponding to melodic intervals measured in number of semi-tones. The frequency of each bin corresponds to the number of melodic intervals that occured of the kind referred to by the bin. Rising and falling intervals are treated as identical. Intervals are held as Integers. Any notes on Channel 10 (percussion) are ignored. It is assumed that there is only one melody per channel during generation of the melodic histogram.


melody_list

public java.util.LinkedList[] melody_list
An array of lists of all melodic intervals occuring in each channel. Indice value corresponds to channel. Units are semi-tones, with positive values for upwards motion and negative values for downwards motion. Order of occurence is preserved. Any notes on Channel 10 (percussion) are ignored. It is assumed that there is only one melody per channel during generation of the melodic histogram.


seconds_per_tick

public double[] seconds_per_tick
An array with an entry for each tick. The value at each indice gives the duration of a tick in seconds at that particular point in the recording.


volumes

public double[][] volumes
A table with rows (first indice) corresponding to MIDI ticks in the MIDI file. The columns (second indice) correspond to the MIDI channels. An entry is set to the channel volume as set by channel volume controller messages divided by 127.

NOTE: the default is set to 1.0, which corresponds to a controller value of 127.

Constructor Detail

MIDIIntermediateRepresentations

public MIDIIntermediateRepresentations(java.lang.String midi_file_path)
                                throws java.lang.Exception
Parses the given MIDI file and fills the fields with the appropriate values extracted from this file.

Throws exceptions if an error is encountered when parsing the file. These exceptions contain informative information about the error.

Parameters:
midi_file_path - Path of MIDI file to parse.
Throws:
java.lang.Exception - Informative exceptions are thrown if problems are encountered during parsing.