1 title:: Internal Snooping
2 summary:: Snooping around SuperCollider
5 You can inspect much of the internal structure of the class library and other data structures.
6 This can often be useful for research and debugging purposes.
8 warning:: The keyboard shortcuts mentioned here only applies to the Mac SC.app. This document should probably be updated. ::
10 section:: Class Definitions, Implementations, and References
12 Selecting the name of any Class (e.g. Object) and typing cmd-j will open its class definition file.
14 note:: Any keypresses that open files identify the files using SuperCollider strings, which may contain only ASCII characters up to code point 127. If any part of the path to your SuperCollider installation contains character codes greater than 127 (such as the old Mac convention of identifying program folders with option-F), automatic file opening will fail. ::
16 Selecting the name of any method (e.g. play) and typing cmd-y will open a window showing all implementations of that method and their arguments. Selecting one of those classes and methods (e.g. Sample:play) and typing cmd-j will open the class definition at that method. (Note that cmd-y only shows implementations, and does not indicate inheritance).
18 Selecting any text (e.g. SCWindow or asStream) and typing shift-cmd-y will open a window showing all references to the selected text, i.e. each place it is used within the class library. (This will not find methods calls compiled with special byte codes like 'value'.)
20 SC has a graphical Class browser which will show all methods, arguments, subclasses, instance variables and class variables. Using the browser's buttons you can easily navigate to the class' superclass, subclasses, class source, method source, helpfile (if there is one), check references or implementation of methods, or even open a web browser to view the corresponding entry in the online SVN repository.
22 SequenceableCollection.browse;
25 subsection:: Snooping in Classes
27 The link::Classes/Class:: help file documents some of these snooping methods.
28 Even though you may access these data structures, if you store things into them, you may break something.
30 Collection.dumpInterface; // print all instance methods defined for this class
32 Collection.class.dumpInterface; // print all class methods defined for this class
35 // The following three include inherited methods
37 Collection.methods.collect(_.name); // print all instance methods that instances of this class respond to
39 Collection.class.methods.collect(_.name); // print all class methods that this class responds to
41 Collection.dumpFullInterface; // print all instance and class methods that this class responds to
43 Collection.dumpMethodList; // print instance methods of this class and superclasses, in alpha order
44 // also shows from which class the method is inherited
45 // does not include Object or Class methods
46 // for class methods, do Meta_Collection.dumpMethodList
48 Collection.dumpClassSubtree; // dump all subclasses of this class
50 Collection.dumpSubclassList; // dump all subclasses, in alphabetical order
52 SCWindow.instVarNames.dump; // dump all instance variable names of this class
54 SCWindow.classVarNames.dump; // dump all class variable names of this class
56 SCWindow.filenameSymbol.postln; // the path to the file that defined this class
59 // print all classes whose names start with 'F'
60 Class.allClasses.do({ arg class;
61 if (class.name.asString.at(0) == $F, { class.name.postln; });
66 // find and print all class variable names defined in the system
67 Class.allClasses.do({ arg class;
68 if (class.classVarNames.notNil, {
69 // classVarNames is an Array of Symbols
70 class.classVarNames.do({ arg varname;
71 (class.name.asString ++ " " ++ varname.asString).postln;
78 // find and print all methods that contain "ascii"
79 Class.allClasses.do({ arg class;
80 class.methods.do({ arg sel;
81 if(sel.name.asString.find("ascii").notNil) {
82 (class.name.asString + "-" + sel.name).postln;
89 subsection:: Snooping in Methods
91 Same thing goes here, if you store things into Methods, you may break something.
93 Collection.findMethod('select'); // does it have this method?
95 Array.findMethod('select'); // this class doesn't
97 Array.findRespondingMethodFor('select'); // climb the class tree to find the method
99 Collection.findMethod('select').dump; // find a method object
101 Collection.findMethod('select').argNames.dump; // dump its argument names
103 Collection.findMethod('select').varNames.dump; // dump its local variable names
105 // dump its code. mostly for debugging the compiler.
106 Collection.findMethod('select').dumpByteCodes;
108 Collection.dumpByteCodes('select'); // a shorter version of the above
110 { 1 + 2 }.dump; // this is a Function
112 { 1 + 2 }.def.dump; // get its FunctionDef
114 { 1 + 2 }.def.dumpByteCodes; // dump its code.
117 subsection:: Snooping in Windows
120 // create some windows to snoop in
123 w = Window.new("snoop " ++ i.asString,
124 Rect.new( 200 + 400.rand, 69 + 300.rand, 172, 90 ));
126 b = Button.new( w, Rect.new( 23, 28, 127, 25 ));
127 b.states = [["BLAM-O", Color.red]];
130 Window.allWindows.dump; // dump a list of all open SCWindows
132 // a little more helpful, dump their names
133 Window.allWindows.collect({ arg w; w.name }).postln;
136 // change background colors of all open windows
137 Window.allWindows.do({ arg window;
138 window.view.background = Color.new(0.5 + 0.5.rand, 0.5 + 0.5.rand, 0.5 + 0.5.rand);
141 Window.closeAll; // close all the windows (This will close the server windows)
144 subsection:: Snooping in SynthDefs
146 // First execute this:
148 f = SynthDef("Help-SnoopSynthDef",
150 Out.ar(out, PinkNoise.ar(0.1))
154 f.dumpUGens; // get the ugens, listed in order of execution, with rate, index and
158 subsection:: Snooping in the Interpreter
160 When evaluating text in the interpreter, the variable 'this' always refers to the interpreter.
162 this.dump; // display the values of all the interpreter variables a-z
164 this.clearAll; // set all variables a-z to nil
166 g = this.compile("(1 + 2).postln"); // compile some text into a Function
168 g.postln; // see, g is a Function
170 g.value; // evaluate g
172 this.interpret("(1 + 2).postln"); // interpret some text
174 this.interpretPrint("1 + 2"); // interpret some text and print the result