# \[SOLVED\] Midi in controls inside patterns

**URL:** <https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [9 May 2026 20:49 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150 "2026-05-09T20:49:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaosbeat](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kaosbeat/32/2343_2.png) [@kaosbeat](https://uzu.lurk.org/u/kaosbeat)\
**Post date:** [9 May 2026 20:49 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/1 "2026-05-09T20:49:03Z")

</div>

HI,

I'm using midicontroller in as described [here](https://tidalcycles.org/docs/configuration/MIDIOSC/midi/#controller-input)  
One of the thing not described on that page but in som etopics on the forum here is that you can use a shorthand "^13" to map CC 13 to 0-1 value. Very handy, and usefull while live coding.

I want to do another thing though. Suppose:

`d1 $ sound "bd*4"` but I want to map the 4 to my controller and have it range from 0-16, meaning I would have to do some math first.

I found [this thread](https://uzu.lurk.org/t/using-variables-within-patterns/1119/9), with a partial solution, but it doesn't really work.

I get I should work with an intermediary variable, from that post like:

`setI "divider" $ (cI 5 "13")`

but then I still want to do some math so something like

`setI "divider" $ (cI 5 "13")*4`

to finally put into my pattern

```haskell
d1 $ sound "bd*divider"

```

but obviously that does not work. Midi input works fine if I just use the  
`"^29"` to map 0-1 values in like in

```haskell
d1 $ sound "bd*4"
  # krush ("^29"*4)

```

How to use this in patterns?

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [9 May 2026 21:42 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/2 "2026-05-09T21:42:56Z")

</div>

You can do things like `"bd*[^13]"`, but I can't think of a way of scaling that in tidal on the way in to mininotation.

It'd probably be easier to send a scaled version from supercollider, something like this should work:

```haskell

cc = MIDIFunc.cc({ |val, num, chan, src|
    osc.sendMsg("/ctrl", num.asString, val/127);
    osc.sendMsg("/ctrl", "s" + num.asString, (val / 10) + 1);

});

```

Then you could do `"bd*[^s13]"`

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 May 2026 06:09 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/3 "2026-05-10T06:09:19Z")

</div>

I guess the question is why this works:

`setF "test" "<8 4>"`  
`d1 $ sound "bd*[^test]"`

and this doesn't:

`setF "test2" ("^test" * 2)`  
`d1 $ sound "bd*[^test2]"`

It's been a while since I looked at the code but I think it's because the pattern embedding is done by the scheduler, which means having one reactive variable referring to another one sadly doesn't work.

---

<div class="post-metadata">

**Author:** ![kaosbeat](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kaosbeat/32/2343_2.png) [@kaosbeat](https://uzu.lurk.org/u/kaosbeat)\
**Post date:** [10 May 2026 17:49 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/4 "2026-05-10T17:49:03Z")

</div>

Ok,

trying to see where I can get with the supercolliderpath. But I cannot get your example to work...  
when debugging I found that supercollider sends

`RECEIVE | ENDPOINT([::ffff:127.0.0.1]:57120) ADDRESS(/ctrl) STRING(s 13) FLOAT(7.4)`

so instead of "s13" I get an "s 13"

I had to correct

```haskell
osc.sendMsg("/ctrl", "s" + num.asString, (val / 10) + 1);

```

to

```haskell
osc.sendMsg("/ctrl", "s" ++ num.asString, (val / 10) + 1);

```

the extra + makes sure there is no space when [concatenating](https://doc.sccode.org/Classes/String.html). I'll see if I can do what I wanted to like this

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 May 2026 18:36 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/5 "2026-05-10T18:36:10Z")

</div>

Makes sense, sorry my supercollider skills are very weak !

---

<div class="post-metadata">

**Author:** ![kaosbeat](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kaosbeat/32/2343_2.png) [@kaosbeat](https://uzu.lurk.org/u/kaosbeat)\
**Post date:** [11 May 2026 07:15 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/6 "2026-05-11T07:15:00Z")

</div>

well they put me in the right direction anyway 🙂  
I made some simple calculations in supercollider, and I can use the midi CCs inside patterns now!

I defined ^iCC to return an int from 0-15 and ^dCC returns a zero or a power of 2

```haskell
~divs = [0, 1, 2, 4, 8, 16, 32, 64];

cc = MIDIFunc.cc({ |val, num, chan, src|
	var divindex, divs;
	divindex = (val / 16).floor.asInteger;
	divindex = divindex.clip(0, 7); // Safety: Ensure the index never goes outside the bounds of our list (0 to 3)
	divs = ~divs[divindex];
	osc.sendMsg("/ctrl", num.asString, val/127);
	osc.sendMsg("/ctrl", "i" ++ num.asString, ((val / 8) ).floor.asInteger;);
	osc.sendMsg("/ctrl", "d" ++ num.asString, divs);
	"d: %".format(val, divs).postln;
	"i: %".format(val, ((val / 8)).floor.asInteger;).postln;
});

```

The only downside is I have to switch to supercollider to define my Math, but using some sensible defaults I don't think a lot will be needed later on.  
but I can do

```haskell

d1 $ n "[^i29]*[^i49] [^i13]*4"
  # s "kick"

```

so yeah that is definitely a step up for me.

---

<div class="post-metadata">

**Author:** ![meneer](https://uzu.lurk.org/user_avatar/uzu.lurk.org/meneer/32/1418_2.png) [@meneer](https://uzu.lurk.org/u/meneer)\
**Post date:** [1 October 2026 12:38 UTC](https://uzu.lurk.org/t/solved-midi-in-controls-inside-patterns/6150/7 "2026-10-01T12:38:02Z")

</div>

not 'midi in inside a pattern' but in the case of your original question on mapping the speed from 0-16, this works without going into supercollider:  
`d1 $ fast (range 0 16 $ cT 1 "13") $ n "0" # s "bd"`
