diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 3adea8a..88eedd3 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -162,7 +162,11 @@ class NonRealTime: public SCUnit using ParamSetType = typename Client::ParamSetType; public: - static void setup(InterfaceTable *ft, const char *name) { registerUnit(ft, name); } + static void setup(InterfaceTable *ft, const char *name) + { + registerUnit(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(mClient.progress()); -// if(in0(0) > 0) mClient.cancel(); } else { mDone = true; @@ -206,6 +209,7 @@ public: auto w = static_cast(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(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'; @@ -242,6 +252,12 @@ public: int doneAction = static_cast(w->in0(static_cast(w->mNumInputs - 1))); world->ft->fDoneAction(doneAction,w); } + + static void doCancel(Unit *unit, sc_msg_iter*) + { + static_cast(unit)->mClient.cancel(); + } + private: diff --git a/release-packaging/Classes/FluidBufNMF.sc b/release-packaging/Classes/FluidBufNMF.sc index a29488a..0eb979f 100644 --- a/release-packaging/Classes/FluidBufNMF.sc +++ b/release-packaging/Classes/FluidBufNMF.sc @@ -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")}; } } diff --git a/release-packaging/HelpSource/Classes/FluidBufNMF.schelp b/release-packaging/HelpSource/Classes/FluidBufNMF.schelp index 6f185f6..d4bc2e6 100644 --- a/release-packaging/HelpSource/Classes/FluidBufNMF.schelp +++ b/release-packaging/HelpSource/Classes/FluidBufNMF.schelp @@ -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") + ::