diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-21 15:23:04 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | d6b928d690ce3633e602e24ca88c23f8ccbaecc4 (patch) | |
| tree | 74d585ae8fd6f73d76ceb1a85bec362c321259dc | |
| parent | add PureOp spec (diff) | |
| download | alive-d6b928d690ce3633e602e24ca88c23f8ccbaecc4.tar.gz alive-d6b928d690ce3633e602e24ca88c23f8ccbaecc4.zip | |
add trigseq to lib/rhythm
| -rw-r--r-- | alv-lib/rhythm.moon | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/alv-lib/rhythm.moon b/alv-lib/rhythm.moon index 35d57ae..8170cf9 100644 --- a/alv-lib/rhythm.moon +++ b/alv-lib/rhythm.moon @@ -39,7 +39,7 @@ euclid = Constant.meta meta: name: 'euclid' summary: "Generate euclidean rhythms." - examples: { '(euclid i n k)', '(euclid trigger! n k)' } + examples: { '(euclid trig! n k)', '(euclid i n k)' } description: "Generates bangs according to the Euclidean algorithm. When fed a bang! trigger, steps forward to the next step on each trigger. @@ -67,7 +67,7 @@ When fed a num~ or num! stream, outputs a bang if the corresponding step is on." if @inputs.trig\type! == T.bang @state += 1 - if @state > n + if @state >= n @state -= n i = 1 + (@state or trig % n) @@ -75,6 +75,47 @@ When fed a num~ or num! stream, outputs a bang if the corresponding step is on." if '1' == pat\sub i, i @out\set true +trigseq = Constant.meta + meta: + name: 'trigseq' + summary: "Generate rhythms based on a trigger-sequence" + examples: { '(trigseq trig! [s1 s2…])', '(trigseq i [s1 s2…])' } + description: "Generates bangs according to the sequence `s1`, `s2`, … + +Each step should be a bool~ that determines whether a bang should be emitted on +that step or not. + +When fed a bang! trigger, steps forward to the next step on each trigger. +When fed a num~ or num! stream, outputs a bang if the corresponding step is on." + + value: class extends Op + pattern = (evt.bang / val.num / evt.num) + val.bool*0 + setup: (inputs) => + { trig, steps } = pattern\match inputs + + @out or= T.bang\mk_evt! + + super + trig: Input.hot trig + steps: [Input.cold s for s in *steps] + + if @inputs.trig\type! == T.bang + @state or= 1 + else + @state = nil + + tick: => + n = #@inputs.steps + if @inputs.trig\type! == T.bang + @state += 1 + if @state >= n + @state -= n + + i = 1 + (@state or trig % n) + if @inputs.steps[i]! + @out\set true + { :euclid + :trigseq } |
