Package org.staccato
Class SignatureSubparser
- java.lang.Object
-
- org.staccato.SignatureSubparser
-
- All Implemented Interfaces:
KeyProvider,Subparser
public class SignatureSubparser extends java.lang.Object implements Subparser, KeyProvider
Parses both Instrument and Layer tokens. Each has values that are parsed as bytes.- Author:
- dkoelle
-
-
Field Summary
Fields Modifier and Type Field Description static charFLAT_CHARstatic java.lang.StringKEY_SIGNATUREstatic intKEYSIG_MIDPOINTstatic java.lang.StringMAJOR_ABBRstatic java.lang.String[]MAJOR_KEY_SIGNATURESstatic java.lang.StringMINOR_ABBRstatic java.lang.String[]MINOR_KEY_SIGNATURESstatic java.lang.StringSEPARATORstatic charSHARP_CHARstatic java.lang.StringTIME_SIGNATURE
-
Constructor Summary
Constructors Constructor Description SignatureSubparser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byteconvertAccidentalCountToKeyRootPositionInOctave(int accidentalCount, byte scale)Turns number of accidentals (negative for flats, positive for sharps) to a key and returns the key's root note's position in the octavebyteconvertKeyToByte(Key key)Converts the given Key to a byte value, from -7 for Cb major or Ab major to +7 for C# minor or A# minor, with 0 being C major or A minorKeycreateKey(java.lang.String keySignature)Given a key signature, like "Cmaj" or "Kbbbb", return the corresponding KeyKeycreateKeyFromAccidentals(java.lang.String keySignature)Returns a Key given a string containing as many flats or sharps as the number one would see on a staff for the corresponding key; e.g., "Kbbbb" = Ab Majorjava.lang.StringcreateKeyString(byte notePositionInOctave, byte scale)Creates a key name, like Cmaj, given the root note's position in an octave (e.g., 0 for C) and a major or minor indicator - @see Scale MAJOR_SCALE_INDICATOR and MINOR_SCALE_INDICATORstatic SignatureSubparsergetInstance()Token.TokenTypegetTokenType(java.lang.String tokenString)Asks the subparser to provide a TokenType for the given token.booleanmatches(java.lang.String music)Indicates whether the subparser should be responsible for parsing the given music string.booleanmatchesKeySignature(java.lang.String music)booleanmatchesTimeSignature(java.lang.String music)intparse(java.lang.String music, StaccatoParserContext context)Parses the given music string.
-
-
-
Field Detail
-
KEY_SIGNATURE
public static final java.lang.String KEY_SIGNATURE
- See Also:
- Constant Field Values
-
TIME_SIGNATURE
public static final java.lang.String TIME_SIGNATURE
- See Also:
- Constant Field Values
-
SEPARATOR
public static final java.lang.String SEPARATOR
- See Also:
- Constant Field Values
-
MAJOR_KEY_SIGNATURES
public static final java.lang.String[] MAJOR_KEY_SIGNATURES
-
MINOR_KEY_SIGNATURES
public static final java.lang.String[] MINOR_KEY_SIGNATURES
-
KEYSIG_MIDPOINT
public static final int KEYSIG_MIDPOINT
- See Also:
- Constant Field Values
-
MAJOR_ABBR
public static final java.lang.String MAJOR_ABBR
- See Also:
- Constant Field Values
-
MINOR_ABBR
public static final java.lang.String MINOR_ABBR
- See Also:
- Constant Field Values
-
SHARP_CHAR
public static final char SHARP_CHAR
- See Also:
- Constant Field Values
-
FLAT_CHAR
public static final char FLAT_CHAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static SignatureSubparser getInstance()
-
matches
public boolean matches(java.lang.String music)
Description copied from interface:SubparserIndicates whether the subparser should be responsible for parsing the given music string.
-
matchesKeySignature
public boolean matchesKeySignature(java.lang.String music)
-
matchesTimeSignature
public boolean matchesTimeSignature(java.lang.String music)
-
getTokenType
public Token.TokenType getTokenType(java.lang.String tokenString)
Description copied from interface:SubparserAsks the subparser to provide a TokenType for the given token.- Specified by:
getTokenTypein interfaceSubparser- Parameters:
tokenString- The Staccato token to map to a type
-
parse
public int parse(java.lang.String music, StaccatoParserContext context)Description copied from interface:SubparserParses the given music string.
-
createKey
public Key createKey(java.lang.String keySignature)
Description copied from interface:KeyProviderGiven a key signature, like "Cmaj" or "Kbbbb", return the corresponding Key- Specified by:
createKeyin interfaceKeyProvider
-
createKeyFromAccidentals
public Key createKeyFromAccidentals(java.lang.String keySignature)
Returns a Key given a string containing as many flats or sharps as the number one would see on a staff for the corresponding key; e.g., "Kbbbb" = Ab Major
-
createKeyString
public java.lang.String createKeyString(byte notePositionInOctave, byte scale)Description copied from interface:KeyProviderCreates a key name, like Cmaj, given the root note's position in an octave (e.g., 0 for C) and a major or minor indicator - @see Scale MAJOR_SCALE_INDICATOR and MINOR_SCALE_INDICATOR- Specified by:
createKeyStringin interfaceKeyProvider
-
convertAccidentalCountToKeyRootPositionInOctave
public byte convertAccidentalCountToKeyRootPositionInOctave(int accidentalCount, byte scale)Description copied from interface:KeyProviderTurns number of accidentals (negative for flats, positive for sharps) to a key and returns the key's root note's position in the octave- Specified by:
convertAccidentalCountToKeyRootPositionInOctavein interfaceKeyProvider
-
convertKeyToByte
public byte convertKeyToByte(Key key)
Description copied from interface:KeyProviderConverts the given Key to a byte value, from -7 for Cb major or Ab major to +7 for C# minor or A# minor, with 0 being C major or A minor- Specified by:
convertKeyToBytein interfaceKeyProvider
-
-