File: SkipJack.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (60 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download | duplicates (2)
1
2
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
SkipJack {

	classvar <>verbose = false, <all, <defaultClock;
	var <updateFunc, <>dt, <>stopTest, <name, <clock, <task, restartFunc;

	*new { arg updateFunc, dt = 0.2, stopTest = false, name = "anon", clock, autostart=true;
		^super.newCopyArgs(updateFunc, dt, stopTest, name, clock).init( autostart );
	}

	*initClass {
		this.stopAll;
		all = IdentitySet[];
		defaultClock = AppClock;
	}

	*stop { |name| all.copy.do { |skip| if (skip.name == name) { skip.stop } } }

	*stopAll { all.copy.do(_.stop).clear }

	init { |autostart=true|
		task = Routine {
			if( verbose ) { ("SkipJack" + name + "starts.").postcln };
			while { dt.value.wait; stopTest.value.not } { updateFunc.value(this) };
			this.stop;
		};
		if ( autostart ) { this.start };
	}

	cmdPeriod {
		task.play(clock ? defaultClock);
		if( verbose ) { ("SkipJack" + name + "is back up.").postcln };
	}

	start {
		if(task.isPlaying) {
			if( verbose ) { ("SkipJack" + name + "already playing.").postcln };
			^this;
		};
		task.reset.play(clock ? defaultClock);
		all.add(this);
		CmdPeriod.add(this);
		if( verbose ) { ("SkipJack" + name + "started.").postcln };
	}

	play { this.start }

	stop {
		task.stop;
		all.remove(this);
		CmdPeriod.remove(this);
		if( verbose ) { ("SkipJack" + name + "stopped.").postcln };
	}
}

Watcher : SkipJack {
	*new { arg name = "anon", updateFunc, dt=0.2, stopTest = false;
		"Watcher is only for backward compatibility, use SkipJack!".postln;
		^super.newCopyArgs(updateFunc, dt, stopTest, name).init.start;
	}
}