QcPenPrinter: no need to allocate QPrintDialog on heap
[supercollider.git] / HelpSource / Classes / Pstep.schelp
blobf89582c3744ee8473d4654ed8572339e326c8dca
1 class:: Pstep
2 summary:: timed embedding of values
3 related:: Classes/Pseg
4 categories:: Streams-Patterns-Events>Patterns>Time
6 description::
8 Pstep is good for representing chord progressions, scale progressions, accent patterns, etc.
10 ClassMethods::
12 method::new
13 Levelpattern can return individual values, arrays, or events. The value returned by levelpattern is returned for the duration returned by durpattern.
15 Examples::
17 code::
19 // select a chord and duration and repeat it for a random time interval
20 p = Pstep(
21         Pbind(
22                 \ctranspose, [0, 4, 7],
23                 \note,  Pwhite(0, 12),
24                 \dur,   Prand([0.2, 0.4, 0.8], inf)
25         ),
26         Prand([1, 2, 4], inf)/4
28 Ppar([p, p]).play;
30 // change degree independant of number of events that have been playing
33 Pchain(
34         Ppar([
35                 Pbind(
36                         \degree, Pbrown(0, 12, 1),
37                         \dur, Pstep( Pseq([0.1, 0.2, 0.4, 0.8, 1.6], inf), 3.2)
38                 ),
39                 Pbind(
40                         \degree, Pbrown(0, 20, 1),
41                         \dur, Pstep( Pseq([0.1, 0.2, 0.4, 0.8, 1.6], inf), 4.5)
42                 )
43         ]),
44         Pbind(
45                 \scale, Pstep(Pseq([ [0, 2, 4, 5, 7, 9, 11], [0, 1, 2, 3, 4, 5, 6]], inf), 5),
46                 \db, Pstep(Pseq([2, -2, 0, -2], inf), 0.25) - 10
47         )
48 ).play;
51 // use a simple pattern
53 Pchain(
54         Ppar([
55                 Pbind(
56                         \octave, [5, 6] + Prand([0, 0, \r], inf),
57                         \degree, Proutine({ | ev | loop { ev = Pseq(ev[\degree]).embedInStream } }),
58                         \dur,   Proutine({ loop { Pseq([0.2, 0.2, 0.2, 0.2, 0.3].scramble).embedInStream } })
59                 ),
60                 Pbind(
61                         \octave, 4,
62                         \legato, 1.2,
63                         \dur, Proutine({ loop { Pseq([0.2, 0.2, 0.2, 0.2, 0.3].scramble * 5).embedInStream }})
64                 ),
65         ]),
66         Pstep(Pbind(
67                 \db, Pseq([0, -4, -2, -4, -3, -4, -3, -4], inf) - 20
68         ), 0.2),
69         Pstep(
70                 Pbind(
71                         \degree,        Pfunc({ {10.rand}.dup(10) }),
72                         \scale, Pfunc({ {rrand(1, 2)}.dup(7).integrate })
73                 ),
74                 5
75         )
76 ).play
81 // change one parameter
83 Pbind(
84         \degree, Pstep(Pseq([1, 2, 3, 4, 5]), 1.0).trace,
85         \dur, Pseries(0.1, 0.1, 15)
86 ).play;
90 // change degree independant of number of events that have been playing
93 var a, b;
94 a = Pbind(
95         \degree, Pstep(Pseq([0, 2b, 3], 1), 1.0),
96         \dur, Prand([0.2, 0.5, 1.1, 0.25, 0.15], inf)
98 b = Pbind(
99         \degree, Pseq([0, 2b, 3], 1),
100         \dur, 2,
101         \ctranspose, -7
103 Pseq([Event.silent(1.25), Ppar([a, b])], inf).play;
108 // test tempo changes
111 var a, b;
112 a = Pbind(
113         \degree, Pstep(Pseq([0, 2b, 3], 1), 1.0),
114         \dur, Prand([0.2, 0.5, 1.1, 0.25, 0.15], 9)
116 b = Pbind(
117         \degree, Pseq([0, 2b, 3], 1),
118         \dur, 2,
119         \ctranspose, -7
122 Ppar([a, b], inf).play;
126 SystemClock.sched(0, { TempoClock.default.tempo = [1, 2, 3, 5].choose.postln; 2 });
128 TempoClock.default.tempo = 1.0;
132 // timing test:
133 // parallel streams
137 var a, b, x;
138 var times, levels;
140 SynthDef(\pgrain,
141         { arg out = 0, freq=800, sustain=0.001, amp=0.5, pan = 0;
142                 var window;
143                 window = Env.sine(sustain, amp);
144                 Out.ar(out,
145                         Pan2.ar(
146                                 SinOsc.ar(freq) * EnvGen.ar(window, doneAction:2),
147                                 pan
148                         )
149                 )
150         }
151 ).add;
153 times = Pseq([3.4, 1, 0.2, 0.2, 0.2], inf);
154 levels = Pseq([0, 1, 2, 3, 4], inf);
156 a = Pstep(levels, times);
157 b = Pbind(\instrument, \pgrain, \octave, 7, \dur, 0.12, \degree, a);
158 x = times;
160 Ppar([b, Pset(\mtranspose, 2, b) ]).play;
162 b.play;
163 r {
164         var z = x.asStream; // direct times
165         0.5.wait;
166         loop {
167                 z.next.wait;
168                 s.makeBundle(0.2, {
169                         Synth(\pgrain, [\freq, 3000, \sustain, 0.01]); // signal tone
170                 })
171         }
172 }.play(quant:1)