public class SequenceCreator
extends java.lang.Object
This class is used to create a MIDI sequence. It is used by one of the parser methods while parsing a MidicaPL or MIDI file.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
charset |
static int |
DEFAULT_RESOLUTION |
static int |
IMPORT_FORMAT_ABC |
static int |
IMPORT_FORMAT_ALDA |
static int |
IMPORT_FORMAT_LY |
static int |
IMPORT_FORMAT_MIDI |
static int |
IMPORT_FORMAT_MIDICAPL |
static int |
IMPORT_FORMAT_MUSESCORE |
static int |
IMPORT_FORMAT_NONE |
private static int |
importFormat |
private static boolean |
isSuccess |
private static java.util.HashMap<java.lang.Integer,java.util.HashMap<java.lang.Integer,javax.sound.midi.MidiEvent>> |
lastNoteOffEvent
channel – note – event
|
static long |
NOW |
static int |
NUM_META_TRACKS |
static int |
NUM_TRACKS |
private static int |
resolution |
private static javax.sound.midi.Sequence |
seq |
private static javax.sound.midi.Track[] |
tracks |
Modifier | Constructor and Description |
---|---|
private |
SequenceCreator()
This class is only used statically so a public constructor is not needed.
|
Modifier and Type | Method and Description |
---|---|
static void |
addMarkers(java.util.TreeMap<java.lang.Long,java.util.TreeSet<java.lang.Byte>> markers)
Adds meta events of the type marker to the sequence.
|
static void |
addMessageCopyright(java.lang.String copyright)
Adds a copyright meta message to tick 0 of the sequence.
|
static void |
addMessageGeneric(javax.sound.midi.MidiMessage msg,
int channel,
long tick)
Adds a channel-dependent generic message.
|
static void |
addMessageGeneric(javax.sound.midi.MidiMessage msg,
long tick)
Adds a channel-independent generic message.
|
static void |
addMessageKeySignature(int note,
boolean isMajor,
long tick,
boolean preferFlat)
Sets the key signature using a meta message.
|
static void |
addMessageKeystroke(int channel,
int note,
long startTick,
long endTick,
int velocity)
Adds the note-ON and note-OFF messages for one note to be played.
|
static void |
addMessageLyrics(java.lang.String lyrics,
long tick,
boolean isRp26)
Adds a lyrics meta message.
|
static void |
addMessageNoteOFF(int channel,
int note,
long tick)
Adds a note-OFF event.
|
static void |
addMessageNoteON(int channel,
int note,
long tick,
int velocity)
Adds a note-ON event.
|
static void |
addMessageTempo(int bpm,
long tick)
Sets the tempo in beats per minute by creating a tempo change message.
|
static void |
addMessageText(java.lang.String text,
long tick,
int skType)
Adds a text meta message.
|
static void |
addMessageTimeSignature(int numerator,
int denominator,
long tick)
Sets the time signature using a meta message.
|
static void |
addMessageToTrack(javax.sound.midi.MidiMessage msg,
int track,
long tick)
Adds a MIDI message to the given track.
|
static java.lang.String |
getCharset()
Returns the chosen (or assumed) charset of the last successfully parsed sequence.
|
static int |
getImportFormat()
Returns the import format of the last attempted import.
|
static int |
getResolution()
Returns the resolution of the MIDI sequence in ticks per quarter note.
|
static javax.sound.midi.Sequence |
getSequence()
Returns the created MIDI sequence from the last import attempt, if any.
|
static void |
initChannel(int channel,
int instrNum,
java.lang.String comment,
long tick)
Initiates or changes the given channel’s instrument, bank and channel comment.
|
static void |
moveNoteOffMessage(int channel,
int note,
long fromTick,
long toTick)
Moves the last note-off event matching the given parameters to a new position.
|
static void |
postprocess()
Remembers that this parsing attempt was successful.
|
static void |
reset(int res,
java.lang.String chosenCharset,
int importFormat)
Creates a new sequence and sets it’s resolution to the given value.
|
static void |
reset(java.lang.String chosenCharset)
Creates a new sequence and sets it’s resolution to the default value.
|
static void |
setBank(int channel,
long tick,
int value,
boolean isLSB)
Sets the bank MSB or LSB by sending an according control change message.
|
public static final long NOW
public static final int DEFAULT_RESOLUTION
public static final int NUM_META_TRACKS
public static final int NUM_TRACKS
public static final int IMPORT_FORMAT_NONE
public static final int IMPORT_FORMAT_MIDICAPL
public static final int IMPORT_FORMAT_MIDI
public static final int IMPORT_FORMAT_ALDA
public static final int IMPORT_FORMAT_ABC
public static final int IMPORT_FORMAT_LY
public static final int IMPORT_FORMAT_MUSESCORE
private static boolean isSuccess
private static int importFormat
private static int resolution
private static java.lang.String charset
private static javax.sound.midi.Track[] tracks
private static javax.sound.midi.Sequence seq
private static java.util.HashMap<java.lang.Integer,java.util.HashMap<java.lang.Integer,javax.sound.midi.MidiEvent>> lastNoteOffEvent
channel – note – event
private SequenceCreator()
This class is only used statically so a public constructor is not needed.
public static void reset(java.lang.String chosenCharset) throws javax.sound.midi.InvalidMidiDataException
Creates a new sequence and sets it’s resolution to the default value. Initiates all necessary data structures.
Only called by MidicaPLParser
.
chosenCharset
- Charset to be used for text-based messages.javax.sound.midi.InvalidMidiDataException
- if Sequence.PPQ
is not a valid division type. This should never happen.public static void reset(int res, java.lang.String chosenCharset, int importFormat) throws javax.sound.midi.InvalidMidiDataException
Creates a new sequence and sets it’s resolution to the given value. Initiates all necessary data structures. This method is called by the MidiParser
.
res
- Resolution of the new sequence.chosenCharset
- Charset to be used for text-based messages.importFormat
- File type of the import file.javax.sound.midi.InvalidMidiDataException
- if Sequence
.PPQ is not a valid division type. This should never happen.public static void postprocess()
Remembers that this parsing attempt was successful.
public static javax.sound.midi.Sequence getSequence()
Returns the created MIDI sequence from the last import attempt, if any.
public static int getImportFormat()
Returns the import format of the last attempted import.
The import format is one of the IMPORT_FILE_* constants. If the last import attempt failed, IMPORT_FORMAT_NONE
is returned.
public static java.lang.String getCharset()
Returns the chosen (or assumed) charset of the last successfully parsed sequence.
Returns null if the last import attempt failed.
public static void setBank(int channel, long tick, int value, boolean isLSB) throws javax.sound.midi.InvalidMidiDataException
Sets the bank MSB or LSB by sending an according control change message.
channel
- Channel number from 0 to 15.tick
- Tickstamp of the bank select or -1 if the method is called during initialization. TODO: test, how much the tick must be BEFORE the program changevalue
- The value to set.isLSB
- false: set the MSB; true: set the LSBjavax.sound.midi.InvalidMidiDataException
public static void initChannel(int channel, int instrNum, java.lang.String comment, long tick) throws javax.sound.midi.InvalidMidiDataException
Initiates or changes the given channel’s instrument, bank and channel comment.
The following steps are performed:
channel
- Channel number from 0 to 15.instrNum
- Instrument number - corresponds to the MIDI program number.comment
- Comment to be used as the track name.tick
- Tickstamp of the instrument change or 0 if the method is called during initialization.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageKeystroke(int channel, int note, long startTick, long endTick, int velocity) throws javax.sound.midi.InvalidMidiDataException
Adds the note-ON and note-OFF messages for one note to be played.
channel
- Channel number from 0 to 15.note
- Note number.startTick
- Tickstamp of the note-ON event.endTick
- Tickstamp of the note-OFF event.velocity
- Velocity of the key stroke.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageNoteON(int channel, int note, long tick, int velocity) throws javax.sound.midi.InvalidMidiDataException
Adds a note-ON event.
channel
- Channel number from 0 to 15.note
- Note number.tick
- Tickstamp of the event.velocity
- Velocity of the key stroke.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageNoteOFF(int channel, int note, long tick) throws javax.sound.midi.InvalidMidiDataException
Adds a note-OFF event.
channel
- Channel number from 0 to 15.note
- Note number.tick
- Tickstamp of the event.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void moveNoteOffMessage(int channel, int note, long fromTick, long toTick) throws java.lang.Exception
Moves the last note-off event matching the given parameters to a new position. This is needed to correct legato-overlappings, otherwise resulting in a sequence like this:
This can happen if a note is played twice in a row in the same channel, with a legato value of more than 100%.
channel
- Channel number from 0 to 15.note
- Note number.fromTick
- Tick from where the event shall be moved away.toTick
- Tick where the event shall be moved to.java.lang.Exception
- if the event to be moved was not found or has a different tick than expected.public static void addMessageTempo(int bpm, long tick) throws javax.sound.midi.InvalidMidiDataException
Sets the tempo in beats per minute by creating a tempo change message.
bpm
- Tempo in beats per minute.tick
- Tickstamp of the tempo change event.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageTimeSignature(int numerator, int denominator, long tick) throws javax.sound.midi.InvalidMidiDataException
Sets the time signature using a meta message.
numerator
- Numerator of the time signaturedenominator
- Denominator of the time signaturetick
- Tickstamp of the time signature eventjavax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageKeySignature(int note, boolean isMajor, long tick, boolean preferFlat) throws javax.sound.midi.InvalidMidiDataException
Sets the key signature using a meta message.
note
- any note number from 0 to 127isMajor
- true for a major key signature, false for a minor onetick
- Tickstamp of the time signature eventpreferFlat
- true use flat symbols, if both is possible; false: use sharpjavax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageCopyright(java.lang.String copyright) throws javax.sound.midi.InvalidMidiDataException
Adds a copyright meta message to tick 0 of the sequence. This is called from the MidicaPLParser
when postprocessing meta commands.
copyright
- The message to be added to the sequence.javax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageLyrics(java.lang.String lyrics, long tick, boolean isRp26) throws javax.sound.midi.InvalidMidiDataException
Adds a lyrics meta message. The message may also be a meta message according to RP-026.
lyrics
- The message to be added.tick
- The tick where the lyrics event shall be added.isRp26
- true in case of a RP-026 message, otherwis: falsejavax.sound.midi.InvalidMidiDataException
- if invalid MIDI data is used to create a MIDI message.public static void addMessageText(java.lang.String text, long tick, int skType) throws javax.sound.midi.InvalidMidiDataException
Adds a text meta message.
The skType parameter can have the following values:
text
- The text to be added.tick
- MIDI tick.skType
- Soft Karaoke text type: 0, 1 or 2 - as described above.javax.sound.midi.InvalidMidiDataException
public static void addMessageGeneric(javax.sound.midi.MidiMessage msg, int channel, long tick)
Adds a channel-dependent generic message. This is called by the MidiParser
to add messages that are not handled by another method.
msg
- Generic MIDI message.channel
- Channel number from 0 to 15.tick
- Tickstamp of the event.public static void addMessageGeneric(javax.sound.midi.MidiMessage msg, long tick)
Adds a channel-independent generic message. This is called by the MidiParser
to add messages that are not handled by another method.
Those messages are added to track 0.
msg
- Generic MIDI message.tick
- Tickstamp of the event.public static void addMessageToTrack(javax.sound.midi.MidiMessage msg, int track, long tick)
Adds a MIDI message to the given track.
This is needed for karaoke-related meta messages from foreign MIDI files. These messages must be put into the right track. That makes sure that they are later processed in the right order. (Sorted by tick, not by original track number).
msg
- Meta message.track
- Track number.tick
- Tickstamp of the event.public static int getResolution()
Returns the resolution of the MIDI sequence in ticks per quarter note.
public static void addMarkers(java.util.TreeMap<java.lang.Long,java.util.TreeSet<java.lang.Byte>> markers) throws javax.sound.midi.InvalidMidiDataException
Adds meta events of the type marker to the sequence. These events show that the activity state of some channels change at this point.
This is called by the SequenceAnalyzer
after all other analyzing is done.
The markers are always added to track 0.
markers
- First dimension: tick; Second dimension: bitmasked channels that change their activity (and/or other properties) at this tick.javax.sound.midi.InvalidMidiDataException
- if one of the marker messages cannot be created.