File: Internal-Snooping.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (242 lines) | stat: -rw-r--r-- 6,621 bytes parent folder | download | duplicates (5)
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
title:: Internal Snooping (Introspection)
summary:: Snooping around SuperCollider
categories:: Debugging, Internals

You can inspect much of the internal structure of the class library and other data structures.
This can be useful for research and debugging purposes.

note:: The keyboard shortcuts mentioned here only apply to the standard SuperCollider IDE.::

section:: Class Definitions, Implementations, and References

subsection::Look up Implementation
Selecting the name of any method (e.g. play) and then the menu item teletype::Language>Look up Implementation:: 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 enter will open the class definition at that method. Note that this only shows implementations, and does not indicate inheritance.

(see link::Reference/KeyboardShortcuts::)


subsection::Look up References
Selecting any text (e.g. Window or asStream) and then the menu item teletype::Language>Look up References:: will open a window showing all references to the selected text, i.e. each place it is used within the class library. Note that this will not find methods calls compiled with special byte codes like 'value'.

(see link::Reference/KeyboardShortcuts::)

subsection::Graphical Class browser
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.

code::
SequenceableCollection.browse;
::



subsection:: Snooping in Classes

code::
// print all instance methods defined for this class
Collection.dumpInterface;

// print all class methods defined for this class
Collection.class.dumpInterface;



// print all instance methods that instances of this class respond to
Collection.methods.collect(_.name);

// print all class methods that this class responds to
// includes inherited methods
Collection.class.methods.collect(_.name);

// print all instance and class methods that this class responds to
// includes inherited methods
Collection.dumpFullInterface;

// print instance methods of this class and superclasses, in alpha order
// also shows from which class the method is inherited
// does not include Object or Class methods
// for class methods, do Meta_Collection.dumpMethodList
Collection.dumpMethodList;

// dump all subclasses of this class
Collection.dumpClassSubtree;

// dump all subclasses, in alphabetical order
Collection.dumpSubclassList;

// dump all instance variable names of this class
Server.instVarNames.dump;

// dump all class variable names of this class
Server.classVarNames.dump;

// the path to the file that defines this class
// Note that there might be extensions to this class in other files
Server.filenameSymbol.postln;

(
// print all classes whose names start with 'F'
Class.allClasses.do { | class |
	if (class.name.asString.beginsWith("F")) {
		class.name.postln
	}
}
)

(
// find and print all class variable names defined in the system
Class.allClasses.do { | class |
	if (class.classVarNames.notNil) {
		// classVarNames is an Array of Symbols
        class.classVarNames.do { | varname |
            (class.name.asString ++ " " ++ varname.asString).postln
        }
    }
}
)

(
// find and print all methods that contain "ascii"
Class.allClasses.do { | class |
   	class.methods.do { | sel |
   			if(sel.name.asString.find("ascii").notNil) {
            		(class.name.asString + "-" + sel.name).postln
            }
	}
}
)
::

subsection:: Snooping in Methods

code::
// does the class implement this method?
Collection.findMethod('select');
// -> Collection:select

// this class doesn't
Array.findMethod('select');
// -> nil

// but a superclass might implement it, so
// climb the class tree to check
Array.findRespondingMethodFor('select');
// -> Collection:select


// find a method object and dump its argument names and
// its local variable names
Collection.findMethod('select').dump;
Collection.findMethod('select').argNames.dump;
Collection.findMethod('select').varNames.dump;
// -> nil // doesn't have any varNames


// dump its code. mostly for debugging the compiler.
Collection.findMethod('select').dumpByteCodes;

// a shorter version of the above
Collection.dumpByteCodes('select');


{ 1 + 2 }.dump;              // this is a Function
{ 1 + 2 }.def.dump;          // dump its FunctionDef
{ 1 + 2 }.asCompileString;   // show its implementation
{ 1 + 2 }.def.dumpByteCodes; // dump its code.
::

subsection:: Snooping in GUI Windows

code::
(
// create some windows to snoop in
5.do { | i |
	var w, b;
	w = Window.new("snoop " ++ i.asString,
		Rect.new( 200 + 400.rand, 69 + 300.rand, 172, 90 ));
	w.front;
	b = Button.new( w, Rect.new( 23, 28, 127, 25 ));
	b.states = [["BLAM-O", Color.red]];
}
)

Window.allWindows.dump;	// dump a list of all open SCWindows

// a little more helpful, dump their names
Window.allWindows.collect { | w | w.name }.postln;

(
// change background colors of all open windows
Window.allWindows.do { | window |
	window.view.background = Color.new(0.5 + 0.5.rand, 0.5 + 0.5.rand, 0.5 + 0.5.rand);
}
)

Window.closeAll; // close all the windows
::

subsection:: Snooping in SynthDefs
code::
// a synthdef to snoop in
(
f = SynthDef(\snoop, { | out=0 |
		Out.ar(out, PinkNoise.ar(0.1))
});
)

// get the ugens, listed in order of execution, with rate,
// index and inputs
f.dumpUGens;
::

subsection:: Snooping on the Server

Lots of information on server-related snooping can be found in the link::Classes/Server:: helpfile under "Information and debugging".

Some examples code::
s.boot;

f = { PinkNoise.ar(0.1) * SinOsc.ar }; // a function
x = f.play;

// look at all the nodes on the server
s.queryAllNodes;

// parsed contents
s.dumpOSC(1);
x.free;
x = f.play;

// contents in hexadecimal
// status messages are not filtered
s.dumpOSC(2);
x.free;
x = f.play;

// turn off
s.dumpOSC(0);
::


subsection:: Snooping in the Interpreter

When evaluating text in the interpreter, the variable 'this' always refers to the interpreter.
code::
// display the values of all the interpreter variables a-z
this.dump;

// set all variables a-z to nil
this.clearAll;


// compile some text into a Function
g = this.compile("(1 + 2).postln");
g.postln;   // g is a Function
g.value;    // evaluate g

// interpret some text
this.interpret("(1 + 2).postln");

// interpret some text and print the result
this.interpretPrint("1 + 2");
::