# Get values from midi keyboard

**URL:** <https://uzu.lurk.org/t/get-values-from-midi-keyboard/674>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [7 May 2020 22:45 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674 "2020-05-07T22:45:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CUSTOM\_ROBO](https://uzu.lurk.org/user_avatar/uzu.lurk.org/custom_robo/32/432_2.png) [@CUSTOM\_ROBO](https://uzu.lurk.org/u/CUSTOM_ROBO)\
**Post date:** [7 May 2020 22:45 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/1 "2020-05-07T22:45:05Z")

</div>

I want to control parameters like `up` with a midi keyboard, but so far, I can only get the velocity value from one note at a time.

I've looked through the list of midi functions (in `Control.hs`), and I'm not sure what to do.  
Is there any way to do this in the current version of tidal?

---

<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:** [8 May 2020 07:47 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/2 "2020-05-08T07:47:59Z")

</div>

Hi, can you explain the problem a bit more please?

---

<div class="post-metadata">

**Author:** ![CUSTOM\_ROBO](https://uzu.lurk.org/user_avatar/uzu.lurk.org/custom_robo/32/432_2.png) [@CUSTOM\_ROBO](https://uzu.lurk.org/u/CUSTOM_ROBO)\
**Post date:** [11 May 2020 15:45 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/3 "2020-05-11T15:45:26Z")

</div>

Basically, I want the tidal code to be a sort of instrument I can control with a keyboard, more like how in a traditional daw you can select a synth and play it with a keyboard.

I want to do that by changing the `up` parameter of a pattern with a midi keyboard. So far, I've found ways to get the velocity values of individual midi keys to control parameters, but I don't want the velocity. I want the midi value of the actual key I'm pressing.

Currently, is there any way to do that?

---

<div class="post-metadata">

**Author:** ![heavy.lifting](https://uzu.lurk.org/user_avatar/uzu.lurk.org/heavy.lifting/32/150_2.png) [@heavy.lifting](https://uzu.lurk.org/u/heavy.lifting)\
**Post date:** [13 May 2020 12:05 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/4 "2020-05-13T12:05:11Z")

</div>

Hi @CUSTOM_ROBO

I've managed to do this following [these instructions](https://tidalcycles.org/index.php/Controller_Input#MIDI)

I slightly edited the SC code to get it to do what I wanted:

> **MIDI IN**
> 
> //To accept MIDI in to Tidal we need to run a bit more code - this lets SuperCollider convert MIDI inputs from your controller into OSC messages
> 
> // Evaluate the block below to start the mapping MIDI -\> OSC.
> 
> (  
> var on, off, cc;  
> var osc;
> 
> osc = NetAddr.new("127.0.0.1", 6010);
> 
> MIDIClient.init;  
> MIDIIn.connectAll;
> 
> on = MIDIFunc.noteOn({ |val, num, chan, src|
> 
> osc.sendMsg("/ctrl", "n", num); // if I remember correctly this was the bit I changed to get notes in!
> 
> });
> 
> off = MIDIFunc.noteOff({ |val, num, chan, src|  
> osc.sendMsg("/ctrl", "n", 0);  
> });
> 
> cc = MIDIFunc.cc({ |val, num, chan, src|  
> osc.sendMsg("/ctrl", num.asString, val/127);
> 
> });
> 
> if (~stopMidiToOsc != nil, {  
> ~stopMidiToOsc.value;  
> });
> 
> ~stopMidiToOsc = {  
> on.free;  
> off.free;  
> cc.free;  
> };  
> )

And then using code in Tidal like this:

`d4 $ sound "arpy" # up (cF 1 "n")`

Depending on the pitch of your samples etc you will probably need to transform the midinote to a lower number, as `up` maps to semitones, rather than midinotes.

Something like:

`d4 $ sound "arpy" # up ((cF 1 "n")-60)`

And you might need to have a play around with noteon/noteoff (I used this in a kind of drone/noise setting so wasn't such a big deal for me, but this setup will still play the tidal pattern even when a note isn't being pressed - you could try mapping noteon/noteoff to `#gain` to help with this).

Hopefully this will get you started - shout back if you need any help.

---

<div class="post-metadata">

**Author:** ![CUSTOM\_ROBO](https://uzu.lurk.org/user_avatar/uzu.lurk.org/custom_robo/32/432_2.png) [@CUSTOM\_ROBO](https://uzu.lurk.org/u/CUSTOM_ROBO)\
**Post date:** [24 May 2020 21:14 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/5 "2020-05-24T21:14:56Z")

</div>

Sorry I haven't replied, been off the forum for a while.

The script you posted as exactly what I was looking for. I'll keep toying with it, and if I find something `SuperDirt` worthy, I'll put in a pull request.

---

<div class="post-metadata">

**Author:** ![mrreason](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mrreason/32/3203_2.png) [@mrreason](https://uzu.lurk.org/u/mrreason)\
**Post date:** [28 August 2020 18:35 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/6 "2020-08-28T18:35:14Z")

</div>

Since I helped someone out with this topic today, I would like to append something to this topic for the sake of completeness. It is also possible to send a list of notes to TidalCycles (e.g. to send whole chords). My SuperCollider code looks like this:

```haskell
(
var on, off;
var osc;

osc = NetAddr.new("127.0.0.1", 6010);

~notes=[];

MIDIClient.init;
MIDIIn.connectAll;

on = MIDIFunc.noteOn({ |val, num, chan, src|
	~notes=~notes.add(num);
	~notes=~notes.sort({|a,b| a>b}).reverse;
	osc.sendMsg("/ctrl", "notes", format("%", ~notes-60));
});

off = MIDIFunc.noteOff({ |val, num, chan, src|
	~notes=~notes.takeThese({|x| x ==num});
	osc.sendMsg("/ctrl", "notes", format("%", ~notes-60));
});

if (~stopMidiToOsc != nil, {
	~stopMidiToOsc.value;
});

~stopMidiToOsc = {
	on.free;
	off.free;
};
)

```

In TidalCycles there is a (undocumented?) function `cP`, which accepts whole lists. So with the code above you could do something like this:

```haskell
d1 $ s "superpiano" <| n (arp "converge" $ cP "notes")

```

So maybe this is useful for someone...

---

<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:** [28 August 2020 19:36 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/7 "2020-08-28T19:36:35Z")

</div>

This is great thank you!

---

<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:** [28 August 2020 20:55 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/8 "2020-08-28T20:55:57Z")

</div>

Nice!  
Note that cP actually accepts mininotation. So when you send a 'list' like "[40,43,50]" to get a chord, you could also send "[40,43,\<50 60\>]" or whatever..

---

<div class="post-metadata">

**Author:** ![mrreason](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mrreason/32/3203_2.png) [@mrreason](https://uzu.lurk.org/u/mrreason)\
**Post date:** [28 August 2020 21:04 UTC](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674/9 "2020-08-28T21:04:14Z")

</div>

I haven't even thought about it, but sure, why not. The controls are basically nothing else than patterns. But that offers endless possibilities in exchange with other systems. I do not know yet where this will end but I like it.
