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.