SCDoc: Use proper static string constants instead of comparing string literals.
[supercollider.git] / SCClassLibrary / Common / Streams / PatternConductor.sc
blobeceadab068e39786242e89f1e079915cb6d9721a
1 /*
2         PatternConductor provides interactive control of patterns. When a Conductor
3 is stopped it flushes its queue, immediately ending any notes left hanging by
4 the pattern.
6 */
8 PatternConductor  {
10         var <>patterns, <>event, <>quant, <>eventStreamPlayers;
11         var <>clock, <tempo, <>defaultPauseTempo, <>defaultStopTempo;
12         *new { |patterns, event, quant|
13                 ^super.new
14                         .patterns_(patterns.asArray)
15                         .event_(event ? Event.default)
16                         .quant_(quant ? 0).tempo_(1).defaultPauseTempo_(1e-8).defaultStopTempo_(1e+8);
17         }
19         play {
21                 Routine.run({ this.prPlay }, 64, TempoClock.default, quant)
22         }
24         prPlay {
25                 if (clock.notNil) { this.stop };
26                 CmdPeriod.add(this);
27                 clock = TempoClock(tempo);
28                 eventStreamPlayers = patterns.collect { | p | p.asEventStreamPlayer(event) };
29                 eventStreamPlayers.do { | p | p.play(clock, false, 0) };
30         }
31         pause { | pauseTempo| clock.tempo = pauseTempo ? defaultPauseTempo }
32         resume {  clock.tempo = tempo }
34         stop { |stopTempo|
35                 var oldClock;
36                 oldClock = clock;
37                 eventStreamPlayers.do { | p | p.stop };
38                 clock.tempo = stopTempo ? defaultStopTempo;
39                 Task({ while {oldClock.queue.size >= 2 } { yield(1) }; oldClock.stop }).play(clock);
40                 clock = nil;
41                 eventStreamPlayers = nil;
42                 CmdPeriod.remove(this);
43         }
45         tempo_ { | temp |
46                 tempo = temp;
47                 if (clock.notNil) { clock.tempo_(tempo) };
48         }
49         cmdPeriod { clock = nil }