net.charlesames.music.midi
Class MidiTrack

java.lang.Object
  extended by net.charlesames.utility.common.Disposable
      extended by net.charlesames.music.midi.MidiEntity
          extended by net.charlesames.music.midi.MidiTrack

public class MidiTrack
extends MidiEntity

The MidiTrack class wraps the javax.sound.midi.Track class. The parent of a MidiTrack instance is a MidiFile. The parent of the wrapped javax.sound.midi.Track instance

Author:
Charles Ames

Method Summary
 void create14BitEvent(long ticks, int command, int channel, int data)
          Create a MIDI short message event.
 void createBalanceEvent(long ticks, int channel, int data)
          Create a balance control-change event.
 void createBreathControllerEvent(long ticks, int channel, int data)
          Create a breath controller control-change event.
 void createChannelPrefixEvent(long ticks, int channel)
          Create a MIDI meta-message channel prefix event.
 void createControllerEvent(long ticks, int channel, int controller, int data)
          Create a MIDI controller event.
 void createCopyrightEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message copyright event.
 void createCuePointEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message cue point event.
 void createDataEntryEvent(long ticks, int channel, int data)
          Create a data-entry control-change event.
 void createDeviceNameEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message device name event.
 void createEffectControl1Event(long ticks, int channel, int data)
          Create an Effect Control #1 control-change event.
 void createEffectControl2Event(long ticks, int channel, int data)
          Create an Effect Control #2 control-change event.
 void createEndOfTrackEvent(long ticks)
          Create a MIDI meta-message end of track event.
 void createExpressionEvent(long ticks, int channel, int data)
          Create an expression control-change event.
 void createFootPedalEvent(long ticks, int channel, int data)
          Create a foot pedal control-change event.
 void createInstrumentNameEvent(long ticks, int channel, java.lang.String text)
          Create a MIDI meta-message instrument name event.
 void createKeySignatureEvent(long ticks, int sharps, int mode)
          Create a MIDI meta-message key signature event.
 void createLyricEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message lyric event.
 void createMarkerEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message marker event.
 void createMetaMessageEvent(int type, long ticks, byte[] data)
          Create a MIDI meta-message event.
 void createModulationWheelEvent(long ticks, int channel, int data)
          Create a modulation wheel control-change event.
 void createNoteEvents(long ticks, long duration, int channel, int key, int velocity)
          Create a MIDI note-on event paired with a MIDI note-off event.
 void createPanPositionEvent(long ticks, int channel, int data)
          Create a pan position control-change event.
 void createPitchBendEvent(long ticks, int channel, int value)
          Create a MIDI pitch bend event
 void createPortamentoTimeEvent(long ticks, int channel, int data)
          Create a portamento control-change event.
 void createProgramChangeEvent(long ticks, int channel, int program)
          Create a MIDI program change event
 void createProgramNameEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message program name event.
 void createShortMessageEvent(long ticks, int status_type, int channel, int data_low, int data_high)
          Create a MIDI short message event.
 void createTempoEvent(long ticks, int microsecondsPerBeat)
          Create a MIDI meta-message tempo event.
 void createTextEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message text event.
 void createTimeSignatureEvent(long ticks, int beats, int beatType, int clocks, int division)
          Create a MIDI meta-message time signature event.
 void createTrackNameEvent(long ticks, java.lang.String text)
          Create a MIDI meta-message track name event.
 void createVolumeEvent(long ticks, int channel, int data)
          Create a MIDI volume control-change event.
 void decodeEvents()
          Generate a text interpretation of a MIDI track.
 MidiFile getContainer()
          Get the parent MidiFile.
 int getID()
          Get the track id.
 java.util.SortedMap<java.lang.Integer,MidiTrackEvent> getMidiTrackEvents()
          Get the MIDI track events.
 java.lang.String getName()
          Get the track name.
 javax.sound.midi.Track getTrack()
          Get the wrapped javax.sound.midi.Track instance.
 void initializeChannel(java.lang.String deviceName, int channel, java.lang.String instrumentName, int midiPitchBendRange)
          Initialize a MIDI channel
 void interpolatePitchBend(int channel, long left, long right, int origin, int goal)
          Create a ramped sequence of MIDI pitch-bend events
 void setName(java.lang.String name)
          Set the instance name.
 void setRegisteredParameter(long ticks, int channel, int rpn_msb, int rpn_lsb, int controller, int data)
          Set a MIDI registered parameter value.
 
Methods inherited from class net.charlesames.music.midi.MidiEntity
dispose
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContainer

public MidiFile getContainer()
Get the parent MidiFile.

Overrides:
getContainer in class MidiEntity
Returns:
The parent MidiFile.

getTrack

public javax.sound.midi.Track getTrack()
Get the wrapped javax.sound.midi.Track instance.

Returns:
The Track instance.

getName

public java.lang.String getName()
Get the track name.

Overrides:
getName in class MidiEntity
Returns:
The track name.

getID

public int getID()
Get the track id.

Overrides:
getID in class MidiEntity
Returns:
The track id.

getMidiTrackEvents

public java.util.SortedMap<java.lang.Integer,MidiTrackEvent> getMidiTrackEvents()
Get the MIDI track events.

Returns:
A collection of MidiTrackEvent instances, indexed by event id.

createShortMessageEvent

public void createShortMessageEvent(long ticks,
                                    int status_type,
                                    int channel,
                                    int data_low,
                                    int data_high)
                             throws javax.sound.midi.InvalidMidiDataException
Create a MIDI short message event.

Parameters:
ticks - The event time in ticks
status_type - The MIDI status nibble.
channel - The MIDI channel number (1-16)
data_low - The low data bit (0-127).
data_high - The high data bit (0-127).
Throws:
javax.sound.midi.InvalidMidiDataException

create14BitEvent

public void create14BitEvent(long ticks,
                             int command,
                             int channel,
                             int data)
                      throws javax.sound.midi.InvalidMidiDataException
Create a MIDI short message event.

Parameters:
ticks - The event time in ticks
command - The MIDI status nibble
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits) which this method unpacks into 7-bit high and low bytes.
Throws:
javax.sound.midi.InvalidMidiDataException

createProgramChangeEvent

public void createProgramChangeEvent(long ticks,
                                     int channel,
                                     int program)
                              throws javax.sound.midi.InvalidMidiDataException
Create a MIDI program change event

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
program - The MIDI program number (1-128)
Throws:
javax.sound.midi.InvalidMidiDataException

createNoteEvents

public void createNoteEvents(long ticks,
                             long duration,
                             int channel,
                             int key,
                             int velocity)
                      throws javax.sound.midi.InvalidMidiDataException
Create a MIDI note-on event paired with a MIDI note-off event.

Parameters:
ticks - The note-on event time in ticks
duration - The number of ticks separating the note-off event from the note-on event.
channel - The MIDI channel number (1-16)
key - The MIDI key number (60 is middle C).
velocity - The MIDI velocity (0-127)
Throws:
javax.sound.midi.InvalidMidiDataException

createControllerEvent

public void createControllerEvent(long ticks,
                                  int channel,
                                  int controller,
                                  int data)
                           throws javax.sound.midi.InvalidMidiDataException
Create a MIDI controller event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
controller - The MIDI control number.
data - (0-127)
Throws:
javax.sound.midi.InvalidMidiDataException

setRegisteredParameter

public void setRegisteredParameter(long ticks,
                                   int channel,
                                   int rpn_msb,
                                   int rpn_lsb,
                                   int controller,
                                   int data)
                            throws javax.sound.midi.InvalidMidiDataException
Set a MIDI registered parameter value.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
rpn_msb - The registered parameter most significant bit.
rpn_lsb - The registered parameter least significant bit.
controller - The controller number.
data - The controller data (0-127).
Throws:
javax.sound.midi.InvalidMidiDataException

createPitchBendEvent

public void createPitchBendEvent(long ticks,
                                 int channel,
                                 int value)
                          throws javax.sound.midi.InvalidMidiDataException
Create a MIDI pitch bend event

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
value - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

interpolatePitchBend

public void interpolatePitchBend(int channel,
                                 long left,
                                 long right,
                                 int origin,
                                 int goal)
                          throws javax.sound.midi.InvalidMidiDataException
Create a ramped sequence of MIDI pitch-bend events

Parameters:
channel - The MIDI channel number (1-16)
left - The starting time in ticks.
right - The ending time in ticks.
origin - The starting pitch-bend value.
goal - The ending pitch-bend value.
Throws:
javax.sound.midi.InvalidMidiDataException

createModulationWheelEvent

public void createModulationWheelEvent(long ticks,
                                       int channel,
                                       int data)
                                throws javax.sound.midi.InvalidMidiDataException
Create a modulation wheel control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createBreathControllerEvent

public void createBreathControllerEvent(long ticks,
                                        int channel,
                                        int data)
                                 throws javax.sound.midi.InvalidMidiDataException
Create a breath controller control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createFootPedalEvent

public void createFootPedalEvent(long ticks,
                                 int channel,
                                 int data)
                          throws javax.sound.midi.InvalidMidiDataException
Create a foot pedal control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createPortamentoTimeEvent

public void createPortamentoTimeEvent(long ticks,
                                      int channel,
                                      int data)
                               throws javax.sound.midi.InvalidMidiDataException
Create a portamento control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createDataEntryEvent

public void createDataEntryEvent(long ticks,
                                 int channel,
                                 int data)
                          throws javax.sound.midi.InvalidMidiDataException
Create a data-entry control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createVolumeEvent

public void createVolumeEvent(long ticks,
                              int channel,
                              int data)
                       throws javax.sound.midi.InvalidMidiDataException
Create a MIDI volume control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createBalanceEvent

public void createBalanceEvent(long ticks,
                               int channel,
                               int data)
                        throws javax.sound.midi.InvalidMidiDataException
Create a balance control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createPanPositionEvent

public void createPanPositionEvent(long ticks,
                                   int channel,
                                   int data)
                            throws javax.sound.midi.InvalidMidiDataException
Create a pan position control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createExpressionEvent

public void createExpressionEvent(long ticks,
                                  int channel,
                                  int data)
                           throws javax.sound.midi.InvalidMidiDataException
Create an expression control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createEffectControl1Event

public void createEffectControl1Event(long ticks,
                                      int channel,
                                      int data)
                               throws javax.sound.midi.InvalidMidiDataException
Create an Effect Control #1 control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createEffectControl2Event

public void createEffectControl2Event(long ticks,
                                      int channel,
                                      int data)
                               throws javax.sound.midi.InvalidMidiDataException
Create an Effect Control #2 control-change event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
data - An integer from 0 to 16383 (14 bits).
Throws:
javax.sound.midi.InvalidMidiDataException

createMetaMessageEvent

public void createMetaMessageEvent(int type,
                                   long ticks,
                                   byte[] data)
                            throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message event.

Parameters:
type - The meta-message number.
ticks - The event time in ticks
data - A byte array.
Throws:
javax.sound.midi.InvalidMidiDataException

createTextEvent

public void createTextEvent(long ticks,
                            java.lang.String text)
                     throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message text event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createCopyrightEvent

public void createCopyrightEvent(long ticks,
                                 java.lang.String text)
                          throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message copyright event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createTrackNameEvent

public void createTrackNameEvent(long ticks,
                                 java.lang.String text)
                          throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message track name event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createInstrumentNameEvent

public void createInstrumentNameEvent(long ticks,
                                      int channel,
                                      java.lang.String text)
                               throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message instrument name event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createLyricEvent

public void createLyricEvent(long ticks,
                             java.lang.String text)
                      throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message lyric event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createMarkerEvent

public void createMarkerEvent(long ticks,
                              java.lang.String text)
                       throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message marker event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createCuePointEvent

public void createCuePointEvent(long ticks,
                                java.lang.String text)
                         throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message cue point event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createProgramNameEvent

public void createProgramNameEvent(long ticks,
                                   java.lang.String text)
                            throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message program name event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createDeviceNameEvent

public void createDeviceNameEvent(long ticks,
                                  java.lang.String text)
                           throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message device name event.

Parameters:
ticks - The event time in ticks
text - A string.
Throws:
javax.sound.midi.InvalidMidiDataException

createTempoEvent

public void createTempoEvent(long ticks,
                             int microsecondsPerBeat)
                      throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message tempo event.

Parameters:
ticks - The event time in ticks
microsecondsPerBeat - The tempo factor expressed in microseconds per beat.
Throws:
javax.sound.midi.InvalidMidiDataException

createChannelPrefixEvent

public void createChannelPrefixEvent(long ticks,
                                     int channel)
                              throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message channel prefix event.

Parameters:
ticks - The event time in ticks
channel - The MIDI channel number (1-16)
Throws:
javax.sound.midi.InvalidMidiDataException

createTimeSignatureEvent

public void createTimeSignatureEvent(long ticks,
                                     int beats,
                                     int beatType,
                                     int clocks,
                                     int division)
                              throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message time signature event.

Parameters:
ticks - The event time in ticks.
beats -
beatType -
clocks -
division -
Throws:
javax.sound.midi.InvalidMidiDataException

createKeySignatureEvent

public void createKeySignatureEvent(long ticks,
                                    int sharps,
                                    int mode)
                             throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message key signature event.

Parameters:
ticks - The event time in ticks.
sharps - Negative for flats
mode - 0 (major) 1 (minor)
Throws:
javax.sound.midi.InvalidMidiDataException

createEndOfTrackEvent

public void createEndOfTrackEvent(long ticks)
                           throws javax.sound.midi.InvalidMidiDataException
Create a MIDI meta-message end of track event.

Parameters:
ticks - The event time in ticks.
Throws:
javax.sound.midi.InvalidMidiDataException

initializeChannel

public void initializeChannel(java.lang.String deviceName,
                              int channel,
                              java.lang.String instrumentName,
                              int midiPitchBendRange)
                       throws javax.sound.midi.InvalidMidiDataException
Initialize a MIDI channel

Parameters:
deviceName -
channel -
instrumentName -
midiPitchBendRange -
Throws:
javax.sound.midi.InvalidMidiDataException

decodeEvents

public void decodeEvents()
Generate a text interpretation of a MIDI track.


setName

public void setName(java.lang.String name)
Description copied from class: MidiEntity
Set the instance name.

Overrides:
setName in class MidiEntity
Parameters:
name - The intended instance name.