Class Pattern

java.lang.Object
org.jfugue.pattern.Pattern
All Implemented Interfaces:
PatternProducer, TokenProducer

public class Pattern extends Object implements PatternProducer, TokenProducer
  • Field Details

  • Constructor Details

    • Pattern

      public Pattern()
    • Pattern

      public Pattern(String string)
    • Pattern

      public Pattern(String... strings)
    • Pattern

      public Pattern(PatternProducer... producers)
  • Method Details

    • add

      public Pattern add(PatternProducer... producers)
    • add

      public Pattern add(String string)
    • add

      public Pattern add(PatternProducer producer, int repetitions)
    • add

      public Pattern add(String string, int repetitions)
    • prepend

      public Pattern prepend(PatternProducer... producers)
      Prepends each producer in the order it is passed in, so if you pass in "F F", "G G", and "E E", and the current pattern is "A A", you will get "F F G G E E A A".
    • prepend

      public Pattern prepend(String string)
      Inserts the given string to the beginning of this pattern. If there is content in this pattern already, this method will insert a space between the given string and this pattern so the tokens remain separate.
    • clear

      public Pattern clear()
    • repeat

      public Pattern repeat(int n)
    • atomize

      public Pattern atomize()
      Turns the given pattern into a pattern of Voice-Instrument-Note atoms
      Returns:
      this pattern for method chaining
    • getPattern

      public Pattern getPattern()
      Description copied from interface: PatternProducer
      Returns a pattern
      Specified by:
      getPattern in interface PatternProducer
    • getTokens

      public List<Token> getTokens()
      Specified by:
      getTokens in interface TokenProducer
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setTempo

      public Pattern setTempo(int explicitTempo)
      Provides a way to explicitly set the tempo on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a tempo will be prepended to the beginning of the pattern in the form of "Tx", where x is the tempo number.
      Returns:
      this pattern
    • setTempo

      public Pattern setTempo(String tempo)
      Provides a way to explicitly set the tempo on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a tempo will be prepended to the beginning of the pattern in the form of "Tx", where x is the tempo number (even though this method takes a string as a parameter)
      Returns:
      this pattern
    • setVoice

      public Pattern setVoice(int voice)
      Provides a way to explicitly set the voice on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a voice will be prepended to the beginning of the pattern after any explicit tempo and before any explicit layer in the form of "Vx", where x is the voice number
      Returns:
      this pattern
    • setLayer

      public Pattern setLayer(int layer)
      Provides a way to explicitly set the layer on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a layer will be prepended to the beginning of the pattern after any explicit voice and before any explicit instrument in the form of "Lx", where x is the voice number
      Returns:
      this pattern
    • setInstrument

      public Pattern setInstrument(int instrument)
      Provides a way to explicitly set the instrument on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a instrument will be prepended to the beginning of the pattern after any explicit voice in the form of "I[instrument-name]" (even though this method takes an integer as a parameter)
      Returns:
      this pattern
    • setInstrument

      public Pattern setInstrument(String instrument)
      Provides a way to explicitly set the instrument on a Pattern directly through the pattern rather than by adding text to the contents of the Pattern. When Pattern.toString() is called, the a instrument will be prepended to the beginning of the pattern after any explicit voice in the form of "I[instrument-name]"
      Returns:
      this pattern
    • addToEachNoteToken

      public Pattern addToEachNoteToken(String decoratorString)
      Expects a parameter of "note decorators" - i.e., things that are added to the end of a note, such as duration or attack/decay settings; splits the given parameter on spaces and applies each decorator to each note as it is encountered in the current pattern. If there is one decorator in the parameter, this method will apply that same decorator to all note in the pattern. If there are more notes than decorators, a counter resets to 0 and the decorators starting from the first are applied to the future notes. Examples: new Pattern("A B C").addToEachNoteToken("q") --> "Aq Bq Cq" new Pattern("A B C").addToEachNoteToken("q i") --> "Aq Bi Cq" (rolls back to q for third note) new Pattern("A B C").addToEachNoteToken("q i s") --> "Aq Bi Cs" new Pattern("A B C").addToEachNoteToken("q i s w") --> "Aq Bi Cs" (same as "q i s")
      Returns:
      this pattern
    • save

      public Pattern save(File file) throws IOException
      Throws:
      IOException
    • save

      public Pattern save(File file, String... comments) throws IOException
      Throws:
      IOException
    • load

      public static Pattern load(File file) throws IOException
      Throws:
      IOException
    • transform

      public Pattern transform(ParserListener listener)
      Parse this pattern and have the given ParserListener listen to it. The user will need to call a function on the listener to get the result. This method returns its own class, the contents of which ARE NOT modified by this call.
    • measure

      public Pattern measure(ParserListener listener)
      Parse this pattern and have the given ParserListener listen to it. The user will need to call a function on the listener to get the result. This method returns its own class, the contents of which ARE NOT modified by this call.