# New topic suggestion "controllers mapping"

**URL:** <https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969>\
**Category:** Development \[obsolete\]\
**Created:** [January 12, 2021, 8:14am UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969 "2021-01-12T08:14:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chip\_luxury\_E.W.A](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/chip_luxury_e.w.a/32/1756_2.png) [@Chip\_luxury\_E.W.A](https://in-thread.sonic-pi.net/u/Chip_luxury_E.W.A)\
**Post date:** [January 12, 2021, 8:14am UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/1 "2021-01-12T08:14:28Z")

</div>

I want to suggest a new topic, “controllers mapping”  
I think controllers mapping section is a must in any music related software.

This topic will have a pre-coded mapping for controllers and the user can use what he needs from the controller for example:

User search for his controller  
----------------V----------------  
User copy text from the post (maybe a git section)  
----------------V----------------  
User paste the text in Sonic-Pi  
----------------V----------------  
User setting the midi controller address in the right variable  
----------------V----------------  
User implementing “KNOB\_1” in his code for controlling stuff.

on those days I’m learning how to setup my arturia beatstep in sonic pi, got to the point where one knob controlling filter cutoff of a synth, while the pads are plaing notes (:  
later on we can write programs inside SP for controllers, I imagine a Synthesizer “ruby text file” that turn my controller to a synth…

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [January 12, 2021, 3:42pm UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/2 "2021-01-12T15:42:35Z")

</div>

You mean a new topic on this forum? This is the kind of general purpose code I use, which picks up the 8 knobs on the Akai MPK Mini I’m using. The default for this keyboard is CC 13…20. The function `:cc()` makes them available, in the following example.

Myself, I’ve generally moved away from mapping midi controllers to things, having been around the houses with it. I’ve more embraced editing the code live - just a cultural thing really.

```ruby
live_loop :midiccin do
  use_real_time
  n,v=sync "/midi:mpk_mini_midi_1:1:1/control_change"
  set "cc_"+n.to_s,v
end

define :cc do |n,min,max,default|
  v=get["cc_"+n.to_s]
  if v==nil
    x=default
  else
    x=min+(v/128.0)*(max-min)
  end
  puts n.to_s + "," + x.to_s
  x
end

```

I’m using them in this loop to control three FX, but they could be used for anything.

```ruby
live_loop :arp0 do
  use_synth :piano
  notes = scale :C4, :chromatic, num_octaves: 1
  with_fx :reverb, mix: cc(19,0.0,1.0,0.0) do
    with_fx :echo, mix: cc(18,0.0,1.0,0.0) do
      with_fx :nbpf, centre: cc(17,30,100,80), amp: 0.2 do
        6.times do
          play notes.tick
          sleep 0.2
        end
      end
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [January 12, 2021, 6:17pm UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/3 "2021-01-12T18:17:46Z")

</div>

A very good example and solution. Thanks for sharing

---

<div class="post-metadata">

**Author:** ![TotoLeTroll](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/totoletroll/32/2288_2.png) [@TotoLeTroll](https://in-thread.sonic-pi.net/u/TotoLeTroll)\
**Post date:** [May 14, 2022, 10:34am UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/4 "2022-05-14T10:34:22Z")

</div>

Seems like I’m late to the party 😅

I also experimented a bit with a basic USB MIDI keyboard like this one.  
 ![keywood-nomad-49](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/f/f027939ea66fa08b37046b585994d4f59f4c7416.png)

I mapped the 4 top left knobs on the ADSR synth envelope parameters, the slider thing on the volume, and I used the two roll knobs on the bottom for modulation synth phase and range control.

> <https://github.com/lyriarte/sonic-pi-music/blob/master/live_kit/midi_keyboard.rb>

What I didn’t manage to do properly though is to use the keyboard as an organ, like play a note on keydown and stop playing on keyup. I suspect I could do this with play / control commands but I haven’t figured it out yet.

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 14, 2022, 11:37am UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/5 "2022-05-14T11:37:24Z")

</div>

hi @TotoLeTroll

bienvenue !

It’s never too late to do well ! So thanks for sharing this piece of code !

ps : j’habite en France itou mais à l’opposé près de Cherbourg 🙂

---

<div class="post-metadata">

**Author:** ![felix.wolfsteller](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@felix.wolfsteller](https://in-thread.sonic-pi.net/u/felix.wolfsteller)\
**Post date:** [August 25, 2024, 6:28pm UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/6 "2024-08-25T18:28:17Z")

</div>

> [@soxsa](#):
>
> ```ruby
> live_loop :midiccin do
> use_real_time
> n,v=sync "/midi:mpk_mini_midi_1:1:1/control_change"
> set "cc_"+n.to_s,v
> end
> 
> define :cc do |n,min,max,default|
> v=get["cc_"+n.to_s]
> if v==nil
> x=default
> else
> x=min+(v/128.0)*(max-min)
> end
> puts n.to_s + "," + x.to_s
> x
> end
> 
> ```
> 
> I’m using them in this loop to control three FX, but they could be used for anything.
> 
> ```ruby
> live_loop :arp0 do
> use_synth :piano
> notes = scale :C4, :chromatic, num_octaves: 1
> with_fx :reverb, mix: cc(19,0.0,1.0,0.0) do
> with_fx :echo, mix: cc(18,0.0,1.0,0.0) do
> with_fx :nbpf, centre: cc(17,30,100,80), amp: 0.2 do
> 6.times do
> play notes.tick
> sleep 0.2
> end
> end
> end
> end
> end
> 
> ```

Thanks for sharing, also the github repo. The code here does nothing on my mpk mini, but I will come back to it when needed 🙂

---

<div class="post-metadata">

**Author:** ![felix.wolfsteller](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@felix.wolfsteller](https://in-thread.sonic-pi.net/u/felix.wolfsteller)\
**Post date:** [August 30, 2024, 9:22pm UTC](https://in-thread.sonic-pi.net/t/new-topic-suggestion-controllers-mapping/4969/7 "2024-08-30T21:22:26Z")

</div>

Oh, that comment was ment for @TotoLeTroll .  
In every case, the max value is 127 (starting from 0), not 128 (@soxsa ) . 😉
