provided.abcParser
Class ABCParser

java.lang.Object
  extended by provided.abcParser.ABCParser

public class ABCParser
extends java.lang.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 Summary
private  ABCTokenizer abcT
          ABCTokenizer to use.
private  java.util.Set<Note> accidentalNotes
          Set of accidental notes in the current measure.
private  DecoratorSeqList beginningTarget
          Proxy to that is used to reference the beginning of the phrase before it has finished being calculated.
private  ATokVisitor checkNextNoteAlgo
          Checks for dotted notes.
private  double dottedCorrection
          The amount to additively correct the duration by due to dotted notes;
(package private)  double grace_multiplier
          Grace note duration multiplier.
(package private)  double graceDuration
          Total grace note duration of previous grace notes
private  boolean isGrace
          Current notes to be parsed are grace notes
private  java.util.Stack<DecoratorSeqList> jumpSecondRepeatStack
          Stack that holds the proxies to the current second repeat start location.
private  java.util.Stack<DecoratorSeqList> jumpTargetStack
          A stack that hold the latest jump targets (repeat start) for repeats.
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).
 
Constructor Summary
ABCParser(java.lang.String inputFileName)
          Constructs a parser for the given ABC input file.
 
Method Summary
private  void addAccidental(Note note)
          Adds a note to the set of accidentals replaces any note with the same name and octave.
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
private  Note makeNote(Token host)
          Parse a Note from the given Token
 IPhrase parse()
          Run the parser and parse the entire file, returning an IPhrase object that represents the entire piece of music.
private  DecoratorSeqList popJumpTarget()
          Pull off the current jump target from the jump target stack.
private  void pushJumpTarget(DecoratorSeqList target)
          Push the given jump target onto the stack so that it is now the current jump target.
private  void removeAccidental(Note note)
          Removes a note from the set of accidentals Removes any note with the same name and octave.
private  Token swapToken(Token t)
          Swap the given token for the next token in the tokenizer, returning the next token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 java.util.Stack<DecoratorSeqList> jumpTargetStack
A stack that hold the latest jump targets (repeat start) for repeats.


jumpSecondRepeatStack

private java.util.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 java.util.Set<Note> accidentalNotes
Set of accidental notes in the current measure.

Constructor Detail

ABCParser

public ABCParser(java.lang.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 Detail

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 -
Returns:
the token that previously was next in the tokenizer.