Insert random value in a pattern

Hello together,

I am exploring at the moment sonic pi and tidal.
Tidal is kind of magical to me, very condensed and different from other programming languages I had contact with. But in its strangeness so beautiful.

What I want to achieve is a simple thing:
First question: How can I add/insert between some values (e.g. in a speed pattern) a random value?
Basically something like this (value, value, random value, value).

d1 $ s "slx slx slx slx"
  # speed ("0.2 0.8" + rand)
  # begin "0.3 0.1 0.6"
  # gain "0.8"
  #release "1"

I already tried many things, and sometimes I do not get an error but I do not understand what happens. Second question: is there a kind of debugging thing like a “print” or “poll” that is good to use?

Thanks in advance,

you can print a pattern: just leave off the d1 $ at the start.

Thanks! That is very helpful.

insert random value:

d1 $ n (fastcat ["c", segment 1 $ 4 * irand 4, "e", "f" ]) # s "superpiano" 

without segment, this wont work, as irand` is a continuous pattern.

If you want to avoid the mental gymnastics of switching inner language (in strings) and outer language (Haskell, fastcat) then perhaps

d1 $ sew "t f t t" (n "c d e f") (n $ segment 4 $ 4 * irand 4) # s "superpiano"
1 Like

Thanks jwaldmann. So ‘rand’ or ‘irand’ are more like (noise) oscillators. And ‘segment’ a kind of sample and hold. Makes sense.

Yes that’s right.

Along these lines you can also do while

d1 $ while "f t f f" (|+ n (irand 4)) $ n "c d e f" # s "superpiano"                     
1 Like

yaxu, thank you for the reply.
this looks also like a very nice solution. It seems to be helpful to know a little bit haskell.
So the false, true pattern tells at which point the random interger will be integrated … hm, very flexible!

some sources of documentation:

NB: I’d be good to have these synchronized. E.g., I don’t see while in the first reference, but it`s in the second one. Of course, all functions must be there but in this case it also has explanatory text. [Edit] I’m not suggesting someone copies texts around. Of course these things are only feasible with automation (automatically create different forms of documentation from one source).

May I also recommend to use the API docs (second ref. above) as a starting point for “learning Haskell by reading code” exercises. Use the “source” links (right end of each line). Then follow hyperlinks in the source. Sure, one point of documenting the API is precisely that users don’t have to read the code that implements it - but they can.

And for the case at hand, you’ll find while b f pat = sew b (f pat) pat, so these functions are closely related.

1 Like

I bow to the community. Thanks for all the help.