Making a template for a MIDI controller (with GUI)

Hi,

For the first time I’m trying some coding (with functions) in SuperCollider.

I want to use my MIDI controller (16 knobs) to explore sounds in SC, quite similar to what you can do with NdefGui, but then using my MIDI controller knobs.

Eventually I might want to make a simple external GUI, which is able to set the lower and upper range of the values (via OSC).

I’d like to have some feedback on the code I’ve atm.


(

  var knobsAmount = 16;

  ~ff = (0..knobsAmount-1);


  // Fill the Array with knobs as events and give them all default values.
  c = { | l = 80, h = 1000, v = 64 |
      ~ff = ~ff.collect({
        | k, i |
        var c = i + 1; 
        k = (
          cc: c,
          lo: l,
          hi: h,
          val: v,
        );
      });
    };


  // Assign default values to the knobs, by calling func
  c.();


  // Free all MIDIdef
  MIDIdef.freeAll;


  // return a function for the MIDIdef as snd arg
  f = { | i |
      {
        arg val, num, chan;
        [val, num, chan].postln;
        ~ff[i].val = val.linlin(0, 127, ~ff[i].lo, ~ff[i].hi);
      };
  };


  // create MIDIdefs.
  16.do{ | i |
      var lab = "knob" ++ i.asString;
      MIDIdef.cc(lab, f.(i), ~ff[i].cc).permanent_(true);
  });
)

Some kind of SynthDef and then experiment with the sounds:

(

  x = Synth(\a);
  Routine({
        loop({
            x.set(\freq, ~ff[0].val); 
            x.set(\mFreq, ~ff[1].val);
            0.01.wait;
        });
    }).play;
)

Change the range manually:

~ff[0].lo = 20;
~ff[0].hi = 20000;

You might want to check this post: Creating a MIDI Bank - #8 by Thor_Madsen

1 Like