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 = Bus.audio(s, 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?

Thanks!

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 = Bus.audio(s, 2);
~busB = Bus.audio(s, 2);
~bufferA = Buffer.read(s, "/path/to/xyz.wav");

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

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

~buses[\a] = Bus.audio(s, 2);
~buses[\b] = Bus.audio(s, 2);
~buffers[\a] = Buffer.read(s, "/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 ~buses.do { |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.

hjh

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.