 # How to create a package that holds two variables at the same time?

Hello. I am very new to supercollider and programming in general. I have a big assignment in my final year of high school/gymnasium to develop a program that creates music through algorithmic composition. I have a slight problem that involves the chord progression. I want to create several packages that each have a definition of z and y so I can create a chord progression that is often used in pop music for example I-IV-V, I-V-IV, ii-V-I etc. So for a start i want to create a variable that has variables stored inside it like the letter a has y=5 and z=7 and b has y=7 and z=5 and then i can randomly choose between those variables through the choose commando: `choose.[a, b]`

``````var frqxbass = rrand(36,47);
chord1 = Synth(\default, [freq: (frqxbass).midicps]);
1.wait;
chord1.release(0);
chord2 = Synth(\default, [freq: (frqxbass + y).midicps]);
1.wait;
chord2.release(0);
chord3 = Synth(\default, [freq: (frqxbass + z).midicps]);
1.wait;
chord3.release(0);
``````

Any help would be appreciated. Sorry for my english

Hello and welcome to this forum,

There can be many ways to approach the question you outline, but to your specific question, you don’t have to think in terms of variables. You could think in terms of Arrays of Arrays, and corresponding indices:

``````x = [ [5, 7], [7, 5] ];
x.choose.at(0);  // this is what you called "y"
x.choose.at(1); // this is your "z"
``````

The choose above randomly picks one of the sub-arrays; then the .at(n) accesses a given index inside that sub-array.

Another route would be to use a Dictionary of Dictionaries, where you could refer to elements by a “label” (key), if you don’t want to think in numerical indices. Take a look at the Dictionary help file for examples.

Hope this helps,

Bruno

here’s an array of events:

a=[(x:5,y:7),(x:7,y:5)]

a.x . //evaluates to 5
a.y . //evaluates to 5
b=a.choose;
b.x
b.y

or the dictionary of dictionaries Bruno suggested (with Events because of nice syntax):
a= ( chord1: (x:5, y:7), chord2: (x:7,y:5) )
a.chord1.x //5
a.chord2.y //7

Thank you so much! Will try this when I get the time