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

Hi there!

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

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

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:

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
  live_loop :ctrlCut do
    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

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:


-> returns the value of that knob.

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

1 Like


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 :slight_smile:
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):

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

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

Anyway, thanks again for this!