Buffers will be stored but doesn't work with ssynth

Hello everyone; I have a script that I like very much for its simplicity. I found it in The Supercollider Book. The problem is that if I don’t boot the server I manage to do what is expected and that is to load x audios on respective buses.
The code is as follows:

(
var file, soundPath;
~buffers = List[];

Dialog.getPaths({arg paths;
    paths.do({|soundPath|
        soundPath.postln;
        ~buffers.add(Buffer.read(s, soundPath)); });

});

)

However with the server booted the script returns the following error:

ERROR: rate must be Symbol.

PROTECTED CALL STACK:
	Meta_UGen:new1	0x128769f40
		arg this = Out
		arg rate = nil
		arg args = nil
	SynthDef:buildUgenGraph	0x128fdf640
		arg this = SynthDef:temp__0buffers-1495194127_1013
		arg func = a Function
		arg rates = nil
		arg prependArgs = [  ]
		var result = nil
		var saveControlNames = nil
	a FunctionDef	0x128fddbc0
		sourceCode = "<an open Function>"
	Function:prTry	0x1283dc300
		arg this = a Function
		var result = nil
		var thread = a Thread
		var next = nil
		var wasInProtectedFunc = false
	
CALL STACK:
	Exception:reportError
		arg this = <instance of Error>
	Nil:handleError
		arg this = nil
		arg error = <instance of Error>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of Error>
	Object:throw
		arg this = <instance of Error>
	Function:protect
		arg this = <instance of Function>
		arg handler = <instance of Function>
		var result = <instance of Error>
	SynthDef:build
		arg this = <instance of ProxySynthDef>
		arg ugenGraphFunc = <instance of Function>
		arg rates = nil
		arg prependArgs = nil
	Meta_ProxySynthDef:new
		arg this = <instance of Meta_ProxySynthDef>
		arg name = "temp__0buffers-1495194127_1013"
		arg func = <instance of Function>
		arg rates = nil
		arg prependArgs = nil
		arg makeFadeEnv = true
		arg channelOffset = 0
		arg chanConstraint = nil
		arg rateConstraint = 'scalar'
		var def = nil
		var rate = nil
		var numChannels = 0
		var output = <instance of BinaryOpUGen>
		var isScalar = false
		var envgen = <instance of EnvGen>
		var canFree = false
		var hasOwnGate = false
		var hasGateArg = false
		var hasOutArg = false
		var outerBuildSynthDef = nil
	SynthDefControl:build
		arg this = <instance of SynthDefControl>
		arg proxy = <instance of NodeProxy>
		arg orderIndex = 0
		var ok = nil
		var rate = nil
		var numChannels = nil
		var outerDefControl = nil
		var outerBuildProxy = <instance of NodeProxy>
		var controlNames = nil
	NodeProxy:put
		arg this = <instance of NodeProxy>
		arg index = nil
		arg obj = <instance of List>
		arg channelOffset = 0
		arg extraArgs = nil
		arg now = true
		var container = <instance of SynthDefControl>
		var bundle = <instance of MixedBundle>
		var oldBus = nil
	NodeProxy:source_
		arg this = <instance of NodeProxy>
		arg obj = <instance of List>
	LazyEnvir:put
		arg this = <instance of ProxySpace>
		arg key = 'buffers'
		arg obj = <instance of List>
	Symbol:envirPut
		arg this = 'buffers'
		arg aValue = <instance of List>
	< closed FunctionDef >
		var file = nil
		var soundPath = nil
	Interpreter:interpretPrintCmdLine
		arg this = <instance of Interpreter>
		var res = nil
		var func = <instance of Function>
		var code = "(
var file, soundPath;
~buff..."
		var doc = nil
		var ideClass = <instance of Meta_ScIDE>
	Process:interpretPrintCmdLine
		arg this = <instance of Main>
^^ The preceding error dump is for ERROR: rate must be Symbol.

Does anyone have any idea why this happens?

The only way this could happen is if a ProxySpace has been .push-ed as the current environment.

So it can’t be only “with the server booted” – it must be “server booted and ProxySpace pushed.”

ProxySpace changes the meaning of ~variables so that they may be used only for signals, not for storage. ~buffers = List.new is not supported within a ProxySpace.

I’m going to guess that you’ve set it up so that booting the server automatically pushes a ProxySpace. Because ProxySpace changes the meaning of environment variables, it’s (IMO) a bad idea to push a ProxySpace automatically. So wherever you’ve configured that, I’d suggest to remove it.

hjh

I’m sorry, I don’t think I understood you correctly, do you mean to remove the proxy? I am preparing my first live coding session and I would like to be able to manage the audio files in this simple way.

Ah, the live coding aspect wasn’t clear.

Within ProxySpace, you can’t even manage one file in that simple way:

s.boot;

p = ProxySpace.new.push;

~buffer = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

ERROR: 'prepareForProxySynthDef' should have been implemented by Buffer.

… because a Buffer does not directly do signal processing or generation (whereas a Function can do the former, and a Pattern can do the latter). Neither does a List. You can’t store either of these directly in a ProxySpace.

Try this:

if(currentEnvironment.isKindOf(ProxySpace).not) {
	p = ProxySpace.new.push;
};

q = ();  // Event i.e. a dictionary

q.buffers = List.new;

Dialog.getPaths({ arg paths;
    paths.do({ |soundPath|
        soundPath.postln;
        q.buffers.add(Buffer.read(s, soundPath));
	});  // btw: please close brackets at the same level
});

hjh

Thank you very much, it works very well now this script.

Excuse me please, one last thing about this script that works well. It loads only one audio. How could it load several, all from one folder ?