[sc-users] how to use initClass with synthdefs?
Alberto de Campo
decampo at iem.at
Fri Dec 1 11:58:19 PST 2006
>Dan Stowell wrote:
>>The thing to bear in mind is that the initClass methods run when the
>>lang is (re)compiled - i.e. typically when the server is not yet
>>booted. So "send(s)" will do nothing, it will send to a basically
>>nonexistent server. The only way is to use a disk-writing method like
>>.writeDefFile or .writeOnce.
>
>right, i suspected as much, thanks for clarifying it :)
>
>>You've said you don't want to save the SynthDef - why? If you're
>>really sure you don't, then there's no point using initClass at all.
>
>just to keep things tidy, more than anything. i figured a class
>could use synths that really have no use in other classes, and it
>wouldn't make sense to store these on the actual disk, if the class
>could make them 'as required'...
>
>>You should instead do something like:
>>
>>* define an instance variable in the class like synthdefssent=false
>>* when the class is called to do its stuff, if(synthdefssent.not, {
>>send the synthdefs; synthdefssent=true})
>>
>>(that works assuming an instance of the class only deals with one
>>server, which is very often true)
>
>...or, i guess, it wouldn't do any harm if i simply send the
>sythdefs through when i instantiate the class - if they're already
>on the server, they'll just be over-written with themselves, which
>shouldn't cause too many problems, i think?
something like this probably:
Bob {
classvar <mySyndefs;
*initClass {
mySyndefs = [
SynthDef(\etc, ...),
...
];
}
*sendDefs { |server|
server = server ? Server.default;
mySyndefs.do(_.send(server));
}
and call Bob.sendDefs only when you use that class.
best, a
--
--
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : decampo at iem.at
--
More information about the sc-users
mailing list