public class SequenceAnalyzer
extends java.lang.Object
This class analyzes a MIDI sequence and collects information from it. This information can be displayed later by the InfoView
It also adds marker events to the sequence at each tick where the channel activity changes for at least one channel.
Modifier and Type | Field and Description |
---|---|
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Integer>> |
activityByChannel
channel – tick – number of keys pressed at this time
|
private static MidicaTreeModel |
banksAndInstrPerChannel |
private static MidicaTreeModel |
banksAndInstrTotal |
private static java.util.TreeMap<java.lang.Byte,java.lang.Byte[]> |
channelParamConfig
Describes which parameter (RPN/NRPN and MSB/LSB) will be changed in case of a data entry / data increment / data decrement.
|
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> |
channelParamHistory
History of
channelParamConfig by tick. |
private static java.lang.String |
chosenCharset |
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.String>> |
commentHistory
channel – tick – comment
|
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte>>> |
controllerHistory
channel – controller – tick – value
|
private static long |
DEFAULT_CHANNEL_CONFIG_TICK |
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> |
instrumentHistory
History of the instrument configuration for each channel.
|
private static java.util.TreeMap<java.lang.Long,java.util.TreeSet<java.lang.Byte>> |
markers
tick – channel
|
private static java.util.TreeSet<java.lang.Long> |
markerTicks
tick
|
private static java.util.ArrayList<SingleMessage> |
messages |
private static java.util.HashMap<javax.sound.midi.MidiMessage,SingleMessage> |
midiMsgToSingleMsg
translates a MIDI message to the derived SingleMessage
|
private static MidicaTreeModel |
msgTreeModel |
static byte |
NOTE_HISTORY_BUFFER_SIZE_FUTURE |
static byte |
NOTE_HISTORY_BUFFER_SIZE_PAST |
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Byte,java.lang.Byte>>> |
noteHistory
channel – tick – note – velocity
|
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Boolean>>> |
noteOnOffByChannel
channel – note – tick – on/off
|
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Integer,java.util.TreeMap<java.lang.Long,java.lang.Integer>>> |
rpnHistory
RPN history by tick.
|
private static javax.sound.midi.Sequence |
sequence |
private static java.util.HashMap<java.lang.String,java.lang.Object> |
sequenceInfo |
Modifier | Constructor and Description |
---|---|
private |
SequenceAnalyzer()
This class is only used statically so a public constructor is not needed.
|
Modifier and Type | Method and Description |
---|---|
private static void |
addNoteOff(long tick,
byte channel,
byte note)
Adds a detected note-off event to the data structures.
|
private static void |
addNoteOn(long tick,
byte channel,
byte note,
byte velocity)
Adds a detected note-on event to the data structures.
|
static void |
analyze(javax.sound.midi.Sequence seq,
java.lang.String charset)
Analyzes the given MIDI sequence and collects information about it.
|
static boolean |
getChannelActivity(byte channel,
long tick)
Calculates the channel activity for the given channel at the given tick.
|
static java.lang.String |
getChannelComment(byte channel,
long tick)
Returns the channel comment for the given channel at the given tick.
|
static java.lang.Byte[] |
getChannelParamMsbLsbType(byte channel,
long tick)
Calculates and returns RPN/NRPN info for the given channel at the given tick.
|
static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.String>> |
getCommentHistory()
Returns the channel comment history.
|
private static byte |
getControllerDefault(int ctrl)
Returns the default value for the given controller number.
|
static java.lang.Byte[] |
getInstrument(byte channel,
long tick)
Calculates and returns bank and instrument information for the given channel at the given tick.
|
static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> |
getInstrumentHistory()
Returns the instrument history.
|
static java.util.ArrayList<SingleMessage> |
getMessages()
Returns a list of all MIDI messages.
|
static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Byte,java.lang.Byte>>> |
getNoteHistory()
Returns the note history.
|
static java.util.ArrayList<java.lang.Long[]> |
getNoteHistory(byte channel,
long tick)
Calculates the note history for the given channel at the given tick.
|
static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Boolean>>> |
getOnOffHistory()
Returns the note-ON/note-OFF history.
|
static float |
getPitchBendSensitivity(byte channel,
long tick)
Returns the pitch bend sensitivity for the given channel at the given tick.
|
private static byte[] |
getRpnDefault(int msb,
int lsb)
Returns the default value for the given RPN.
|
static java.util.HashMap<java.lang.String,java.lang.Object> |
getSequenceInfo()
Returns the information that have been collected while analyzing the MIDI sequence.
|
static SingleMessage |
getSingleMsgByMidiMsg(javax.sound.midi.MidiMessage msg)
Searches for the single message in the message list that has been derived by the given MIDI message.
|
private static void |
init()
Initializes the internal data structures so that they are ready to be filled with sequence information during the parsing process.
|
private static void |
parse()
Parses the MIDI sequence track by track and event by event and collects information.
|
private static void |
postprocess()
Adds last information to the info data structure about the MIDI sequence.
|
private static void |
processMetaMessage(javax.sound.midi.MetaMessage msg,
long tick,
int trackNum,
int msgNum)
Retrieves general information from meta messages.
|
private static void |
processMetaMessageByChannel(javax.sound.midi.MetaMessage msg,
long tick,
int trackNum)
Retrieves instrument specific information from meta messages.
|
private static void |
processShortMessageByChannel(javax.sound.midi.ShortMessage msg,
long tick)
Retrieves some channel-specific information from short messages that can affect following messages.
|
static void |
reset()
Resets all information that can be queried in public getter methods.
|
private static void |
resetAllControllers(byte channel,
long tick)
Resets all controllers of the given channel to their default values.
|
private static void |
resetAllRPNs(byte channel,
long tick)
Resets all known RPNs to their default values.
|
static void |
retrieveSoftwareVersion(java.lang.String text)
Analyzes the software version string from the MIDI sequence.
|
public static final byte NOTE_HISTORY_BUFFER_SIZE_PAST
public static final byte NOTE_HISTORY_BUFFER_SIZE_FUTURE
private static final long DEFAULT_CHANNEL_CONFIG_TICK
private static javax.sound.midi.Sequence sequence
private static java.lang.String chosenCharset
private static java.util.HashMap<java.lang.String,java.lang.Object> sequenceInfo
private static MidicaTreeModel banksAndInstrPerChannel
private static MidicaTreeModel banksAndInstrTotal
private static MidicaTreeModel msgTreeModel
private static java.util.ArrayList<SingleMessage> messages
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Boolean>>> noteOnOffByChannel
channel – note – tick – on/off
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Byte,java.lang.Byte>>> noteHistory
channel – tick – note – velocity
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Integer>> activityByChannel
channel – tick – number of keys pressed at this time
private static java.util.TreeMap<java.lang.Long,java.util.TreeSet<java.lang.Byte>> markers
tick – channel
private static java.util.TreeSet<java.lang.Long> markerTicks
tick
private static java.util.HashMap<javax.sound.midi.MidiMessage,SingleMessage> midiMsgToSingleMsg
translates a MIDI message to the derived SingleMessage
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> instrumentHistory
History of the instrument configuration for each channel.
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.String>> commentHistory
channel – tick – comment
private static java.util.TreeMap<java.lang.Byte,java.lang.Byte[]> channelParamConfig
Describes which parameter (RPN/NRPN and MSB/LSB) will be changed in case of a data entry / data increment / data decrement.
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> channelParamHistory
History of channelParamConfig
by tick.
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte>>> controllerHistory
channel – controller – tick – value
private static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Integer,java.util.TreeMap<java.lang.Long,java.lang.Integer>>> rpnHistory
RPN history by tick.
private SequenceAnalyzer()
This class is only used statically so a public constructor is not needed.
public static void reset()
Resets all information that can be queried in public getter methods. This is called before a MIDI or MidicaPL file is parsed so that the getters don’t return the information of a former parsing after a later parsing failed.
public static void analyze(javax.sound.midi.Sequence seq, java.lang.String charset) throws ParseException
Analyzes the given MIDI sequence and collects information about it. Adds marker events for channel activity changes.
seq
- The MIDI sequence to be analyzed.charset
- The charset that has been chosen in the file chooser.ParseException
- if something went wrong.public static java.util.ArrayList<SingleMessage> getMessages()
Returns a list of all MIDI messages.
public static SingleMessage getSingleMsgByMidiMsg(javax.sound.midi.MidiMessage msg)
Searches for the single message in the message list that has been derived by the given MIDI message. Returns the message from the list, if found.
Used by the decompiler to create warnings due to ignored messages.
msg
- MIDI messagepublic static java.util.HashMap<java.lang.String,java.lang.Object> getSequenceInfo()
Returns the information that have been collected while analyzing the MIDI sequence.
If no MIDI sequence has been loaded: returns an empty data structure.
public static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Byte[]>> getInstrumentHistory()
Returns the instrument history.
Structure:
public static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.String>> getCommentHistory()
Returns the channel comment history.
Structure:
public static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Byte,java.lang.Byte>>> getNoteHistory()
Returns the note history.
Structure:
public static java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Byte,java.util.TreeMap<java.lang.Long,java.lang.Boolean>>> getOnOffHistory()
Returns the note-ON/note-OFF history.
Structure:
private static void init() throws java.lang.ReflectiveOperationException
Initializes the internal data structures so that they are ready to be filled with sequence information during the parsing process.
java.lang.ReflectiveOperationException
- if the root node of the message tree cannot be created.private static void parse() throws java.lang.ReflectiveOperationException
Parses the MIDI sequence track by track and event by event and collects information.
java.lang.ReflectiveOperationException
- if a tree node cannot be created.private static void processShortMessageByChannel(javax.sound.midi.ShortMessage msg, long tick) throws java.lang.ReflectiveOperationException
Retrieves some channel-specific information from short messages that can affect following messages.
The regarded messages are:
Stores these information in order to lookup their values later, when other (affected) messages are found.
Fills the trees for the info view tab “Banks, Instruments, Notes”.
Does not fill the tree in the tab “MIDI Messages”.
msg
- Short messagetick
- Tickstampjava.lang.ReflectiveOperationException
- if the note-on event cannot be added to one of the tree models.private static void processMetaMessage(javax.sound.midi.MetaMessage msg, long tick, int trackNum, int msgNum) throws java.lang.ReflectiveOperationException
Retrieves general information from meta messages.
msg
- Meta messagetick
- TickstamptrackNum
- Track number (beginning with 0).msgNum
- Number of the message inside the track.java.lang.ReflectiveOperationException
- if the message cannot be added to the tree model.private static void processMetaMessageByChannel(javax.sound.midi.MetaMessage msg, long tick, int trackNum)
Retrieves instrument specific information from meta messages.
msg
- Meta message.tick
- Tickstamp.trackNum
- Track number of the created string.private static void addNoteOn(long tick, byte channel, byte note, byte velocity) throws java.lang.ReflectiveOperationException
Adds a detected note-on event to the data structures.
tick
- The tickstamp when this event occurred.channel
- The MIDI channel number.note
- The note number.velocity
- The note’s velocity.java.lang.ReflectiveOperationException
- if the note cannot be added to one of the tree models.private static void addNoteOff(long tick, byte channel, byte note)
Adds a detected note-off event to the data structures.
tick
- The tickstamp when this event occurred.channel
- The MIDI channel number.note
- The note number.private static void postprocess() throws ParseException
Adds last information to the info data structure about the MIDI sequence. Adds marker events to the sequence.
ParseException
- if the marker events cannot be added to the MIDI sequence.public static boolean getChannelActivity(byte channel, long tick)
Calculates the channel activity for the given channel at the given tick.
channel
- MIDI channeltick
- tickstamp of the sequencepublic static java.util.ArrayList<java.lang.Long[]> getNoteHistory(byte channel, long tick)
Calculates the note history for the given channel at the given tick.
The returned history consists of past and future notes, ordered by the tickstamp of their occurrence. Each entry contains the following parts:
channel
- MIDI channeltick
- tickstamp of the sequencepublic static java.lang.Byte[] getInstrument(byte channel, long tick)
Calculates and returns bank and instrument information for the given channel at the given tick.
The returned value consists of 3 bytes with the following meaning:
channel
- MIDI channeltick
- tickstamp of the sequencepublic static java.lang.String getChannelComment(byte channel, long tick)
Returns the channel comment for the given channel at the given tick.
channel
- MIDI channeltick
- tickstamp of the sequencepublic static java.lang.Byte[] getChannelParamMsbLsbType(byte channel, long tick)
Calculates and returns RPN/NRPN info for the given channel at the given tick. Called from MessageClassifier
while processing a data entry/increment/decrement message.
The returned value consists of 3 bytes with the following meaning:
channel
- MIDI channeltick
- tickstamp of the sequencepublic static final float getPitchBendSensitivity(byte channel, long tick)
Returns the pitch bend sensitivity for the given channel at the given tick.
channel
- MIDI channeltick
- tickstamp of the sequencepublic static void retrieveSoftwareVersion(java.lang.String text)
Analyzes the software version string from the MIDI sequence. Called from the KaraokeAnalyzer
.
text
- software version string.private static final void resetAllControllers(byte channel, long tick)
Resets all controllers of the given channel to their default values.
channel
- MIDI channeltick
- tickstamp of the sequenceprivate static final byte getControllerDefault(int ctrl)
Returns the default value for the given controller number.
ctrl
- Controller numberprivate static final void resetAllRPNs(byte channel, long tick)
Resets all known RPNs to their default values.
channel
- MIDI channeltick
- tickstamp of the sequenceprivate static final byte[] getRpnDefault(int msb, int lsb)
Returns the default value for the given RPN.
msb
- RPN MSBlsb
- RPN LSB