'Select' function

Could anyone give me an example of how to select between a list of different patterns using the 'select' function. I don't understand the documentation well enough.

Ideally, I would like to have a list of pre-written drum patterns, and to be able to switch which pattern is playing by changing one simple value, such as an integer.

Thank you for your help.

1 Like

in the first argument you specify a value between 0 and 1, the second argument will be a list of your patterns. Say you have two patterns in that list, then all values from 0 to 0.5 will result in the first pattern in the list and all values greater will result in the second pattern in the list.

This generalizes to a list of n patterns and the fractions 1/n, 2/n, ... , n/n.

for example:

d1 $ select (1/3) [s "bd", s "sn", s "hh"]

will select the first pattern

d1 $ select (2/3) [s "bd", s "sn", s "hh"]

will select the second pattern

d1 $ select (3/3) [s "bd", s "sn", s "hh"]

will select the third pattern

3 Likes

Thanks very much that's perfect :slight_smile:

I'd add that one of the most useful uses of this is using oscillators since they all work from 0 to 1.

for example

d1 $ select (slow 3 $ sine) [s "bd*8", s "sn(9,16)", s "hh*12"]
2 Likes

Can anyone think of a way to use the select function to choose between different stacks?
I can choose between layered patterns like this. But it would be really nice to have to the flexibility of working within a stack, not to mention that it's much cleaner.

d1 $ select (2/2) [s
"[bd, hh] [hh] [hh27:7, hh] [hh]  [bd, hh, cp] [hh] [hh27:7, hh] [hh]  [bd, hh] [hh] [hh27:7, hh] [hh]  [bd, hh, cp] [hh] [hh27:7, hh] [hh]  ",
"[bd, hh] [hh] [hh27:7, hh] [hh]  [bd, hh] [hh] [hh27:7, hh] [hh]  [bd, hh] [hh] [hh27:7, hh] [hh]  [bd, hh] [hh] [hh27:7, hh] [hh]"]

use the stack function inside of every element in the array that goes in select ?
so maybe this works?

d1 $ select (2/2) [
    stack[
    s "bd", s "sd sd"
    ],
    stack[
    s "bev" # legato 1 # begin rand
    ]
]

oh and remember you can omit the 's' too, to me it looks cleaner:

d1 $ select (2/2) [
    stack[
    "bd",
    "sd"
    ],
    stack[
    "bev" # legato 1 # begin rand
    ]
]

Thank you so much, I really appreciate your help :slight_smile: This is perfect!

Today is becoming a very good day.

Is there any way to randomise the select function?

I would like the select function to pick a random pattern from a list of patterns, every 8 bars, but every way i've tried to do this so far has failed.

I was gonna propose something convoluted using scramble and outside, but then I realized that randcat existed and that this seems to do what you're looking for:

d1 $ slow 8 $ randcat (fmap (fast 8) ["arpy", "[~ bleep]*2", "hh*3"])

So you could define your selectRand function like this:

let selectRand n patlist = 
    slow n $ randcat (fmap (fast n) patlist)

I think select (segment (1/8) rand) would also do it.

3 Likes

Ooh, right, I completely forgot about segment!

Thanks Yaxu, segment certainly makes things much easier.

I am now trying to create a series of let statements describing patterns. I would like 'select' to pick the patterns at random every few bars. But the patterns in each variable should always be laid over each other according to the order they appear in the list.

Rand allows me to achieve this within a single patch, as the random stream is the same for each channel. But I can't get it to work as a series of let statements. Can anybody work out why, and how I might write this so it works?

let var1 = select (segment 0.25 ((rand)+0.33)) ["2 1", "3 4", "1 0"]
    var2 = select (segment 0.25 ((rand)+0.33)) ["1 2", "2 1", "2 1"]
    var3 = select (segment 0.25 ((rand)+0.33)) ["2 0", "1 2", "3 1"]

I'm not sure how you're using these variables. P what isn't working, but...

I'd store them in an array as:

let xs = [select ... blablabla ,
                select ... blablabla,
                select ... blablabla
                ]

then you can:

d1 $ xs!!0
d2 $ xs!!1

or

d1 $ stack xs

Thank you very much for your reply, but I'm not sure I can use this in the context I need it. I'm using the numbers to multiple sequence patterns in the same stack, using fit.

It works when it's part of the patch, like so:

d1 $ sound (fit 3 ["bd", "cp", "hh"] (select (2/3) ["2 1", "3 4", "1 0"]))

But not if it's part of a let statement like this, which is what I need:

let var1 = (select (2/3) ["2 1", "3 4", "1 0"])

d1 $ sound (fit 3 ["bd", "cp", "hh"] var1)

Evaluating the let statement gives an error message which no combination of brackets seems to prevent?

Yes there's only one random stream in Tidal.

You can work around this by changing rand to e.g. slow 1.01 rand or 1000 <~ rand to use a different part of the random stream for part of your pattern