Tracking Ndef activity

I would like to track some information from various Ndefs which run simultaneously on the server.

For example, how long a Ndef is being active. NodeWatcher could do that but the Ndef uses dynamic nodeIDs. Is it possible to create Ndefs with static nodeIDs in order to register them in the NodeWatcher?

Additionally, I would like to track the RunningSum from each Ndef. Would this be possible at all?

There are this.changed calls for: the following methods: { |x| x.selectors.asArray.includes(\changed) }.collect { |x| }
[ clear, end, free, pause, resume, put, removeAt, rebuildToBundle ]

So you can work with a SimpleController to catch these.

They call, respectively:

\clear -> \clear,
\end -> \end,
\freq -> \free,
\pause -> \pause,
\resume -> \resume,
\put -> \source, // source changed
\removeAt -> \source, // source changed
\rebuildToBundle -> \rebuild, // source rebuilt
1 Like

Thanks, that looks great!

Could you please provide a simple example with a Ndef? I cannot figure out how to apply these methods and the help files don’t help me much…

~controllers = ();
~registerNdef = { |obj, what, func|
	var ctrl =;
	if(ctrl.isNil) { ctrl = SimpleController(obj); ~controllers[obj] = ctrl };
	ctrl.put(what, func)
~unregisterNdef = { |obj, what, func|
	var ctrl =;
	if(ctrl.notNil) { ctrl.remove; ~controllers.removeAt(obj) }

~registerNdef.(Ndef(\x), \source, { "source has changed!".postln });

Ndef(\x, { * 0.1 });


For more, you need to read up on SimpleController

Thanks so much!

I am trying to track the duration of a Ndef being active:

var temp=0;

~registerNdef.(Ndef(\x), \source, {
	var dur, abs_time = Main.elapsedTime;
	if (Ndef(\x).source.isFunction)
	{temp = abs_time}
	{dur = abs_time - temp; dur.postln;};
Ndef(\x, { * 0.01 }).play;
Ndef(\x, { * 0.01 }).clear;

When the clear method is called the controller is activated twice. In the first activation, the source is still a function, thus reassigning the temp variable and messing up the duration calculation. Is there any workaround that?

I found another way to track the current rms of a Ndef:

~accumulated_amplitudes = Dictionary();

~trackRMS = {
	arg tag;
	var bus = Bus.control(s);

	//write the accumulated rms in a private control bus
	{}.play(outbus: bus);

	//insert the bus to the dictionary
	~accumulated_amplitudes.put(tag, bus)

Just creating private buses for each Ndef, writing the RMS and storing the pair in a dictionary.

Try this:

~registerNdef.(Ndef(\x), \source, { |...args| args.postln });
Ndef(\x, { * 0.01 });

The arguments tell you what.

// from NodeProxy::put:
		this.changed(\source, [obj, index, channelOffset, extraArgs, now]);

I keep making the same mistake, I should call the clear method without setting a source for the Ndef.