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
|
title:: jitlib_basic_concepts_01
summary:: some placeholders in supercollider
categories:: Libraries>JITLib>Tutorials
related:: Overviews/JITLib, Tutorials/JITLib/jitlib_basic_concepts_02
this helpfile explains some basic concepts of interactive programming with supercollider and proxy space.
section::a) What is a proxy?
A proxy is a place holder that is often used to operate on something that does not yet exist. For example, an emphasis::OutputProxy:: is used to represent multiple outputs of a ugen, even if only one ugen is created eventually. Any object can have proxy behaviour (it may delegate function calls to different objects for example) but specially functions and references can be used as operands while they keep their referential quality.
see also: link::Classes/OutputProxy::, link::Classes/Function::, link::Classes/Ref::
subsection::using a Ref as a proxy
code::
// reference example
// create a new Ref object
y = `(nil);
// you can start to calcuate with y, even if its value is not yet given:
z = y + 10; // returns a function
// now the source can be set:
y.value = 34;
// the function z can be evaluated now.
z.value
// the same without a reference does not work:
y = nil; // empty y first
z = y + 10; // this fails.
// also an array does not provide this referentiality:
y = [nil]; // array with nil as element
z = y + 10; // this fails.
// an environment without sufficient defaults has the same problem:
currentEnvironment.postln; // anEnvironment
~x; // access the enironment: there is nothing stored: nil
~x = 9; // store something
~x; // now 9 is stored
~x + 100; // calculate with it
currentEnvironment.postln; // the value is stored in the environment
~y + ~x; // cause an error: ~y is nil.
~y = -90; // set ~y
~y + ~x; // this works.
::
subsection::using a Function as a proxy
code::
// a function can serve the same purpose
y = nil; // empty y first
z = { y } + 10; // this does not fail, instead it creates a new function, which
// does not fail when evaluating it after y is set to 34.
y = 34;
z.value;
::
see also client side proxies like link::Classes/Tdef::, link::Classes/Pdefn::, link::Classes/Pdef::, link::Classes/Fdef::
section::b) NodeProxy
For interactive programming it can be useful to be able to use something before it is there - it makes evaluation order more flexible and allows to postpone decisions to a later moment. Some preparations have to be done usually - like above, a reference has to be created. In other situations this sort of preparation is not enough, for example if one wants to do maths with running processes on the server.
Audio output on the server has mainly two properties - a emphasis::calculation rate:: (audio or control) and a certain emphasis::number of channels::. These are the main static properties of a node proxy, which cannot be changed while it is in use.
code::
// boot the server
s.boot;
// two proxies on a server. calculation rate is audio rate, number of channels is 2
y = NodeProxy.audio(s, 2);
z = NodeProxy.audio(s, 2);
// use them in calculation
z.play;
z.source = y.sin * 0.2;
// set its source now.
y.source = { Saw.ar([300, 301], 4*pi) };
// the source can be of various type, one of them would be a number:
y.source = 0.0;
// post the source
y.source;
// end them, free their bus number
y.clear;
z.clear;
::
In order to provide a simple way of creating node proxies, a proxy space can be used.
So the above reads like this:
code::
p = ProxySpace.push(s.boot); // store proxy space in p so it can be accessed easily.
~z.play;
~z = ~y.sin * 0.2;
~y = { Saw.ar([300, 301], 4*pi) };
// clear the space (all proxies)
p.clear;
// move out of the proxyspace.
p.pop;
::
further readings: link::Classes/NodeProxy::, link::Classes/ProxySpace::, link::Classes/Ndef::
next: link::Tutorials/JITLib/jitlib_basic_concepts_02::
|