Use NodeProxy filter in Environment

hey, i have been trying to create an Environment which prepares a NodeProxy with a trigger SynthDef and a method .maskOn to filter the triggers with a Demand Sequence:

(
SynthDef(\trig, {
	var tFreq, trig;
	tFreq = \tFreq.kr(8, spec: ControlSpec(1, 100, \exp));
	trig = Impulse.ar(tFreq);
	OffsetOut.ar(\out.kr(0), trig);
}).add;
)

(
~makeTriggers = { |synthDefName, initArgs=#[]|
	
	Environment.make { |self|
		
		~synthDef = SynthDescLib.global[synthDefName].def ?? {
			Error("SynthDef '%' not found".format(synthDefName)).throw
		};
		
		~nodeProxy = NodeProxy.audio(s, 1);
		~nodeProxy.prime(~synthDef).set(*initArgs);
			
		~triggerMask = { |in|
			var trig = in;
			trig * Demand.ar(trig, 0, Dseq([1, 0, 0, 1, 0, 0, 1, 0], inf));
		};
	
		~maskOn = { |self|
			self.nodeProxy.put(150, \filter -> ~triggerMask );
		};
		
	}.know_(true);
};
)

~trig = ~makeTriggers.(\trig, [\tFreq, 8]);
~trig.maskOn;
~trig.nodeProxy.play;

I would have thought that i can evaluate ~makeTriggers and assign it to a variable like ~trig, call .maskOn and to play the NodeProxy and get filtered Impulse triggers. But i get no sound at all.

if i do it the straightforward way without the Environment, i can filter the triggers without any problem:

(
~triggerMask = { |in|
	var trig = in;
	trig * Demand.ar(trig, 0, Dseq([1, 0, 0, 1, 0, 0, 1, 0], inf));
};
)

~trig = NodeProxy.audio(s, 1).source_(\trig);
~trig.put(150, \filter -> ~triggerMask );
~trig.play;

whats wrong here? thanks

\filter -> self[\triggerMask]

… I think. (Note, not self.triggerMask.)

hjh

hey, thanks :slight_smile: unfortunately still no sound.

(
~makeTriggers = { |synthDefName, initArgs=#[]|

	Environment.make { |self|

		~synthDef = SynthDescLib.global[synthDefName].def ?? {
			Error("SynthDef '%' not found".format(synthDefName)).throw
		};

		~nodeProxy = NodeProxy.audio(s, 1);
		~nodeProxy.prime(~synthDef).set(*initArgs);

		~triggerMask = { |in|
			var trig = in;
			trig * Demand.ar(trig, 0, Dseq([1, 0, 0, 1, 0, 0, 1, 0], inf));
		};

		~maskOn = { |self|
			self.nodeProxy.put(150, \filter -> self[\triggerMask] );
		};

	}.know_(true);
};
)

~trig = ~makeTriggers.(\trig, [\tFreq, 8]);
~trig.maskOn;
~trig.nodeProxy.play;

Another difference is that your non-working example uses prime while the working example uses source_. I don’t know exactly what prime does but for testing purposes, it would be a good idea to eliminate all differences except for the use of the environment.

I’m not at the computer now so I’m not able to run your code directly.

hjh

1 Like

okay, it seems it has been a combination of two things:

1.)
use \filter -> self[\triggerMask] instead of \filter -> ~triggerMask or \filter -> self.triggerMask

2.)

  • and either use NodeProxy.prime, NodeProxy.play and then .maskOn
  • or use NodeProxy.source_, .maskOn and then NodeProxy.play

i dont really understand the difference using .source or .prime. I thought .prime is the method one would like to use to prepare a NodeProxy without playing it, but filter -> some function can then only be used when a NodeProxy is already playing?

Wondering if .source_ or .prime should then be used when wanting to use .map or .set and start and stop triggers and source at the same moment.

(
SynthDef(\trig, {
	var tFreq, trig;
	tFreq = \tFreq.kr(8, spec: ControlSpec(1, 100, \exp));
	trig = Impulse.ar(tFreq);
	OffsetOut.ar(\out.kr(0), trig);
}).add;

SynthDef(\source, {
	var trig;
	trig = \trig.ar(0);
	trig = Pan2.ar(trig, \pan.kr(0, spec: ControlSpec(-1, 1, \lin)));
	OffsetOut.ar(\out.kr(0), trig);
}).add;
)

(
~makeTriggers = { |synthDefName, initArgs=#[]|

	Environment.make { |self|

		~synthDef = SynthDescLib.global[synthDefName].def ?? {
			Error("SynthDef '%' not found".format(synthDefName)).throw
		};

		~nodeProxy = NodeProxy.audio(s, 1);
		~nodeProxy.source_(~synthDef).set(*initArgs);
		//~nodeProxy.prime(~synthDef).set(*initArgs);

		~triggerMask = { |in|
			var trig = in;
			trig * Demand.ar(trig, 0, Dseq([1, 0, 0, 1, 0, 0, 1, 0], inf));
		};

		~maskOn = { |self|
			self.nodeProxy.put(150, \filter -> self[\triggerMask] );
		};

	}.know_(true);
};
)

(
~trig = ~makeTriggers.(\trig, [\tFreq, 8]);
~trig.maskOn;
)

(
~source = NodeProxy.audio(s, 2).source_(\source);
~source.map(\trig, ~trig.nodeProxy);
~source.play;
)

~source.stop;
~source.free;
~trig.nodeProxy.free;

whats weird is if i use .prime, then .play then .maskOn and map it to the source, i hear the triggers in the left channel and additionally the source on both channels. if you use .source_ without play and .maskOn and then map it to the source you only hear the source on both channels.

if you specify self.know = true; at the top of the Environment you could also use self.triggerMask