Package org.staccato

Class 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
    • 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 octave
      byte 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 minor
      Key createKey​(java.lang.String keySignature)
      Given a key signature, like "Cmaj" or "Kbbbb", return the corresponding Key
      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
      java.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_INDICATOR
      static 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAJOR_KEY_SIGNATURES

        public static final java.lang.String[] MAJOR_KEY_SIGNATURES
      • MINOR_KEY_SIGNATURES

        public static final java.lang.String[] MINOR_KEY_SIGNATURES
    • Constructor Detail

      • SignatureSubparser

        public SignatureSubparser()
    • Method Detail

      • 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.
        Specified by:
        matches in interface Subparser
        Parameters:
        music - The Staccato music string to consider
        Returns:
        true if this subparser will accept the music string, false otherwise
      • 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 interface Subparser
        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.
        Specified by:
        parse in interface Subparser
        Parameters:
        music - The Staccato music string to parse
        Returns:
        index Updated parsing index into the Staccato 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 interface KeyProvider
      • 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 interface KeyProvider
      • 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 interface KeyProvider
      • 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 interface KeyProvider