# MIDI CC (control change) input help to a newb \[SOLVED i think\]

**URL:** <https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991>\
**Category:** Support, Help & Resources\
**Created:** [February 11, 2019, 1:28am UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991 "2019-02-11T01:28:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![256k](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/256k/32/860_2.png) [@256k](https://in-thread.sonic-pi.net/u/256k)\
**Post date:** [February 11, 2019, 1:28am UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/1 "2019-02-11T01:28:07Z")

</div>

Hi there!

First let me just say quickly how awesome sonic Pi is and im really happy i discovered it 🙂

I’ve been searching alot on this but i cant find a definitive clear solution to my problem so i’m trying on the forums, if this has already been convered then i apologize, I was also not able to find this infomation in the sonic Pi documentation/tutorial

I’m Hoping someone can help me out with this:

I’m trying to get a parameter of a synth let’s say the cutoff of the tb303 synth to change based on my controller CC value

I’ve managed to get everything running well BUT i noticed that the loop only transfers the value of the CC once the note is triggered but it does no modify the value as the note is playing

I’m trying to understand how i can program a synth or any other node to have it’s parameter controlled continuously while a note is being played

or is that not even possible in sonic Pi?

Ideally i wanna have a controller controlling some parameters in real time and maybe have a few groups of loops’s amp controlled by a volume fader to be able to mix live the audio

thank you

---

<div class="post-metadata">

**Author:** ![256k](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/256k/32/860_2.png) [@256k](https://in-thread.sonic-pi.net/u/256k)\
**Post date:** [February 11, 2019, 3:06am UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/2 "2019-02-11T03:06:15Z")

</div>

I think i finally cracked it!

Took me a long time and a lot of learning, especially knowing what i didn’t know so i could learn that but i managed to finally get a functioning knob to control a parameter in real time!

The biggest thing i learned about sonic Pi in order to get this to work is this:

You cannot modify a synth parameter while the note is playing… the parameter will only go into effect once the note is retriggered.

However, FX units CAN be controlled in real time without retriggering the note!

Here is the code, it’s a very simplified proof of concept:

```ruby

with_fx :lpf, cutoff: get(:knobVal) do |fx|
  live_loop :synth do
    s = synth :zawa, release: 0.1
    control s, note: scale(:e1, :minor_pentatonic).pick
    set :s, s
    set :fx, fx
    sleep 0.125
    
  end
  
  live_loop :ctrlCut do
    use_real_time
    cc, val =sync '/midi/cmd_mm-1/2/5/control_change'
    puts val
    puts fx
    set :knobVal, val
    control get(:fx), cutoff: val, resonance: 90
    sleep 0.01
  end
end

```

an important note about this code is that the control loop that waits for the midi change and changes the value has to be also inside the same fx loop block so using the same knob for diff loops and diff effects might not work then

I’m not 100% sure of any of my claims, if someone could review this and tell me what i did right and what i did wrong and how can i maybe optimize this and make it more user friendly that would be great.

I’m thinking of writing a function that will return the knob value based on the function param which would be the cc number of the knob, that i will probably use in a variable to make it more explicit

something like:

```ruby
CUTOFF_KNOB = 18

findVal(CUTOFF_KNOB)
-> returns the value of that knob.

```

Sorry im not a ruby coder so im not familiar with the syntax.

---

<div class="post-metadata">

**Author:** ![simesky](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@simesky](https://in-thread.sonic-pi.net/u/simesky)\
**Post date:** [May 26, 2021, 11:09pm UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/3 "2021-05-26T23:09:02Z")

</div>

Hi,

I’m a few years late to the party, but I wanted to thank you for posting this solution, I’m kind of astonished that the tutorials don’t offer a hint for this common MIDI task. It’s a minor pick, I’m still very fond of this brilliant program 🙂  
I was wondering if you continued to develop this solution in the meantime. Also, I’ve no idea if this is the correct way, but here is a simpler version that seems to work (I removed the things that seemed redundant concerning the set commands):

```ruby
with_fx :lpf do |fx|
  live_loop :synth do
    synth :square, note: scale(:e1, :minor_pentatonic).pick, release: 0.1
    sleep 0.125
  end

 live_loop :ctrlCut do
    use_real_time
    cc, val =sync "/midi/loopmidi_port/1/1/control_change"
    control fx, cutoff: val
    sleep 0.01
  end
end

```

Anyway, thanks again for this!

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [September 23, 2023, 7:46pm UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/4 "2023-09-23T19:46:17Z")

</div>

Has anyone figured out a way to use CC messages to change, for example, the `cutoff` setting of the _square wave itself_ in the above example? I just can’t work out how to change synth parameters with CC messages live using a controller.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [September 23, 2023, 8:18pm UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/5 "2023-09-23T20:18:45Z")

</div>

Here’s how to change the square synth cutoff via midi\_cc

```ruby
set :co,80 #sets an initial cutoff until it is changed by midi input
live_loop :synth do
  synth :square, note: scale(:e1, :minor_pentatonic).pick, release: 0.1,cutoff: get(:co)
  sleep 0.125
end

live_loop :ctrlCut do
  use_real_time
  cc, val =sync "/midi*/control_change" #responds to any midi device with relevant controlchange
  #val is in range 0=>127 you can scale or set min value if needs be
  set :co,val if cc ==20 #sets the cc number to respond to
end

```

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [September 23, 2023, 9:35pm UTC](https://in-thread.sonic-pi.net/t/midi-cc-control-change-input-help-to-a-newb-solved-i-think/1991/6 "2023-09-23T21:35:11Z")

</div>

Thanks for the clear example!

I notice that this will only change the cutoff at the start of each new note - i.e. it doesn’t affect a currently playing note. I know this isn’t a problem for fast sequences, like the above, but for anyone reading this in the future (who wants to change values in real-time as synth is playing) Robin has explained the process brilliantly in [this other thread](https://in-thread.sonic-pi.net/t/change-parameters-of-a-synth-with-midi-cc-from-controller/8179/2) 😉
