deprecate old Help class
[supercollider.git] / SCClassLibrary / DefaultLibrary / Main.sc
blobf6052ed325b7f9177d9f0125f43d008e2dacb6dc
1 Main : Process {
2         var <platform, argv;
3         var recvOSCfunc, prRecvOSCFunc;
4         var openPorts;
6                 // proof-of-concept: the interpreter can set this variable when executing code in a file
7                 // should be nil most of the time
9         startup {
10             var didWarnOverwrite = false;
11                 // setup the platform first so that class initializers can call platform methods.
12                 // create the platform, then intialize it so that initPlatform can call methods
13                 // that depend on thisProcess.platform methods.
14                 platform = this.platformClass.new;
15                 platform.initPlatform;
17                 super.startup;
19                 // set the 's' interpreter variable to the default server.
20                 interpreter.s = Server.default;
21                 GUI.fromID( this.platform.defaultGUIScheme );
22                 GeneralHID.fromID( this.platform.defaultHIDScheme );
23                 this.platform.startup;
24                 StartUp.run;
25                 openPorts = Set[NetAddr.langPort];
27                 ("Welcome to SuperCollider" + Main.version
28                         ++ (Platform.ideName.switch(
29                                 "scvim", {", type :SChelp for help"},
30                                 "scel",  {", type C-c C-y for help"},
31                                 "sced",  {", type ctrl-U for help"},
32                                 "scapp", {", type cmd-d for help"}
33                         ) ?? {
34                                 (
35                                         osx: ", type cmd-d for help",
36                                         linux: ", for help type ctrl-c ctrl-h (Emacs) or :SChelp (vim) or ctrl-U (sced/gedit)",
37                                         windows: ", press F1 for help",
38                                         iphone: ""
39                                  ).at(platform.name);
41                         })
42                 ).postln;
44                 Main.overwriteMsg.split(Char.nl).drop(-1).collect(_.split(Char.tab)).do {|x|
45                         if(x[2].beginsWith(Platform.classLibraryDir) and: {x[1].contains(""+/+"SystemOverwrites"+/+"").not}
46                         ) {
47                                 warn("Extension in '%' overwrites % in main class library.".format(x[1],x[0]));
48                                 didWarnOverwrite = true;
49                         }
50                 };
51                 if(didWarnOverwrite) {
52                         inform("\nIntentional overwrites must be put in a 'SystemOverwrites' subfolder.")
53                 }
54         }
56         shutdown { // at recompile, quit
57                 Server.quitAll;
58                 this.platform.shutdown;
59                 super.shutdown;
60         }
62         run { // used to be called by command-R, customisation now via CocoaMenuItem
63                 //interpreter.interpretPrintCmdLine;
64         }
66         stop { // called by command-.
67                 CmdPeriod.run;
68         }
70         hardStop { // called by command alt dot
71                 CmdPeriod.hardRun;
72         }
74         recvOSCmessage { arg time, replyAddr, recvPort, msg;
75                 // this method is called when an OSC message is received.
76                 recvOSCfunc.value(time, replyAddr, msg);
77                 prRecvOSCFunc.value(msg, time, replyAddr, recvPort); // same order as OSCFunc
78                 OSCresponder.respond(time, replyAddr, msg);
79         }
81         recvOSCbundle { arg time, replyAddr, recvPort ... msgs;
82                 // this method is called when an OSC bundle is received.
83                 msgs.do({ arg msg;
84                         this.recvOSCmessage(time, replyAddr, recvPort, msg);
85                 });
86         }
88         addOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.addFunc(func) }
90         removeOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.removeFunc(func) }
92         replaceOSCRecvFunc { |func, newFunc| prRecvOSCFunc = prRecvOSCFunc.replaceFunc(func, newFunc) }
94         openPorts { ^openPorts.copy } // don't allow the Set to be modified from the outside
96         openUDPPort {|portNum|
97                 var result;
98                 if(openPorts.includes(portNum), {^true});
99                 result = this.prOpenUDPPort(portNum);
100                 if(result, { openPorts = openPorts.add(portNum); });
101                 ^result;
102         }
104         prOpenUDPPort {|portNum|
105                 _OpenUDPPort
106                 ^false
107         }
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 {^[this.scVersionMajor, ".", this.scVersionMinor, this.scVersionPostfix].join}
145         *versionAtLeast { |maj, min|
146                 ^if((maj==this.scVersionMajor) and:{min.notNil}){
147                         this.scVersionMinor >= min
148                 }{
149                         this.scVersionMajor >= maj
150                 };
151         }
153         *versionAtMost { |maj, min|
154                 ^if((maj==this.scVersionMajor) and:{min.notNil}){
155                         this.scVersionMinor <= min
156                 }{
157                         this.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         }