I’ve been naming a set of Busses by associating them with environmental variables (i.e., ~a = Bus.audio(s, 2))
I’d like to collect all of these into a list, but I’d like the list to post the names of the environmental variables, rather than the bus allocation information.
Is there a simple way to do that? The only thing I can think of is registering the “names” separately somewhere…
Yes this is possible, but it’s generally better to not use environment variables and use an Event to store things.
To get the environment, use currentEnvironment, or topEnvironment. These are both identity dictionarys so you can do keysValueDo or something to get the entries.
Now, you won’t know that the global variable is a bus without checking it, so you will need to check each entry x.isKindOf(Bus).
Why are there two way to get the environment? Well environments can change, you can nest them inside one another, meaning sometimes ~a might be a bus, and sometimes not!!
These are the two main reasons why not to use environment variables, there is also an argument to be made about reducing mutable global state, but that only really matters if you are working in multiple files.