File: PmonoStreams.sc

package info (click to toggle)
supercollider 1%3A3.4.5-1wheezy1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,972 kB
  • sloc: cpp: 116,645; lisp: 64,914; ansic: 10,725; python: 3,548; perl: 766; ruby: 487; sh: 152; makefile: 117; xml: 13
file content (136 lines) | stat: -rwxr-xr-x 3,225 bytes parent folder | download
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
136

// these are internal classes, used by Pmono and PmonoArtic
// they're not likely to work well if you try to use them outside that context

PmonoStream : Stream {
	var	pattern,
		id, server, cleanup, currentCleanupFunc,
		event,
		streamout, name,
		streampairs, endval,
		msgFunc, hasGate, synthLib, desc, schedBundleArray, schedBundle;

	*new { |pattern|
		^super.newCopyArgs(pattern)
	}
	
	embedInStream { |inevent|
		inevent ?? { ^nil.yield };

		this.prInit(inevent)
			.prInitNode;

		loop {
			if(this.prDoStreams) {
				cleanup.update(event);
				inevent = event.yield;	
				this.prSetNextEvent(inevent);		
			} {
				^cleanup.exit(inevent)
			}
		}
	}
	
		// private methods abstracted out for the benefit of subclasses
		// you should not use these directly
	prInit { |inevent|
		cleanup = EventStreamCleanup.new;
		streampairs = pattern.patternpairs.copy;
		endval = pattern.patternpairs.size - 1;
		forBy (1, endval, 2) { | i | streampairs[i] = streampairs[i].asStream };

		event = inevent.copy;
		event.use {
			synthLib = ~synthLib ?? { SynthDescLib.global };
			~synthDesc = desc = synthLib.match(pattern.synthName);
			if (desc.notNil) {
				~hasGate = hasGate = desc.hasGate;
				~msgFunc = desc.msgFunc;
			}{
				~msgFunc = ~defaultMsgFunc;
				~hasGate = hasGate = false;
			};
			msgFunc = ~msgFunc;
		}
	}
	
	prInitNode {
		event.use {
			if (~id.notNil) {	
				~type = \monoSet;	
			} {
				~type = \monoNote; 
				~instrument = pattern.synthName;
				~updatePmono = { | argID, argServer | 
					 id = argID;
					 server = argServer;
					 schedBundleArray = ~schedBundleArray;
					 schedBundle = ~schedBundle;
				};
				cleanup.addFunction(event, currentCleanupFunc = { | flag |
					if (flag) { (id: id, server: server, type: \off, 
						hasGate: hasGate,
						schedBundleArray: schedBundleArray,
						schedBundle: schedBundle).play
					}
				}); 
			}
		};
	}
	
	prDoStreams {
		forBy (0, endval, 2) { | i |
			name = streampairs[i];
			streamout = streampairs[i+1].next(event);
			streamout ?? { ^false };
			if (name.isSequenceableCollection) {
				name.do { | n, i | event[n] = streamout[i] };
			}{
				event[name] = streamout;
			};
		};
		^true
	}
	
	prSetNextEvent { |inevent|
		event = inevent.copy;
		event.use{
			~server = server;
			~id = id; 
			~type = \monoSet;
			~msgFunc= msgFunc;
		};
	}
}

PmonoArticStream : PmonoStream {
	embedInStream { |inevent|
		var	sustain, rearticulating = false;
		inevent ?? { ^nil.yield };

		this.prInit(inevent)
			.prInitNode;

		loop {
			if(this.prDoStreams) {
				sustain = event.use { ~sustain.value };
				if(sustain.notNil and: { sustain < event.delta }) {
					event[\removeFromCleanup] = event[\removeFromCleanup].add(currentCleanupFunc);
					thisThread.clock.sched(sustain, {
						currentCleanupFunc.value(true);
						rearticulating = true;
					});
				} { rearticulating = false };
				cleanup.update(event);
				inevent = event.yield;
				this.prSetNextEvent(inevent);	
				if(rearticulating) {
					event[\id] = nil;
					this.prInitNode;
				};
			} {
				^cleanup.exit(inevent)
			}
		}
	}
}