Internal Functions

These functions are more low level, probably not needed by the live coder.

Haskell-style functor, applicative and monadic operations

withValue

Synonyms: fmap

Returns a new pattern, with the function applied to the value of each hap. It has the alias fmap.

  • func (function): to to apply to the value
"0 1 2".withValue(v => v + 10).log()

appWhole

Assumes 'this' is a pattern of functions, and given a function to resolve wholes, applies a given pattern of values to that pattern of functions.

  • whole_func (function):
  • func (function):

appBoth

When this method is called on a pattern of functions, it matches its haps with those in the given pattern of values. A new pattern is returned, with each matching value applied to the corresponding function.

In this _appBoth variant, where timespans of the function and value haps are not the same but do intersect, the resulting hap has a timespan of the intersection. This applies to both the part and the whole timespan.

  • pat_val (Pattern):

appLeft

As with appBoth, but the whole timespan is not the intersection, but the timespan from the function of patterns that this method is called on. In practice, this means that the pattern structure, including onsets, are preserved from the pattern of functions (often referred to as the left hand or inner pattern).

  • pat_val (Pattern):

appRight

As with appLeft, but whole timespans are instead taken from the pattern of values, i.e. structure is preserved from the right hand/outer pattern.

  • pat_val (Pattern):

bindWhole

bind

join

outerBind

outerJoin

innerBind

innerJoin

resetJoin

restartJoin

squeezeJoin

squeezeBind

Utility methods mainly for internal use

queryArc

Query haps inside the given time span.

  • begin (Fraction|number): from time
  • end (Fraction|number): to time
const pattern = sequence('a', ['b', 'c'])
const haps = pattern.queryArc(0, 1)
console.log(haps)
silence

splitQueries

Returns a new pattern, with queries split at cycle boundaries. This makes some calculations easier to express, as all haps are then constrained to happen within a cycle.

    withQuerySpan

    Returns a new pattern, where the given function is applied to the query timespan before passing it to the original pattern.

    • func (function): the function to apply

    withQuerySpanMaybe

    withQueryTime

    As with withQuerySpan, but the function is applied to both the begin and end time of the query timespan.

    • func (function): the function to apply

    withHapSpan

    Similar to withQuerySpan, but the function is applied to the timespans of all haps returned by pattern queries (both part timespans, and where present, whole timespans).

    • func (function):

    withHapTime

    As with withHapSpan, but the function is applied to both the begin and end time of the hap timespans.

    • func (function): the function to apply

    withHaps

    Returns a new pattern with the given function applied to the list of haps returned by every query.

    • func (function):

    withHap

    As with withHaps, but applies the function to every hap, rather than every list of haps.

    • func (function):

    setContext

    Returns a new pattern with the context field set to every hap set to the given value.

    • context (*):

    withContext

    Returns a new pattern with the context field set to every hap set to the given value.

    • context (*):

    stripContext

    Returns a new pattern with the context field of every hap set to an empty object.

      withLoc

      Returns a new pattern with the given location information added to the context of every hap.

      • start (Number): start offset
      • end (Number): end offset

      filterHaps

      Returns a new Pattern, which only returns haps that meet the given test.

      • hap_test (function): a function which returns false for haps to be removed from the pattern

      filterValues

      As with filterHaps, but the function is applied to values inside haps.

      • value_test (function):

      removeUndefineds

      As with filterHaps, but the function is applied to values inside haps.

      • value_test (function):

      onsetsOnly

      Returns a new pattern, with all haps without onsets filtered out. A hap with an onset is one with a whole timespan that begins at the same time as its part timespan.

        discreteOnly

        Returns a new pattern, with 'continuous' haps (those without 'whole' timespans) removed from query results.

          defragmentHaps

          Combines adjacent haps with the same value and whole. Only intended for use in tests.

            firstCycle

            Queries the pattern for the first cycle, returning Haps. Mainly of use when debugging a pattern.

            • with_context (Boolean): set to true, otherwise the context field will be stripped from the resulting haps.

            firstCycleValues

            Accessor for a list of values returned by querying the first cycle.

              showFirstCycle

              More human-readable version of the firstCycleValues accessor.

                sortHapsByPart

                Returns a new pattern, which returns haps sorted in temporal order. Mainly of use when comparing two patterns for equality, in tests.

                  asNumber

                  Returns a new pattern, which returns haps sorted in temporal order. Mainly of use when comparing two patterns for equality, in tests.

                    Operators

                    • _opIn
                    • _opOut
                    • _opMix
                    • _opSqueeze
                    • _opSqueezeOut
                    • _opTrig
                    • _opTrigzero

                    Other

                    onTrigger

                    log

                    logValues

                    drawLine

                    collect

                    Functions

                    groupHapsBy

                    pure

                    A discrete value that repeats once per cycle.

                      pure('e4') // "e4"

                      reify

                      slowcatPrime

                      Concatenation: combines a list of patterns, switching between them successively, one per cycle. Unlike slowcat, this version will skip cycles.

                      • items (any): The items to concatenate

                      isPattern

                      register

                      Registers a new pattern method. The method is added to the Pattern class + the standalone function is returned from register.

                      • name (string): name of the function
                      • func (function): function with 1 or more params, where last is the current pattern

                      toBipolar

                      Assumes a numerical pattern, containing unipolar values in the range 0 ..

                      1. Returns a new pattern with values scaled to the bipolar range -1 .. 1

                        fromBipolar

                        Assumes a numerical pattern, containing bipolar values in the range -1 .. 1 Returns a new pattern with values scaled to the unipolar range 0 .. 1

                          compressSpan

                          focus

                          Similar to compress, but doesn't leave gaps, and the 'focus' can be bigger than a cycle

                            s("bd hh sd hh").focus(1/4, 3/4)

                            focusSpan

                            _composeOp

                            Composers

                            set keep keepif add sub mul div mod pow band bor bxor blshift brshift lt gt lte gte eq eqt ne net and or func
                            In Out Mix Squeeze SqueezeOut Trig Trigzero