Add cancellation and put placeholder example of kr usage in help file

nix
Owen Green 7 years ago
parent 8c0099565f
commit 5dcfd66c1b

@ -162,7 +162,11 @@ class NonRealTime: public SCUnit
using ParamSetType = typename Client::ParamSetType;
public:
static void setup(InterfaceTable *ft, const char *name) { registerUnit<Wrapper>(ft, name); }
static void setup(InterfaceTable *ft, const char *name)
{
registerUnit<Wrapper>(ft, name);
ft->fDefineUnitCmd(name, "cancel", doCancel);
}
/// Final input is the doneAction, not a param, so we skip it in the controlsIterator
NonRealTime() :
@ -188,7 +192,6 @@ public:
if(!mClient.done())
{
out0(0) = static_cast<float>(mClient.progress());
// if(in0(0) > 0) mClient.cancel();
}
else {
mDone = true;
@ -206,6 +209,7 @@ public:
auto w = static_cast<Wrapper*>(f->mData);
Result result = validateParameters(w);
if (!result.ok())
{
std::cout << "ERROR: " << Wrapper::getName() << ": " << result.message().c_str() << std::endl;
@ -222,6 +226,12 @@ public:
auto w = static_cast<Wrapper*>(data);
Result r;
w->mClient.checkProgress(r);
if(r.status() == Result::Status::kCancelled)
{
std::cout << Wrapper::getName() << ": Processing cancelled \n";
return false;
}
if(!r.ok())
{
std::cout << "ERROR: " << Wrapper::getName() << ": " << r.message().c_str() << '\n';
@ -243,6 +253,12 @@ public:
world->ft->fDoneAction(doneAction,w);
}
static void doCancel(Unit *unit, sc_msg_iter*)
{
static_cast<Wrapper *>(unit)->mClient.cancel();
}
private:
static Result validateParameters(NonRealTime *w)

@ -1,5 +1,8 @@
FluidBufNMF : UGen {
var <>server, <>synth;
*kr {|source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, bases, basesMode = 0, activations, actMode = 0, components = 1, iterations = 100, windowSize = 1024, hopSize = -1, fftSize = -1, windowType = 0, randomSeed = -1, doneAction = 0|
source = source.asUGenInput;
@ -20,6 +23,8 @@ FluidBufNMF : UGen {
*process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, bases, basesMode = 0, activations, actMode = 0, components = 1, iterations = 100, windowSize = 1024, hopSize = -1, fftSize = -1, windowType = 0, randomSeed = -1, action|
var instance,synth;
source = source.asUGenInput;
destination = destination.asUGenInput;
bases = bases.asUGenInput;
@ -30,9 +35,12 @@ FluidBufNMF : UGen {
destination = destination ? -1;
bases = bases ? -1;
activations = activations ? -1;
// this.server = server;
synth = {instance = FluidBufNMF.kr(source, startFrame, numFrames, startChan, numChans, destination, bases, basesMode, activations, actMode, components,iterations, windowSize, hopSize, fftSize, doneAction: Done.freeSelf)}.play(server);
forkIfNeeded{
{FluidBufNMF.kr(source, startFrame, numFrames, startChan, numChans, destination, bases, basesMode, activations, actMode, components,iterations, windowSize, hopSize, fftSize, doneAction: Done.freeSelf)}.play(server).waitForFree;
synth.waitForFree;
server.sync;
if (destination != -1) {
destination = server.cachedBufferAt(destination);
@ -51,5 +59,14 @@ FluidBufNMF : UGen {
} {activations = nil};
action.value(destination, bases, activations);
};
instance.synth = synth;
instance.server = server;
^instance;
}
cancel{
if(this.server.notNil)
{this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")};
}
}

@ -389,3 +389,28 @@ e.plot;
// look at the activations (sharper 3rd component at transitions)
g.plot;
::
STRONG:: Placeholder: Run process as .kr ugen and use Poll to get progress updates, cancel with server message::
CODE::
//load some buffers
(
b = Buffer.read(s,File.realpath(FluidBufNMF.class.filenameSymbol).dirname.withTrailingSlash ++ "../AudioFiles/Tremblay-AaS-SynthTwoVoices-M.wav");
c = Buffer.new(s);
x = Buffer.new(s);
y = Buffer.new(s);
~fft_size = 1024;
~frame_size = 512;
~hop_size = 256;
~which_component = 3;
)
//Run this to see progress in the scope
(
~synthID;
a = {
var nmf = FluidBufNMF.kr(b, 0,-1,0,-1,c,x,0,y,0,5,100,~frame_size,~hop_size,~fft_size, doneAction: Done.freeSelf);
~synthID = nmf.synthIndex;
Poll.kr(Impulse.kr(3),nmf)
}.scope
)
//Run this to cancel processing
Server.default.sendMsg("/u_cmd", a.nodeID, ~synthID, "cancel")
::

Loading…
Cancel
Save