MIDIdef soft Takeover

Hello Everyone,

I am quite new to SuperCollider and trying to build multiple Pages/Scenes for my Midi-Controller (Nanokontrol2). I use the “argTemplate” for switching between MIDIdefs.
To avoid jumping values when the position of the controller differs from the former param value, I think I need to store the lastval in a variable, and only allow the param to change, when the new value matches or is close enough. But I can’t figure out how I can do that.
I found out about “softPut” but don’t know how to use it in a MIDIdef or if that is even possible.

This is what I’ve got so far:

~midistate = 1;  // Changing MIDIdef
~midistate = 2;

(
MIDIdef.cc(\first, {|val, ccNum|
		switch(ccNum,
		16, {~attack = val.linlin(0, 127, 1, 2);  "attack: ".post; ~attack.postln;},
		17, {~decay = val.linlin(0, 127, 3, 4);  "decay: ".post; ~decay.postln;}
	);
},argTemplate: {~midistate == 1} );
)



(
MIDIdef.cc(\second, {|val, ccNum|
		switch(ccNum,
		16, {~sustain = val.linlin(0, 127, 1, 2);  "sustain: ".post; ~sustain.postln;},
		17, {~release = val.linlin(0,127, 0.01,2);    "release: ".post; ~release.postln;},
	);
},argTemplate: {~midistate == 2} );
)

would appreciate any help! thank you very much :slightly_smiling_face:

Hello Valentin,
welcome to SC.
You can take a look at that:
http://sccode.org/1-5b2
I hope it helps

1 Like

I have some similar logic in my AbstractMIDIControl class @ https://github.com/jamshark70/ddwMIDI/blob/master/BasicMIDIControl.sc

hjh

1 Like

Thank you very much for your answers!

http://sccode.org/1-5b2

This really helped me understanding the logic!

AbstractMIDIControl looks very interesting! Unfortunately I couldn’t figure out how to use the setSync-method. Is it possible to use it with BasicMIDIControl as well? Or do I have to write my own Controller-Object?
I Could only make it work like this:

k = BasicMIDIControl.new([1,0],16, {|value, divisor, ccnum| ~release = value.linlin(0,127,1,4); ~release.postln})

I tried k.clear to pause the function but couldn’t get back to it without setting the values immediately.
Sorry if I am missing something obvious here…
Thanks! valentin

An abstract class exists to support logic that is shared among multiple subclasses – in general, an abstract class is not to be used directly.

To get MIDI values and handle them in a function, use BasicMIDIControl.

BasicMIDIControl should receive values automatically from MIDIIn, so you shouldn’t have to call setSync by yourself.

hjh

1 Like