# Sharing custom functions

**URL:** <https://uzu.lurk.org/t/sharing-custom-functions/1032>\
**Category:** TidalCycles\
**Tags:** resources\
**Created:** [19 May 2020 01:59 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032 "2020-05-19T01:59:50Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [19 May 2020 01:59 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/1 "2020-05-19T01:59:50Z")

</div>

Hi all!

I watched this excellent video (1st video below) by @kindohm and have been feeling pretty inspired by the **plyWith** function. To that end, I started looking into custom functions to save some time writing code. @kindohm also has a super informative tutorial on writing custom functions (2nd video below) that I used to make the following:

```haskell
let plyCato num amt = plyWith num (|* legato amt)
    plyDown num amt = plyWith num (|* gain amt)

```

Here's a tldr/tldw for each function:  
plyCato takes a sound and repeats it in increasing/decreasing increments determined by amt. In short, it creates a stuttery repeat trail for a sound.  
plyDown does the same as plyCato but reduces/increases the gain instead of playback length.

I'd love to use this thread to share functions and help each other find new shortcuts to interesting sounds!

[![](https://img.youtube.com/vi/59w_ne9jeI8/maxresdefault.jpg "Live stream: TidalCycles plyWith function") ](https://www.youtube.com/watch?v=59w_ne9jeI8&t=1661s)

[![](https://img.youtube.com/vi/jU5QKgiO2IY/maxresdefault.jpg "Live Stream: TidalCycles custom functions") ](https://www.youtube.com/watch?v=jU5QKgiO2IY&t=1961s)

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [19 May 2020 02:07 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/2 "2020-05-19T02:07:41Z")

</div>

Here's an example of both functions in action:

[![](https://img.youtube.com/vi/dsEyC-AQ6NI/hqdefault.jpg "Example of plyCato and plyDown") ](https://www.youtube.com/watch?v=dsEyC-AQ6NI)

---

<div class="post-metadata">

**Author:** ![a314sces](https://uzu.lurk.org/user_avatar/uzu.lurk.org/a314sces/32/1202_2.png) [@a314sces](https://uzu.lurk.org/u/a314sces)\
**Post date:** [19 May 2020 03:41 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/3 "2020-05-19T03:41:54Z")

</div>

I love this idea of sharing custom functions.

I made a few modulation functions that kind of behave like zenith plugin (little window wave functions) to modulate parameters.

```haskell
let parabolamod = listToPat([x^2 | x<-[0.1,0.12..0.5]])
    recparabola = listToPat([1/x^2 | x<-[0.1,0.12..0.5]])
    linmod = listToPat([0.4*x+0.4 | x<-[0.1,0.12..0.4]])
    sinemod = listToPat([sin(0.4*x+0.4) | x<-[0.1,0.12..0.4]])
    cosmod = listToPat([cos(0.4*x+0.4) | x<-[0.1,0.12..0.4]])
    downstairs = listToPat([x | x<-[1 ,1, 0.8 ,0.8 ,0.6, 0.6, 0.4, 0.4, 0.2, 0.2, 0, 0]])

```

I wanted make the setbuilder notation dynamic and add the ability to control the set size, but I don't know how to pass a size parameter to the setbuilder notation without getting an error.  
math-wise:

```haskell
let cosmod n = listToPat([cos(0.4*x+0.4) | x<-[0.1,0.2..(n*0.1)]])

```

I also made a couple of more melodic examples:

```haskell
let odds y = listToPat([2*x+1 | x<-[1,2..y]]) -- odd numbers
    evens y = listToPat([2*x | x<-[1,2..y]]) -- even numbers

```

If you have those supersynths installed:

```haskell
d4 $ plyWith 2 (# n (odds 4)) $ n ( evens 16) # s "gabor cyclo supergong" # accelerate "0 0.2 0.8" # gain downstairs

```

---

<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:** [19 May 2020 13:21 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/4 "2020-05-19T13:21:20Z")

</div>

These ones i use frequently:

**Oscillators:** Just to livecode faster

```haskell
let sinosc min max frq = (fast frq $ range min max sine)   
    triosc min max frq = (fast frq $ range min max tri)
    sqrosc min max frq = (fast frq $ range min max square)
    sawosc min max frq = (fast frq $ range min max saw)
    randosc min max = (range min max rand)
-- Usage
d1 $ s "bd*8" # gain (sinosc 0.4 1 1)

```

**Get random notes in a scale**

```haskell
let randscale sc n f = (|+ note (scale sc (irand n))) f
-- Usage
d1 $ randscale "phryigian" 7 $ s "arpy(9,16,12)"

```

**Flip your melody/harmony vertically**

```haskell
let invnote n = 0-n
    invnote' axis x = (2*axis)-n
-- Usage
d1 $ note (invnote' "<5 7>/4" "<c'maj7(5,8) d'm11(<3 [3 5]>,8)>") # s "superpiano" # room 0.5 # velocity 0.8

```

---

<div class="post-metadata">

**Author:** ![tedthetrumpet](https://uzu.lurk.org/user_avatar/uzu.lurk.org/tedthetrumpet/32/39_2.png) [@tedthetrumpet](https://uzu.lurk.org/u/tedthetrumpet)\
**Post date:** [19 May 2020 13:37 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/5 "2020-05-19T13:37:48Z")

</div>

Thanks, this could open a whole new door for me, I think! Two questions: could I put these in my BootTidal.hs so that they are ready to go? Or somewhere else? And, is it necessary to write type declarations to go with them?

---

<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:** [19 May 2020 13:53 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/6 "2020-05-19T13:53:57Z")

</div>

Yes you could place them at the end of your BootTidal.hs. I'm assuming you're talking about Haskell's type declaration, using `::` and `->`. **If I recall correctly** that's not needed, the compiler will do the work for you, and since these are a small number of functions it shouldn't be a problem at all.

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [19 May 2020 14:11 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/7 "2020-05-19T14:11:16Z")

</div>

These are great! Thanks!

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [19 May 2020 14:12 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/8 "2020-05-19T14:12:05Z")

</div>

I tried downstairs modulating speed along with plyCato and got some sweet results! Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![satoruki](https://uzu.lurk.org/user_avatar/uzu.lurk.org/satoruki/32/492_2.png) [@satoruki](https://uzu.lurk.org/u/satoruki)\
**Post date:** [19 May 2020 16:15 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/9 "2020-05-19T16:15:17Z")

</div>

These are fun! Thank you.  
I'll try to share my functions as well.

**Apply oscillators to arp in a scale**

```
let roundy p = (fromIntegral . round) <$> p
    stepr n r1 r2 f = segment n $ range r1 r2 $ f
    stepr' n r1 r2 f = roundy $ stepr n r1 r2 f
    myarp sc r2 f = scale sc (stepr' 32 0 r2 f)
-- ex.)
    setcps 0.2
    d1 $ note (myarp "major" 7 sine) # s "superpiano"
    d1 $ note (myarp "locrian" 12 (fast 2 $ isaw)) # s "superpiano"
    d1 $ note (myarp "dorian" 12 (fast 8 $ (perlin*isaw**2))) # s "superpiano"
```

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [26 May 2020 18:44 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/10 "2020-05-26T18:44:00Z")

</div>

Hi all!

A small helper function that you may utilize to make panning less jarring if you're working on phones:

`smallpan wave = pan (range 0.3 0.7 wave)`

Just treat it like you would a normal pan parameter and you'll get a less drastic outcome.

---

<div class="post-metadata">

**Author:** ![kit-christopher](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kit-christopher/32/686_2.png) [@kit-christopher](https://uzu.lurk.org/u/kit-christopher)\
**Post date:** [26 May 2020 19:23 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/11 "2020-05-26T19:23:13Z")

</div>

really nice! (also, you don't have to highlight your whole entire block to evaluate it. if you just hit ctrl-enter, it'll grab everything for you.)

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [26 May 2020 19:45 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/12 "2020-05-26T19:45:32Z")

</div>

Atom doesn't work for me that way, but I've been kinda eager to fix it! Do you use atom as well?

---

<div class="post-metadata">

**Author:** ![kit-christopher](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kit-christopher/32/686_2.png) [@kit-christopher](https://uzu.lurk.org/u/kit-christopher)\
**Post date:** [26 May 2020 19:53 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/13 "2020-05-26T19:53:33Z")

</div>

i do! i've got it loaded on both PC and Mac and ctrl-enter works for both. let me see if i can look up a fix.

---

<div class="post-metadata">

**Author:** ![kit-christopher](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kit-christopher/32/686_2.png) [@kit-christopher](https://uzu.lurk.org/u/kit-christopher)\
**Post date:** [26 May 2020 19:59 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/14 "2020-05-26T19:59:06Z")

</div>

![multiline](https://club.tidalcycles.org/uploads/default/original/1X/0cfaacdea4980d4ab9c93d126cb10124da900f83.png)

found this in my keybindings pane under settings.

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [27 May 2020 01:17 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/15 "2020-05-27T01:17:01Z")

</div>

Thanks! I found it as well; appreciate it.

---

<div class="post-metadata">

**Author:** ![ndr\_brt](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ndr_brt/32/396_2.png) [@ndr\_brt](https://uzu.lurk.org/u/ndr_brt)\
**Post date:** [24 July 2020 10:24 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/16 "2020-07-24T10:24:10Z")

</div>

Two functions I wrote those days:

```haskell
rslice x p = slice x (segment (toTime <$> x) $ ((>>= irand) x)) $ p 
rsplice x p = splice x (segment (toTime <$> x) $ ((>>= irand) x)) $ p 

```

they are two shorthands for:

```haskell
slice x (segment x $ irand x)
splice x (segment x $ irand x)

```

---

<div class="post-metadata">

**Author:** ![mrreason](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mrreason/32/3203_2.png) [@mrreason](https://uzu.lurk.org/u/mrreason)\
**Post date:** [30 July 2020 10:36 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/17 "2020-07-30T10:36:47Z")

</div>

Hi folks!

[Edit:] I completely overlooked that there is already the `up` function. However I have made this for using and customizing the live pitch-shifting of an input signal. So this could be helpfully anyway, I think.

I made my own function that converts the speed ratio parameter into notes. For this I wrote a speed' function which I am currently experimenting with:

```haskell
-- Calculating the n'th root of a value
nroot :: (Integral a, Floating b) => a -> b -> b 
n `nroot` x = x ** (1 / fromIntegral n)

-- Calculates the n'th root of all pattern values in p and use the function f (like speed)
nrootFuncs :: Pattern Double -> (Pattern Double -> ControlPattern) -> ControlPattern
nrootFuncs p f = f (fmap (12 `nroot` 2 **) (p))

-- Define custom speed function
speed' :: Pattern Double -> ControlPattern
speed' p = nrootFuncs p speed  

```

To demonstrate this I have created a short video for you:

[![](https://img.youtube.com/vi/LaJaaGAtPmc/maxresdefault.jpg "Custom speed function for Tidal") ](https://www.youtube.com/watch?v=LaJaaGAtPmc)

The video also contains the function `psrate` and `psrate'`. Unfortunately, you can't reproduce the `in` stuff with `psrate` at the moment, because there is a small bug in SuperDirt (but it's fixed and waits for the approval)

You can also download the code from the video here:

> **[algorithm-mu/tidal/custom at master · thgrund/algorithm-mu](https://github.com/thgrund/algorithm-mu/tree/master/tidal/custom)**
>
> master/tidal/custom

---

<div class="post-metadata">

**Author:** ![lannzach](https://uzu.lurk.org/user_avatar/uzu.lurk.org/lannzach/32/3519_2.png) [@lannzach](https://uzu.lurk.org/u/lannzach)\
**Post date:** [30 July 2020 17:41 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/18 "2020-07-30T17:41:02Z")

</div>

This is awesome! I think I'm gonna experiment with it a bit. I love that texture of the 808s used melodically also.

---

<div class="post-metadata">

**Author:** ![ghales](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ghales/32/2171_2.png) [@ghales](https://uzu.lurk.org/u/ghales)\
**Post date:** [31 July 2020 16:32 UTC](https://uzu.lurk.org/t/sharing-custom-functions/1032/19 "2020-07-31T16:32:27Z")

</div>

Sharing a post from another thread, this is some WIP on rhythm structure 🙂

[![](https://i.vimeocdn.com/video/932396401-9e3ac814319c4dd28fe4d508005a0b056298f82e42b4617b66810f67c21bdf7e-d?f=webp "Patch Logs #3: Rhythm") ](https://vimeo.com/443051520)

> [@Club meeting!](https://club.tidalcycles.org/t/club-meeting/1719/7):
>
> Hey all, so I made a quick video demoing the rhythm thing I mentioned in the meeting. I see more of these vids coming soon, so I decided to make a mini-series just to keep things together. Anyway, tell me what you guys think! edit: though not explained in the video, keep this in mind: l a b c ... = [a, b, c, ...]
