org.jfugue
Class PatternTransformer

java.lang.Object
  |
  +--org.jfugue.PatternTransformer
All Implemented Interfaces:
ParserListener
Direct Known Subclasses:
DurationPatternTransformer, IntervalPatternTransformer, ReversePatternTransformer

public abstract class PatternTransformer
extends java.lang.Object
implements ParserListener

This class is used to transform a pattern. Extend this class to create your own PatternTransformer, which listens to parser events and can modify the events that are fired off by the parser. Some sample PatternTransformer subclasses are packaged with JFugue; refer to those to see examples of transformers in action.

Version:
2.0
Author:
David Koelle
See Also:
DurationPatternTransformer, IntervalPatternTransformer, ReversePatternTransformer

Field Summary
protected  Pattern returnPattern
          Contains the pattern to return at the end of the transformation.
 
Constructor Summary
PatternTransformer()
           
 
Method Summary
 void controllerEvent(Controller controller)
          Extend this method to make your transformer modify the controller messages.
abstract  java.lang.String getDescription()
          Indicates what this PatternTransformer does.
 java.lang.Object getVariable(java.lang.String name)
          Returns a variable setting.
abstract  java.lang.String getVariables()
          Returns a list of variables needed by your Transformer.
 void instrumentEvent(Instrument instrument)
          Extend this method to make your transformer modify the instrument.
 void noteEvent(Note note)
          Extend this method to make your transformer modify the note.
 void parallelNoteEvent(Note note)
          Extend this method to make your transformer modify the note.
 void putVariable(java.lang.String name, java.lang.Object value)
          Places a value for a variable.
 void sequentialNoteEvent(Note note)
          Extend this method to make your transformer modify the note.
 void tempoEvent(Tempo tempo)
          Extend this method to make your transformer modify the tempo.
 Pattern transform(Pattern p)
          Transforms the pattern, according to the event method that you have presumably extended.
 void voiceEvent(Voice voice)
          Extend this method to make your transformer modify the voice.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

returnPattern

protected Pattern returnPattern
Contains the pattern to return at the end of the transformation.
Constructor Detail

PatternTransformer

public PatternTransformer()
Method Detail

getVariables

public abstract java.lang.String getVariables()
Returns a list of variables needed by your Transformer.

It is very important to keep these strings standardized! This will allow future programs to understand what is required of each Transformer. Therefore, make your Transformer return strings like this. Notice the use of quotes and slashes.

'variable name'/type/description/default

If you need to return multiple Strings, end each String with a \n, the newline character.

Also, be sure to add your strings to the JavaDoc for the getVariables() method as well, so users can learn what your code needs from its documentation.


getDescription

public abstract java.lang.String getDescription()
Indicates what this PatternTransformer does.
Returns:
A String giving a quick description of this transformer

putVariable

public void putVariable(java.lang.String name,
                        java.lang.Object value)
Places a value for a variable.

getVariable

public java.lang.Object getVariable(java.lang.String name)
Returns a variable setting.

transform

public Pattern transform(Pattern p)
Transforms the pattern, according to the event method that you have presumably extended.

voiceEvent

public void voiceEvent(Voice voice)
Extend this method to make your transformer modify the voice.
Specified by:
voiceEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
voice - the event that has been parsed

tempoEvent

public void tempoEvent(Tempo tempo)
Extend this method to make your transformer modify the tempo.
Specified by:
tempoEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
tempo - the event that has been parsed

instrumentEvent

public void instrumentEvent(Instrument instrument)
Extend this method to make your transformer modify the instrument.
Specified by:
instrumentEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
instrument - the event that has been parsed

controllerEvent

public void controllerEvent(Controller controller)
Extend this method to make your transformer modify the controller messages.
Specified by:
controllerEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
controller - the event that has been parsed

noteEvent

public void noteEvent(Note note)
Extend this method to make your transformer modify the note. Don't forget to also extend sequentialNoteEvent and parallelNoteEvent.
Specified by:
noteEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
note - the event that has been parsed

sequentialNoteEvent

public void sequentialNoteEvent(Note note)
Extend this method to make your transformer modify the note. Don't forget to also extend noteEvent and parallelNoteEvent.
Specified by:
sequentialNoteEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
note - the event that has been parsed

parallelNoteEvent

public void parallelNoteEvent(Note note)
Extend this method to make your transformer modify the note. Don't forget to also extend noteEvent and sequentialNoteEvent.
Specified by:
parallelNoteEvent in interface ParserListener
Following copied from interface: org.jfugue.ParserListener
Parameters:
note - the event that has been parsed