scide: implement selectionLength for openDocument
[supercollider.git] / HelpSource / Classes / Sweep.schelp
blob3a3580c819eb3dbf22a0efc3b421b3d07908b322
1 class:: Sweep
2 summary:: Triggered linear ramp
3 categories::  UGens>Triggers
5 Description::
7 Starts a linear raise by rate/sec from zero when trig input crosses from
8 non-positive to positive.
11 classmethods::
12 private:: categories
14 method::ar, kr
16 argument::trig
18 triggers when trig input crosses from non-positive to positive.
21 argument::rate
23 rate/sec raise rate
26 Examples::
28 code::
29 // using sweep to modulate sine frequency
31 { var trig;
32         trig = Impulse.kr(MouseX.kr(0.5, 20, 1));
33         SinOsc.ar(Sweep.kr(trig, 700) + 500, 0, 0.2)
34 }.play;
38 // using sweep to index into a buffer
39 b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
42 { var trig;
43         trig = Impulse.kr(MouseX.kr(0.5, 10, 1));
44         BufRd.ar(1, b, Sweep.ar(trig, BufSampleRate.ir(0)))
45 }.play;
48 // backwards, variable offset
50 { var trig, pos, rate;
51         trig = Impulse.kr(MouseX.kr(0.5, 10, 1));
52         rate = BufSampleRate.ir(0);
53         pos = Sweep.ar(trig, rate.neg) + (BufFrames.ir(0) * LFNoise0.kr(0.2));
54         BufRd.ar(1, b, pos)
55 }.play;
58 // raising rate
60 { var trig, rate;
61         trig = Impulse.kr(MouseX.kr(0.5, 10, 1));
62         rate = Sweep.kr(trig, 2) + 0.5;
63         BufRd.ar(1, b, Sweep.ar(trig, BufSampleRate.ir(0) * rate))
64 }.play;
67 b.free
71 Sweep can be used as a resettable link::Classes/Phasor:: or link::Classes/Line:: - one that can start, pause, resume and stop. To get a resettable link::Classes/XLine:: behavior change the code::linlin:: to code::linexp:: in the SynthDef below.
72 code::
74 SynthDef(\lineReset, {|start= 0, end= 1, dur= 1, t_trig= 1, run= 1|
75         var phasor= (Sweep.ar(t_trig, 1/dur*run)).linlin(0, 1, start, end, \minmax);
76         phasor.poll;
77         Out.ar(0, SinOsc.ar(phasor, 0, 0.2));
78 }).add;
80 a= Synth(\lineReset, [\start, 400, \end, 800, \dur, 2])
81 a.set(\t_trig, 1)
82 a.set(\run, 0)
83 a.set(\run, 1)
84 a.set(\t_trig, 1)
85 a.free
87 //shorter duration and downwards...
88 a= Synth(\lineReset, [\start, 1000, \end, 500, \dur, 0.5])
89 a.set(\t_trig, 1)
90 a.set(\run, 0)
91 a.set(\run, 1)
92 a.set(\t_trig, 1)
93 a.free