The thing that is missing here is: after closing the bundle, you want access to the bundle’s contents!
Julian’s suggestion throws away the bundle lets you access the bundle before closing it. But then closing the bundle throws it away, so there was no way to add it to the Score. This led you to believe that you needed to re-collect the bundle.
Also, collecting the bundle is slightly complicated by the fact that JITLib’s MixedBundles are sent asynchronously. If you run his entire code block at once, closeBundle
happens before the bundles are sent, and the bundle ends up being empty.
Also, we should guard against errors.
So:
(
~getNodeProxyBundle = { |jitFunc, action|
var result;
if(s.addr.isKindOf(BundleNetAddr)) {
Error("Cannot bundle while another bundle is in progress").throw;
};
fork {
protect {
s.openBundle;
jitFunc.value;
0.01.wait; // arbitrary, just a guess; s.sync didn't help
} { |error|
if(error.isNil) {
result = s.closeBundle(false); // close, don't send, but keep the bundle
action.value(result);
} {
s.closeBundle(false); // on error, bundle is not reliable, so discard
}
};
};
};
)
Then, when you inspect the bundle, you’ll find that it has two types of array elements:
- [ \syncFlag, [ [ … msg …], [ … msg… ] ] ]
- or just a flat message array
Sync doesn’t matter in NRT, so the code to add to the Score will need to flatten this.
(
x = Score.new;
~getNodeProxyBundle.({
n = NodeProxy.audio(s, 2);
n[0] = {Impulse.ar(490)};
n[1] = \filter->{|sig| SVF.ar(sig*0.2, LFDNoise0.ar(3).range(100, 9000), 0.8);};
}, { |bundle|
bundle.do { |row|
if(row[0] == \syncFlag) {
row[1].do { |msg|
x.add([0, msg]);
}
} {
x.add(0, row);
}
};
});
)
(In this example, I’m just adding all the messages at the beginning, time = 0 – I’ve run out of time for now; you will have to figure out how to handle the timing according to your requirements.)
hjh