|* Operator and stack

Hi,

I ran into a few questions while busily learning the basics of tidal. One of my musical questions to solve was, how I can set a 'master' volume for a list of control values using the |*-Operator (see this section of the Tutorial).

Here is a my simple example:

let kick = "1 1 0.75 0.9 1 0.75 1 1"

let hat = "0.9 1 0.8 1"

d1 $ (|* gain "1.25")
   $ sound "[bd*8]/2"
   # gain kick

d2 $ (|* gain "1")
   $ sound "[~ hc]*4"
   # gain hat

Modifying the first gain value of d1 allows to adjust the level for each value of the list (e. g. in a live coding situation).

Now while also trying to use stack I was not able to find out how to group the statements without producing an error:

d1 $ stack [
   (|* gain "1")
   sound "[bd*8]/2"
   # gain kick,
   sound "[~ hc]*4"
   # gain hat
]

I must admit right now I don't really see how to fix what tidal is angry about. Obviously in connection with stack the syntax has to be different.

I that context also:

I am not able to put my variable declaration of kick and hat within the stack block. This also produces an error.

I tried to group the two statements with do:

do
  let kick = "1 1 0.75 0.9 1 0.75 1 1"
  let hat = "0.9 1 0.8 1"

But tidal again complains: " The last statement in a 'do' block must be an expression" (Googling tells me that this might be due to faulty indentation but I tripple-checked).

Is there a recommended way to group variable declaration and other commands to evaluate all at once?

I know, these are newbie questions and I am very grateful if someone might bother and take the time to help!

What about doing

d1 $ stack [
   (|* gain "1")
   (sound "[bd*8]/2")
   # gain kick,
   sound "[~ hc]*4"
   # gain hat
]

or, alternatively,

d1 $ stack [
   (|* gain "1") $
   sound "[bd*8]/2"
   # gain kick,
   sound "[~ hc]*4"
   # gain hat
]

? Note that these would only modify one of the elements of the stack, as gain is not a global parameter (unless it is, but then my entire worldview crumbles).

If you want the gain modification to apply to both the bd and hc patterns (if I understand correctly what you need), I think you could either do:

d1 $ (|* gain "1") $ stack [
   sound "[bd*8]/2"
   # gain kick,
   sound "[~ hc]*4"
   # gain hat
]

or

d1 $ stack [
   sound "[bd*8]/2"
   # gain kick,
   sound "[~ hc]*4"
   # gain hat
] |* gain "1"

If you're not using |* as an infix operator (which is done by putting it at the end of the block), you have to surround it with parentheses to make it into a regular function (which is something that is often done in general Haskell).

2 Likes

Hi,

thanks a lot. Your first fix does avoid the error, but does not seem to influence the gain.

The second one is just what I was looking for. Just using parenthesis' this could be paraphrased:

d1 $ stack [
   (|* gain "0.8")
   (sound "[bd*8]/2"
   # gain kick),
   (|* gain "0.75") # I extended the original example
   (sound "[~ hc]*4"
   # gain hat)
]

Thanks a lot!

And also thanks for giving an example for the 'global' variation. Actually I meant to separately set kick and hihat but as I am learning I am eager to absorb everything I can;)

Haha, ok, I was confused as to what you meant by "master volume".
And, I mean, you could actually combine both, if you wanted to increase the overall volume but still control each instrument on its own.

Yes, I see.

Thanks. This did help to go further steps. Gradually I feel like this is going to be managable... :wink: