Eduard;<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
My question, actually, should have been about polymorphism and not inheritance. What I want is that having a base class Point and another class Point2D which inherits from Point, that I can define a Point p, that could morph and become a Point2D. Or in other words, that an UGen, can become a SinOsc.<br>
<br>
Is that possible?<br>
<br>
</blockquote></div><br>Well, the thing is; You can assign a SinOsc to a object of type UGen because a SinOsc is a UGen. However, a UGen object doesn't have a .freq() member function so you can't use that with it, even though a SinOsc (which does have that function) has been asigned to it.<br>
<br>Let's take a practical example;<br>----------------8<-----------<br>UGen u;<br><br>if (maybe) new SinOsc @=> u;<br>else new Gain @=> u;<br><br>//so far so good<br><br><br>//here comes trouble;<br>440 => u.freq;<br>
--------------8<----------------<br><br>That last line is the trouble-maker; it adresses a UGen and at that point we're not sure that UGen has that function, hence the parser objects. That line may well be valid but we don't know this for sure.<br>
<br>What I think you may need is a new class that can generate modulation signals, then extend that for various behaviours. This won't work like a UGen but you could connect it using a "dummy" Gain UGen in the parrent class that might serve as a output. How you'd do that in practice would depend on the exact scenario, for a extremely general case this could become somehwat lengthy and involved. For a extremely basic frame-work see below.<br>
<br>Yours,<br>Kas.<br><br>--------------8<-------------------<br>//this will parse. It may or may not be the kind of thing you are after.<br>//clearly a lot more infrastucture is needed<br><br>class Modulator<br> {<br>
Gain out;<br> }<br> <br>class Foo extends Modulator<br> {<br> ADSR env => out;<br> }<br> <br>class Bar extends Modulator<br> {<br> Envelope env => out;<br> }<br><br>Modulator m;<br>m.out => SinOsc s => dac;<br>
<br>new Foo @=> m;<br>-----8<----------------------<br><br>ps; you'll be fighting the type system. Typically fighting the type system leads to bug-reports. If it's 4am and you're throwing the keyboard against the wall do considder that you may be right and ChucK might be wrong.<br>