Thanx Andy. I was worried that this would be the case; getting too used to
Javascript where anything is possible.
Will the casting work for any UGen type? I.e. since most (all) UGens support
mix, then can I just pretend that everything in the array is one type (say
Chorus for instance) and then use that type's mix?
Thanx.
-- Rich
----- Original Message -----
From: "Andrew Turley"
Hey Rich,
You can work around the problem by casting ug[0] as a Chorus object like this: 0.0 => (ug[0] $ Chorus).mix; Casts are ugly, but they'll almost get the example working. The other thing you need to do is change the line UGen @ ug[]; to UGen @ ug[0]; I'm a little rusty on the syntax, but I think what you're doing in your code is declaring a reference to an array of references to UGens, when what you want is an array of references to an array of UGens. If you make the change then you get the array of references. You can then begin to fill the array using the "array << item" syntax, which adds elements to the end of the array. So to add the UGens to the array you'll end up with lines like this: ug << chorus; ug << reverb;
// BEGIN CODE SinOsc s => Chorus chorus => JCRev reverb => dac; 880.0 => s.freq; .2 => s.gain; UGen @ ug[0]; ug << chorus; ug << reverb; 0.0 => (ug[0] $ Chorus).mix;
while (true) { 1::second => now; } // main loop // END CODE
And once you've done all this you still have your original problem, which is that you want to be able to create an array of objects that all respond to "mix" (or some other method) and treat them the same way. Unfortunately there isn't a built-in way to do this. Chuck is strongly-typed, so you can't call a method unless the object is known to support the method. Chuck doesn't have an introspection system so you can't ask an object what methods it supports. And Chuck doesn't have multiple inheritance (nor does it have interfaces) so there isn't a "MixableUGen" interface that you could use to indicated that all the UGens in the array support the "mix" method.
You can create your own classes that have references to the UGens and wrap up the functionality you need, so that you can call the "mix" method an an object and it will know what to do with its associated UGen.
andy
On Sun, Nov 7, 2010 at 6:45 PM, Rich Caloggero
wrote: Whan I run the following code, I get an error at line 7 - class UGen has no member 'mix'. How do I do this type of thing in chuck?
// code SinOsc s => Chorus chorus => JCRev reverb => dac; 880.0 => s.freq; .2 => s.gain; UGen @ ug[]; chorus @=> ug[0]; reverb @=> ug[1]; 0.0 => ug[0].mix;
while (true) { 1::second => now; } // main loop
----- Original Message ----- From: "Rich Caloggero"
To: "ChucK Users Mailing List" Sent: Sunday, November 07, 2010 1:11 PM Subject: [chuck-users] Intraspection? I want to find some way of controlling various parameters via the keyboard. The problem I'm having is that in order to write some sort of generic class that can change arbitrary UGen parameters (or really anything), one needs to know what types your dealing with. Is there a way of asking chuck what things are? For instance, I can maintain some sort of list of UGens I want to control via an array of UGens, but then when I attempt to access a parameter on one of the objects in that array, it tells me there is no such member in class UGen. THe idea is that the array would contain references to various UGens I want to manipulate, and they may be of any UGen subtype. However, in order to access any members, the compiler needs to know exactly which type each object is.
Any ideas?
-- Rich
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users