mckay.utilities.sound.midi
Class MIDIMethods

java.lang.Object
  extended by mckay.utilities.sound.midi.MIDIMethods

public class MIDIMethods
extends java.lang.Object

A holder class for static methods relating to MIDI.


Constructor Summary
MIDIMethods()
           
 
Method Summary
static javax.sound.midi.Sequence[] breakSequenceIntoWindows(javax.sound.midi.Sequence original_sequence, double window_duration, double window_overlap_offset)
          IMPORTANT: THIS METHOD IS NOT YET FINISHED.
static java.lang.String getMIDIFileFormatData(java.io.File file)
          Returns information regarding a given MIDI file.
static double[] getSecondsPerTick(javax.sound.midi.Sequence sequence)
          Returns an array with an entry for each MIDI tick in the given MIDI sequence.
static javax.sound.midi.Sequencer playMIDISequence(javax.sound.midi.Sequence midi_sequence)
          Plays the given MIDI Sequence and returns the Sequencer that is playing it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MIDIMethods

public MIDIMethods()
Method Detail

playMIDISequence

public static javax.sound.midi.Sequencer playMIDISequence(javax.sound.midi.Sequence midi_sequence)
                                                   throws java.lang.Exception
Plays the given MIDI Sequence and returns the Sequencer that is playing it. The default system Sequencer and Synthesizer are used.

Parameters:
midi_sequence - The MIDI sequence to play
Returns:
A sequencer that is playing the midi_sequence
Throws:
java.lang.Exception - Throws an exception if an empty MIDI sequence is passed as an argument or if cannoth play.

getMIDIFileFormatData

public static java.lang.String getMIDIFileFormatData(java.io.File file)
                                              throws java.lang.Exception
Returns information regarding a given MIDI file. This information consists of the file name, the number of tracks in the file, its duration in seconds, the total number of MIDI ticks, its MIDI timing division type, its MIDI resolution type and the tick duration. Also returned is the MIDI file type and any stored meta-data.

Parameters:
file - The file to return data about.
Returns:
Data in string form about the specified MIDI file.
Throws:
java.lang.Exception - Throws informative exceptions if the file is invalid.

getSecondsPerTick

public static double[] getSecondsPerTick(javax.sound.midi.Sequence sequence)
Returns an array with an entry for each MIDI tick in the given MIDI sequence. The value at each indice gives the duration of a tick in seconds at that particular point in the recording. Tempo change messages ARE taken into account.

Parameters:
sequence - The MIDI Sequence from which to extract the tick durations.
Returns:
An array with an entry for each MIDI tick in the given MIDI sequence.

breakSequenceIntoWindows

public static javax.sound.midi.Sequence[] breakSequenceIntoWindows(javax.sound.midi.Sequence original_sequence,
                                                                   double window_duration,
                                                                   double window_overlap_offset)
                                                            throws java.lang.Exception
IMPORTANT: THIS METHOD IS NOT YET FINISHED. IT CURRENTLY ONLY OUTPUTS EMPTY WINDOWS OF MIDI DATA. Breaks the given MIDI Sequence into windows of equal duration. These windows may or may not be overlapping. The original Sequence is not changed. Tempo change messages ARE taken into account, so different windows will have the same time duration, but not necessarily the same number of MIDI ticks.

Parameters:
original_sequence - The MIDI Sequence to break into windows.
window_duration - The duration in seconds of each window.
window_overlap_offset - The number of seconds that windows are offset by. A value of zero means that there is no window overlap.
Returns:
An array of sequences representing the windows of the original sequence in consecutive order.
Throws:
java.lang.Exception - Throws an informative exception if the MIDI file uses SMTPE timing instead of PPQ timing or if it is too large.