cmake build system: visiblity support for clang
[supercollider.git] / SCClassLibrary / Common / Control / SkipJack.sc
blobe6960c8f3b0cc5454e38e6de19e6ef5c1d821e4c
1 SkipJack {
3         classvar <>verbose = false, <all, <defaultClock;
4         var <updateFunc, <>dt, <>stopTest, <name, <clock, <task, restartFunc;
6         *new { arg updateFunc, dt = 0.2, stopTest = false, name = "anon", clock, autostart=true;
7                 ^super.newCopyArgs(updateFunc, dt, stopTest, name, clock).init( autostart );
8         }
10         *initClass {
11                 this.stopAll;
12                 all = IdentitySet[];
13                 defaultClock = AppClock;
14         }
16         *stop { |name| all.do { |skip| if (skip.name == name) { skip.stop } }; }
18         *stopAll { all.do(_.stop).clear; }
20         init { |autostart=true|
21                 task = Routine {
22                         if( verbose ) { ("SkipJack" + name + "starts.").postcln };
23                         while { dt.value.wait; stopTest.value.not } { updateFunc.value(this) };
24                         this.stop;
25                 };
26                 if ( autostart ) { this.start };
27         }
29         cmdPeriod {
30                 task.play(clock ? defaultClock);
31                 if( verbose ) { ("SkipJack" + name + "is back up.").postcln };
32         }
34         start {
35                 if(task.isPlaying) {
36                         if( verbose ) { ("SkipJack" + name + "already playing.").postcln };
37                         ^this;
38                 };
39                 task.reset.play(clock ? defaultClock);
40                 all.add(this);
41                 CmdPeriod.add(this);
42                 if( verbose ) { ("SkipJack" + name + "started.").postcln };
43         }
45         play { this.start }
47         stop {
48                 task.stop;
49                 all.remove(this);
50                 CmdPeriod.remove(this);
51                 if( verbose ) { ("SkipJack" + name + "stopped.").postcln };
52         }
55 Watcher : SkipJack {
56         *new { arg name = "anon", updateFunc, dt=0.2, stopTest = false;
57                 "Watcher is only for backward compatibility, use SkipJack!".postln;
58                 ^super.newCopyArgs(updateFunc, dt, stopTest, name).init.start;
59         }