sclang: ServerShmInterface - avoid object duplication in deepCopy
[supercollider.git] / SCClassLibrary / DefaultLibrary / Main.sc
blob19079d08862f001fd59c25a10c44baf572f21554
1 Main : Process {
2         // do not change the next lines manually:
3         //==== replace with new version from bash script ====
4 classvar scVersionMajor=3, scVersionMinor=5, scVersionPostfix="beta";
5         //==== end replace ====
7         var <platform, argv;
8         var recvOSCfunc, prRecvOSCFunc;
9         var <customPorts;
11                 // proof-of-concept: the interpreter can set this variable when executing code in a file
12                 // should be nil most of the time
14         startup {
15             var didWarnOverwrite = false;
16                 // setup the platform first so that class initializers can call platform methods.
17                 // create the platform, then intialize it so that initPlatform can call methods
18                 // that depend on thisProcess.platform methods.
19                 platform = this.platformClass.new;
20                 platform.initPlatform;
22                 super.startup;
24                 // set the 's' interpreter variable to the default server.
25                 interpreter.s = Server.default;
26                 GUI.fromID( this.platform.defaultGUIScheme );
27                 GeneralHID.fromID( this.platform.defaultHIDScheme );
28                 this.platform.startup;
29                 StartUp.run;
31                 ("Welcome to SuperCollider" + Main.version
32                         ++ (Platform.ideName.switch(
33                                 "scvim", {", type :SChelp for help"},
34                                 "scel",  {", type ctrl-c ctrl-h for help"},
35                                 "sced",  {", type ctrl-U for help"},
36                                 "scapp", {", type cmd-d for help"}
37                         ) ?? {
38                                 (
39                                         osx: ", type cmd-d for help",
40                                         linux: ", for help type ctrl-c ctrl-h (Emacs) or :SChelp (vim) or ctrl-U (sced/gedit)",
41                                         windows: ", press F1 for help",
42                                         iphone: ""
43                                  ).at(platform.name);
45                         })
46                 ).postln;
48                 Main.overwriteMsg.split(Char.nl).drop(-1).collect(_.split(Char.tab)).do {|x|
49                         if(x[2].beginsWith(Platform.classLibraryDir) and: {x[1].contains("/SystemOverwrites/").not}
50                         ) {
51                                 warn("Extension in '%' overwrites % in main class library.".format(x[1],x[0]));
52                                 didWarnOverwrite = true;
53                         }
54                 };
55                 if(didWarnOverwrite) {
56                         inform("\nIntentional overwrites must be put in a 'SystemOverwrites' subfolder.")
57                 }
58         }
60         shutdown { // at recompile, quit
61                 Server.quitAll;
62                 this.platform.shutdown;
63                 super.shutdown;
64         }
66         run { // used to be called by command-R, customisation now via CocoaMenuItem
67                 //interpreter.interpretPrintCmdLine;
68         }
70         stop { // called by command-.
71                 CmdPeriod.run;
72         }
74         hardStop { // called by command alt dot
75                 CmdPeriod.hardRun;
76         }
78         recvOSCmessage { arg time, replyAddr, recvPort, msg;
79                 // this method is called when an OSC message is received.
80                 recvOSCfunc.value(time, replyAddr, msg);
81                 prRecvOSCFunc.value(msg, time, replyAddr, recvPort); // same order as OSCFunc
82                 OSCresponder.respond(time, replyAddr, msg);
83         }
85         recvOSCbundle { arg time, replyAddr, recvPort ... msgs;
86                 // this method is called when an OSC bundle is received.
87                 msgs.do({ arg msg;
88                         this.recvOSCmessage(time, replyAddr, recvPort, msg);
89                 });
90         }
92         addOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.addFunc(func) }
93         
94         removeOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.removeFunc(func) }
95         
96         replaceOSCRecvFunc { |func, newFunc| prRecvOSCFunc = prRecvOSCFunc.replaceFunc(func, newFunc) }
97         
98         openUDPPort {|portNum|
99                 var result;
100                 result = this.prOpenUDPPort(portNum);
101                 if(result, { customPorts = customPorts ++ [portNum]; });
102                 ^result;
103         }
104         
105         prOpenUDPPort {|portNum|
106                 _OpenUDPPort
107         }
108         
109         newSCWindow {
110                 var win, palette;
111                 win = SCWindow("construction");
112                 win.front;
113                 win.toggleEditMode;
114         }
116 //      override in platform specific extension
118 //      platformClass {
119 //              ^Platform
120 //      }
122         argv {
123                 ^argv ?? { argv = this.prArgv }
124         }
126         showHelpBrowser {
127                 HelpBrowser.openBrowsePage;
128         }
129         showHelpSearch {
130                 HelpBrowser.openSearchPage(this.getCurrentSelection);
131         }
132         showHelp {
133                 HelpBrowser.openHelpFor(this.getCurrentSelection);
134         }
136         showClassBrowser {
137                 var string, class, method, words;
138                 string = interpreter.cmdLine;
139                 class = string.asSymbol.asClass;
140                 (class ? Object).browse;
141         }
143         *version {^[scVersionMajor, ".", scVersionMinor, scVersionPostfix].join}
145         *versionAtLeast { |maj, min|
146                 ^if((maj==scVersionMajor) and:{min.notNil}){
147                         scVersionMinor >= min
148                 }{
149                         scVersionMajor >= maj
150                 };
151         }
153         *versionAtMost { |maj, min|
154                 ^if((maj==scVersionMajor) and:{min.notNil}){
155                         scVersionMinor <= min
156                 }{
157                         scVersionMajor <= maj
158                 };
159         }
161         pid {
162                 _GetPid
163                 ^this.primitiveFailed
164         }
166         // PRIVATE
167         prArgv {
168                 _Argv
169                 ^[]
170         }
172         recompile { platform.recompile }
174         escapeWindow { platform.escapeWindow }
176         exitFullScreen { platform.exitFullScreen }
178         setDeferredTaskInterval { |interval| platform.setDeferredTaskInterval(interval) }
180         *overwriteMsg { _MainOverwriteMsg ^this.primitiveFailed }
184 MethodOverride {
185         var <ownerClass, <selector, <activePath, <overriddenPath;
187         *new { arg ownerClass, selector, activePath, overriddenPath;
188                 ^super.newCopyArgs(ownerClass, selector, activePath, overriddenPath)
189         }
191         *fromLine { arg string;
192                 var parts = string.split(Char.tab);
193                 var class, selector;
194                 #class, selector = parts[0].split($:);
195                 ^this.new(class.asSymbol.asClass, selector, parts[1], parts[2])
196         }
198         openFiles {
199                 var path2 = if(overriddenPath.beginsWith("/Common")) {
200                         Platform.classLibraryDir +/+ overriddenPath
201                         } { overriddenPath };
202                 activePath.openTextFile;
203                 path2.openTextFile;
204         }
206         *simplifyPath { arg path;
207                 var extDir, sysExtDir, quarkDir;
208                 extDir = Platform.userExtensionDir;
209                 sysExtDir = Platform.systemExtensionDir;
210                 quarkDir = LocalQuarks.globalPath;
211                 path = path.replace("'" ++ extDir, "Platform.userExtensionDir ++ '");
212                 path = path.replace("'" ++ sysExtDir, "Platform.systemExtensionDir ++ '");
213                 path = path.replace("'" ++ quarkDir, "LocalQuarks.globalPath ++ '");
214                 ^path
216         }
218         *all {
219                 var msg = Main.overwriteMsg.drop(-1); // drop last newline
220                 var lines = msg.split(Char.nl);
221                 ^lines.collect { |line| this.fromLine(line) };
222         }
224         *printAll { arg simplifyPaths = true;
225                 var all = this.all;
226                 var classes = all.collect(_.ownerClass).as(Set);
227                 if(all.isEmpty) { "There are no overwritten methods in class library".postln; ^this };
228                 ("Overwritten methods in class library:".underlined ++ "\n\n").post;
229                 classes.do { |class|
230                         class.asString.underlined.postln;
231                         all.select { |x| x.ownerClass == class }.do { |x|
232                                 var activePath = x.activePath;
233                                 var overriddenPath = x.overriddenPath;
234                                 if(simplifyPaths) {
235                                         activePath = this.simplifyPath(x.activePath);
236                                         overriddenPath = this.simplifyPath(x.overriddenPath);
237                                 };
238                                 ("\t" ++ x.ownerClass.name ++ ":" ++ x.selector).postln;
239                                 ("\t\t" ++ activePath).postln;
240                                 ("\t\t" ++ overriddenPath).postln;
241                         };
242                         "\n".post;
243                 }
244         }
246         *printAllShort {
247                 var all = this.all;
248                 var classes = all.collect(_.ownerClass).as(Set);
249                 if(all.isEmpty) { "There are no overwritten methods in class library".postln; ^this };
250                 ("Overwritten methods in class library:".underlined ++ "\n").post;
251                 classes.do { |class|
252                         all.select { |x| x.ownerClass == class }.collect { |x| x.selector }.as(Set).do { |x|
253                                 postf("\t%:%\n", class, x);
254                         }
255                 }
256         }