# 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:** 1\
**Showing post:** 4

<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.

---

_[View the full topic](https://uzu.lurk.org/t/get-values-from-midi-keyboard/674)._
