Skip to content

Commit

Permalink
simplified and made ready to use in patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rohrhuber committed May 23, 2003
1 parent a970f53 commit f49b8b9
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions build/SCClassLibrary/JITLib/various/SoundDef.sc
@@ -1,63 +1,61 @@

//globally referenceable wrapper for a SynthDef.
//keeps servers updated.

SoundDef {
var <obj, <synthDef, <servers;
classvar <all;
var <synthDef, <controlNames;
classvar <all, <>servers;

*new { arg key, obj;
if(obj.isNil, { ^all.at(key) });
^super.newCopyArgs(obj, obj.asSynthDef).toLib(key.asSymbol) //add some preparation later
*new { arg key, func, lags, prependArgs;
var synthDef;
if(func.isNil, { ^all.at(key.asSymbol) });
if(servers.isNil, { servers = [Server.local] }); //lazy init for now
synthDef = SynthDef(key, func, lags, prependArgs);
^super.newCopyArgs(synthDef).toLib(key.asSymbol) //add some preparation later
}

*initClass {
*initClass {
all = IdentityDictionary.new;
}

toLib { arg key;
var old, local;
if(synthDef.name.isNil,{ synthDef.name ? "soundDef_" ++ key });
servers = IdentitySet.new;
local = Server.local;
old = this.class.at(key);
if(old.notNil, {
//keep old servers updated
old.servers.do({ arg item; this.send(item) });
}, {
//send to local by default
if(local.serverRunning, {this.send(local)}, {this.load(local)});
});
this.class.all.put(key,this);

this.send;
this.class.all.put(key, this);
//cache control names to use with patterns
controlNames = synthDef.controlNames.collect({ arg item; item.name })
}

*at { arg key;
^all.at(key)
}

*sendAll {
all.do({ arg item; item.send });
}

*loadAll {
all.do({ arg item; item.load });
}

newMsg { arg args, target, addActionNumber=1;
^[9,synthDef.name,-1,addActionNumber,target.asTarget.nodeID]++args
}

asDefName {
^synthDef.name
}
argNames {
^obj.eventArgNames
}

send { arg server;
if(servers.includes(server).not, {
servers.add(server);
});
synthDef.send(server);

send {
this.class.servers.do({ arg server;
synthDef.send(server);
})
}

load { arg server;
if(servers.includes(server).not, {
servers.add(server);
});
synthDef.load(server);
this.class.servers.do({ arg server;
synthDef.load(server);
})
}

play { arg args, target;
Expand Down

0 comments on commit f49b8b9

Please sign in to comment.