[chuck-users] Latest on subclassing UGen within ChucK?

Chris Harris ryguasu at gmail.com
Fri Feb 22 04:08:00 EST 2013


Can you create a UGen in the ChucK language, by subclassing the UGen
class? Because I just tried to do it for a couple hours and it was
frustrating the heck out of me.

The documentation makes it seem like it should work. (ChucK has
virtual methods, and you can subclass UGen. So why wouldn't it work.)
So something like this should be viable:

    class IGen extends UGen {
        SinOsc osc => blackhole;

        // Docs don't make it clear how all the methods should work, but
        // at least last() seems more or less straightforward:
        1 => int first;
        fun float last()
        {
            if (first)
            {
                return 0.0;
            }
            else
            {
                0 => first;

                return osc.last();
            }
        }
    }

    IGen fg => dac;
    4::day => now;

This whole thing compiles fine and runs in the VM without errors. The
only problem is that none of the methods defined on IGen get called,
nor does any sound come out.

Unless I'm totally doing it wrong, I'm suspecting you can't, in fact,
make a viable UGen subclass using the ChucK language itself (vs C++ or
whatever).

If this sort of subclasses can't work, a nice improvement would be for
ChucK to provide an error here. Is there any legitimate reason to
subclass a UGen in ChucK language? If not, attempting to do so should
generate a compile error. Alternatively, maybe trying to chuck a
non-C++ Ugen subclass into another Ugen (and especially into dac)
should throw a runtime error.

I did finally find about the chugen facility, which seems like a neat
alternative. But it was not an easy find.

So I guess some documentation updates might be in order too. A note
that you can't write UGens in ChucK and a mention that chugen stuff
exists.

Not sure if I'll have time to look into all this or not. But I wanted
to start by getting the facts straight.

Thanks,
Chris


More information about the chuck-users mailing list