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,
Sebastian

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.