[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] A bug in switch/case?
Well, the simplest use is:
// define your cases once
d = IdentityDictionary [
'white' -> {in = WhiteNoise.ar(inmul, inadd);},
'pink' -> {in = PinkNoise.ar(inmul, inadd);},
'brown' -> {in = BrownNoise.ar(inmul, inadd);},
'gray' -> {in = GrayNoise.ar(inmul, inadd);},
'clip' -> {in = ClipNoise.ar(inmul, inadd);},
'crackle' -> {in = Crackle.ar(param, inmul, inadd);},
'dust' -> {in = Dust.ar(param, inmul, inadd);}
];
// whatever other code
...
100.do { // maybe inside a loop,
// you generate your case key somehow.
// can be as complicated as you want:
input = ['white', 'pink', 'brown'].choose;
// and look up your case.
d[input].value;
};
I am not sure I understand what you want beyond that.
best, adc
Thanks Alberto, for your answer. But can we do anything with
IdentityDictionary?
For example, the code below works, with switch:
switch (input,
"white", {in = WhiteNoise.ar(inmul, inadd);},
"pink", {in = PinkNoise.ar(inmul, inadd);},
"brown", {in = BrownNoise.ar(inmul, inadd);},
"gray", {in = GrayNoise.ar(inmul, inadd);},
"clip", {in = ClipNoise.ar(inmul, inadd);},
"crackle", {in = Crackle.ar(param, inmul, inadd);},
"dust", {in = Dust.ar(param, inmul, inadd);}
);
Then, I dug into the SC list, and found this code written by hjh:
c = IdentityDictionary[
{ x == 1 } -> { "case 1".postln },
{ x == 2 } -> { "case 2".postln },
{ x == 3 } -> { "case 3".postln }
];
functions as keys make little sense to me;
but I don't know the context this comes from.
I tried to write this:
inputdic = IdentityDictionary [
{input == "white"} -> {in = WhiteNoise.ar(inmul, inadd);},
{input == "pink"} -> {in = PinkNoise.ar(inmul, inadd);},
{input == "brown"} -> {in = BrownNoise.ar(inmul, inadd);},
{input == "gray"} -> {in = GrayNoise.ar(inmul, inadd);},
{input == "clip"} -> {in = ClipNoise.ar(inmul, inadd);},
{input == "crackle"} -> {in = Crackle.ar(param,
inmul, inadd);},
{input == "dust"} -> {in = Dust.ar(param, inmul, inadd);}
];
But, it doesn't seem to work. I'm just wondering whether my code is
wrong or there is an impossibility of doing this with
IdentityDictionary. I should add that input is not a variable but an
argument of a proto-synthdef function.
the point is, if you do dict.at(input);
you _are_ already comparing key == input to find the key,
so there is no need to wrap a function around it.
--
--
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : decampo@xxxxxx
--