Class Rhythm

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Map<java.lang.Character,​java.lang.String> DEFAULT_RHYTHM_KIT  
    • Constructor Summary

      Constructors 
      Constructor Description
      Rhythm()  
      Rhythm​(java.lang.String... layers)  
      Rhythm​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit)  
      Rhythm​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit, java.lang.String... layers)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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.
      Rhythm addLayer​(java.lang.String layer)
      Adds a layer to this Rhythm, but fails silently if the rhythm already has MAX_LAYERS layers.
      Rhythm addOneTimeAltLayer​(int layer, int oneTime, java.lang.String rhythmString)
      Sets an alt layer that will play one time, at the given segment.
      Rhythm addOneTimeAltLayer​(int layer, int oneTime, java.lang.String rhythmString, int zOrder)
      Sets an alt layer that will play one time, at the given segment.
      Rhythm addRangedAltLayer​(int layer, int start, int end, java.lang.String rhythmString)
      Sets an alt layer that will play between and including the start and end indices.
      Rhythm addRangedAltLayer​(int layer, int start, int end, java.lang.String rhythmString, int zOrder)
      Sets an alt layer that will play between and including the start and end indices.
      Rhythm addRecurringAltLayer​(int layer, int start, int end, int recurrence, java.lang.String rhythmString)
      Sets an alt layer that will recur every recurrence times *after* the start index is reached.
      Rhythm addRecurringAltLayer​(int layer, int start, int end, int recurrence, java.lang.String rhythmString, int zOrder)
      Sets an alt layer that will recur every recurrence times *after* the start index is reached.
      boolean canAddLayer()
      Returns true if the number of layers is less than MAX_LAYERS, which is limited to 16 by the MIDI Specification
      Rhythm clone()  
      static Rhythm combine​(Rhythm... rhythms)
      Combines rhythms into multiple layers.
      java.util.List<org.jfugue.rhythm.Rhythm.AltLayer> getAltLayersForLayer​(int layer)
      Returns all AltLayers for the given layer; the resulting list is unsorted by z-order
      java.lang.String getLayer​(int layer)  
      java.util.List<java.lang.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.
      java.lang.String[] getLayersAt​(int segment)
      Returns all layers, including altLayers, for the given segment
      int getLength()  
      Pattern getPattern()
      Returns a pattern
      Pattern getPatternAt​(int segment)  
      java.lang.String[] getRhythm()
      Returns the full rhythm, including alt layers, but not translated into Staccato music strings by looking up rhythm entries into the RhythmKit
      java.util.Map<java.lang.Character,​java.lang.String> getRhythmKit()  
      java.util.List<org.jfugue.rhythm.Rhythm.AltLayer> getSortedAltLayersForLayer​(int layer)
      Returns all AltLayers for the given layer sorted by each AltLayer's z-order
      java.lang.String getStaccatoStringForRhythm​(java.lang.String rhythm)
      Uses the RhythmKit to translate the given rhythm into a Staccato music string.
      Rhythm setLayers​(java.util.List<java.lang.String> layers)
      Sets all of the layers
      Rhythm setLength​(int length)
      Sets the length of the rhythm, which is the number of times that a single pattern is repeated.
      Rhythm setRhythmKit​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit)  
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_RHYTHM_KIT

        public static final java.util.Map<java.lang.Character,​java.lang.String> DEFAULT_RHYTHM_KIT
    • Constructor Detail

      • Rhythm

        public Rhythm()
      • Rhythm

        public Rhythm​(java.lang.String... layers)
      • Rhythm

        public Rhythm​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit)
      • Rhythm

        public Rhythm​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit,
                      java.lang.String... layers)
    • Method Detail

      • setRhythmKit

        public Rhythm setRhythmKit​(java.util.Map<java.lang.Character,​java.lang.String> rhythmKit)
      • getRhythmKit

        public java.util.Map<java.lang.Character,​java.lang.String> getRhythmKit()
      • addLayer

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

        public java.lang.String getLayer​(int layer)
      • getLayers

        public java.util.List<java.lang.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:
        getLayersForSegment
      • setLayers

        public Rhythm setLayers​(java.util.List<java.lang.String> layers)
        Sets all of the layers
      • getLayersAt

        public java.lang.String[] getLayersAt​(int segment)
        Returns all layers, including altLayers, for the given segment
        See Also:
        getLayers()
      • 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 java.lang.Object
      • getAltLayersForLayer

        public java.util.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:
        getSortedAltLatersForLayer
      • getSortedAltLayersForLayer

        public java.util.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,
                                           java.lang.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,
                                           java.lang.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,
                                        java.lang.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,
                                        java.lang.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,
                                         java.lang.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,
                                         java.lang.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:
        RhythmAltLayerProvider
      • 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:
        RhythmAltLayerProvider
      • 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 java.lang.String getStaccatoStringForRhythm​(java.lang.String rhythm)
        Uses the RhythmKit to translate the given rhythm into a Staccato music string.
        See Also:
        getPattern()
      • getPatternAt

        public Pattern getPatternAt​(int segment)
      • getRhythm

        public java.lang.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: