/*
Spawn - generate events
arguments :
argEventFunc - a function which
returns a ugen graph
argNumChannels
argNextTime
argMaxRepeats
mul - multiply by signal or scalar
add - add to signal or scalar
*/
Spawn : MultiOutUGen {
var newEventFunction;
var <>nextTime = 0;
var nextTimeValue;
var defaultNextTime;
var maxRepeats;
var numRepeats = 0;
var runningSynths;
var recentSynth; // most recently started voice
var <>maxVoices; // maximum simultaneous notes - can't change
after start
var stop = false; // set to true
(via the stop method) to stop spawning events
var envir; // environment to set for spawning synths
var <>bufsync = false; // setting
bufsync to true will turn off sample accurate scheduling
// and
force the event's synth buffers to start aligned with
// the
parent's buffers.
// creation
*ar { arg newEventFunc, numChannels
= 1, nextTime = nil, maxRepeats,
mul = 1.0, add = 0.0;
^this.multiChannelPerform('ar1', newEventFunc, numChannels, nextTime,
maxRepeats,
mul, add)
}
*ar1 { arg argEventFunc, argNumChannels
= 1, argNextTime = 1.0, argMaxRepeats,
mul = 1.0, add = 0.0;
^super.ar1.init(argEventFunc, argNumChannels, argNextTime,
argMaxRepeats,
mul, add)
}
*ugen_ar1 { // this is provided so Voicer
can bypass Spawn's initialization code
^super.ar1
}
// no control rate version available
stop {
stop = true;
}
releaseAll {
_Spawn_ReleaseAll
^this.primitiveFailed
}
stealAll {
_Spawn_StealAll
^this.primitiveFailed
}
// PRIVATE:
init { arg argEventFunc, argNumChannels,
argNextTime, argMaxRepeats ... theInputs;
newEventFunction = argEventFunc;
inputs = theInputs;
defaultNextTime = argNextTime;
maxRepeats = argMaxRepeats;
runningSynths = Array.new(16);
envir = currentEnvironment;
^this.initOutputs(argNumChannels);
}
getNewEvent {
var newSynth;
// this method is called internally.
Users should not call it.
newSynth = Synth.new({
arg synth;
newEventFunction.spawn(this,
numRepeats, synth);
});
nextTimeValue = nextTime.value(this,
numRepeats);
^newSynth
}
}
TSpawn : Spawn
{
// creation
*ar { arg newEventFunc, numChannels
= 1, maxRepeats,
trig = 0.0, mul = 1.0, add = 0.0;
^this.multiChannelPerform('ar1', newEventFunc, numChannels, maxRepeats,
trig, mul, add);
}
*ar1 { arg argEventFunc, argNumChannels
= 1, argMaxRepeats,
trig = 0.0, mul = 1.0, add = 0.0;
^super.ugen_ar1.init(argEventFunc, argNumChannels, argMaxRepeats,
trig, mul, add);
}
// no control rate version available
trigger { arg ... extraArgs;
// this causes the event function
to be called
_TSpawn_Trigger
^this.primitiveFailed
}
triggerSynth { arg newSynth,
bufSync = false;
// pass the TSpawn a synth to
add directly.
_TSpawn_TriggerSynth
^this.primitiveFailed
}
// PRIVATE:
init { arg argEventFunc, argNumChannels,
argMaxRepeats ... theInputs;
newEventFunction = argEventFunc;
inputs = theInputs;
maxRepeats = argMaxRepeats;
runningSynths = Array.new(16);
envir = currentEnvironment;
^this.initOutputs(argNumChannels);
}
triggerNewEvent { arg ... extraArgs;
var newSynth;
// this method is called internally.
Users should not call it.
newSynth = Synth.new({
arg synth;
newEventFunction.spawn(this,
numRepeats, synth, extraArgs);
});
nextTimeValue = nextTime.value(this,
numRepeats);
^newSynth
}
}
Voicer : Spawn
{
var midiChannel; // MIDI channel which will trigger events
var triggerMode = 'normal'; // or 'toggle'
*ar { arg newEventFunc, numChannels
= 1, midiChan=1, maxVoices=8,
mul = 1.0, add = 0.0;
^this.multiChannelPerform('ar1', newEventFunc, numChannels, midiChan,
maxVoices, mul, add)
}
*ar1 { arg argNewEventFunction,
argNumChannels = 1, argMIDIChan=1, argMaxVoices=8,
mul = 1.0, add = 0.0;
^super.ugen_ar1.init(argNewEventFunction, argNumChannels, argMIDIChan,
argMaxVoices,
mul, add)
}
noteOn { arg chan=1, note=60,
veloc=64;
_Voicer_NoteOn
^this.primitiveFailed
}
noteDur { arg chan=1, note=60,
veloc=64, dur=1.0;
this.noteOn(chan, note,
veloc);
synth.sched(dur, { this.noteOn(chan,
note, 0); });
}
sustainPedal { arg isOn=true;
_Voicer_SustainPedal
^this.primitiveFailed
}
sostenutoPedal { arg isOn=true;
_Voicer_SostenutoPedal
^this.primitiveFailed
}
// PRIVATE :
init { arg argEventFunc, argNumChannels,
argMIDIChan, argMaxVoices ... theInputs;
newEventFunction = argEventFunc;
inputs = theInputs;
midiChannel = argMIDIChan;
if (argMaxVoices >= 0, {
maxVoices = argMaxVoices;
},{
maxVoices = argMaxVoices.neg;
triggerMode = 'toggle';
});
runningSynths = Array.new(maxVoices
+ 1);
^this.initOutputs(argNumChannels);
}
getNewEvent { arg chan, note,
veloc;
var newSynth;
// this method is called internally.
Users should not call it.
newSynth = Synth.new({
arg synth;
newEventFunction.spawn(this,
numRepeats, synth, nil, chan, note,
veloc);
});
nextTimeValue = nextTime.value(this,
numRepeats, synth);
^newSynth
}
trigger { arg argChan, argNote,
argVeloc;
// this causes the event function
to be called
_Voicer_Trigger
^this.primitiveFailed
}
}
This page was created by SimpleText2Html 1.0.3 on 22-Feb-100.