public class NestableBlock
extends java.lang.Object
This class represents a nestable block, used by the MidicaPL parser.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
closingLine |
private boolean |
condChainHit |
private boolean |
condChainOpened |
private java.lang.String |
condition |
private java.util.ArrayList<java.lang.Object> |
elements |
private boolean |
isElse |
private boolean |
isElsif |
private boolean |
isIf |
private boolean |
isMultipleSet |
private boolean |
isQuantitySet |
private boolean |
isShiftSet |
private boolean |
isTupletSet |
private boolean |
multiple |
private java.lang.String |
openingLine |
private MidicaPLParser |
parser |
private static java.util.regex.Pattern |
plus |
private int |
quantity |
private int |
shift |
private java.lang.String |
tuplet |
private static java.util.regex.Pattern |
whitespaces |
Constructor and Description |
---|
NestableBlock(MidicaPLParser parser,
java.lang.String openingLine)
Creates a new nestable block.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Object element)
Adds a new content element to this block.
|
private java.lang.String[] |
addTuplets(java.lang.String[] tokens)
Applies the block’s tuplets to the given tokens.
|
private java.lang.String |
addTupletToLength(java.lang.String lengthStr)
Applies the tuplet to all summands of the given length string.
|
void |
applyTupletsAndShifts(java.lang.String parentTuplets,
int parentShifts)
Applies tuplets and shifts to all child blocks.
|
java.lang.String |
getCondition()
Returns the condition, if this block contains an if or elsif.
|
int |
getConditionType()
Returns the condition type of the block, representing if, elsif, else or none.
|
java.lang.String |
getLengthFromCompactElement(java.lang.String compactElement)
Calculates and returns the length defined by a compact syntax element.
|
int |
getNumberOfLines()
Recursively calculates the number of lines of this block.
|
private java.lang.String |
getOptionsForStackTrace()
Returns the resulting options string for the current block so that it can be used in a stack trace.
|
void |
play(java.util.Deque<StackTraceElement> callStack,
boolean isRootBlock,
java.io.File file,
int lineNumber)
Executes the content of the block.
|
static void |
reset()
Resets the precompiled PLUS pattern because in the next compile run it could be redefined.
|
void |
setClosingLine(java.lang.String closingLine)
Sets the content of the block closing line.
|
void |
setElse()
Sets the else option.
|
void |
setElsif(java.lang.String condition)
Sets the elsif option as well as the according condition.
|
void |
setIf(java.lang.String condition)
Sets the if option as well as the according condition.
|
void |
setMultiple(java.lang.String optId)
Sets the multiple option.
|
void |
setQuantity(int quantity,
java.lang.String optId)
Sets the quantity option.
|
void |
setShift(int shift,
java.lang.String optId)
Sets the shift modifier.
|
void |
setTuplet(java.lang.String tuplet,
java.lang.String optId)
Sets the tuplet modifier.
|
java.lang.String |
tupletizeCompactElement(java.lang.String compactElement,
java.lang.String tupletizedLength)
Applies the given (tupletized) length to the given compact element, if possible.
|
private static java.util.regex.Pattern plus
private static java.util.regex.Pattern whitespaces
private MidicaPLParser parser
private boolean multiple
private int quantity
private java.lang.String tuplet
private int shift
private java.util.ArrayList<java.lang.Object> elements
private java.lang.String condition
private java.lang.String openingLine
private java.lang.String closingLine
private boolean condChainOpened
private boolean condChainHit
private boolean isMultipleSet
private boolean isQuantitySet
private boolean isTupletSet
private boolean isShiftSet
private boolean isIf
private boolean isElsif
private boolean isElse
public NestableBlock(MidicaPLParser parser, java.lang.String openingLine)
Creates a new nestable block.
parser
- The parser object that was responsible to create the block.openingLine
- content of the line that opens the blockpublic static void reset()
Resets the precompiled PLUS pattern because in the next compile run it could be redefined.
public void setClosingLine(java.lang.String closingLine)
Sets the content of the block closing line.
closingLine
- line contentpublic void setMultiple(java.lang.String optId) throws ParseException
Sets the multiple option. This option indicates if the channel tickstamps are reverted at the end of the block.
optId
- option ID (only needed for the exception description)ParseException
- if this option has already been set for this block.public void setQuantity(int quantity, java.lang.String optId) throws ParseException
Sets the quantity option. This option indicates how often the block is executed.
quantity
- the quantity valueoptId
- option ID (only needed for the exception description)ParseException
- if this option has already been set for this block.public void setTuplet(java.lang.String tuplet, java.lang.String optId) throws ParseException
Sets the tuplet modifier. This modifier shortens all notes of this block according to the tuplet value. This applies for notes and rests as well as for child blocks.
tuplet
- the tuplet valueoptId
- option ID (only needed for the exception description)ParseException
- if this option has already been set for this block.public void setShift(int shift, java.lang.String optId) throws ParseException
Sets the shift modifier. This modifier applies a transposition of the block by the shift value. This applies for notes and chords as well as for child blocks.
shift
- the shift value (a positive or negative number of half tone steps)optId
- option ID (only needed for the exception description)ParseException
- if this option has already been set for this block.public void setIf(java.lang.String condition) throws ParseException
Sets the if option as well as the according condition.
condition
- the IF condition.ParseException
- if this option is combined with other if-elsif-else options.public void setElsif(java.lang.String condition) throws ParseException
Sets the elsif option as well as the according condition.
condition
- the ELSIF condition.ParseException
- if this option is combined with other if-elsif-else options.public void setElse() throws ParseException
Sets the else option.
ParseException
- if this option is combined with other if-elsif-else options.public int getConditionType()
Returns the condition type of the block, representing if, elsif, else or none.
public java.lang.String getCondition()
Returns the condition, if this block contains an if or elsif. Otherwise: returns null.
public void applyTupletsAndShifts(java.lang.String parentTuplets, int parentShifts)
Applies tuplets and shifts to all child blocks.
parentTuplets
- The tuplet modifiers from all (grand)parents to be applied as well.parentShifts
- The sum of all shift modifiers from all (grand)parents to be applied as well.private java.lang.String[] addTuplets(java.lang.String[] tokens) throws ParseException
Applies the block’s tuplets to the given tokens.
tokens
- command tokensParseException
- if there’s an unexpected problem with a compact channel commandpublic java.lang.String getLengthFromCompactElement(java.lang.String compactElement) throws ParseException
Calculates and returns the length defined by a compact syntax element.
Returns null if the element does not define a new length. That’s the case for:
compactElement
- the element to analyzeParseException
- if compact options cannot be parsedpublic java.lang.String tupletizeCompactElement(java.lang.String compactElement, java.lang.String tupletizedLength) throws ParseException
Applies the given (tupletized) length to the given compact element, if possible. The length is applied to normal notes/chords/rests and the (length=…) option.
Pattern calls or other compact options are left unchanged.
compactElement
- the compact elementtupletizedLength
- tupletized note length stringParseException
- if compact options cannot be parsedprivate java.lang.String addTupletToLength(java.lang.String lengthStr)
Applies the tuplet to all summands of the given length string.
E.g.: *1+/8 –> *1t4:3+/8t4:3
lengthStr
- the length string to be tupletizedpublic void add(java.lang.Object element)
Adds a new content element to this block. The content to be added can be one of the following objects:
element
- the content to be addedpublic void play(java.util.Deque<StackTraceElement> callStack, boolean isRootBlock, java.io.File file, int lineNumber) throws ParseException
Executes the content of the block. Adds all resulting shifts and tuplets to channel or call commands before execution. Also tracks the current line in the call stack.
For root blocks, the provided lineNumber is the line where the block is closed. For other blocks it’s the line where the block is opened.
callStack
- the call stack of the parser.isRootBlock
- true, if this is the root block, otherwise false.file
- the file where the block is definedlineNumber
- first or last line number of the blockParseException
- if one of the content lines cannot be parsed.private java.lang.String getOptionsForStackTrace()
Returns the resulting options string for the current block so that it can be used in a stack trace.
public int getNumberOfLines()
Recursively calculates the number of lines of this block.