File: Psym.sc

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 (135 lines) | stat: -rw-r--r-- 2,615 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
Psym : FilterPattern {
	var <>dict;

	*new { arg pattern, dict;
		^super.new(pattern).dict_(dict)
	}

	storeArgs { ^[pattern,dict] }

	lookupClass { ^Pdef }

	lookUp { arg key;
		^(dict ?? { this.lookupClass.all }).at(key.asSymbol) ?? { this.lookupClass.default }
	}

	embedInStream { arg inval;
		var str, outval, pat;
		str = pattern.asStream;
		while {
			outval = str.next(inval);
			outval.notNil
		} {
			pat = this.getPattern(outval);
			inval = pat.embedInStream(inval);
		};
		^inval

	}

	getPattern { arg key;
		^if(key.isSequenceableCollection) {
			this.lookupClass.parallelise(
				key.collect {|each|
					this.lookUp(each)
				}
			);
		} {
			this.lookUp(key)
		}
	}

}

Pnsym : Psym {
	lookupClass { ^Pdefn }
}

Ptsym : Psym {
	var <>quant, <>dur, <>tolerance;

	*new { arg pattern, dict, quant, dur, tolerance = 0.001;
		^super.newCopyArgs(pattern, dict, quant, dur, tolerance)
	}

	storeArgs { ^[ pattern, dict, quant, dur, tolerance ] }

	embedInStream { arg inval;
		var outval, pat, quantVal, durVal;
		var str = pattern.asStream;
		var quantStr = quant.asStream;
		var durStr = dur.asStream;

		while {
			outval = str.next(inval);
			quantVal = quantStr.next(inval) ? quantVal;
			durVal = durStr.next(inval) ? durVal;
			outval.notNil
		} {
			pat = Psync(this.getPattern(outval), quantVal, durVal, tolerance);
			inval = pat.embedInStream(inval);
		};
		^inval

	}
}

Pnsym1 : Pnsym {

	embedInStream { arg inval;

		var which, outval, pat, currentStream;
		var str = pattern.asStream;
		var streams = IdentityDictionary.new;

		while {
			which = str.next(inval);
			which.notNil
		} {
			pat = this.getPattern(which);
			currentStream = streams.at(pat);
			if(currentStream.isNil) {
				currentStream = pat.asStream;
				streams.put(pat, currentStream);
			};
			outval = currentStream.next(inval);
			outval ?? { ^inval };
			inval = outval.yield
		};
		^inval

	}
}

Psym1 : Psym {

	embedInStream { arg inval;

		var which, outval, pat, currentStream;
		var str = pattern.asStream;
		var streams = IdentityDictionary.new;
		var cleanup = EventStreamCleanup.new;

		while {
			which = str.next(inval);
			which.notNil
		} {
			if(which.isSequenceableCollection) {
				Error("Psym1 cannot embed arrayed keys: %\n".format(which)).throw;
			};
			pat = this.lookUp(which);
			currentStream = streams.at(pat);
			if(currentStream.isNil) {
				currentStream = pat.asStream;
				streams.put(pat, currentStream);
			};
			outval = currentStream.next(inval);
			if(outval.isNil) { ^cleanup.exit(inval) };

			cleanup.update(outval);
			inval = outval.yield
		};

		^cleanup.exit(inval);
	}
}