[chuck-users] parent and children classes

eduard aylon eduard.aylon at gmail.com
Tue Jan 20 06:20:50 EST 2009


Dear chucklist,

I have a question regarding parent and children classes. I'm building  
a patch with operators that may have one or anoother user defined  
envelope (i.e. gaussian like, percussive like, etc.). I want to avoid  
to have to define each operator with 4 different envelopes and then  
connect-disconnect-reconnect. What I would like is to define a parent  
class EnvelopeClass from which the rest can inherit. I remember from  
the past that in chuck inheritance is not very "handy", so if children  
have different functions or members than its base class, these cannot  
be accessed. Does anybody have good recommendations to this problem?

So the idea is:

EnvelopeClass -> this is the base class
GaussEnvelope -> children class that inherits from EnvelopeClass
PercussiveEnvelope-> children class that inherits from EnvelopeClass

now I'd like to have

class Operator
{
     SinOsc s;
     EnvelopeClass @ env;
}

and be able to assign different envelope types and be able to access  
their members. Maybe the example at the bottoom of the email is more  
explanatory.

Operator op;
GaussianEnvelope gaussEnv @=> op.env;

Operator op2;
PercussiveEnvelope percEnv @=> op2.env;

and even later be able to change the type of the envelope for any  
operator:

GaussianEnvelope gaussEnv2 @=> op2.env;


 From what I remember, the trick would be that parent and children  
classes have EXACTLY the same member vars and functions although the  
implementation contained in it may differ. However, a gauss envelope  
or a percussive envelope have very different demands, and the best  
would be to be able to have diffferent implementations for each but  
inherit from the same base class.

any thoughts are very much appreciated,

thanks

eduard


Another example could be:

class operator
{
   UGen @ ugen;
}

Operator op;
SinOsc s @=> op.ugen; // this is fine so far but none of the functions  
of sinosc can be accessed
220 => op.ugen.freq; // this throws an error, as far as I remember....



More information about the chuck-users mailing list