| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 
 | 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;
)
::
 |