Week 4 lesson 2 - random marathon: rand, irand, mininotation randomness, scramble, shuffle, choose + more

Stumbled upon something that gives a syntax error that I would have thought would have worked:
d1 $ s "bd!8?"
This is ok:
d1 $ s "[bd!8]?"

Erp, so I did!

1 Like

hm yes.. maybe worth a bug report

Done, did the bug report.

1 Like

Thanks @yaxu, that is going to take some mental gymnastics (and trial and error) to understand the structures. Am I right in understanding that you can use haskell variables across TC more generally? In particular can you declare global variables that can be used in multiple OSC sends?

To borrow the SuperCollider global variable vernacular a bit. Sorry, this is probably for a different topic.

do
   ~globalVar1 = "some pattern"
   ~globalVar2 = "some other pattern"

d1 $ n ~globalVar1|~globalVar2 # s "bd -- mininotation pipe

d2 $ n ~globalVar1 # s "synth"

d3 $ n ~globalVar2 # s "bass"
2 Likes

Rather than do a long discussion about this (it's one of my favs), I started a new thread!

2 Likes

If I do this:

d1 $ scramble 8 $ n "0 1 2 3" # s "arpy"

is that a structure of 8 events from the scramble or a structure of 4 events from the n?

1 Like

I got the following error when trying to run:

d1 $ n "0 [0|1*3|2*8|3 4 5] 2 3" # sound "cpu"
   # speed 1.5
Error in pattern: Syntax error in sequence:
  "0 [0|1*3|2*8|3 4 5] 2 3"
       ^  
unexpected "|"
expecting float, "'", rest, "[", "{", "<", ".", "_", "," or "]"

Any ideas?

Seems like it's the " | " (straight line) in between that it's not liking?

Hi @tomh, I think you'll just have an older version of tidal installed, the | syntax is fairly new

Btw I took the liberty of editing your post to put

```

above and below the code blocks, as the forum was messing up the formatting otherwise.

2 Likes

Hey @vin would you mind explaining a bit what the "do" line does? Is this necessary for declaring variables?

1 Like

Hey @julianmrn5, in the above it is pseudocode. But in reality it encapsulates everything below it that is indented by one tab (or more) into a single execution. I’m not sure how variable scopes work in Haskell/Tidal but to my mind if in the above pseudocode the subsequent Dirt connections were indebted correctly then those variables would be local in scope. When I get in front of a computer I can paste in some actual code if that would be helpful? I can’t answer about the necessity for variables but I reckon @yaxu or @eris (I think) can give better answers around variable creation and scope!

1 Like

Ah I missed this question sorry !

You can give names to values with

a = "bd sn"

and then use them

d1 $ s a

With older versions of haskell you have to use let

let a = "bd sn"

that's still useful for naming more than one value at once:

let a = "bd sn"
    faster = fast 2
    squizit = (# squiz 4)

d1 $ squizit $ faster $ s a 
4 Likes

That is a super interesting question!

I tried the snippet myself and I'll give you my interpretation: since you are asking scramble to create 8 pieces from a 4-piece long pattern, it will fill the pattern up with some fictive steps of silence.
That is, the pattern to scramble might look something like
n "0 1 2 3 ~!4"
And that is probably why I hear silence now and then when I play it.

(although I would love @yaxu to confirm or refute)

Ah missed this question! Yes, sort of.

scramble 8 "a b c d" chop the pattern into eight parts, being the first half of a, then second half of a, then first half of b, second half of b and so on. Then you scramble them, and you will probably end up with two or more second halfs in a row, which will sound like a gap, because only the event starts actually trigger anything. You'll also end up with two or more first halfs in a row, which will sound faster.

1 Like

OMG how much I love the | operator!

One question: what is the highest value (i.e. probability) that wchoose can take on?

A side thing: I was quite sure that random generators were lazy i.e. they gave a number only when asked, but you say that they are continuous in their generation. What is the rate of generation then?

Aaah!
So the fact that I hear silence is just a byproduct of the length of the sample - if I had a longer one then I would be listening to the second halfs?

There's no real limit apart from the underlying haskell type which will be big enough. If you have two elements, one with '1' and another with 999999, then the first one would have a million-to-one chance of being picked.

There's one number for every possible point in time, counting from when the cycle counter started (usually when you start tidal, unless you use something like resetCycles).

Time in Tidal is infinite, both in terms of how long things can last and in terms of detail. So there are an infinite number of random numbers even in the first cycle.. So when I say continuous, I mean continuous.. We call these laptops digital computers but they can represent analogue things perfectly. Of course computer memory isn't infinite so there are some constraints :wink:

1 Like

Hm this is tricky to explain. When I say first / second halves I'm talking about tidal events. This is a confusing thing with Tidal.. You chop up these events but it's only the start (onset) of the event that actually triggers a message to SuperDirt. So currently the second half of an event does nothing in a lot of cases.. Does that make sense?

Yes sort of.
I can then deduce there is a difference between e.g. chop and scramble - the former creates new Tidal events from a single event whereas the latter just chops the event.

If I take this example:

d1
    $ scramble "<4 8>"
    $ slow 2
    $ chop 8
    $ s "bev:1"
    # legato 1

when the no. of parts to scramble equals the no. of parts in which bev is cut, 4 events per cycles are triggered - thus bev is now a series of Tidal events. Do I understand correctly?

1 Like