# Choosing sounds with a Boolean list

**URL:** <https://forum.toplap.org/t/choosing-sounds-with-a-boolean-list/1133>\
**Category:** TidalCycles\
**Created:** [1 March 2020 20:55 UTC](https://forum.toplap.org/t/choosing-sounds-with-a-boolean-list/1133 "2020-03-01T20:55:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crashingbooth](https://forum.toplap.org/user_avatar/forum.toplap.org/crashingbooth/32/601_2.png) [@crashingbooth](https://forum.toplap.org/u/crashingbooth)\
**Post date:** [1 March 2020 20:55 UTC](https://forum.toplap.org/t/choosing-sounds-with-a-boolean-list/1133/1 "2020-03-01T20:55:07Z")

</div>

I’m looking for a way (or more precisely, a better way) to apply a list of Bools to a list of notes or sounds to determine which ones get played. Sort of like `mask`, but applied vertically to a stack of sounds/notes simultaneously, not to successive events in a pattern.

So that if I had a list of samples (e.g., `[“bd, “sn”, “hh”, “bass”, “can”]`), I could apply a list (?) of `Bool`s such as  
`[True, False, False, False, True]`  
and the result would be equivalent to  
`s “[bd, can]” `  
or applying:  
`[False, True, True, False, True]`,  
it would be:  
`s “[sn, hh, can]”`.

I have kludged together something that sort of accomplishes this, but it feels awful.

I convert the `Bool` list to an `Int` list such that the indices of the `True` elements of the Bool list are in the Int list, i.e, `[True, False, False, False, True]` becomes `[0,4]` or `[False, True, True, False, True]` becomes `[1,2,4]`

Then apply `parseBP_E . show` to my intList to make a pattern that I can use with `fit`, like so:

`d1 $ s (fit 5 [“bd, “sn”, “hh”, “bass”, “can”], myKludgilyAssembledPattern)`

There has to be less awful way of doing this, and I would really appreciate some guidance. FWIW, the use case here would be applying the output of a cellular automaton.

---

<div class="post-metadata">

**Author:** ![jwaldmann](https://forum.toplap.org/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jwaldmann](https://forum.toplap.org/u/jwaldmann)\
**Post date:** [2 March 2020 12:24 UTC](https://forum.toplap.org/t/choosing-sounds-with-a-boolean-list/1133/2 "2020-03-02T12:24:33Z")

</div>

like this?

```
let pick :: [Bool] -> [a] -> [a]
    pick bs xs = map snd $ filter fst $ zip bs xs
in d1 $ s
      $ stack
      $ pick [True, False, False, False, True]
             ["bd", "sn", "hh", "bass", "can"]

```

but if you want the Booleans to be patternable, then take

```
let pick :: [Pattern Bool] -> [Pattern a] -> [Pattern a]
    pick bs xs = map ( \(b,x) -> b >>= \ f -> if f then x else silence) $ zip bs xs
in d1 $ s
      $ stack
      $ pick ["t" , "f t" , "f" , "f" , "t"]
             ["bd", "sn*2" , "hh", "bass", "can"]

```

in this variant, you need “sn \* 2” for the “f t” to have an effect. This is a property  
of the “bind” (\>\>=) operation.

---

<div class="post-metadata">

**Author:** ![crashingbooth](https://forum.toplap.org/user_avatar/forum.toplap.org/crashingbooth/32/601_2.png) [@crashingbooth](https://forum.toplap.org/u/crashingbooth)\
**Post date:** [3 March 2020 11:39 UTC](https://forum.toplap.org/t/choosing-sounds-with-a-boolean-list/1133/3 "2020-03-03T11:39:09Z")

</div>

Fantastic! Thanks so much.

I don’t really need to pattern over bools (but good to know!). I do need to cat together the outputs of a bunch of iterations of my function outputting the bools lis thought.

I probably doesn’t look like idiomatic Haskell, but this seems to work:

```
pickCat sounds manyBoolLists = cat . map (s . stack) $ map (pick sounds) manyBoolLists where
  pick sounds oneBoolList = map snd $ filter fst $ zip oneBoolList sounds

```

Thanks again!
