Organizing Buses

Hi there -

I’m hoping this is a relatively straight-forward question: I’d like to keep track of all the named buses in a project. In otherwords, if

~busA =, 2)

Is there any way I can access the string “~busA”? Or do I need to do some sort of key pairing/dictionary type deal?


variables you define using ~xyz can be found in currentEnvironment
you can get a Set of just the names with currentEnvironment.keys

That will likely produce a very long list of bus and non-bus items in the current project, but thanks for the tip!

I suppose I could just filter the list with a search term like “bus”, though.

Dictionaries are nice, perhaps:

var bus = (); bus.a = Bus(); bus.b = Bus(); bus.keys

which has the usual doesNotUnderstand rules, else:

var bus = (); bus['a'] = Bus(); bus['b'] = Bus(); bus.keys

I think this question reflects a normal and healthy development in programming.

At first, your needs were simple enough that you could dump all the resources into one flat namespace.

Now your needs are getting more complicated, outgrowing the single flat namespace (“… produce a very long list of bus and non-bus items…”).

That’s good – it means it’s time to start thinking about organizing the resources in a way that’s helpful for your purposes.

If you expect to need to access “all buses” or “all buffers,” then it makes sense to create separate collections for them. That’s rdd’s suggestion.

// old way
~busA =, 2);
~busB =, 2);
~bufferA =, "/path/to/xyz.wav");

Synth(\something, [out: ~busA]);

// new way
~buses =;
~buffers =;

~buses[\a] =, 2);
~buses[\b] =, 2);
~buffers[\a] =, "/path/to/xyz.wav");

Synth(\something, [out: ~buses[\a]]);

~buses[\a] is perhaps slightly less convenient to write than ~busA, but it has the advantage of allowing { |bus| ... } to loop over all the buses, without fragile filtering logic.

In my own work, I use objects representing musical processes. Each process keeps its own resources. If the process is playing to a bus, then the Bus object lives in the process object, and I access it by way of the process. You might not need to go that far just yet; just pointing out that you’re not limited to organizing resources in terms of the lower-level classes.


Carrying on from what @jamshark70 said, you can also organise in terms of synths if that works better for you…

~snd1 = ();
~snd1[\inBus] = Bus(...);
~snd1[\outBus] = Bus(...);
~snd1[\synth] = Synth(.... args: [\inBus, ~snd1[\inBus], \bus, ~snd1[\\outBus]);

Personally, I’ve always found grouping by resource type to get messy very quickly and actually slowed everything down.