rsc3/doc-schelp/HelpSource/Classes/Demand.schelp

152 lines
3.5 KiB
Text

class:: Demand
summary:: Demand results from demand rate UGens.
related:: Classes/Duty, Classes/TDuty
categories:: UGens>Demand
Description::
When there is a trigger at the trig input, a value is demanded each UGen
in the list and output. The unit generators in the list should be
'demand' rate.
When there is a trigger at the reset input, the demand rate UGens in the
list are reset.
classmethods::
private:: categories
method::ar, kr
argument::trig
Trigger. Can be any signal. A trigger happens when the signal
changes from non-positive to positive.
argument::reset
Trigger. Resets the list of UGens when triggered.
argument::demandUGens
List of demand-rate UGens to get values from. When the shortest stream ends, this ugen will set the link::Classes/Done##'done' flag::.
discussion::
By design, a reset trigger only resets the demand ugens; it does not reset the value at Demand's output. Demand continues to hold its value until the next value is demanded, at which point its output value will be the first expected item in the list.
To jump to the start value upon receipt of a reset trigger, one can add (+) the two triggers together:
code::
(
a = { |t_trig, t_reset|
var d = Demand.kr(t_trig + t_reset, t_reset, Dseries(0, 1, inf));
d.poll(t_trig + t_reset);
0.0;
}.play
)
a.set(\t_trig, 1); // do this a few times -- the demand value should increase by 1 each time
a.set(\t_reset, 1); // goes immediately back to 0
::
One demand ugen represents a single stream of values, so that embedding the same ugen twice calls this stream twice. To isolate a demand ugen, use a function:
code::
{
var a, b, t = Impulse.kr(2);
a = { Dseq([1, 2, 3, 4, 5], inf) } * 100;
b = a + 1;
Demand.kr(t, 0, [a, b]).poll(t)
}.play
::
Examples::
code::
// examples
(
{
var trig, seq, freq;
trig = Impulse.kr(24);
seq = Drand([Dseq((1..5).mirror1, 1), Drand((4..10), 8)], 2000);
freq = Demand.kr(trig, 0, seq * 100);
SinOsc.ar(freq + [0,0.7]).cubed.cubed.scaleneg(MouseX.kr(-1,1)) * 0.1;
}.play;
)
(
{
var trig, seq, freq;
trig = Impulse.kr(12);
seq = Drand([Dseq((1..5).mirror1, 1), Drand((4..10), 8)], 2000) * Drand([1,2,4,8],2000);
freq = Demand.kr(trig, 0, seq * 100);
SinOsc.ar(freq + [0,0.7]).cubed.cubed.scaleneg(MouseX.kr(-1,1)) * 0.1;
}.play;
)
(
{
var freq, trig, reset, seq;
trig = Impulse.kr(10);
seq = Diwhite(60, 72, inf).midicps;
freq = Demand.kr(trig, 0, seq);
SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;
}.play;
)
(
{
var freq, trig, reset, seq;
trig = Impulse.kr(10);
seq = Dseq([72, 75, 79, Drand([82,84,86])], inf).midicps;
freq = Demand.kr(trig, 0, seq);
SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;
}.play;
)
(
{
var freq, trig, reset, seq;
trig = Impulse.kr(10);
seq = Dswitch1(
[
Diwhite(60, 72, inf),
Dseq([72, 75, 79, Drand([82,84,86])], inf)
],
LFPulse.kr(0.2)
);
freq = Demand.kr(trig, 0, seq.midicps);
SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;
}.play;
)
(
{
var freq, trig, reset, seq1, seq2;
trig = Impulse.kr(10);
seq1 = Drand([72, 75, 79, 82] - 12, inf).midicps;
seq2 = Dseq([72, 75, 79, Drand([82,84,86])], inf).midicps;
freq = Demand.kr(trig, 0, [seq1, seq2]);
SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;
}.play;
)
(
{
var trig, seq;
trig = Impulse.kr(8);
seq = Drand([
Dseq([4,0,0,1,2,1,0,1]),
Dseq([4,0,2,0,1,0,1,1]),
Dseq([4,0,0,2,0,0,1,1]),
Dseq([4,0,1,2,0,1,2,0]),
Dseq([4,1,1,1,2,2,3,3]),
Dseq([4,1,0,1,0,1,0,1])
], inf);
trig = Demand.kr(trig, 0, seq * 0.4) * trig;
{LPF.ar(PinkNoise.ar, 5000)}.dup * Decay.kr(trig, 0.5);
}.play;
)
::