Class Rhythm

java.lang.Object
org.jfugue.rhythm.Rhythm
All Implemented Interfaces:
PatternProducer

public class Rhythm extends Object implements PatternProducer
  • Field Details

  • Constructor Details

  • Method Details

    • setRhythmKit

      public Rhythm setRhythmKit(Map<Character,String> rhythmKit)
    • getRhythmKit

      public Map<Character,String> getRhythmKit()
    • addLayer

      public Rhythm addLayer(String layer)
      Adds a layer to this Rhythm, but fails silently if the rhythm already has MAX_LAYERS layers.
      Parameters:
      layer -
      Returns:
    • getLayer

      public String getLayer(int layer)
    • getLayers

      public List<String> getLayers()
      Returns all layers that have been added with the traditional addLayer() method - but to truly find out what the layer will sound like at a given segment, use getLayersForSegment(), which takes alt layers into account.
      See Also:
      • invalid reference
        getLayersForSegment
    • setLayers

      public Rhythm setLayers(List<String> layers)
      Sets all of the layers
    • getLayersAt

      public String[] getLayersAt(int segment)
      Returns all layers, including altLayers, for the given segment
      See Also:
    • canAddLayer

      public boolean canAddLayer()
      Returns true if the number of layers is less than MAX_LAYERS, which is limited to 16 by the MIDI Specification
      Returns:
    • clone

      public Rhythm clone()
      Overrides:
      clone in class Object
    • getAltLayersForLayer

      public List<org.jfugue.rhythm.Rhythm.AltLayer> getAltLayersForLayer(int layer)
      Returns all AltLayers for the given layer; the resulting list is unsorted by z-order
      See Also:
      • invalid reference
        getSortedAltLatersForLayer
    • getSortedAltLayersForLayer

      public List<org.jfugue.rhythm.Rhythm.AltLayer> getSortedAltLayersForLayer(int layer)
      Returns all AltLayers for the given layer sorted by each AltLayer's z-order
    • addRecurringAltLayer

      public Rhythm addRecurringAltLayer(int layer, int start, int end, int recurrence, String rhythmString)
      Sets an alt layer that will recur every recurrence times *after* the start index is reached. If the start index is 2 and the recurrence is 5, this alt layer will be used every time the segment % recurrence == start. By default, this has a Z-Order of 1.
    • addRecurringAltLayer

      public Rhythm addRecurringAltLayer(int layer, int start, int end, int recurrence, String rhythmString, int zOrder)
      Sets an alt layer that will recur every recurrence times *after* the start index is reached. If the start index is 2 and the recurrence is 5, this alt layer will be used every time the segment % recurrence == start
    • addRangedAltLayer

      public Rhythm addRangedAltLayer(int layer, int start, int end, String rhythmString)
      Sets an alt layer that will play between and including the start and end indices. By default, this has a Z-Order of 2.
    • addRangedAltLayer

      public Rhythm addRangedAltLayer(int layer, int start, int end, String rhythmString, int zOrder)
      Sets an alt layer that will play between and including the start and end indices.
    • addOneTimeAltLayer

      public Rhythm addOneTimeAltLayer(int layer, int oneTime, String rhythmString)
      Sets an alt layer that will play one time, at the given segment. By default, this has a Z-Order of 3.
    • addOneTimeAltLayer

      public Rhythm addOneTimeAltLayer(int layer, int oneTime, String rhythmString, int zOrder)
      Sets an alt layer that will play one time, at the given segment.
    • addAltLayerProvider

      public Rhythm addAltLayerProvider(int layer, RhythmAltLayerProvider altLayerProvider)
      Gives a RhythmAltLayerProvider, which will make its own determination about what type of alt layer to play, and when to play it. By default, this has a Z-Order of 4.
      See Also:
    • addAltLayerProvider

      public Rhythm addAltLayerProvider(int layer, RhythmAltLayerProvider altLayerProvider, int zOrder)
      Gives a RhythmAltLayerProvider, which will make its own determination about what type of alt layer to play, and when to play it.
      See Also:
    • combine

      public static Rhythm combine(Rhythm... rhythms)
      Combines rhythms into multiple layers. If there are more than MAX_LAYERS layers in the provided rhythms, only the first MAX_LAYERS are used (for example, if you pass five rhythms that each have four layers, the combined rhythm will only contain the layers from the first four rhythms). This method also ensures that the Rhythm Kit for each of the provided Rhythms is added to the return value's Rhythm Kit.
      Parameters:
      rhythms - the rhythms to combine
      Returns:
      the combined rhythm
    • setLength

      public Rhythm setLength(int length)
      Sets the length of the rhythm, which is the number of times that a single pattern is repeated. For example, creating a layer of "S...S...S...O..." and a length of 3 would result in a Rhythm pattern of "S...S...S...O...S...S...S...O...S...S...S...O..."
    • getLength

      public int getLength()
    • getStaccatoStringForRhythm

      public String getStaccatoStringForRhythm(String rhythm)
      Uses the RhythmKit to translate the given rhythm into a Staccato music string.
      See Also:
    • getPatternAt

      public Pattern getPatternAt(int segment)
    • getPattern

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

      public String[] getRhythm()
      Returns the full rhythm, including alt layers, but not translated into Staccato music strings by looking up rhythm entries into the RhythmKit
      Returns: