# Trigger a pattern and play once from Midi

**URL:** <https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762>\
**Category:** TidalCycles\
**Tags:** innards\
**Created:** [30 December 2021 16:59 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762 "2021-12-30T16:59:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![badger](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@badger](https://uzu.lurk.org/u/badger)\
**Post date:** [30 December 2021 16:59 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/1 "2021-12-30T16:59:27Z")

</div>

I have been trying to do something like this: trigger from a midi pad and play a pattern through an arbitrary number of times. I have seen the solutions based on cApply, which work well to engage a pattern relative to the current cycle. I have tried using "once" which is close to what I'd like to do, but I'd like to assign a pattern to an arbitrary stream so that it is interruptible. I believe once always plays through... And I would like this to be triggered with a midi controller Something like this:

```haskell
do
  let b = (fmap (\x -> if x > 0 then True else False)) (discretise 1 $ cF 0 "24" )
  if b then (d1 $ trigger 1 $ playFor 0 0.2 $ n "[1 0]*16" # s "808") else s ""

```

But this fails because is a Pattern Bool rather than a Bool. That makes sense to me, but is there any convenient way to work around this?

---

<div class="post-metadata">

**Author:** ![ben](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ben/32/362_2.png) [@ben](https://uzu.lurk.org/u/ben)\
**Post date:** [30 December 2021 17:42 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/2 "2021-12-30T17:42:43Z")

</div>

Watching this! I didn't know it was possible to trigger patterns with MIDI but I've often wanted to.

---

<div class="post-metadata">

**Author:** ![badger](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@badger](https://uzu.lurk.org/u/badger)\
**Post date:** [30 December 2021 18:28 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/3 "2021-12-30T18:28:40Z")

</div>

Have a look at this. Works well for enabling and replacing patterns, just not repetitive single-shots: [Trigger Tidal code with MIDI](https://club.tidalcycles.org/t/trigger-tidal-code-with-midi/2168)

---

<div class="post-metadata">

**Author:** ![ben](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ben/32/362_2.png) [@ben](https://uzu.lurk.org/u/ben)\
**Post date:** [30 December 2021 18:32 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/4 "2021-12-30T18:32:25Z")

</div>

Ahhh, so good thanks!  
Not sure how I missed that.

---

<div class="post-metadata">

**Author:** ![badger](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@badger](https://uzu.lurk.org/u/badger)\
**Post date:** [8 January 2022 13:22 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/5 "2022-01-08T13:22:47Z")

</div>

After digging through the code and reading the posts here, I see how non-trivial it is to access the triggering code in the way I was suggesting. Checking out the Atom line eval method now. Should be able to do what I wanted that way. Thanks mrreason!

---

<div class="post-metadata">

**Author:** ![geikha](https://uzu.lurk.org/user_avatar/uzu.lurk.org/geikha/32/2701_2.png) [@geikha](https://uzu.lurk.org/u/geikha)\
**Post date:** [9 January 2022 00:01 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/6 "2022-01-09T00:01:30Z")

</div>

My first topic on the forum is about this precisely lol

> [@Using Tidal as a MIDI Instrument](https://club.tidalcycles.org/t/using-tidal-as-a-midi-instrument/1059):
>
> All of MIDI IN to tidal I've seen is [controlling values of pre-defined patterns](https://tidalcycles.org/index.php/Controller_Input). Even if that control is [spread across the keyboard](https://club.tidalcycles.org/t/get-values-from-midi-keyboard/674/4), you are still controlling variables instead of triggering events. I was wondering about this and commented about it in the [last stream (Stream #5)](https://club.tidalcycles.org/t/live-stream-5-general-catchup-q-a/994). Alex responded it would be possible, so I'm creating this topic to talk about it. I'm not 100% my idea came across in the stream or in this paragraph so I'll explain better: I imagine the possibility of writing somethi…

still haven't found a satisfying way. i reckon we would have to see what `once $` aka `asap $` does and see how to trigger that action with MIDI. probably all inside haskell

---

<div class="post-metadata">

**Author:** ![badger](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@badger](https://uzu.lurk.org/u/badger)\
**Post date:** [9 January 2022 01:21 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/7 "2022-01-09T01:21:40Z")

</div>

Well, there's possible and then there's possible in the interval between now and the heat death of the universe. There's a nice capply function for patterning by mrreason (#2168). But since the triggering condition is tested within the "every" conditional of a pattern, the logic is inverted from what would be necessary to reset the pattern. Hacked on this for a couple of days and it seems a larger issue than I'd like to tackle. Maybe Alex sees an easy path, but I'm finally punting and trying the atom/eval line triggering (also implemented by mrreason I think).

---

<div class="post-metadata">

**Author:** ![Tomas\_Ciccola](https://uzu.lurk.org/user_avatar/uzu.lurk.org/tomas_ciccola/32/843_2.png) [@Tomas\_Ciccola](https://uzu.lurk.org/u/Tomas_Ciccola)\
**Post date:** [12 January 2022 19:58 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/8 "2022-01-12T19:58:34Z")

</div>

I think there's a tidal-api now that allows to send code to the interpreter vía osc. So using supercollider as a bridge it should be easy. Haven't tried it though and keen to know how stable/easy to use it is.  
I've been using a plugin I wrote for neovim combined with some shell tools to send and receive midi. Kinda hacky though, but it works

---

<div class="post-metadata">

**Author:** ![badger](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@badger](https://uzu.lurk.org/u/badger)\
**Post date:** [12 January 2022 21:23 UTC](https://uzu.lurk.org/t/trigger-a-pattern-and-play-once-from-midi/3762/9 "2022-01-12T21:23:12Z")

</div>

Yes, there's a tidal api that's great for manipulating controls of patterns, but doesn't actually trigger patterns (as far as I could tell). That was my specific use case. The atom-eval functionality by mr reason with a Pure Data interface is a good work around for me.
