public class MidicaPLParser extends SequenceParser
This class is used to parse a MidicaPL source file.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BANK_SEP |
static java.lang.String |
BAR_LINE |
private static java.util.regex.Pattern |
barLinePattern |
static java.lang.String |
BLOCK_CLOSE |
static java.lang.String |
BLOCK_OPEN |
static java.lang.String |
CALL |
private static java.util.regex.Pattern |
callPattern |
static java.lang.String |
CHORD |
static java.lang.String |
CHORD_ASSIGNER |
static java.lang.String |
CHORD_SEPARATOR |
private static java.util.regex.Pattern |
chordAssignPattern |
private static java.util.TreeMap<java.lang.String,java.util.TreeSet<java.lang.Integer>> |
chords |
private static java.util.regex.Pattern |
chordSepPattern |
private static java.lang.String |
chosenCharset |
static java.lang.String |
COMMENT |
static java.lang.String |
COMPACT_CHANNEL |
static java.lang.String |
COMPACT_NOTE_SEP |
static java.lang.String |
COMPACT_OPT_CLOSE |
static java.lang.String |
COMPACT_OPT_OPEN |
private static java.util.regex.Pattern |
compactChannelPattern |
private static java.util.HashSet<java.lang.String> |
compactOptionsWithoutRest |
private static java.util.HashSet<java.lang.String> |
compactOptionsWithRest |
private static java.util.regex.Pattern |
compactOptPattern |
static java.lang.String |
COND_EQ |
static java.lang.String |
COND_GE |
static java.lang.String |
COND_GT |
static java.lang.String |
COND_IN |
static java.lang.String |
COND_IN_SEP |
static java.lang.String |
COND_LE |
static java.lang.String |
COND_LT |
static java.lang.String |
COND_NDEF |
static java.lang.String |
COND_NEQ |
static int |
COND_TYPE_ELSE |
static int |
COND_TYPE_ELSIF |
static int |
COND_TYPE_IF |
static int |
COND_TYPE_NONE |
private boolean |
condChainHit |
private boolean |
condChainOpened |
private static java.util.regex.Pattern |
condInPattern |
private static java.util.regex.Pattern |
condPattern |
static java.lang.String |
CONST |
protected static java.util.HashMap<java.lang.String,java.lang.String> |
constants |
private static java.util.regex.Pattern |
crlfSkPattern |
private java.util.ArrayList<java.lang.String> |
currentFunction |
private java.lang.String |
currentFunctionName |
private java.lang.String |
currentLineContent |
private int |
currentLineNumber |
private int |
currentMode |
private java.util.ArrayList<java.lang.String> |
currentPattern |
private java.lang.String |
currentPatternName |
static java.lang.String |
D |
static java.lang.String |
DEFINE |
private static java.util.HashSet<java.lang.String> |
definedFunctionNames |
private static java.util.HashSet<java.lang.String> |
definedPatternNames |
static java.lang.String |
DOT |
static java.lang.String |
DURATION |
static java.lang.String |
DURATION_PERCENT |
static java.lang.String |
ELSE |
static java.lang.String |
ELSIF |
static java.lang.String |
END |
private java.io.File |
file |
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
fileCache |
private static java.util.regex.Pattern |
flatPattern |
private static boolean |
frstInstrBlkOver |
static java.lang.String |
FUNCTION |
private static java.util.Deque<java.io.File> |
functionFileStack |
private static java.util.Deque<java.lang.Integer> |
functionLineStack |
private static java.util.Deque<java.lang.String> |
functionNameStack |
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
functions |
private static java.util.HashMap<java.lang.String,java.io.File> |
functionToFile |
private static java.util.HashMap<java.lang.String,java.lang.Integer> |
functionToLineOffset |
static java.lang.String |
GLOBAL |
static java.lang.String |
IF |
static java.lang.String |
INCLUDE |
static java.lang.String |
INSTRUMENT |
protected static java.util.ArrayList<Instrument> |
instruments |
static java.lang.String |
INSTRUMENTS |
private static boolean |
instrumentsParsed |
private static java.util.regex.Pattern |
invalidNoteIdxPattern |
private static boolean |
isChInstMetaParsRun |
private static boolean |
isCondCheckParsRun |
private static boolean |
isConstParsRun |
private static boolean |
isDefaultParsRun |
private static boolean |
isDefineParsRun |
private static boolean |
isFuncNameParsRun |
private static boolean |
isFuncParsRun |
static boolean |
isPlayingTupletBlock |
private boolean |
isRootParser
Indicates if the current parser object parses the file chosen by the user.
|
private static boolean |
isSoftKaraoke |
static java.lang.String |
KEY_MAJ |
static java.lang.String |
KEY_MIN |
static java.lang.String |
KEY_SEPARATOR |
static java.lang.String |
KEY_SIG |
static java.lang.String |
L |
static java.lang.String |
LENGTH |
static java.lang.String |
LENGTH_1 |
static java.lang.String |
LENGTH_16 |
static java.lang.String |
LENGTH_2 |
static java.lang.String |
LENGTH_32 |
static java.lang.String |
LENGTH_4 |
static java.lang.String |
LENGTH_8 |
static java.lang.String |
LENGTH_M1 |
static java.lang.String |
LENGTH_M16 |
static java.lang.String |
LENGTH_M2 |
static java.lang.String |
LENGTH_M32 |
static java.lang.String |
LENGTH_M4 |
static java.lang.String |
LENGTH_M8 |
static java.lang.String |
LENGTH_PLUS |
static java.lang.String |
LENGTH_ZERO |
static java.lang.String |
LYRICS |
static java.lang.String |
LYRICS_COMMA |
static java.lang.String |
LYRICS_CR |
static java.lang.String |
LYRICS_LF |
static java.lang.String |
LYRICS_SPACE |
private static LyricUtil |
lyricUtil |
static java.lang.String |
M |
static java.lang.String |
MAGIC_VAR_ALL |
static java.lang.String |
MAGIC_VAR_NC |
static java.lang.String |
MAGIC_VAR_REV |
private static java.util.Deque<java.util.HashMap<java.lang.String,java.lang.String>> |
magicVarStack |
private static int |
MAX_RECURSION_DEPTH_CONST |
private static int |
MAX_RECURSION_DEPTH_FUNCTION |
private static int |
MAX_RECURSION_DEPTH_PATTERN |
private static int |
MAX_RECURSION_DEPTH_VAR |
private static java.util.TreeMap<java.lang.Long,java.lang.Long> |
measureLengthHistory |
static java.lang.String |
META |
static java.lang.String |
META_ARTIST |
static java.lang.String |
META_COMPOSER |
static java.lang.String |
META_COPYRIGHT |
static java.lang.String |
META_LYRICIST |
static java.lang.String |
META_SK_AUTHOR |
static java.lang.String |
META_SK_COPYRIGHT |
static java.lang.String |
META_SK_INFO |
static java.lang.String |
META_SK_LANG |
static java.lang.String |
META_SK_TITLE |
static java.lang.String |
META_SK_VERSION |
static java.lang.String |
META_SOFT_KARAOKE |
static java.lang.String |
META_TITLE |
private static java.util.HashMap<java.lang.String,java.lang.StringBuilder> |
metaInfo |
private static int |
MODE_DEFAULT |
private static int |
MODE_FUNCTION |
private static int |
MODE_INSTRUMENTS |
private static int |
MODE_META |
private static int |
MODE_PATTERN |
private static int |
MODE_SOFT_KARAOKE |
static java.lang.String |
MULTIPLE |
private static int |
nestableBlkDepth |
private static java.util.Deque<NestableBlock> |
nestableBlkStack |
static java.lang.String |
OPT_ASSIGNER |
static java.lang.String |
OPT_DURATION |
static java.lang.String |
OPT_ELSE |
static java.lang.String |
OPT_ELSIF |
static java.lang.String |
OPT_IF |
static java.lang.String |
OPT_LENGTH |
static java.lang.String |
OPT_LYRICS |
static java.lang.String |
OPT_MULTIPLE |
static java.lang.String |
OPT_QUANTITY |
static java.lang.String |
OPT_SEPARATOR |
static java.lang.String |
OPT_SHIFT |
static java.lang.String |
OPT_TREMOLO |
static java.lang.String |
OPT_TUPLET |
static java.lang.String |
OPT_VELOCITY |
private static java.util.regex.Pattern |
optAssignPattern |
static java.lang.String |
ORIGINAL_COMMENT |
static java.lang.String |
ORIGINAL_DEFINE |
static java.lang.String |
ORIGINAL_INCLUDE |
static java.lang.String |
P |
static java.lang.String |
PARAM_ASSIGNER |
static java.lang.String |
PARAM_CLOSE |
static java.lang.String |
PARAM_INDEX_CLOSE |
static java.lang.String |
PARAM_INDEX_OPEN |
static java.lang.String |
PARAM_NAMED_CLOSE |
static java.lang.String |
PARAM_NAMED_OPEN |
static java.lang.String |
PARAM_OPEN |
static java.lang.String |
PARAM_SEPARATOR |
private static java.util.Deque<java.util.ArrayList<java.lang.String>> |
paramStackIndexed |
private static java.util.Deque<java.util.HashMap<java.lang.String,java.lang.String>> |
paramStackNamed |
static java.lang.String |
PARTIAL_SYNC_RANGE |
static java.lang.String |
PARTIAL_SYNC_SEP |
static java.lang.String |
PATTERN |
static java.lang.String |
PATTERN_INDEX_SEP |
private static java.util.Deque<java.io.File> |
patternFileStack |
private static java.util.Deque<java.lang.Integer> |
patternLineStack |
private static java.util.Deque<java.lang.String> |
patternNameStack |
static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
patterns |
private static java.util.HashMap<java.lang.String,java.io.File> |
patternToFile |
private static java.util.HashMap<java.lang.String,java.lang.Integer> |
patternToLineOffset |
static java.lang.String |
PROG_BANK_SEP |
static java.lang.String |
Q |
static java.lang.String |
QUANTITY |
private static java.util.HashSet<java.lang.String> |
redefinitions |
static java.lang.String |
REST |
private static int |
REST_VALUE |
static java.lang.String |
S |
private static java.util.regex.Pattern |
sharpPattern |
static java.lang.String |
SHIFT |
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
softKaraokeInfo |
static java.lang.String |
SOUNDBANK |
private static boolean |
soundbankParsed |
static java.lang.String |
SOUNDFONT |
private static java.util.Deque<StackTraceElement> |
stackTrace |
static java.lang.String |
T |
static java.lang.String |
TEMPO |
private static int |
TICK_BANK_BEFORE_PROGRAM |
static java.lang.String |
TIME_SIG |
static java.lang.String |
TIME_SIG_SLASH |
static java.lang.String |
TR |
static java.lang.String |
TREMOLO |
static java.lang.String |
TRIPLET |
static java.lang.String |
TUPLET |
static java.lang.String |
TUPLET_FOR |
static java.lang.String |
TUPLET_INTRO |
static java.lang.String |
V |
static java.lang.String |
VAR |
static java.lang.String |
VAR_ASSIGNER |
static java.lang.String |
VAR_SYMBOL |
private static java.util.regex.Pattern |
varAssignPattern |
protected static java.util.HashMap<java.lang.String,java.lang.String> |
variables |
private static java.util.regex.Pattern |
varPattern |
static java.lang.String |
VELOCITY |
private static java.util.regex.Pattern |
whitespace |
transposeLevel
Constructor and Description |
---|
MidicaPLParser(boolean isRootParser)
Creates a new MidicaPL parser.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
addMultipleIfNotYetDone(java.lang.String original)
Adds the option MULTIPLE to an option string, if it has not yet been added.
|
java.lang.String[] |
addShift(java.lang.String[] tokens,
int shift)
Adds the shift option to the given command, if it’s a note, chord or call command.
|
void |
adjustCompactNoteLength(int channel,
java.lang.String length,
boolean fromTupletBlock)
Sets the channel’s compact note length (and natural length) of compact commands, if necessary.
|
private void |
applySyllable(java.lang.String syllable,
long tick)
Unescapes the given syllable and puts it into the MIDI sequence.
|
private void |
assertNoOpenOTO(java.lang.String dictKey)
Checks if any channel has an open one-time option for compact syntax.
|
void |
assertNoOpenOTO(java.lang.String dictKey,
java.lang.String lineContent,
int lineNumber)
Checks if any channel has an open one-time option for compact syntax.
|
private void |
checkBarLine(int channel,
java.util.regex.Matcher barLineMatcher,
int barLineCounter)
Checks if a bar line is correctly set.
|
private void |
checkIfCmdExists(java.lang.String cmd)
Throws an error if the given command does not exist.
|
private void |
checkInstrumentsParsed()
Checks if the first instruments block is expected to be parsed already and have not yet been parsed.
|
private void |
checkNesting(java.lang.String cmd)
Checks nesting of named or nestable blocks.
|
private void |
checkNestingAtEOF()
Checks nesting of named or nestable blocks at end of file.
|
private void |
checkPatternIndices(java.lang.String indicesStr)
Checks if the given string consists of comma-separated note index numbers.
|
private java.lang.String |
clean(java.lang.String input)
Cuts away any leading and trailing whitespaces from an input string and returns the resulting string.
|
private java.lang.String |
cleanLine(java.lang.String line)
Removes comments and leding and trailing whitespaces from a source code line.
|
private void |
cleanLines(java.util.ArrayList<java.lang.String> lines)
Removes comments and leding and trailing whitespaces from a whole list of source code lines.
|
private void |
compilePatterns()
Create regex patterns.
|
boolean |
evalCondition(java.lang.String condition)
Evaluates the given if/elsif condition.
|
int |
getCompactChannel(java.lang.String token)
Returns the channel of a compact (multi-note) channel command.
|
boolean |
isCompactCmd(java.lang.String token)
Checks if the given token indicates a compact (multi-note) channel command.
|
boolean |
isCompactPatternCall(java.lang.String lengthOrPatternCall)
Checks if the given string is a pattern call or a normal length definition.
|
private boolean |
isMetaCmd(java.lang.String cmd)
Determins if the given command is a META command.
|
private boolean |
mustIgnore(java.lang.String cmd)
Determins if a command must be ignored in the current parsing run and mode.
|
void |
parse(java.lang.Object fileAsObj)
Parses a MidicaPL source file.
|
private void |
parseBLOCK(java.lang.String[] tokens,
boolean isFake)
Parses opening or closing a nestable block.
|
private void |
parseCALL(java.lang.String[] tokens,
boolean isFake)
Parses a CALL command.
|
private void |
parseChannelCmd(java.lang.String[] tokens,
boolean isFake)
Parses a channel command.
|
private java.util.ArrayList<java.lang.Integer> |
parseChord(java.lang.String token)
Analyzes the note/chord string of a channel command.
|
private void |
parseCHORD(java.lang.String[] tokens)
Parses a CHORD command.
|
private boolean |
parseChordNotes(java.lang.String[] tokens)
Splits a channel command with a chord into the single notes and applies one channel command for each note.
|
private void |
parseCompactCmd(java.lang.String[] tokens,
boolean isFake)
Parses a compact (multi-note) channel command.
|
java.util.ArrayList<CommandOption> |
parseCompactOptions(java.lang.String compactElement,
boolean isFake)
Parses the options of a compact element.
|
private void |
parseCONST(java.lang.String[] tokens)
Parses a CONST command.
|
private void |
parseDEFINE(java.lang.String[] tokens)
Parses a DEFINE command.
|
static int |
parseDuration(java.lang.String s)
Parses the duration string from a channel command and calculates the duration in ticks.
|
private static int |
parseDurationSummand(java.lang.String s)
Parses the duration string from one duration summand channel command and calculates the duration in ticks.
|
private void |
parseEND(java.lang.String[] tokens)
Parses an END command.
|
private void |
parseFUNCTION(java.lang.String[] tokens)
Parses a FUNCTION command.
|
private void |
parseGlobalCmd(java.lang.String[] tokens,
boolean isFake)
Parses a global command.
|
private void |
parseINCLUDE(java.lang.String[] tokens)
Parses an INCLUDE command.
|
private void |
parseInstrumentCmd(java.lang.String[] tokens,
boolean isFake)
Parses an instrument command inside an INSTRUMENTS block or a single line INSTRUMENT change.
|
void |
parseLine(java.lang.String line)
Parses one single line of a MidicaPL source file.
|
private void |
parseMETA(java.lang.String[] tokens)
Parses a META command.
|
private void |
parseMetaCmd(java.lang.String[] tokens)
Parses one command inside of a META block.
|
private void |
parseModeCmd(java.lang.String[] tokens)
Parses a mode command.
|
private int |
parseNote(java.lang.String noteName)
Returns the note value of a given string.
|
private int |
parseNote(java.lang.String note,
int channel)
Returns the note value of a given string in the context of the given channel.
|
(package private) CommandOption |
parseOption(java.lang.String[] optParts,
boolean isFake)
Parses one single command option.
|
private java.util.ArrayList<CommandOption> |
parseOptions(java.lang.String optString,
boolean isFake)
Parses the options part of a command.
|
private java.lang.Object[] |
parseParameters(java.lang.String paramStr)
Parses (indexed and named) parameters of a function call or a pattern usage.
|
private void |
parsePATTERN(java.lang.String[] tokens)
Parses a PATTERN command.
|
private void |
parsePatternCall(java.lang.String[] tokens,
boolean isFake)
Parses a channel call with a pattern instead of a note length.
|
private void |
parsePatternLine(java.lang.String[] tokens)
Parses a line inside of a pattern definition.
|
private void |
parseRootLevelCmd(java.lang.String[] tokens)
Parses a command that is not allowed inside of any block and has nothing to do with blocks.
|
private void |
parseSingleLineInstrumentSwitch(java.lang.String[] tokens,
boolean isFake)
Parses a single line instrument switch command (outside of an instruments bock).
|
private void |
parseSOFT_KARAOKE(java.lang.String[] tokens)
Parses a SOFT_KARAOKE command.
|
private void |
parseSoftKaraokeCmd(java.lang.String[] tokens)
Parses one command inside of a SOFT_KARAOKE block.
|
private void |
parseSOUNDBANK(java.lang.String[] tokens)
Parses a SOUNDBANK command.
|
private void |
parseTokens(java.lang.String[] tokens)
Parses the tokens of one MidicaPL command.
|
private void |
parseVAR(java.lang.String[] tokens,
boolean isFake)
Parses a VAR command.
|
private void |
parsingRun(java.util.ArrayList<java.lang.String> lines)
Parses all MidicaPL source lines for a specific purpose.
|
private java.lang.String |
patternIndicesToChord(java.lang.String indicesStr,
java.lang.Integer[] noteNumbers)
Translates a string with comma-separated indices to a chord with comma-separated notes.
|
private void |
postprocessInstrumentsIfNotYetDone()
Postprocesses a finished INSTRUMENTS block, if not yet done.
|
private void |
postprocessMeta()
Postprocesses a finished META block.
|
static void |
refreshSyntax()
Restores the configured MidicaPL keywords and symbols.
|
java.util.ArrayList<java.lang.Long> |
rememberTickstamps()
Creates and returns a snapshot of the tickstamps of all channels.
|
java.lang.String[] |
reorganizeCompactCmd(java.lang.String[] tokens)
Transforms compact channel commands with 3 tokens to those with only 2 tokens, if necessary.
|
private java.lang.String[] |
reorganizePatternCallTokens(java.lang.String[] tokens,
int indexOffset)
Ensures that (nested or real) pattern call tokens contain the pattern call and the options token in the right position.
|
private java.lang.String |
replaceConstants(java.lang.String str)
Replaces all constants in the given string by their values.
|
private int |
replaceInstrument(java.lang.String shortcut,
int channel)
Transforms an instrument or drumkit name or number string into the corresponding MIDI number.
|
private void |
replaceShortcuts(java.lang.String[] tokens)
Replaces shortcuts in normal channel commands.
|
java.lang.String |
replaceVariables(java.lang.String str)
Replaces all variables (or parameters) in the given string by their values.
|
private void |
reset()
Initializes the parser for a new parsing run.
|
void |
restoreTickstamps(java.util.ArrayList<java.lang.Long> tickstamps)
Restores a snapshot of tickstamps for each channel.
|
private void |
synchronize(java.lang.String channelDesc)
Synchronizes all channels according to the given channel description.
|
int |
toChannel(java.lang.String s)
Parses a channel number.
|
private float |
toFloat(java.lang.String s)
Parses a String that is expected to be a float.
|
private static int |
toInt(java.lang.String s)
Parses a String that is expected to be an integer, accepting only values >= 0.
|
private static int |
toInt(java.lang.String s,
boolean greaterZero)
Parses a String that is expected to be an integer.
|
private void |
trackNesting(java.lang.String cmd)
Tracks nesting and mode of nestable and named blocks.
|
getFileName, getFilePath, getTransposeLevel, postprocessSequence, preprocess, setTransposeLevel, transpose
public static final java.lang.String OPT_LENGTH
public static final java.lang.String OPT_VELOCITY
public static final java.lang.String OPT_MULTIPLE
public static final java.lang.String OPT_DURATION
public static final java.lang.String OPT_QUANTITY
public static final java.lang.String OPT_LYRICS
public static final java.lang.String OPT_TUPLET
public static final java.lang.String OPT_TREMOLO
public static final java.lang.String OPT_SHIFT
public static final java.lang.String OPT_IF
public static final java.lang.String OPT_ELSIF
public static final java.lang.String OPT_ELSE
private static final java.util.HashSet<java.lang.String> compactOptionsWithRest
private static final java.util.HashSet<java.lang.String> compactOptionsWithoutRest
private static final int MODE_DEFAULT
private static final int MODE_INSTRUMENTS
private static final int MODE_FUNCTION
private static final int MODE_PATTERN
private static final int MODE_META
private static final int MODE_SOFT_KARAOKE
public static final int COND_TYPE_NONE
public static final int COND_TYPE_IF
public static final int COND_TYPE_ELSIF
public static final int COND_TYPE_ELSE
private static final int TICK_BANK_BEFORE_PROGRAM
private static final int REST_VALUE
private static final int MAX_RECURSION_DEPTH_FUNCTION
private static final int MAX_RECURSION_DEPTH_PATTERN
private static final int MAX_RECURSION_DEPTH_CONST
private static final int MAX_RECURSION_DEPTH_VAR
public static java.lang.String BANK_SEP
public static java.lang.String TEMPO
public static java.lang.String TIME_SIG
public static java.lang.String TIME_SIG_SLASH
public static java.lang.String KEY_SIG
public static java.lang.String KEY_SEPARATOR
public static java.lang.String KEY_MAJ
public static java.lang.String KEY_MIN
public static java.lang.String PARTIAL_SYNC_RANGE
public static java.lang.String PARTIAL_SYNC_SEP
public static java.lang.String CHORD
public static java.lang.String CHORD_ASSIGNER
public static java.lang.String CHORD_SEPARATOR
public static java.lang.String COMPACT_CHANNEL
public static java.lang.String COMPACT_NOTE_SEP
public static java.lang.String COMPACT_OPT_OPEN
public static java.lang.String COMPACT_OPT_CLOSE
public static java.lang.String COMMENT
public static java.lang.String CONST
public static java.lang.String VAR
public static java.lang.String VAR_ASSIGNER
public static java.lang.String VAR_SYMBOL
public static java.lang.String DEFINE
public static java.lang.String DOT
public static java.lang.String END
public static java.lang.String BLOCK_OPEN
public static java.lang.String BLOCK_CLOSE
public static java.lang.String GLOBAL
public static java.lang.String CALL
public static java.lang.String INCLUDE
public static java.lang.String SOUNDBANK
public static java.lang.String SOUNDFONT
public static java.lang.String INSTRUMENT
public static java.lang.String INSTRUMENTS
public static java.lang.String META
public static java.lang.String META_COPYRIGHT
public static java.lang.String META_TITLE
public static java.lang.String META_COMPOSER
public static java.lang.String META_LYRICIST
public static java.lang.String META_ARTIST
public static java.lang.String META_SOFT_KARAOKE
public static java.lang.String META_SK_VERSION
public static java.lang.String META_SK_LANG
public static java.lang.String META_SK_TITLE
public static java.lang.String META_SK_AUTHOR
public static java.lang.String META_SK_COPYRIGHT
public static java.lang.String META_SK_INFO
public static java.lang.String LENGTH
public static java.lang.String LENGTH_ZERO
public static java.lang.String LENGTH_32
public static java.lang.String LENGTH_16
public static java.lang.String LENGTH_8
public static java.lang.String LENGTH_4
public static java.lang.String LENGTH_2
public static java.lang.String LENGTH_1
public static java.lang.String LENGTH_M1
public static java.lang.String LENGTH_M2
public static java.lang.String LENGTH_M4
public static java.lang.String LENGTH_M8
public static java.lang.String LENGTH_M16
public static java.lang.String LENGTH_M32
public static java.lang.String L
public static java.lang.String LYRICS
public static java.lang.String LYRICS_SPACE
public static java.lang.String LYRICS_CR
public static java.lang.String LYRICS_LF
public static java.lang.String LYRICS_COMMA
public static java.lang.String FUNCTION
public static java.lang.String PATTERN
public static java.lang.String PATTERN_INDEX_SEP
public static java.lang.String PARAM_OPEN
public static java.lang.String PARAM_CLOSE
public static java.lang.String PARAM_SEPARATOR
public static java.lang.String PARAM_ASSIGNER
public static java.lang.String PARAM_NAMED_OPEN
public static java.lang.String PARAM_NAMED_CLOSE
public static java.lang.String PARAM_INDEX_OPEN
public static java.lang.String PARAM_INDEX_CLOSE
public static java.lang.String MAGIC_VAR_ALL
public static java.lang.String MAGIC_VAR_NC
public static java.lang.String MAGIC_VAR_REV
public static java.lang.String M
public static java.lang.String MULTIPLE
public static java.lang.String OPT_ASSIGNER
public static java.lang.String OPT_SEPARATOR
public static java.lang.String P
public static java.lang.String BAR_LINE
public static java.lang.String REST
public static java.lang.String S
public static java.lang.String SHIFT
public static java.lang.String IF
public static java.lang.String ELSIF
public static java.lang.String ELSE
public static java.lang.String COND_EQ
public static java.lang.String COND_NEQ
public static java.lang.String COND_NDEF
public static java.lang.String COND_LT
public static java.lang.String COND_LE
public static java.lang.String COND_GT
public static java.lang.String COND_GE
public static java.lang.String COND_IN
public static java.lang.String COND_IN_SEP
public static java.lang.String PROG_BANK_SEP
public static java.lang.String Q
public static java.lang.String QUANTITY
public static java.lang.String D
public static java.lang.String DURATION
public static java.lang.String DURATION_PERCENT
public static java.lang.String TR
public static java.lang.String TREMOLO
public static java.lang.String T
public static java.lang.String TUPLET
public static java.lang.String V
public static java.lang.String VELOCITY
public static java.lang.String TRIPLET
public static java.lang.String TUPLET_INTRO
public static java.lang.String TUPLET_FOR
public static java.lang.String LENGTH_PLUS
public static java.lang.String ORIGINAL_DEFINE
public static java.lang.String ORIGINAL_INCLUDE
public static java.lang.String ORIGINAL_COMMENT
protected static java.util.ArrayList<Instrument> instruments
private static LyricUtil lyricUtil
private static java.util.regex.Pattern whitespace
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> fileCache
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> functions
private static java.util.HashMap<java.lang.String,java.io.File> functionToFile
private static java.util.HashMap<java.lang.String,java.lang.Integer> functionToLineOffset
public static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> patterns
private static java.util.HashMap<java.lang.String,java.io.File> patternToFile
private static java.util.HashMap<java.lang.String,java.lang.Integer> patternToLineOffset
private static java.util.TreeMap<java.lang.String,java.util.TreeSet<java.lang.Integer>> chords
private static boolean instrumentsParsed
private static java.util.HashMap<java.lang.String,java.lang.StringBuilder> metaInfo
private static java.util.HashMap<java.lang.String,java.util.ArrayList<java.lang.String>> softKaraokeInfo
private static boolean frstInstrBlkOver
private static java.lang.String chosenCharset
private static java.util.HashSet<java.lang.String> definedFunctionNames
private static java.util.HashSet<java.lang.String> definedPatternNames
private static int nestableBlkDepth
private static java.util.Deque<NestableBlock> nestableBlkStack
private static java.util.Deque<StackTraceElement> stackTrace
private static java.util.Deque<java.lang.String> functionNameStack
private static java.util.Deque<java.lang.Integer> functionLineStack
private static java.util.Deque<java.io.File> functionFileStack
private static java.util.Deque<java.util.HashMap<java.lang.String,java.lang.String>> paramStackNamed
private static java.util.Deque<java.util.ArrayList<java.lang.String>> paramStackIndexed
private static java.util.Deque<java.util.HashMap<java.lang.String,java.lang.String>> magicVarStack
private static java.util.Deque<java.lang.String> patternNameStack
private static java.util.Deque<java.lang.Integer> patternLineStack
private static java.util.Deque<java.io.File> patternFileStack
private static java.util.HashSet<java.lang.String> redefinitions
private static boolean soundbankParsed
protected static java.util.HashMap<java.lang.String,java.lang.String> constants
protected static java.util.HashMap<java.lang.String,java.lang.String> variables
private static java.util.regex.Pattern varPattern
private static java.util.regex.Pattern callPattern
private static java.util.regex.Pattern barLinePattern
private static java.util.regex.Pattern condPattern
private static java.util.regex.Pattern condInPattern
private static java.util.regex.Pattern crlfSkPattern
private static java.util.regex.Pattern sharpPattern
private static java.util.regex.Pattern flatPattern
private static java.util.regex.Pattern optAssignPattern
private static java.util.regex.Pattern chordAssignPattern
private static java.util.regex.Pattern varAssignPattern
private static java.util.regex.Pattern chordSepPattern
private static java.util.regex.Pattern compactChannelPattern
private static java.util.regex.Pattern compactOptPattern
private static java.util.regex.Pattern invalidNoteIdxPattern
private static boolean isSoftKaraoke
public static boolean isPlayingTupletBlock
private static java.util.TreeMap<java.lang.Long,java.lang.Long> measureLengthHistory
private static boolean isDefineParsRun
private static boolean isConstParsRun
private static boolean isChInstMetaParsRun
private static boolean isFuncNameParsRun
private static boolean isFuncParsRun
private static boolean isCondCheckParsRun
private static boolean isDefaultParsRun
private java.io.File file
private int currentLineNumber
private java.lang.String currentLineContent
private int currentMode
private java.lang.String currentFunctionName
private java.util.ArrayList<java.lang.String> currentFunction
private java.lang.String currentPatternName
private java.util.ArrayList<java.lang.String> currentPattern
private boolean condChainOpened
private boolean condChainHit
private boolean isRootParser
Indicates if the current parser object parses the file chosen by the user.
Otherwise it parses an included file.
public MidicaPLParser(boolean isRootParser)
Creates a new MidicaPL parser.
isRootParser
- true, if the parser object is created in order to parse a user-defined file. false, if the parser object is created in order to parse a file which has been included by another MidicaPL file.public static void refreshSyntax()
Restores the configured MidicaPL keywords and symbols.
public void parse(java.lang.Object fileAsObj) throws ParseException
Parses a MidicaPL source file. Creates a MIDI sequence from that file.
fileAsObj
- MidicaPL source file.ParseException
- If the file or URL can not be parsed correctly.private void compilePatterns()
Create regex patterns. This is called after the define run so that the syntax keywords cannot change any more.
public void parseLine(java.lang.String line) throws ParseException
Parses one single line of a MidicaPL source file. The line is expected to be cleaned already from comments and leading/trailing whitespaces. Can also be called from a NestableBlock
.
line
- The line to be parsed.ParseException
- If the line cannot be parsed.private boolean isMetaCmd(java.lang.String cmd)
Determins if the given command is a META command.
cmd
- The command to be judged.public java.util.ArrayList<java.lang.Long> rememberTickstamps() throws ParseException
Creates and returns a snapshot of the tickstamps of all channels. The indexes of the returned structure are the channels. The values are the tickstamps.
ParseException
- if something went wrong.public void restoreTickstamps(java.util.ArrayList<java.lang.Long> tickstamps)
Restores a snapshot of tickstamps for each channel.
tickstamps
- the tickstamps to be restored - indexes are channels, values are tickstamps.public int toChannel(java.lang.String s) throws ParseException
Parses a channel number.
s
- Channel number string.ParseException
- If the command cannot be parsed.private void parsingRun(java.util.ArrayList<java.lang.String> lines) throws ParseException, java.io.IOException
Parses all MidicaPL source lines for a specific purpose. E.g. find definition commands, chords, functions, and so on.
lines
- All lines of the MidicaPL source.ParseException
- if one of the lines cannot be parsed.java.io.IOException
- if the file path cannot be calculated.private void parseTokens(java.lang.String[] tokens) throws ParseException
Parses the tokens of one MidicaPL command.
tokens
- The tokens from one MidicaPL line.ParseException
- If the tokens cannot be parsed.private void checkIfCmdExists(java.lang.String cmd) throws ParseException
Throws an error if the given command does not exist.
Each command is also checked at the place it’s parsed. But sometimes this is too late. Different parsing runs ignore different lines, so that the real error is not shown but a consecutive error with a much higher line number.
Example:
DEFINE CHORD CRD
// ...
CHORD cmay c,e,g
// ...
0 cmay /4
This would say: unknown note: cmay
But correct is: unknown command: CHORD
We need this check early or otherwise the error messages could be confusing.
cmd
- The command to be checkedParseException
- if the command does not exist.private boolean mustIgnore(java.lang.String cmd) throws ParseException
Determins if a command must be ignored in the current parsing run and mode.
Also sets the current mode or nesting depth, if this is required but no further parsing is needed.
This is called for each line in each parsing run.
There are different parsing runs, in the following order:
cmd
- The first token in the lineParseException
- if this method is called without configuring the parsing run before.private void trackNesting(java.lang.String cmd)
Tracks nesting and mode of nestable and named blocks. Used only if nothing more is needed. Otherwise the nesting will be tracked by the according parse method.
cmd
- command to be trackedprivate void checkNesting(java.lang.String cmd) throws ParseException
Checks nesting of named or nestable blocks.
cmd
- The command to be checkedParseException
- if the check fails.private void checkNestingAtEOF() throws ParseException
Checks nesting of named or nestable blocks at end of file.
ParseException
- if the check fails.private void checkInstrumentsParsed() throws ParseException
Checks if the first instruments block is expected to be parsed already and have not yet been parsed. In this case an exception is thrown.
ParseException
- the first instruments block has not yet been parsed.private void replaceShortcuts(java.lang.String[] tokens) throws ParseException
Replaces shortcuts in normal channel commands.
The following shortcuts are replaced:
tokens
- Channel command token array.ParseException
- if something goes wrongprivate int replaceInstrument(java.lang.String shortcut, int channel) throws ParseException
Transforms an instrument or drumkit name or number string into the corresponding MIDI number.
This is only called while a command inside an INSTRUMENTS block is parsed.
shortcut
- String containing the instrument/drumkit name or numberchannel
- MIDI channel numberParseException
- if the given shortcut is neither a valid shortcut nor a valid number.public static int parseDuration(java.lang.String s) throws ParseException
Parses the duration string from a channel command and calculates the duration in ticks.
The duration can be a sum of durations, separated by + characters.
s
- The duration string, extracted from the MidicaPL line.ParseException
- If the duration string cannot be parsed.private static int parseDurationSummand(java.lang.String s) throws ParseException
Parses the duration string from one duration summand channel command and calculates the duration in ticks.
s
- One duration summand, extracted from the MidicaPL line.ParseException
- If the duration summand cannot be parsed.private void parseModeCmd(java.lang.String[] tokens) throws ParseException
Parses a mode command.
This is one of the following commands:
Determines the type of mode command and calls the appropriate method to parse that command type.
tokens
- Mode command token array.ParseException
- If the mode command cannot be parsed.private void parseRootLevelCmd(java.lang.String[] tokens) throws ParseException
Parses a command that is not allowed inside of any block and has nothing to do with blocks.
This is one of the following commands:
Checks if we are in the root level.
Determines the type of root-level command and calls the appropriate method to parse that command.
tokens
- Mode command token array.ParseException
- If the command cannot be parsed or is inside of a block.private void parseEND(java.lang.String[] tokens) throws ParseException
Parses an END command. An END command is a mode command that finishes a previously opened mode.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseFUNCTION(java.lang.String[] tokens) throws ParseException
Parses a FUNCTION command. A FUNCTION command is a mode command that opens a FUNCTION definition.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parsePATTERN(java.lang.String[] tokens) throws ParseException
Parses a PATTERN command. A PATTERN command is a mode command that opens a PATTERN definition.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseMETA(java.lang.String[] tokens) throws ParseException
Parses a META command. A META command is a mode command that opens a META definition block.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseSOFT_KARAOKE(java.lang.String[] tokens) throws ParseException
Parses a SOFT_KARAOKE command. A SOFT_KARAOKE command is a mode command that opens a SOFT_KARAOKE definition block inside of a META block.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseBLOCK(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses opening or closing a nestable block. By default, that is { or }.
tokens
- Token array.isFake
- true, if this is called inside a function definition or block.ParseException
- If the command cannot be parsed.private void parseCHORD(java.lang.String[] tokens) throws ParseException
Parses a CHORD command. A CHORD command defines which a new chord name and describes the included notes.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseCALL(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a CALL command. A CALL command calls a previously defined FUNCTION.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.private void parsePatternCall(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a channel call with a pattern instead of a note length.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- if something is wrong.private java.lang.String patternIndicesToChord(java.lang.String indicesStr, java.lang.Integer[] noteNumbers) throws ParseException
Translates a string with comma-separated indices to a chord with comma-separated notes.
Needed for pattern calls.
indicesStr
- the comma-separated indices string (e.g. “0,2,3”)noteNumbers
- the note numbers to be used for the chord (e.g. [64, 66, 67, 76])ParseException
- if an index is not a positie integer or too high for the given noteNumbers.private java.lang.Object[] parseParameters(java.lang.String paramStr) throws ParseException
Parses (indexed and named) parameters of a function call or a pattern usage.
Returns the indexed parameters in index 0 and the named parameters in index 1 of the returned array.
paramStr
- the parameter stringParseException
- if something is wrong with the parameter string.private void parsePatternLine(java.lang.String[] tokens) throws ParseException
Parses a line inside of a pattern definition.
tokens
- command tokensParseException
- if something is wrong.private void checkPatternIndices(java.lang.String indicesStr) throws ParseException
Checks if the given string consists of comma-separated note index numbers.
Needed to check a pattern at pattern line parsing time (before any pattern call).
indicesStr
- ParseException
private java.lang.String[] reorganizePatternCallTokens(java.lang.String[] tokens, int indexOffset) throws ParseException
Ensures that (nested or real) pattern call tokens contain the pattern call and the options token in the right position.
For real pattern calls:
For nested pattern calls:
For nested compact pattern calls:
tokens
- tokens to be checked or changedindexOffset
- pattern call index (**2** for real calls, 1 for nested calls)ParseException
- on syntax errors.private void applySyllable(java.lang.String syllable, long tick) throws ParseException
Unescapes the given syllable and puts it into the MIDI sequence.
Takes care about SoftKaraoke.
syllable
- the syllable to be unescaped.tick
- the tick when the syllable occurs.ParseException
- if a MIDI problem occurs.public boolean evalCondition(java.lang.String condition) throws ParseException
Evaluates the given if/elsif condition.
condition
- the condition to be evaluated.ParseException
- if the condition is invalidpublic java.lang.String[] addShift(java.lang.String[] tokens, int shift) throws ParseException
Adds the shift option to the given command, if it’s a note, chord or call command. Applies the shift option to all notes, if it’s a compact command.
tokens
- command tokensParseException
- if something goes wrong.private void parseINCLUDE(java.lang.String[] tokens) throws ParseException
Parses an INCLUDE command. An INCLUDE command parses another MidicaPL source file. Therefore another parser instance of this class is created.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseSOUNDBANK(java.lang.String[] tokens) throws ParseException
Parses a SOUNDBANK command. A SOUNDBANK command includes a soundbank by file path or URL.
tokens
- Token array.ParseException
- If the soundbank cannot be loaded.private void parseDEFINE(java.lang.String[] tokens) throws ParseException
Parses a DEFINE command. A DEFINE command is used to re-define a mode command name.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseCONST(java.lang.String[] tokens) throws ParseException
Parses a CONST command. A CONST command is used to define a constant.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseVAR(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a VAR command. A VAR command is used to define and/or (re)assign a variable.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.private java.lang.String replaceConstants(java.lang.String str) throws ParseException
Replaces all constants in the given string by their values.
str
- The string to be replaced.ParseException
- if the recursion depth is too highpublic java.lang.String replaceVariables(java.lang.String str) throws ParseException
Replaces all variables (or parameters) in the given string by their values.
str
- The string to be replaced.ParseException
- if an undefined variable is found or the recursion depth is too high.private void parseSingleLineInstrumentSwitch(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a single line instrument switch command (outside of an instruments bock).
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.private void parseInstrumentCmd(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses an instrument command inside an INSTRUMENTS block or a single line INSTRUMENT change. This command assigns a certain instrument to a certain channel. A bank number can also be assigned for the channel.
TODO: test soundbanks with bankLSB > 0
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.private void parseMetaCmd(java.lang.String[] tokens) throws ParseException
Parses one command inside of a META block.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseSoftKaraokeCmd(java.lang.String[] tokens) throws ParseException
Parses one command inside of a SOFT_KARAOKE block.
tokens
- Token array.ParseException
- If the command cannot be parsed.private void parseGlobalCmd(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a global command. Global commands apply to every channel. So they always contain a syncronization of the current ticks of each channel.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.public int getCompactChannel(java.lang.String token) throws ParseException
Returns the channel of a compact (multi-note) channel command.
token
- the command (first token) to be checkedParseException
- if the channel cannot be determinedpublic java.lang.String[] reorganizeCompactCmd(java.lang.String[] tokens) throws ParseException
Transforms compact channel commands with 3 tokens to those with only 2 tokens, if necessary.
Needed in order to apply tuplets or shifts.
tokens
- the original tokensParseException
- if the given tokens contain more than 3 elementspublic boolean isCompactCmd(java.lang.String token)
Checks if the given token indicates a compact (multi-note) channel command.
token
- the command (first token) to be checkedprivate void parseCompactCmd(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a compact (multi-note) channel command.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.public boolean isCompactPatternCall(java.lang.String lengthOrPatternCall)
Checks if the given string is a pattern call or a normal length definition.
lengthOrPatternCall
- pattern call or length definitionpublic void adjustCompactNoteLength(int channel, java.lang.String length, boolean fromTupletBlock)
Sets the channel’s compact note length (and natural length) of compact commands, if necessary.
channel
- MIDI channellength
- length string from the syntaxfromTupletBlock
- true if called from a tuplet block, otherwise falseprivate void parseChannelCmd(java.lang.String[] tokens, boolean isFake) throws ParseException
Parses a channel command. A channel command is a channel-based command like a note or a rest.
tokens
- Token array.isFake
- true, if this is called inside a function definition or blockParseException
- If the command cannot be parsed.public java.util.ArrayList<CommandOption> parseCompactOptions(java.lang.String compactElement, boolean isFake) throws ParseException
Parses the options of a compact element.
An element with compact options looks like: (name1=value1,name2=value2,…). If another type of compact element is given, null is returned.
compactElement
- the element to be parsedisFake
- true, if this is called inside a function definition, pattern definition or block.ParseException
- if the options cannot be parsed.private java.util.ArrayList<CommandOption> parseOptions(java.lang.String optString, boolean isFake) throws ParseException
Parses the options part of a command.
The options may still contain unreplaced variables or parameters. These are replaced or left as-is. This depends on the current parsing run, the given isFake parameter, and other criteria.
optString
- The raw options string of the command to be parsed.isFake
- true, if this is called inside a function definition, pattern definition or block.ParseException
- if the options cannot be parsed.CommandOption parseOption(java.lang.String[] optParts, boolean isFake) throws ParseException
Parses one single command option.
The given optParts may have one or two elements.
The first element is the option name. The second element is the option’s value.
optParts
- first element: name; second element: value (optional)isFake
- true, if this is called inside a function definition, pattern definition or block.ParseException
- if the options cannot be parsed.private int parseNote(java.lang.String note, int channel) throws ParseException
Returns the note value of a given string in the context of the given channel. (Used to parse a note from a channel command)
The string can be:
note
- The note string to be parsed.channel
- The channel number.ParseExceptionif
- the note or percussion name is unknown or the note value is out of the legal range for MIDI notesParseException
private int parseNote(java.lang.String noteName) throws ParseException
Returns the note value of a given string. (Used for parsing a note from a chord definition)
The string can be:
noteName
- string defining the noteParseException
- if the note name is unknown or the note value is out of the legal range for MIDI notesprivate java.util.ArrayList<java.lang.Integer> parseChord(java.lang.String token) throws ParseException
Analyzes the note/chord string of a channel command. This token can be a note string, a note number, a predefined chord or an inline chord, consisting of any combination of the former.
token
- The note/chord part of a channel command (second column).ParseException
- if one of the notes cannot be parsed.private boolean parseChordNotes(java.lang.String[] tokens) throws ParseException
Splits a channel command with a chord into the single notes and applies one channel command for each note.
tokens
- Token array.ParseException
- if one of the notes cannot be parsed.private java.lang.String addMultipleIfNotYetDone(java.lang.String original) throws ParseException
Adds the option MULTIPLE to an option string, if it has not yet been added. This is used if a note of a predefined chord is produced - so that the next note of the same chord starts at the same tick.
original
- token containing the velocity and the option string: token[2]ParseException
- if the original options cannot be parsedpublic void assertNoOpenOTO(java.lang.String dictKey, java.lang.String lineContent, int lineNumber) throws ParseException
Checks if any channel has an open one-time option for compact syntax. In this case, an exception is thrown.
dictKey
- dictionary key for the error messagelineContent
- content of the opening or closing line of the blocklineNumber
- line number causing the problem (opening or closing of the block)ParseException
- if an open one-time option is found.private void assertNoOpenOTO(java.lang.String dictKey) throws ParseException
Checks if any channel has an open one-time option for compact syntax. In this case, an exception is thrown.
dictKey
- dictionary key for the error messageParseException
- if an open one-time option is found.private void synchronize(java.lang.String channelDesc) throws ParseException
Synchronizes all channels according to the given channel description. Sets the current ticks of each of these channels to the value of the channel with the maximum current tick value.
channelDesc
- channel description (e.g. “1-3,5,7-p”)ParseException
- If the channel description cannot be parsed.private void postprocessInstrumentsIfNotYetDone() throws ParseException
Postprocesses a finished INSTRUMENTS block, if not yet done.
In this case:
Thereby all undefined channels will be initialized with a fake instrument so that the data structures work.
ParseException
- if something went wrong.private void postprocessMeta() throws ParseException
Postprocesses a finished META block.
Sets all defined meta events in the MIDI sequence.
ParseException
- if something went wrong.private static int toInt(java.lang.String s, boolean greaterZero) throws ParseException
Parses a String that is expected to be an integer.
s
- The string to be parsed.greaterZero
- true, if only positive integers are allowed. false, if negative values are allowed.ParseException
- If the string cannot be parsed.private static int toInt(java.lang.String s) throws ParseException
Parses a String that is expected to be an integer, accepting only values >= 0.
s
- The string to be parsed.ParseException
- If the string cannot be parsed.private float toFloat(java.lang.String s) throws ParseException
Parses a String that is expected to be a float.
s
- The string to be parsed.ParseException
- If the string cannot be parsed.private java.lang.String clean(java.lang.String input)
Cuts away any leading and trailing whitespaces from an input string and returns the resulting string.
input
- The string to be cleaned.private java.lang.String cleanLine(java.lang.String line)
Removes comments and leding and trailing whitespaces from a source code line.
line
- The source code line.private void cleanLines(java.util.ArrayList<java.lang.String> lines)
Removes comments and leding and trailing whitespaces from a whole list of source code lines.
lines
- The source code lines to be cleaned.private void checkBarLine(int channel, java.util.regex.Matcher barLineMatcher, int barLineCounter) throws ParseException
Checks if a bar line is correctly set. Otherwise, throws an exception.
channel
- midi channelbarLineMatcher
- the matcher matching the bar line (and maybe the tolerance value)barLineCounter
- the bar line number to be checked (1st, 2nd, …) inside the compact commandParseException
- if the bar line check failsprivate void reset() throws ParseException
Initializes the parser for a new parsing run. This is called at the beginning of parse().
ParseException
- if sequence creation fails.