File: jitlib_asCompileString.schelp

package info (click to toggle)
supercollider 1%3A3.11.2%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 71,152 kB
  • sloc: cpp: 387,846; lisp: 80,328; ansic: 76,515; sh: 22,779; python: 7,932; makefile: 2,333; perl: 1,123; javascript: 915; java: 677; xml: 582; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (89 lines) | stat: -rw-r--r-- 2,054 bytes parent folder | download | duplicates (4)
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
title:: jitlib_asCompileString
summary:: asCompileString in JITLib
categories:: JITLib>Tutorials

code::
{ 10 + 6 * ~harry }.asCompileString;
::

Many objects understand strong::.storeOn::, which a way to post their string that is needed to reproduce them by compilation. Sometimes one wants to store a certain configuration of a proxy space, which can be done
if all functions used are closed functions.

code::
// an example how ProxySpace can document its current state:

p = ProxySpace.push(s);


(
~ctl1 = {
	var z = 1;
	4.do { |i| z = z * SinOsc.kr(i.sqrt, i+[0,0.2]) };
	z
};

~ctl2[0] = { LFNoise2.kr([20,20],20) };
~ctl2[1] = {
	LFNoise2.kr([20,20],20) * LFNoise0.kr([20,20],20)
};

~out = {
	SinOsc.ar(~freq.kr, 0, 0.1)
};

~freq[0] = { ~ctl1.kr(2) + ~ctl2.kr(2) + 400 };
~freq[5] = ~ctl1.wrap2(~ctl2) * ~ctl1 / (~ctl2 + ~ctl1);

~pat = Pbind(\freq, Pfunc({ 1.2.rand }));
~z = 9;
~out.set(\freq, 760, \ffreq, 20);
)

p.asCompileString;

// the document message creates a new document which it posts the code into

p.document;		// document everything
p.document([\out]); 	// document all dependants of ~out
p.document([\ctl1]);	// document all dependants of ~ctl1
::

Ndefs and NodeProxies can also store their full state as a code string:
code::
// Ndef with source
Ndef(\x, { Saw.ar(\freq.kr(234), 0.1) });
Ndef(\x).asCode;
// returns:
"Ndef('x', { Saw.ar(\freq.kr(234), 0.1) });
"

// Ndef with source and settings
Ndef(\a,  { Saw.ar(\freq.kr, 0.1) }).set(\freq, 123);
Ndef(\a).asCode;
// returns:
"(
Ndef('a', { Saw.ar(\freq.kr, 0.1) });
Ndef('a').set('freq', 123);
);
"

// anonymous nodeproxy - returns example code with interpreter variable "a = ..."
z = NodeProxy.new.source = { DC.ar };
z.asCode
// returns:
"a = NodeProxy.new.source_({ DC.ar });"

// nodeproxy  in a pushed proxyspace, which is also playing
p = ProxySpace.push(s);
~x = { Saw.ar(\freq.kr(234), 0.1) };
~x.play;
~x.asCode;
// returns code that assumes there is a pushed proxyspace:
"(
~x = { Saw.ar(\freq.kr(234), 0.1) };
~x.play;
);
"
~x.end.clear;
p.pop; p.clear;
::