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)
|
private int |
barLineTolerance
current bar line tolerance
|
int |
channel
Channel number as defined by the MIDI specification.
|
private long |
currentTicks
Current tickstamp
|
private static int |
DEFAULT_BAR_LINE_TOLERANCE
Default tolerance for bar line checks in ticks.
|
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 |
naturalLength
current note length for compact syntax WITHOUT block-tuplets
|
private java.lang.String |
noteLength
current note length for compact syntax or ALDA
|
private byte |
octave |
private boolean |
otoMultiple
one-time option for compact syntax: multiple
|
private java.lang.Integer |
otoQuantity
one-time option for compact syntax: quantity
|
private java.lang.String |
otoTremolo
one-time option for compact syntax: tremolo
|
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.
|
int |
getBarLineTolerance()
Returns the currently configured bar line tolerance.
|
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 |
getNaturalLength()
Returns the currently configured natural length.
|
java.lang.String |
getNoteLength()
Returns the currently configured note length.
|
byte |
getOctave()
Returns the currently configured octave.
|
int |
getOtoQuantity()
Returns the one-time quantity for compact syntax.
|
java.lang.String |
getOtoTremolo()
Returns the one-time tremolo value for compact syntax, if set.
|
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.
|
boolean |
isOtoMultiple()
Determins if a one-time multiple option is set for compact syntax.
|
void |
reset()
Resets the current tickstamp and the data structures storing the last pressed notes.
|
void |
resetOto()
Resets all one-time option for compact syntax.
|
boolean[] |
setBank(int msb,
int lsb)
Sets the bank.
|
void |
setBarLineTolerance(int barLineTolerance)
Sets the bar line tolerance.
|
void |
setCurrentTicks(long currentTicks)
Sets the current tickstamp.
|
void |
setDurationRatio(float durationRatio)
Sets a new key-press/note-length duration ratio.
|
void |
setNaturalLength(java.lang.String naturalLength)
Sets the natural length of the channel (note length without block tuplets).
|
void |
setNoteLength(java.lang.String noteLength)
Sets the note length of the channel.
|
void |
setOctave(byte octave)
Sets the octave of the channel.
|
void |
setOtoMultiple(boolean multiple)
Sets or resets the one-time multiple option for compact syntax.
|
void |
setOtoQuantity(int quantity)
Sets the one-time quantity for compact syntax.
|
void |
setOtoTremolo(java.lang.String tremolo)
Sets or resets the one-time tremolo value for compact syntax.
|
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 int DEFAULT_BAR_LINE_TOLERANCE
Default tolerance for bar line checks in ticks.
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 java.lang.String noteLength
current note length for compact syntax or ALDA
private java.lang.String naturalLength
current note length for compact syntax WITHOUT block-tuplets
private int barLineTolerance
current bar line tolerance
private java.lang.Integer otoQuantity
one-time option for compact syntax: quantity
private java.lang.String otoTremolo
one-time option for compact syntax: tremolo
private boolean otoMultiple
one-time option for compact syntax: multiple
private byte octave
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.public java.lang.String getNaturalLength()
Returns the currently configured natural length.
public void setNaturalLength(java.lang.String naturalLength)
Sets the natural length of the channel (note length without block tuplets).
naturalLength
- note length without block tupletspublic int getBarLineTolerance()
Returns the currently configured bar line tolerance.
public void setBarLineTolerance(int barLineTolerance)
Sets the bar line tolerance.
barLineTolerance
- bar line tolerance to be set.public int getOtoQuantity()
Returns the one-time quantity for compact syntax. The default is 1.
public void setOtoQuantity(int quantity) throws ParseException
Sets the one-time quantity for compact syntax.
quantity
- number to setParseException
- if the option is already setpublic java.lang.String getOtoTremolo()
Returns the one-time tremolo value for compact syntax, if set. Otherwise, returns null.
tremolo
- one-time tremolo value or nullpublic void setOtoTremolo(java.lang.String tremolo) throws ParseException
Sets or resets the one-time tremolo value for compact syntax.
tremolo
- tremolo value to set, or null to resetParseException
- if the option is already setpublic boolean isOtoMultiple()
Determins if a one-time multiple option is set for compact syntax.
public void setOtoMultiple(boolean multiple) throws ParseException
Sets or resets the one-time multiple option for compact syntax.
multiple
- true to set the multiple option, false to reset it.ParseException
- if the option is already setpublic void resetOto()
Resets all one-time option for compact syntax.