File: Ref.sc

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (80 lines) | stat: -rw-r--r-- 1,643 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
// a Ref is a handle to a value. you can use it to return results by reference
// example:
//		x = Ref.new(nil);
// 		z = obj.method(x); // method puts something in reference
//		x.value.doSomething; // retrieve value
//
// it is also used as a quoting device to insulate from multiChannelPerform in UGens
//
// A special syntax shortcut for Ref.new( expr ) is to use a backquote: `expr


Ref : AbstractFunction {
	var <>value;

	*new { |thing|
		^super.new.value_(thing)
	}

	set { |thing| value = thing }

	get { ^value }

	dereference { ^value }

	asRef { ^this }

	valueArray { ^value }

	valueEnvir { ^value }

	valueArrayEnvir { ^value }

	// behave like a stream
	next { ^value }

	// prevent multichannel expansion in ugens
	asUGenInput { ^this }

	// array interface
	at { |key| ^value.at(key) }

	put  { |key, val|
		value.put(key, val)
	}

	seq { |pat|
		value = pat.embedInStream(this)
	}

	asControlInput { ^value.asControlInput }

	// Some UGens take Buffer data which
	// the user might want to specify simply as `[0.9, 0.1, 0.3]
	asBufWithValues {
		^LocalBuf.newFrom(value);
	}

	// Allow to multichannel expand ugen specs, like those of Klank,
	// in the case of which two is the rank, but could be otherwise.
	multichannelExpandRef { |rank|
		var array, refarray;
		array = this.value.asArray;
		if(array.maxSizeAtDepth(rank) <= 1) { ^this }; // no need to expand
		refarray = array.flopDeep(rank).collect { |item| this.class.new(item) };
		^refarray.unbubble
	}

	printOn { |stream|
		stream << "`(" << value << ")";
	}

	storeOn { |stream|
		stream << "`(" <<< value << ")";
	}

}

RefCopy : Ref {
	next { ^value.copy }
}