public class Instrument extends java.lang.Object implements java.lang.Comparable<Instrument>
Objects of this class represent a specific MIDI channel. They adjust their state according to the commands of the MidicaPLParser
while parsing source files - or according to the commands of the MidicaPLExporter
while exporting source files.
The following elements of a channel’s state need further explication:
Modifier and Type | Field and Description |
---|---|
boolean |
autoChannel
Indicates if this channel has been automatically (true) or explicitly (false) defined.
|
private int |
bankLSB
LSB of the bank number (0-127)
|
private int |
bankMSB
MSB of the bank number (0-127)
|
int |
channel
Channel number as defined by the MIDI specification.
|
private long |
currentTicks
Current tickstamp
|
private static float |
DEFAULT_DURATION_RATIO
Default duration ratio for this channel unless defined differently.
|
private static java.lang.String |
DEFAULT_NOTE_LENGTH |
private static byte |
DEFAULT_OCTAVE |
private static int |
DEFAULT_VELOCITY
Default velocity for this channel unless defined differently.
|
private float |
durationRatio
Ratio between key press duration and note length duration
|
java.lang.String |
instrumentName
Instrument name like it is read from the MidicaPL source file.
|
int |
instrumentNumber
Instrument number as defined by the MIDI specification.
|
private java.util.HashMap<java.lang.Integer,java.lang.Long> |
lastNoteOff
key = note; value = tickstamp of the last NOTE-OFF
|
private java.util.HashMap<java.lang.Integer,java.lang.Long> |
lastNoteOn
key = note; value = tickstamp of the last NOTE-ON
|
private static int |
MIN_CURRENT_TICKS
First tickstamp where any action can occur.
|
private static long |
MIN_NOTE_LENGTH
Minimum remaining note length after applying the duration ratio
|
private java.lang.String |
noteLength |
private byte |
octave |
private java.lang.Long |
stopTickForLegatoCorrection
If legato overlappings are detected while adding a note, this is the stop tick of the detected note to be corrected.
|
private int |
velocity
Current velocity
|
Constructor and Description |
---|
Instrument(int channel,
int instrumentNumber,
java.lang.String instrumentName,
boolean automatic)
Creates a new Instrument object representing a channel during the parsing or export procedure of a MidicaPL source file.
|
Modifier and Type | Method and Description |
---|---|
long |
addNote(int note,
int duration)
Increments the tickstamp according to the note’s duration in ticks.
|
int |
compareTo(Instrument other) |
int |
getBankLSB()
Returns the currently configured bank LSB.
|
int |
getBankMSB()
Returns the currently configured bank MSB.
|
long |
getCurrentTicks()
Returns the current tickstamp.
|
float |
getDurationRatio()
Returns the current duration ratio of the channel.
|
static long |
getMaxCurrentTicks(java.util.ArrayList<Instrument> instruments)
Returns the maximum tickstamp of all the channels.
|
java.lang.String |
getNoteLength()
Returns the currently configured note length.
|
byte |
getOctave()
Returns the currently configured octave.
|
java.lang.Long |
getStopTickToCorrect()
Returns the stop tick of the note to be corrected due to legato overlappings, or null if no overlappings have been detected.
|
int |
getVelocity()
Returns the current velocity of the channel.
|
void |
incrementTicks(int duration)
Increments the tickstamp according to the note length duration.
|
void |
reset()
Resets the current tickstamp and the data structures storing the last pressed notes.
|
boolean[] |
setBank(int msb,
int lsb)
Sets the bank.
|
void |
setCurrentTicks(long currentTicks)
Sets the current tickstamp.
|
void |
setDurationRatio(float durationRatio)
Sets a new key-press/note-length duration ratio.
|
void |
setNoteLength(java.lang.String noteLength)
Sets the note length of the channel.
|
void |
setOctave(byte octave)
Sets the octave of the channel.
|
void |
setVelocity(int velocity)
Sets the velocity of the channel.
|
java.lang.String |
toString() |
private static final int MIN_CURRENT_TICKS
First tickstamp where any action can occur.
private static final int DEFAULT_VELOCITY
Default velocity for this channel unless defined differently.
private static final float DEFAULT_DURATION_RATIO
Default duration ratio for this channel unless defined differently.
private static final long MIN_NOTE_LENGTH
Minimum remaining note length after applying the duration ratio
private static final byte DEFAULT_OCTAVE
private static final java.lang.String DEFAULT_NOTE_LENGTH
public final int channel
Channel number as defined by the MIDI specification. Between 0 and 15.
public int instrumentNumber
Instrument number as defined by the MIDI specification. Between 0 and 127.
public java.lang.String instrumentName
Instrument name like it is read from the MidicaPL source file.
public boolean autoChannel
Indicates if this channel has been automatically (true) or explicitly (false) defined.
private int bankMSB
MSB of the bank number (0-127)
private int bankLSB
LSB of the bank number (0-127)
private java.util.HashMap<java.lang.Integer,java.lang.Long> lastNoteOn
key = note; value = tickstamp of the last NOTE-ON
private java.util.HashMap<java.lang.Integer,java.lang.Long> lastNoteOff
key = note; value = tickstamp of the last NOTE-OFF
private java.lang.Long stopTickForLegatoCorrection
If legato overlappings are detected while adding a note, this is the stop tick of the detected note to be corrected. If no legato overlappings are detected, this is null.
private int velocity
Current velocity
private long currentTicks
Current tickstamp
private float durationRatio
Ratio between key press duration and note length duration
private byte octave
private java.lang.String noteLength
public Instrument(int channel, int instrumentNumber, java.lang.String instrumentName, boolean automatic)
Creates a new Instrument object representing a channel during the parsing or export procedure of a MidicaPL source file. While parsing this can be done explicitly inside the first INSTRUMENTS block or (if not defined in this block) when the first INSTRUMENTS block is left.
channel
- Channel number as defined by the MIDI specification (0-15)instrumentNumber
- Instrument number as defined by the MIDI specification (0-127)instrumentName
- Instrument name as defined in the INSTRUMENTS command or (if not defined explicitly) the default channel comment (in the parsing procedure) or the pre-configured instrument name (in the export procedure)automatic
- false, as soon as the instrument has been defined explicitly inside an INSTRUMENTS block; otherwise (or until the first definition inside an INSTRUMENTS block): truepublic int compareTo(Instrument other)
compareTo
in interface java.lang.Comparable<Instrument>
public int getVelocity()
Returns the current velocity of the channel.
public void setVelocity(int velocity)
Sets the velocity of the channel.
velocity
- New velocity of the channel as defined in the MIDI specification. (0-127)public long getCurrentTicks()
Returns the current tickstamp. This is the amount of MIDI ticks for which this channel has already been parsed so far.
public void setCurrentTicks(long currentTicks)
Sets the current tickstamp. This is the amount of MIDI ticks for which this channel has already been parsed so far.
currentTicks
- New tickstamp to be set.public void reset()
Resets the current tickstamp and the data structures storing the last pressed notes.
This is done during the initial instruments setup.
public float getDurationRatio()
Returns the current duration ratio of the channel. This is the ratio between key press duration and note length duration. 0.1 means 10% (strong staccato)
0.5 means 50% (staccato)
1.0 means 100% (legato)
more than 1.0 is overlapping legato
public void setDurationRatio(float durationRatio)
Sets a new key-press/note-length duration ratio.
durationRatio
- New duration ratio.public long addNote(int note, int duration)
Increments the tickstamp according to the note’s duration in ticks.
note
- Note number.duration
- Note length duration in ticks.public java.lang.Long getStopTickToCorrect()
Returns the stop tick of the note to be corrected due to legato overlappings, or null if no overlappings have been detected.
public void incrementTicks(int duration)
Increments the tickstamp according to the note length duration.
duration
- duration in tickspublic java.lang.String toString()
toString
in class java.lang.Object
public static long getMaxCurrentTicks(java.util.ArrayList<Instrument> instruments)
Returns the maximum tickstamp of all the channels.
instruments
- List of all Instrument
objects.public boolean[] setBank(int msb, int lsb)
Sets the bank.
Returns the following two values.
msb
- bank MSBlsb
- bank LSBpublic int getBankMSB()
Returns the currently configured bank MSB.
public int getBankLSB()
Returns the currently configured bank LSB.
public byte getOctave()
Returns the currently configured octave.
public void setOctave(byte octave)
Sets the octave of the channel.
octave
- New octave of the channel.public java.lang.String getNoteLength()
Returns the currently configured note length.
public void setNoteLength(java.lang.String noteLength)
Sets the note length of the channel.
noteLength
- New note length of the channel.