class library: Volume - remove debug message
[supercollider.git] / SCClassLibrary / Common / Quarks / packages.sc
blobff57ab96cd0e6edcdfa0eba32116603f453223ad
1 + Main {
2         // a package is either a quark or a folder in SCClassLibrary or extensions folders
4         // a class is in a 'package' determined by where its Class file is
5         // all folders in class library :
6                 // Common
7                 // JITlib
8                 // crucial
9                 // your own
10         // all folders in system extension
11         // all folders in user extension
12         // all quarks
13         // any loose files are placed in a packaged calle SCClassLibrary or Extensions
14                 // possiblity for error: if you have loose files in user extensions and system extensions
15                 // they will both be placed in the same package: Extensions
17         // [ name -> folderPath, name -> folderPath ... ]
18         *packages {
20                 var platform,scClassLibrary,looseFiles;
21                 var packages,f;
23                 // cache
24                 packages = Library.at(Quarks,\packages);
25                 if(packages.notNil,{ ^packages });
27                 platform = thisProcess.platform;
29                 f = { arg dir;
30                         var folders,packages,paths,files;
31                         dir = dir.withTrailingSlash;
32                         paths = (dir++"*").pathMatch;
33                         folders = paths.reject({ |p| p.last != $/ or: {p.basename == "quarks"} });
34                         files = paths.select({ |p| p.last != $/ });
35                         packages = folders.collect({ |p| p.basename.asSymbol -> p });
36                         if(files.notEmpty,{
37                                 // if there are any loose files then create a package called dir
38                                 packages = packages.add( dir.basename.asSymbol -> dir )
39                         });
40                         packages
41                 };
43                 packages =
44                         (f.value(platform.classLibraryDir)
46                         ++
48                         f.value(platform.systemExtensionDir)
50                         ++
52                         Quarks.installed.collect({ |q|
53                                 q.name.asSymbol -> (Platform.userExtensionDir +/+ "quarks" +/+ q.path.withTrailingSlash)
54                         }))
55                         .sort({ |a,b| a.value.size > b.value.size }) // sort longer paths first
57                         ++
59                         f.value(platform.userExtensionDir);
60                 Library.put(Quarks,\packages,packages);
61                 ^packages
62         }
65 + Class {
66         package {
67                 var path;
68                 path = this.filenameSymbol.asString;
69                 Main.packages.do({ |namepath|
70                         if(path.copyRange(0,namepath.value.size-1) == namepath.value,{
71                                 ^namepath.key
72                         })
73                 });
74                 Error("Discrepancy: Package not found for class !").throw;
75         }
79         method
80                 extensions:
81                         may not be the package that its class is in
83 + Method {
84         package {
85                 var path;
86                 path = this.filenameSymbol.asString;
87                 Main.packages.do({ |namepath|
88                         if(path.copyRange(0,namepath.value.size-1) == namepath.value,{
89                                 ^namepath.key
90                         })
91                 });
92                 Error("Discrepancy: Package not found for method !").throw;
93         }
97 + Quark {
99         definesClasses {
100                 var myPath,end;
101                 myPath = Platform.userExtensionDir +/+ "quarks" +/+ this.path;
102                 end = myPath.size-1;
103                 ^Class.allClasses.reject(_.isMetaClass).select({ |class|
104                         class.filenameSymbol.asString.copyRange(0,end) == myPath
105                 })
106         }
107         definesExtensionMethods {
108                 // all methods whose path is in this quark folder
109                 // where the class is not in this quark
110                 var myPath,end;
111                 myPath = Platform.userExtensionDir +/+ "quarks" +/+  this.path;
112                 end = myPath.size-1;
113                 ^Class.allClasses.collect({ |c| c.methods }).reject(_.isNil).flat
114                         .select({ |method|
115                                 method.filenameSymbol.asString.copyRange(0,end) == myPath
116                                 and: {
117                                         method.ownerClass.filenameSymbol.asString.copyRange(0,end) != myPath
118                                 }
119                         })
120         }
121         // of the classes you defined, what packages are the superclasses in ?
122         // of the extension methods you defined, what packages are the super classes in ?
123         /*      checkDependencies {
125         }*/
128 + Quarks {
129         // the equivalent to Quark-definesClasses
130         // but works for non-quarks like Quarks.classesInPackage("JITlib")
131         *classesInPackage { |packageName|
132                 var myPath,end,package;
133                 package = Main.packages.detect({ |pk| pk.key == packageName });
134                 if(package.isNil,{ Error("Package not found:"+packageName).throw });
136                 myPath = package.value;
137                 end = myPath.size-1;
138                 ^Class.allClasses.select({ |class|
139                         class.isMetaClass.not and: {
140                                 class.filenameSymbol.asString.copyRange(0,end) == myPath
141                         }
142                 })
143         }