«midi soft takeover» by meunier.fabien

on 21 Nov'18 11:25 in midi control change cc soft takeover gui

it avoids jump of value when the value on your GUI and the value of your midi controller are differents. In other words your midi controller take control only when it reaches the value of your GUI. Thanks to sludgefree and alberto de campo for their help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(
MIDIIn.connectAll;
SynthDef(\SimpleSynth, { arg out = 0, freq = 1000, t_trig = 0, level =
0.2;
       var sig, env;
    env = EnvGen.kr(Env.adsr(releaseTime: 240), t_trig, doneAction: 0);
       sig = SinOsc.ar(freq, 0, env * level);
       Out.ar(out, sig!2);
}).add;
)

(
var knob, active;
active = false;

~a = Synth(\SimpleSynth);

w = Window("Test",Rect(0, 0, 200, 200), scroll: true);
w.front;

knob = EZKnob(w, 112@70, 'freq', ControlSpec(20, 20000, step: 1,
default: 20, units: 'hz'), { arg knob; ~a.set(\freq, knob.value); active = false; },
margin: 39@0);

MIDIFunc.cc({ arg val, num, chan, src;
    var guiControl, midiControl, treshold;
    midiControl = val.linlin(0, 127, 20, 20000);
    guiControl = knob.value;
    treshold = 500; // adapt this with your needs, it depends on the values of step in ControlSpec and the value of step of your midi controller
    if ( // soft takeover
        (active or: ((midiControl > (guiControl - treshold)) and: (midiControl < (guiControl + treshold)))),
        {
            active = true;
            {
                ~a.set(\freq, midiControl);
                knob.value_(midiControl);
            }.defer;
        }
    );
    (midiControl).debug("Ext Contoller value");
    (guiControl).debug("GUI value");
}, 21, 0, 0); // cc number 21 on channel 1
)

~a.set(\t_trig, 1);
raw 1378 chars (focus & ctrl+a+c to copy)
reception
comments