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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
Platform {
classvar defaultStartupFile;
// IDE actions
classvar <>makeServerWindowAction, <>makeSynthDescWindowAction, <>openHelpFileAction, <>openHTMLFileAction;
var <classLibraryDir, <helpDir, <>recordingsDir, features;
var <>devpath;
*initClass {
defaultStartupFile = this.userConfigDir +/+ "startup.scd"
}
initPlatform {
classLibraryDir = thisMethod.filenameSymbol.asString.dirname.dirname;
helpDir = thisMethod.filenameSymbol.asString.dirname.dirname.dirname ++ "/Help";
features = IdentityDictionary.new;
recordingsDir = this.userAppSupportDir +/+ "Recordings";
}
name { ^this.subclassResponsibility }
recompile {
_Recompile
^this.primitiveFailed
}
*case { | ... cases |
^thisProcess.platform.name.switch(*cases)
}
// directories
*classLibraryDir { ^thisProcess.platform.classLibraryDir }
*helpDir { ^thisProcess.platform.helpDir }
userHomeDir {
_Platform_userHomeDir
^this.primitiveFailed
}
*userHomeDir { ^thisProcess.platform.userHomeDir }
systemAppSupportDir {
_Platform_systemAppSupportDir
^this.primitiveFailed
}
*systemAppSupportDir { ^thisProcess.platform.systemAppSupportDir }
userAppSupportDir {
_Platform_userAppSupportDir
^this.primitiveFailed
}
*userAppSupportDir { ^thisProcess.platform.userAppSupportDir }
systemExtensionDir {
_Platform_systemExtensionDir
^this.primitiveFailed
}
*systemExtensionDir { ^thisProcess.platform.systemExtensionDir }
userExtensionDir {
_Platform_userExtensionDir
^this.primitiveFailed
}
*userExtensionDir { ^thisProcess.platform.userExtensionDir }
userConfigDir {
_Platform_userConfigDir
^this.primitiveFailed
}
*userConfigDir { ^thisProcess.platform.userConfigDir }
resourceDir {
_Platform_resourceDir
^this.primitiveFailed
}
*resourceDir { ^thisProcess.platform.resourceDir }
*recordingsDir { ^thisProcess.platform.recordingsDir }
defaultTempDir { ^this.subclassResponsibility() }
*defaultTempDir { ^thisProcess.platform.defaultTempDir }
// The "ideName" is for ide-dependent compilation.
// From SC.app, the value is "scapp" meaning "scide_scapp" folders will be compiled and other "scide_*" ignored.
ideName {
_Platform_ideName
^this.primitiveFailed
}
*ideName { ^thisProcess.platform.ideName }
platformDir { ^this.name.asString }
*platformDir { ^thisProcess.platform.platformDir }
pathSeparator { ^this.subclassResponsibility }
*pathSeparator { ^thisProcess.platform.pathSeparator }
pathDelimiter{ ^this.subclassResponsibility }
*pathDelimiter { ^thisProcess.platform.pathDelimiter }
isPathSeparator { |char| ^this.subclassResponsibility }
*isPathSeparator { |char| ^thisProcess.platform.isPathSeparator(char) }
clearMetadata { |path| ^this.subclassResponsibility }
*clearMetadata { |path| ^thisProcess.platform.clearMetadata(path) }
// startup/shutdown hooks
startup { }
shutdown { }
startupFiles {
^[defaultStartupFile];
}
*deprecatedStartupFiles {|paths|
var postWarning = false;
paths.do {|path|
if (File.exists(path.standardizePath)) {
warn("Deprecated startup file found: %\n".format(path));
postWarning = true;
}
};
if (postWarning) {
postln("Please use % as startup file.\nDeprecated startup files will be ignored in future versions.\n".format(defaultStartupFile));
}
}
loadStartupFiles { this.startupFiles.do{|afile|
afile = afile.standardizePath;
if(File.exists(afile), {afile.load})
}
}
// features
declareFeature { | aFeature |
var str = aFeature.asString;
if (str.first.isUpper) {
Error("cannot declare class name features").throw;
};
if (str.first == $_) {
Error("cannot declare primitive name features").throw;
};
features.put(aFeature, true);
}
hasFeature { | symbol |
if (features.includesKey(symbol).not) {
features.put(
symbol,
symbol.asSymbol.asClass.notNil or: { symbol.isPrimitive }
)
};
^features.at(symbol)
}
when { | features, ifFunction, elseFunction |
^features.asArray.inject(true, { |v,x|
v and: { this.hasFeature(x) }
}).if(ifFunction, elseFunction)
}
*when { | features, ifFunction, elseFunction |
^thisProcess.platform.when(features, ifFunction, elseFunction)
}
// Prefer qt but fall back to swing if qt not installed.
defaultGUIScheme { if (GUI.get(\qt).notNil) {^\qt} {^\swing} }
// Predicate to check if SuperCollider was built with Qt.
*hasQt {
_Platform_hasQt
^this.primitiveFailed
}
// Predicate to check if SuperCollider was built with QtWebEngine
*hasQtWebEngine {
_Platform_hasQtWebEngine
^this.primitiveFailed
}
// Architecture for which this version of SuperCollider was built.
*architecture {
_Platform_architecture
^this.primitiveFailed
}
*hasBelaSupport {
_Platform_hasBelaSupport
^this.primitiveFailed
}
isSleeping { ^false } // unless defined otherwise
// used on systems to deduce a svn directory path, if system wide location is used for installed version. (tested on Linux).
devLoc{ |inpath|
var outpath;
if ( devpath.isNil ){ ^inpath };
outpath = inpath.copyToEnd( inpath.find( "SuperCollider") );
outpath = outpath.replace( "SuperCollider", devpath );
^outpath;
}
// hook for clients to write frontend.css
writeClientCSS {}
killProcessByID { |pid|
^this.subclassResponsibility(\killProcessByID)
}
killAll { |cmdLineArgs|
^this.subclassResponsibility(\killAll)
}
// used to format paths correctly for command-line calls
// On Windows, encloses with quotes; on Unix systems, escapes spaces.
formatPathForCmdLine { |path|
^this.subclassResponsibility
}
}
UnixPlatform : Platform {
pathSeparator { ^$/ }
pathDelimiter { ^$: }
isPathSeparator { |char|
^(char === this.pathSeparator)
}
clearMetadata { |path|
"rm -f %\.*meta".format(path.splitext[0].escapeChar($ )).systemCmd;
}
arch {
var pipe, arch;
pipe = Pipe("arch", "r");
arch = pipe.getLine;
pipe.close;
^arch.asSymbol;
}
killProcessByID { |pid|
("kill -9 " ++ pid).unixCmd;
}
killAll { |cmdLineArgs|
("killall -9 " ++ cmdLineArgs).unixCmd;
}
defaultTempDir {
// +/+ "" looks funny but ensures trailing slash
^["/tmp/", this.userAppSupportDir +/+ ""].detect({ |path|
File.exists(path);
});
}
formatPathForCmdLine { |path|
^path.escapeChar($ );
}
}
|