Loading external .scd files


#1

I am fairly new to SuperCollider and still trying to get my bearings.
I have found the ability to load external .scd files in the documentation like so:
“/home/pi/customlibs/launch_control.scd”.load;
This does in fact execute that scd file, but none of the variables I have assigned in that file are accessible out of that file. I tried declaring the variables used in that file prior to load like so:

 var lc, on, lc_pi, lc_uid, getLaunchControl, turnPad;
 "/home/pi/customlibs/launch_control.scd".load;
 {SinOsc.ar([400, 404])}.play;
 lc = getLaunchControl.value;
 turnPad.value(1,"green",lc);

However, the assignments I make in launch_control.scd of getLaunchControl and turnPad do not seem to effect this namespace, as my later code does not call the function. Is it possible for the loaded scd file to write to the global namespace of the scd file doing the loading?

Perhaps what I need to do is write classes and load them in as extensions. I am trying to define common functionality across many SuperCollider scripts, which I can just load in depending on the project. I’d like to avoid classes if I have to, so let me know if there is another way to do this. But if the only way to do this is through classes, let me know and I will make the dive. I have taken a few stabs at classes already, but the documentation is hard to interpret for someone new to SuperCollider (I am not new to OOP though). I will happily take recommendations for tutorials if that is the case.


#2

I just fixed this by adding tilde’s in my function definition of the loaded files, and function calls in my main file. So this:

 var lc, on, lc_pi, lc_uid;
 "/home/pi/customlibs/launch_control.scd".load;
 {SinOsc.ar([400, 404])}.play;
 lc = ~getLaunchControl.value;
 ~turnPad.value(1,"green",lc);

and in my launch_control.scd:

~getLaunchControl = { // some code here };
~turnPad = { | pad_no, state, lc_object | // some code here };

But if someone wants to advise me on the appropriate context to use classes, I am happy to hear it


#3

You could also have a look at the Require quark.
You can install it with Quarks.gui