Module hw06

Class ABCParser

java.lang.Object
provided.abcMusic.parser.ABCParser

public class ABCParser extends Object
Parses an abc file into IPhrase music structures
Usage:
ABCParser parser = new ABCParser("/data/aMusicFile.abc");
IPhrase phrase = parser.parse();
Cases handled:
- single notes with and without accidentals and naturals with regards to measures
- chords
- dotted notes
- grace notes
- repeats, including first and second repeats.
- triplets
- tuplets
- all headers
- quoted text
- D.C. al fine
- EOF (End Of File)

All other cases ignored.
Author:
swong
  • Field Details

    • logger

      private ILogger logger
      Logger for to use
    • abcT

      private ABCTokenizer abcT
      ABCTokenizer to use.
    • beginningTarget

      private DecoratorSeqList beginningTarget
      Proxy to that is used to reference the beginning of the phrase before it has finished being calculated.
    • jumpTargetStack

      private Stack<DecoratorSeqList> jumpTargetStack
      A stack that hold the latest jump targets (repeat start) for repeats.
    • jumpSecondRepeatStack

      private Stack<DecoratorSeqList> jumpSecondRepeatStack
      Stack that holds the proxies to the current second repeat start location.
    • makeSeqListAlgo

      private ATokVisitor makeSeqListAlgo
      Main algo used to create a list of IPhrases from the stream of tokens that represents the progression of the song (phrase).
    • isGrace

      private boolean isGrace
      Current notes to be parsed are grace notes
    • grace_multiplier

      double grace_multiplier
      Grace note duration multiplier.
    • graceDuration

      double graceDuration
      Total grace note duration of previous grace notes
    • dottedCorrection

      private double dottedCorrection
      The amount to additively correct the duration by due to dotted notes;
    • checkNextNoteAlgo

      private ATokVisitor checkNextNoteAlgo
      Checks for dotted notes. Takes in a duration and returns the correct value as per any dotted-ness.
    • accidentalNotes

      private Set<Note> accidentalNotes
      Set of accidental notes in the current measure.
  • Constructor Details

    • ABCParser

      public ABCParser(String inputFileName)
      Constructs a parser for the given ABC input file. Does not actually run that parser yet. Prints error message to System.err if there is a problem opening the given file. The returned parser will be null in the event of an error.
      Parameters:
      inputFileName - the name of the input text file
  • Method Details

    • popJumpTarget

      private DecoratorSeqList popJumpTarget()
      Pull off the current jump target from the jump target stack. If the stack is empty, return the proxy for the beginning of the phrase, as this is the default jump target.
      Returns:
      The current jump target or the beginning of the phrase.
    • pushJumpTarget

      private void pushJumpTarget(DecoratorSeqList target)
      Push the given jump target onto the stack so that it is now the current jump target. This corresponds to the innermost nested repeat.
      Parameters:
      target - The new current jump target.
    • parse

      public IPhrase parse()
      Run the parser and parse the entire file, returning an IPhrase object that represents the entire piece of music.
      Returns:
      An IPhrase object
    • makeNote

      private Note makeNote(Token host)
      Parse a Note from the given Token
      Parameters:
      host - The Note token
      Returns:
      A Note object
    • checkAccidentals

      private void checkAccidentals(Note note)
      Checks to see if the given Note is in the set of accidentals Checks name and octave but not duration or accidental
      Parameters:
      note - The note to check
    • addAccidental

      private void addAccidental(Note note)
      Adds a note to the set of accidentals replaces any note with the same name and octave. duration and accidental are ignored.
      Parameters:
      note - the Note to add.
    • removeAccidental

      private void removeAccidental(Note note)
      Removes a note from the set of accidentals Removes any note with the same name and octave. duration and accidental are ignored.
      Parameters:
      note - the note to remove
    • swapToken

      private Token swapToken(Token t)
      Swap the given token for the next token in the tokenizer, returning the next token. The given token will be the next token out of the tokenizer.
      Parameters:
      t - The token to be swapped into the tokenizer
      Returns:
      the token that previously was next in the tokenizer.