HelpBrowser: path box becomes a more conventional search box
[supercollider.git] / SCClassLibrary / Common / Control / SystemActions.sc
blobd83f1c4a1cac6e6518cc724c35092ecfe2fff68b
1 AbstractSystemAction {
3         *init {
4                 this.objects = List.new;
5         }
7         *add { arg object;
8                 if(this.objects.isNil) { this.init }; // lazy init
9                 if(this.objects.includes(object).not) { this.objects.add(object) }
10         }
12         *remove { arg object;
13                 this.objects.remove(object)
14         }
16         *removeAll {
17                 this.init
18         }
21         *objects { ^this.shouldNotImplement(thisMethod) }
22         *objects_ { arg obj; ^this.shouldNotImplement(thisMethod) }
27 // things to clear when hitting cmd-.
29 CmdPeriod : AbstractSystemAction {
30         classvar <>objects;
31         classvar <era = 0;
32         classvar <>clearClocks = true;
33         classvar <>freeServers = true;
34         classvar <>freeRemote = false;
38         *doOnce { arg object;
39                 var f = { this.remove(f); object.doOnCmdPeriod  };
40                 this.add(f);
41         }
42         *run {
43                 if(clearClocks, {
44                         SystemClock.clear;
45                         AppClock.clear;
46         //              TempoClock.default.clear;
47                 });
49                 objects.copy.do({ arg item; item.doOnCmdPeriod;  });
51                 if(freeServers, {
52                         Server.freeAll(freeRemote); // stop all sounds on local, or remote servers
53                         Server.resumeThreads;
54                 });
56                 era = era + 1;
58         }
60         *hardRun {
62                 SystemClock.clear;
63                 AppClock.clear;
64                 TempoClock.default.clear;
66                 objects.copy.do({ arg item; item.doOnCmdPeriod;  });
70                 Server.hardFreeAll; // stop all sounds on local servers
71                 Server.resumeThreads;
72                 era = era + 1;
74         }
80 // things to do after startup file executed
82 StartUp : AbstractSystemAction {
85         classvar <>objects, <done=false;
88         *run {
89                 done = true;
90                 objects.copy.do({ arg item; item.doOnStartUp  });
91                 // "StartUp done.".postln;
92         }
95         *defer { arg object;
96                  if(done) { object.doOnStartUp } { this.add(object) }
97         }
103 // things to do before system shuts down
105 ShutDown : AbstractSystemAction {
107         classvar <>objects;
109         *initClass {
110                 UI.registerForShutdown({ this.run });
111         }
113         *run {
114                 objects.copy.do({ arg item; item.doOnShutDown;  });
115         //      "ShutDown done.".postln;
116         }
121 AbstractServerAction : AbstractSystemAction {
123         *init {
124                 this.objects = IdentityDictionary.new;
125         }
127         *performFunction { arg server, function;
128                 this.objects.at(server).copy.do(function);
129                 if(server === Server.default) {
130                         this.objects.at(\default).copy.do(function)
131                 };
132                 this.objects.at(\all).copy.do(function);
133         }
135         *run { arg server;
136                 var selector = this.functionSelector;
137                 // selector.postln;
138                 this.performFunction(server, { arg obj; obj.perform(selector, server) });
139         }
141         *functionSelector {
142                 ^this.subclassResponsibility(thisMethod)
143         }
145         *add { arg object, server;
146                 var list;
147                 if(server.isNil) { server = \default };
148                 list = this.objects.at(server);
149                 if(list.isNil) { list = List.new; this.objects.put(server, list) };
150                 if (list.includes(object).not) { list.add(object) };
152         }
154         *addToAll { arg object;
156                 Server.set.do({ arg s; this.add(object, s) });
158         }
160         *remove { arg object, server;
162                 if(server.isNil) { server = \default };
163                 this.objects.at(server).remove(object);
165         }
167         *removeServer { arg server;
168                 this.objects.removeAt(server)
169         }
173 // things to do after server has booted
176 ServerBoot : AbstractServerAction {
178         classvar <>objects;
180         *initClass {
181                 this.objects = IdentityDictionary.new;
182         }
184         *functionSelector {
185                 ^\doOnServerBoot
186         }
190 // things to do after server has quit
193 ServerQuit : AbstractServerAction {
195         classvar <>objects;
197         *initClass {
198                 this.objects = IdentityDictionary.new;
199         }
201         *functionSelector {
202                 ^\doOnServerQuit
203         }
208 // things to do after server has booted and initialised
211 ServerTree : AbstractServerAction {
214         classvar <>objects;
217         *initClass {
218                 this.objects = IdentityDictionary.new;
219         }
221         *functionSelector {
222                 ^\doOnServerTree
223         }