java.lang.Object
provided.abcMusic.parser.ABCParser
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.
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
FieldsModifier and TypeFieldDescriptionprivate ABCTokenizer
ABCTokenizer to use.Set of accidental notes in the current measure.private DecoratorSeqList
Proxy to that is used to reference the beginning of the phrase before it has finished being calculated.private ATokVisitor
Checks for dotted notes.private double
The amount to additively correct the duration by due to dotted notes;(package private) double
Grace note duration multiplier.(package private) double
Total grace note duration of previous grace notesprivate boolean
Current notes to be parsed are grace notesprivate Stack<DecoratorSeqList>
Stack that holds the proxies to the current second repeat start location.private Stack<DecoratorSeqList>
A stack that hold the latest jump targets (repeat start) for repeats.private ILogger
Logger for to useprivate ATokVisitor
Main algo used to create a list of IPhrases from the stream of tokens that represents the progression of the song (phrase). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 accidentalprivate Note
Parse a Note from the given Tokenparse()
Run the parser and parse the entire file, returning an IPhrase object that represents the entire piece of music.private DecoratorSeqList
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
Swap the given token for the next token in the tokenizer, returning the next token.
-
Field Details
-
logger
Logger for to use -
abcT
ABCTokenizer to use. -
beginningTarget
Proxy to that is used to reference the beginning of the phrase before it has finished being calculated. -
jumpTargetStack
A stack that hold the latest jump targets (repeat start) for repeats. -
jumpSecondRepeatStack
Stack that holds the proxies to the current second repeat start location. -
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 isGraceCurrent notes to be parsed are grace notes -
grace_multiplier
double grace_multiplierGrace note duration multiplier. -
graceDuration
double graceDurationTotal grace note duration of previous grace notes -
dottedCorrection
private double dottedCorrectionThe amount to additively correct the duration by due to dotted notes; -
checkNextNoteAlgo
Checks for dotted notes. Takes in a duration and returns the correct value as per any dotted-ness. -
accidentalNotes
Set of accidental notes in the current measure.
-
-
Constructor Details
-
ABCParser
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
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
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
Run the parser and parse the entire file, returning an IPhrase object that represents the entire piece of music.- Returns:
- An IPhrase object
-
makeNote
Parse a Note from the given Token- Parameters:
host
- The Note token- Returns:
- A Note object
-
checkAccidentals
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
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
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
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.
-