Package org.staccato

Class SignatureSubparser

java.lang.Object
org.staccato.SignatureSubparser
All Implemented Interfaces:
KeyProvider, Subparser

public class SignatureSubparser extends Object implements Subparser, KeyProvider
Parses both Instrument and Layer tokens. Each has values that are parsed as bytes.
Author:
dkoelle
  • Field Details

  • Constructor Details

    • SignatureSubparser

      public SignatureSubparser()
  • Method Details

    • getInstance

      public static SignatureSubparser getInstance()
    • matches

      public boolean matches(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(String music)
    • matchesTimeSignature

      public boolean matchesTimeSignature(String music)
    • getTokenType

      public Token.TokenType getTokenType(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(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
      context -
      Returns:
      index Updated parsing index into the Staccato music string.
    • createKey

      public Key createKey(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(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 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