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 char
FLAT_CHAR
static java.lang.String
KEY_SIGNATURE
static int
KEYSIG_MIDPOINT
static java.lang.String
MAJOR_ABBR
static java.lang.String[]
MAJOR_KEY_SIGNATURES
static java.lang.String
MINOR_ABBR
static java.lang.String[]
MINOR_KEY_SIGNATURES
static java.lang.String
SEPARATOR
static char
SHARP_CHAR
static java.lang.String
TIME_SIGNATURE
-
Constructor Summary
Constructors Constructor Description SignatureSubparser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
convertAccidentalCountToKeyRootPositionInOctave(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 octavebyte
convertKeyToByte(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 minorKey
createKey(java.lang.String keySignature)
Given a key signature, like "Cmaj" or "Kbbbb", return the corresponding KeyKey
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 Majorjava.lang.String
createKeyString(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 SignatureSubparser
getInstance()
Token.TokenType
getTokenType(java.lang.String tokenString)
Asks the subparser to provide a TokenType for the given token.boolean
matches(java.lang.String music)
Indicates whether the subparser should be responsible for parsing the given music string.boolean
matchesKeySignature(java.lang.String music)
boolean
matchesTimeSignature(java.lang.String music)
int
parse(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:Subparser
Indicates 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:Subparser
Asks the subparser to provide a TokenType for the given token.- Specified by:
getTokenType
in 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:Subparser
Parses the given music string.
-
createKey
public Key createKey(java.lang.String keySignature)
Description copied from interface:KeyProvider
Given a key signature, like "Cmaj" or "Kbbbb", return the corresponding Key- Specified by:
createKey
in 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:KeyProvider
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_INDICATOR- Specified by:
createKeyString
in interfaceKeyProvider
-
convertAccidentalCountToKeyRootPositionInOctave
public byte convertAccidentalCountToKeyRootPositionInOctave(int accidentalCount, byte scale)
Description copied from interface:KeyProvider
Turns 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:
convertAccidentalCountToKeyRootPositionInOctave
in interfaceKeyProvider
-
convertKeyToByte
public byte convertKeyToByte(Key key)
Description copied from interface:KeyProvider
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 minor- Specified by:
convertKeyToByte
in interfaceKeyProvider
-
-