# |\* Operator and stack

**URL:** <https://uzu.lurk.org/t/operator-and-stack/2385>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [8 November 2020 11:51 UTC](https://uzu.lurk.org/t/operator-and-stack/2385 "2020-11-08T11:51:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbutz](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mbutz/32/1085_2.png) [@mbutz](https://uzu.lurk.org/u/mbutz)\
**Post date:** [8 November 2020 11:51 UTC](https://uzu.lurk.org/t/operator-and-stack/2385/1 "2020-11-08T11:51:57Z")

</div>

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](https://tidalcycles.org/index.php/Tutorial#Modifying_control_values)).

Here is a my simple example:

```haskell
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:

```haskell
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`:

```haskell
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!

---

<div class="post-metadata">

**Author:** ![th4](https://uzu.lurk.org/user_avatar/uzu.lurk.org/th4/32/505_2.png) [@th4](https://uzu.lurk.org/u/th4)\
**Post date:** [8 November 2020 12:15 UTC](https://uzu.lurk.org/t/operator-and-stack/2385/2 "2020-11-08T12:15:47Z")

</div>

What about doing

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

```

or, alternatively,

```haskell
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:

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

```

or

```haskell
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).

---

<div class="post-metadata">

**Author:** ![mbutz](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mbutz/32/1085_2.png) [@mbutz](https://uzu.lurk.org/u/mbutz)\
**Post date:** [8 November 2020 12:51 UTC](https://uzu.lurk.org/t/operator-and-stack/2385/3 "2020-11-08T12:51:07Z")

</div>

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:

```haskell
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;)

---

<div class="post-metadata">

**Author:** ![th4](https://uzu.lurk.org/user_avatar/uzu.lurk.org/th4/32/505_2.png) [@th4](https://uzu.lurk.org/u/th4)\
**Post date:** [8 November 2020 13:57 UTC](https://uzu.lurk.org/t/operator-and-stack/2385/4 "2020-11-08T13:57:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mbutz](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mbutz/32/1085_2.png) [@mbutz](https://uzu.lurk.org/u/mbutz)\
**Post date:** [8 November 2020 14:04 UTC](https://uzu.lurk.org/t/operator-and-stack/2385/5 "2020-11-08T14:04:57Z")

</div>

Yes, I see.

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