org.jfugue
Class MusicStringParser

java.lang.Object
  extended by org.jfugue.Parser
      extended by org.jfugue.MusicStringParser

public final class MusicStringParser
extends Parser

Parses music strings, and fires events for ParserListener interfaces when tokens are interpreted. The ParserListener does intelligent things with the resulting events, such as create music, draw sheet music, or transform the data. As of Version 3.0, the Parser supports turning MIDI Sequences into JFugue Patterns with the parse(Sequence) method. In this case, the ParserListeners established by a ParserBuilder use the parsed events to construct the Pattern string.

Version:
3.0
Author:
David Koelle

Field Summary
 
Fields inherited from class org.jfugue.Parser
listenerList, progressListenerList, TRACING_OFF, TRACING_ON
 
Constructor Summary
MusicStringParser()
          Creates a new Parser object, and populates the dictionary with initial entries.
 
Method Summary
protected  int getTempo()
          Returns the tempo for the current song.
 boolean isValidToken(java.lang.String token)
          Checks whether a token is valid.
static void main(java.lang.String[] args)
          Used for diagnostic purposes.
 void parse(Pattern pattern)
          Parses a Pattern and fires events to subscribed ParserListener interfaces.
protected  void setTempo(int tempo)
          Sets the tempo for the current song.
 
Methods inherited from class org.jfugue.Parser
addParserListener, addParserProgressListener, clearParserListeners, clearParserProgressListeners, fireChannelPressureEvent, fireControllerEvent, fireInstrumentEvent, fireKeySignatureEvent, fireLayerEvent, fireMeasureEvent, fireNoteEvent, fireParallelNoteEvent, firePitchBendEvent, firePolyphonicPressureEvent, fireProgressReported, fireSequentialNoteEvent, fireTempoEvent, fireTimeEvent, fireVoiceEvent, getTracing, removeParserListener, removeParserProgressListener, setTracing, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MusicStringParser

public MusicStringParser()
Creates a new Parser object, and populates the dictionary with initial entries.

See Also:
JFugueDefinitions
Method Detail

setTempo

protected void setTempo(int tempo)
Sets the tempo for the current song. Tempo is measured in "pulses per quarter". The parser uses this value to convert note durations, which are relative values and not directly related to time measurements, into actual times. For example, a whole note has the same duration as four quarter notes, but neither a whole note nor a quarter note equates to any real-life time delay until it's multplied by the tempo. The default value for Tempo is 120 pulses per quarter.

Parameters:
tempo - the tempo for the current song, in pulses per quarter.

getTempo

protected int getTempo()
Returns the tempo for the current song.


parse

public void parse(Pattern pattern)
           throws JFugueException
Parses a Pattern and fires events to subscribed ParserListener interfaces. As the Pattern is parsed, events are sent to ParserLisener interfaces, which are responsible for doing something interesting with the music data, such as playing the music, displaying it as sheet music, or transforming the pattern.

The parser breaks a music string into tokens, which are separated by spaces. It then determines the type of command based on the first character of the token. If the parser does not recognize the first character of the token, which is limited to the command letters (K, V, T, I, L, X, #, $, @, &, +, *, |), the notes (A, B, C, D, E, F, G, R), and the open-bracket character ( [ ), then the token will be ignored.

Parameters:
pattern - the Pattern to parse
Throws:
java.lang.Exception - if there is an error parsing the pattern
JFugueException

isValidToken

public boolean isValidToken(java.lang.String token)
Checks whether a token is valid. This method is provided for testing purposes, and is not used during normal operation.

Parameters:
token - the token to test for validity
Returns:
true is the token is valid; false otherwise.

main

public static void main(java.lang.String[] args)
Used for diagnostic purposes. main() makes calls to test the Pattern-to-MIDI parser. If you make any changes to this parser, run this method ("java org.jfugue.MusicStringParser"), and make sure everything works correctly.

Parameters:
args - not used