File: SystemActions.sc

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (209 lines) | stat: -rw-r--r-- 3,504 bytes parent folder | download | duplicates (5)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
AbstractSystemAction {

	*init {
		this.objects = List.new;
	}

	*add { arg object;
		if(this.objects.isNil) { this.init }; // lazy init
		if(this.objects.includes(object).not) { this.objects.add(object) }
	}

	*remove { arg object;
		this.objects.remove(object)
	}

	*removeAll {
		this.init
	}


	*objects { ^this.shouldNotImplement(thisMethod) }
	*objects_ { arg obj; ^this.shouldNotImplement(thisMethod) }
}



// things to clear when hitting cmd-.

CmdPeriod : AbstractSystemAction {
	classvar <>objects;
	classvar <era = 0;
	classvar <>clearClocks = true;
	classvar <>freeServers = true;
	classvar <>freeRemote = false;



	*doOnce { arg object;
		var f = { this.remove(f); object.doOnCmdPeriod  };
		this.add(f);
	}
	*run {
		if(clearClocks, {
			SystemClock.clear;
			AppClock.clear;
		});

		objects.copy.do({ arg item; item.doOnCmdPeriod;  });

		if(freeServers, {
			Server.freeAll(freeRemote); // stop all sounds on local, or remote servers
			Server.resumeThreads;
		});

		era = era + 1;

	}

	*hardRun {

		SystemClock.clear;
		AppClock.clear;
		TempoClock.default.clear;

		objects.copy.do({ arg item; item.doOnCmdPeriod;  });



		Server.hardFreeAll; // stop all sounds on local servers
		Server.resumeThreads;
		era = era + 1;

	}


}


// things to do after startup file executed

StartUp : AbstractSystemAction {


	classvar <>objects, <done=false;


	*run {
		done = true;
		objects.copy.do({ arg item; item.doOnStartUp  });
		// "StartUp done.".postln;
	}


	*defer { arg object;
		if(done) { object.doOnStartUp } { this.add(object) }
	}


}


// things to do before system shuts down

ShutDown : AbstractSystemAction {

	classvar <>objects;

	*run {
		objects.copy.do({ arg item; item.doOnShutDown;  });
	//	"ShutDown done.".postln;
	}

}

// things to do on a system reset
OnError : AbstractSystemAction {
	classvar <>objects;

	*run {
		objects.copy.do({ arg item; item.doOnError;  });
	}
}


AbstractServerAction : AbstractSystemAction {

	*init {
		this.objects = IdentityDictionary.new;
	}

	*performFunction { arg server, function;
		if (this.objects.notNil) {
			this.objects.at(server).copy.do(function);
			if(server === Server.default) {
				this.objects.at(\default).copy.do(function)
			};
			this.objects.at(\all).copy.do(function);
		}
	}

	*run { arg server;
		var selector = this.functionSelector;
		// selector.postln;
		this.performFunction(server, { arg obj; obj.perform(selector, server) });
	}

	*functionSelector {
		^this.subclassResponsibility(thisMethod)
	}

	*add { arg object, server;
		var list;
		if (server.isNil)  { server = \all };
		if (this.objects.isNil) { this.init };
		list = this.objects.at(server);
		if (list.isNil) { list = List.new; this.objects.put(server, list) };
		if (list.includes(object).not) { list.add(object) };
	}

	*addToAll { arg object;
		this.add(object, \all);
	}

	*remove { arg object, server;
		if(server.isNil) { server = \all };
		this.objects !? { this.objects.at(server).remove(object) };
	}

	*removeServer { arg server;
		this.objects.removeAt(server)
	}
}

// things to do after server has booted


ServerBoot : AbstractServerAction {

	classvar <>objects;

	*functionSelector {
		^\doOnServerBoot
	}
}

// things to do after server has quit


ServerQuit : AbstractServerAction {

	classvar <>objects;

	*functionSelector {
		^\doOnServerQuit
	}
}


// things to do after server has booted and initialised


ServerTree : AbstractServerAction {

	classvar <>objects;

	*functionSelector {
		^\doOnServerTree
	}
}