# Runmod (an interesting way of generating sequences)

**URL:** <https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880>\
**Category:** TidalCycles\
**Tags:** resources\
**Created:** [17 September 2023 01:32 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880 "2023-09-17T01:32:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![geikha](https://uzu.lurk.org/user_avatar/uzu.lurk.org/geikha/32/2701_2.png) [@geikha](https://uzu.lurk.org/u/geikha)\
**Post date:** [17 September 2023 01:32 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880/1 "2023-09-17T01:32:24Z")

</div>

Hello, geikha here!

I want to show you another function I use often. The original idea is from @alejandrosame , who used it as a way to generate complex, non-random, drum breaks for breakcore-like music. His code was similar to the following:

```haskell
do
    setcps (168 / 60 / 4)
    d1 $ n (run 16 |% "<16 _ _ [5 _ 2]>") # s "amencutup" # cut 1 |+ sp 1.5

```

> ~~Note that Alejandro wasn't using "amencutup" exactly, he had his own cut-up breaks.~~

We were rehearsing for an Algorave in-person, and there I suggested the idea of turning that into a simple function, then we started exploring other possibilities:

* * *

## runmod

`runmod` takes 3 numbers, the number to which to run (`"0..n"`), a modulus to apply and an offset. The following example should self-explain by listening to it:

```haskell
do
    resetCycles
    let runmod r m o = ((run r) |% m |+ o)
    d1 $ n (slow 2 $ runmod 8 5 "<0 2>/2") |+ n 1 # s "numbers" # legato 1 # speed 2
    d2 $ "bd/2"

```

```haskell
runmod 8 5 "<0 2>/2" |+ 1 (adding one to make it easier to grasp) :
|123451234|123451234|345673456|345673456|

```

### Usage on drums

The original use Alejandro gave to the function:

```haskell
d1 $ slice 16 (runmod 16 "<16 _ 8 [3 1]>" 0) $ "breaks125" # cut 1 |+ note 5

```

### Usage on melodic loops

```haskell
do
    d1 $ slice 32 (slow 2 $ runmod 32 "7" "<0 10>") $ "bev" # cut 1 
        # speed 2 # room 0.4 # size 0.8
    d2 $ "808bd:3*4" # shape 0.6 # cut 1

```

### Usage as melody

```haskell
do
    d1 $ note (scale "phrygian" $ runmod 16 "<5 7>/4" "0@5e <0 -2>") # "gtr:1" 
        # cut 1 # speed 2 # release 0.1
        # lpf (range 700 10000 $ slow 3 sine)
        # gain 0.7 # delay 0.2 # delayt 0.4
    d2 $ "808bd:3(5,8)" # shape 0.6 # cut 1

```

## runmod'

`runmod'` adds a multiplier to the `runmod` function. This is very useful for melodic elements!

```haskell
let runmod' r m mul o = ((run r) |% m |* mul |+ o)

```

### Usage as melody

```haskell
do
    d1 $ note (scale "phrygian" $ runmod' 16 "<5 7>/4" "<[1 <2 -2>] 3>/3" "0@5e <0 -2>") # "gtr:1" 
        # cut 1 # speed 2 # release 0.1
        # lpf (range 700 10000 $ slow 3 sine)
        # gain 0.7 # delay 0.2 # delayt 0.4
    d2 $ "808bd:3(5,8)" # shape 0.6 # cut 1

```

> Here the notes instead of simply increasing one by one, in some parts it jumps by 2, others it decreases by 2, and others it jumps by 3.

### Usage on melodic loops

```haskell
do
    d1 $ slice 32 (slow 2 $ runmod' 32 7 3 "<0 10>") $ "bev" # cut 1 
        # speed 2 # room 0.4 # size 0.8
    d2 $ "808bd:3*4" # shape 0.6 # cut 1

```

> Note how now that the `run` is multiplied, `slice` reaches very different parts of the sample.

## slicemod, bitemod

You may want to use an utility `slicemod` function if you know you'll `slice` the sample by the same amount you'll `run`.

```haskell
let slicemod r m o = slice r (runmod r m o)
    bitemod r m o = bite r (runmod r m o)

```

```haskell
do
    d1 $ slicemod 16 7 "<0 10>" $ "bev" # cut 1 
        # speed 2 # room 0.4 # size 0.8 # rel 0.1
    d2 $ "808bd:3*2" # shape 0.6 # cut 1

```

`bite` it's basically a `slice` for `Pattern`'s, so you could also use these functions to modify them:

```haskell
do
    d1 $ bitemod 8 5 0 $ stack [
        s "bd ~ [~ bd] ~"
        , "1*16" # s "hh27" # release 0.4
        , press "1*2" # s "909sd"
        ,"<~ [~ 808ht]>"
        ]

```

* * *

#### Tidal definitions

```haskell
let runmod r m o = ((run r) |% m |+ o)
    runmod' r m mul o = ((run r) |% m |* mul |+ o)
    slicemod r m o = slice r (runmod r m o)
    bitemod r m o = bite r (runmod r m o)

```

#### Strudel definitions

```js
let runmod = (r,m,o) => run(r).mod(m).add(o) 
let runmod_ = (r,m,mult,o) => run(r).mod(m).mul(mult).add(o) 

n(runmod(8,5,2)).scale("C:major").s("square").sustain(0.2)
// n(runmod_(8,5,2,2)).scale("C:major").s("square").sustain(0.2)

```

---

<div class="post-metadata">

**Author:** ![alejandrosame](https://uzu.lurk.org/user_avatar/uzu.lurk.org/alejandrosame/32/2836_2.png) [@alejandrosame](https://uzu.lurk.org/u/alejandrosame)\
**Post date:** [17 September 2023 16:21 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880/2 "2023-09-17T16:21:57Z")

</div>

Thank you @geikha for sharing this!

I never explored this function further since I haven't come back to attempt live coded breakcore after that performance. I've improved the code a little bit and performed it in other events, though. I'll definitely explore breakcore further sometime in the future starting with your definitions 🙂

For historical context, [this](https://github.com/alejandrosame/20220623-baires/blob/c11cb9b6f8d3dfc34f54550ca0a14f9920fd11a9/mate.tidal) was the piece I was practicing and rehearsing that night.

And, in the same repo, the definition of `runmod` that I made is in the [`setInit.tidal`](https://github.com/alejandrosame/20220623-baires/blob/c11cb9b6f8d3dfc34f54550ca0a14f9920fd11a9/setInit.tidal#L8) file:

```haskell
runMod sl m d a = (run sl) |* m |% d |+ a

```

**PS** : I do indeed use `amencutup` in that performance. But I do remember a conversation about wanting to use other samples. It hasn't happened yet, though!

---

<div class="post-metadata">

**Author:** ![geikha](https://uzu.lurk.org/user_avatar/uzu.lurk.org/geikha/32/2701_2.png) [@geikha](https://uzu.lurk.org/u/geikha)\
**Post date:** [17 September 2023 19:10 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880/3 "2023-09-17T19:10:52Z")

</div>

Ah yes now I remember! We had that difference of where to put the multiplier, yours makes more sense for drum breaks definitely!

I may make that into `runmod''` on my setup

---

<div class="post-metadata">

**Author:** ![staxl](https://uzu.lurk.org/user_avatar/uzu.lurk.org/staxl/32/1717_2.png) [@staxl](https://uzu.lurk.org/u/staxl)\
**Post date:** [20 September 2023 22:10 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880/4 "2023-09-20T22:10:09Z")

</div>

Thanks so much for sharing this, @geikha!

Having started getting into breakbeats just recently, this seems like a lot of fun to play around with.

---

<div class="post-metadata">

**Author:** ![ganz](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ganz/32/64_2.png) [@ganz](https://uzu.lurk.org/u/ganz)\
**Post date:** [21 September 2023 06:50 UTC](https://uzu.lurk.org/t/runmod-an-interesting-way-of-generating-sequences/4880/5 "2023-09-21T06:50:31Z")

</div>

Again very helpful custom functions, again many thanks, @geikha !
