File: Pkey.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 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 (58 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (2)
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
class:: Pkey
summary:: access a key in an event stream
related:: Classes/Penvir
categories:: Streams-Patterns-Events>Patterns>Data Sharing

description::

Pkey simplifies backward access to values in an event being processed by link::Classes/Pbind:: or another event pattern.

ClassMethods::

method::new

argument::key
The name of the event variable to read from.

argument::repeats
The number of items returned before finishing. Using code::nil::, the default value, makes the stream infinite.

Examples::

code::
// \b should thus take twice the value of \a in each event:
p = Pbind(\a, Pwhite(1, 10, inf), \b, Pkey(\a) * 2).asStream;


p.next(())	// for Pbind, must pass in a default event even if empty

( 'a': 10, 'b': 20 )
( 'a': 2, 'b': 4 )
( 'a': 5, 'b': 10 )
( 'a': 4, 'b': 8 )
( 'a': 2, 'b': 4 )

// note: to check if a Pkey's result /equals/ another value,
// be sure to use |==|
p = Pbind(
	\a, Pseries(1, 1, inf),
	\b, Pif(
		Pkey(\a) == 2,
		"equals 2",
		"nope"
	)
).asStream;

p.next(());  // 'b' is always "nope"

p = Pbind(
	\a, Pseries(1, 1, inf),
	\b, Pif(
		Pkey(\a) |==| 2,
		"equals 2",
		"nope"
	)
).asStream;

p.next(());  // 'b' is as expected
::