Translating OSCresponderNode to OSCFunc

Hi,

Im updating some older code and need to translate this into an OSCFunc:

OSCresponderNode(server.addr, '/n_end', {|time, responder, msg|
	if(msg[1]==synth.nodeID, {
		isPlaying= false;
		responder.remove; // <-------
	});
}).add;

I cant see any argument referring to the responder itself in the OSCFunc action function like OSCresponderNode has, is it hidden away somewhere?

Like this?

n = NetAddr("127.0.0.1", 57120); // local machine

OSCdef(\test, { 
   \triggered.postln; 
   OSCdef(\test).free // <--
}, '/chat', n);

n.sendMsg("/chat", 1) // posts triggered here then not again
n.sendMsg("/chat", 1)
n.sendMsg("/chat", 1)
n.sendMsg("/chat", 1)

Maybe I should have added some more context.

This is part of a class where a new responder is created every time a Synth is played, which happens a lot. It seems like OSCdef names can only exist one at a time so that won’t work in my case.

I guess I can just store the OSCFunc in a variable but it seems odd to remove this argument from the action function when “upgrading” from OSCresponderNode…

var responder;

responder= OSCFunc({|msg|
	if(msg[1]==synth.nodeID, {
		isPlaying= false;
		responder.remove;
	});
}, '/n_end', server.addr).add;

Could you achieve the same result with Synth().onFree?

If not

n = NetAddr("127.0.0.1", 57120); // local machine

OSCdef(\test, {\triggered.postln}, '/chat', n, argTemplate: [10]).oneShot;

n.sendMsg("/chat", 1)
n.sendMsg("/chat", 10) // triggers
n.sendMsg("/chat", 1)
n.sendMsg("/chat", 1)


Note the argTemplate, but your nodeId in there instead of 10.

If I try to create 100 instances of OSCdef(\test) will it not only end up replacing itself as one responder?

It looks like .oneShot also is a method for OSCFunc so I think it should work with that and the argTemplate you suggested.

Ah my mistake, yes, use OSCFunc not def there.

Yep, it works. Thanks for your help!

Yes, the idiomatic way is to use the oneShot method. It fires once and then frees itself. But consider if you may need to hold a reference anyway, eg if your synth fails to create or something and you need to cleanup.