«how to use the SynthDef's default argument in an Event?» by julian.rohrhuber

on 03 Nov'17 10:03 in patterneventhelpeventtype

One answer to the question "how to use the SynthDef's default argument in an Event?"

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
// This question comes up sometimes.
// one way to do it is to define an event type:


(
Event.addEventType(\dnote, { |server|
	
	var instrument = ~instrument.asDefName;
	var synthLib = ~synthLib ?? { SynthDescLib.global };
	var desc = synthLib.at(instrument);
	
	
	if (desc.notNil) {
		desc.controls.do { |x|
			x.defaultValue !? { x.name.asSymbol.envirPut(x.defaultValue) }
		};
		// for efficiency, get this now
		~hasGate = desc.hasGate;
		~msgFunc = desc.msgFunc;
	};
	~type = \note;
	
	currentEnvironment.play;
});
)

(
SynthDef(\test, { |out, freq = 1000| 
	Out.ar(out, Line.ar(0.1, 0, 0.1, doneAction:2) * SinOsc.ar(freq)) 
}).add
)

Pbind(\type, \dnote, \instrument, \test, \dur, 0.3).play;
raw 731 chars (focus & ctrl+a+c to copy)
reception
comments