diff --git a/src/FluidBufNMF/FluidBufNMF.cpp b/src/FluidBufNMF/FluidBufNMF.cpp index bc14bec..2e75538 100644 --- a/src/FluidBufNMF/FluidBufNMF.cpp +++ b/src/FluidBufNMF/FluidBufNMF.cpp @@ -1,135 +1,10 @@ - // FD_BufNMF, an NRT buffer NMF Processor -// A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) - -#include "fdNRTBase.hpp" - -#include "algorithms/STFT.hpp" -#include "data/FluidTensor.hpp" -#include "clients/nrt/NMFClient.hpp" -#include "clients/common/FluidParams.hpp" - - -#include "SC_PlugIn.h" - -#include -#include +#include +#include static InterfaceTable *ft; -//Using statements for fluidtensor -using fluid::FluidTensor; -using fluid::FluidTensorView; -using fluid::client::NMFClient; - -namespace fluid { - namespace wrapper{ - - class BufNMF: public NRTCommandBase - { - /* - - srcbuf num - – src start frame - - src numframes - – src start chan - – src num chans - – resynths dst - – dicts dst - – acts dst - - 'overwrite' flag [-1:1] - - - rank - - iterations - – window size - – hop size - – fft size - -– boundary flag - -– rand seed - */ - - public: - using client_type = NMFClient; - using NRTCommandBase::NRTCommandBase; - - - ~BufNMF() - { -// if(src) delete src; -// if(resynth) delete resynth; -// if(dict) delete dict; -// if(act) delete act; - } - - void runCommand(World* world, void* replyAddr, char* completionMsgData, size_t completionMsgSize) - { - cmd(world, "/BufNMF", replyAddr, completionMsgData, completionMsgSize); - } - - bool process(World* world) - { - //sanity check the parameters - bool parametersOk; - NMFClient::ProcessModel processModel; - std::string whatHappened;//this will give us a message to pass back if param check fails - std::tie(parametersOk,whatHappened,processModel) = nmf.sanityCheck(); - if(!parametersOk) - { - Print("fdNMF: %s \n", whatHappened.c_str()); - return false; - } - //Now, we can proceed - - nmf.process(processModel); - mModel = processModel; - - src = static_cast(client::lookupParam("src", nmf.getParams()).getBuffer()); - resynth = static_cast(client::lookupParam("resynthbuf", nmf.getParams()).getBuffer()); - dict = static_cast(client::lookupParam("filterbuf", nmf.getParams()).getBuffer()); - act = static_cast(client::lookupParam("envbuf", nmf.getParams()).getBuffer()); - - return true; - } - - bool postProcess(World* world) - { - - - if(mModel.resynthesise) - resynth->assignToRT(world); - if(mModel.returnDictionaries) - dict->assignToRT(world); - if(mModel.returnActivations) - act->assignToRT(world); - - return true; - } - - bool postComplete(World*) { - if(mModel.resynthesise) - resynth->cleanUp(); - if(mModel.returnDictionaries) - dict->cleanUp(); - if(mModel.returnActivations) - act->cleanUp(); - return true; - } - - std::vector& parameters() - { - return nmf.getParams(); - } - private: - NMFClient nmf; - NMFClient::ProcessModel mModel; - SCBufferView* src; - SCBufferView* resynth; - SCBufferView* dict; - SCBufferView* act; - };//class - } //namespace wrapper -}//namespace fluid - - PluginLoad(OfflineFluidDecompositionUGens) { ft = inTable; - registerCommand(ft, "BufNMF"); + using namespace fluid::client; + makeSCWrapper(ft, "BufNMF"); } diff --git a/src/FluidBufSines/FluidBufSines.cpp b/src/FluidBufSines/FluidBufSines.cpp index 6cf22d4..abd82fd 100644 --- a/src/FluidBufSines/FluidBufSines.cpp +++ b/src/FluidBufSines/FluidBufSines.cpp @@ -1,99 +1,15 @@ // FD_BufSines, an NRT buffer Sinusoidal Modelling Processor // A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) -#include "fdNRTBase.hpp" -#include "algorithms/STFT.hpp" -#include "data/FluidTensor.hpp" -#include "clients/nrt/Sines.hpp" -#include "clients/common/FluidParams.hpp" -#include "SC_PlugIn.h" -#include -#include +#include +#include +#include static InterfaceTable *ft; -//Using statements for fluidtensor -using fluid::FluidTensor; -using fluid::FluidTensorView; - -namespace fluid { - namespace wrapper{ - - class BufSines: public NRTCommandBase - { - /* - - srcbuf num - – src start frame - - src numframes - – src start chan - – src num chans - – sines dst - – residual dst - – bandwidth (bins) - – threshold (0-1) - – minTrackLen (frames, 0 for no tracking) - - magnitude weight(0-1) - - freq weight (0-1) - – window size - – hop size - – fft size - */ - public: - using client_type = client::SinesClient; - using NRTCommandBase::NRTCommandBase; - - ~BufSines() {} - - void runCommand(World* world, void* replyAddr, char* completionMsgData, size_t completionMsgSize) - { - cmd(world, "/BufSines", replyAddr, completionMsgData, completionMsgSize); - } - - bool process(World* world) - { - //sanity check the parameters - bool parametersOk; - client::SinesClient::ProcessModel processModel; - std::string whatHappened;//this will give us a message to pass back if param check fails - std::tie(parametersOk,whatHappened,processModel) = processor.sanityCheck(); - if(!parametersOk) - { - Print("fdNMF: %s \n", whatHappened.c_str()); - return false; - } - //Now, we can proceed - processor.process(processModel); - mModel = processModel; - return true; - } - - bool postProcess(World* world) - { - static_cast(mModel.sine)->assignToRT(world); - static_cast(mModel.res)->assignToRT(world); - return true; - } - - bool postComplete(World* w) { - static_cast(mModel.sine)->cleanUp(); - static_cast(mModel.res)->cleanUp(); - return true; - } - - std::vector& parameters() - { - return processor.getParams(); - } - private: - client::SinesClient processor; - client::SinesClient::ProcessModel mModel; - };//class - } //namespace wrapper -}//namespace fluid - - PluginLoad(OfflineFluidDecompositionUGens) { ft = inTable; - registerCommand(ft, "BufSines"); - fluid::wrapper::printCmd(ft,"BufSines","FDSines"); + using namespace fluid::client; + makeSCWrapper>>(ft, "BufSines"); + } diff --git a/src/FluidBufTransientSlice/FluidBufTransientSlice.cpp b/src/FluidBufTransientSlice/FluidBufTransientSlice.cpp index 2780a33..3e0db18 100644 --- a/src/FluidBufTransientSlice/FluidBufTransientSlice.cpp +++ b/src/FluidBufTransientSlice/FluidBufTransientSlice.cpp @@ -1,77 +1,15 @@ // FD_BufNMF, an NRT buffer NMF Processor // A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) -#define EIGEN_USE_BLAS - -#include "clients/nrt/TransientSliceNRT.hpp" -#include "fdNRTBase.hpp" -#include "data/FluidTensor.hpp" -#include "clients/common/FluidParams.hpp" -#include "SC_PlugIn.h" -#include -#include - -static InterfaceTable *ft; - -namespace fluid { - namespace wrapper{ - - class BufTransientsSlice: public NRTCommandBase - { - public: - using client_type = client::TransientSliceNRT; - using NRTCommandBase::NRTCommandBase; - - ~BufTransientsSlice() {} - - void runCommand(World* world, void* replyAddr, char* completionMsgData, size_t completionMsgSize) - { - cmd(world, "/BufTransientSlice", replyAddr, completionMsgData, completionMsgSize); - } - - bool process(World* world) - { - //sanity check the parameters - bool parametersOk; - client_type::ProcessModel processModel; - std::string whatHappened;//this will give us a message to pass back if param check fails - std::tie(parametersOk,whatHappened,processModel) = trans.sanityCheck(); - if(!parametersOk) - { - Print("FluidBufTransientSlice: %s \n", whatHappened.c_str()); - return false; - } - trans.process(processModel); - mModel = processModel; - return true; - } - - bool postProcess(World* world) - { - static_cast(mModel.trans)->assignToRT(world); - return true; - } - - bool postComplete(World*) - { - static_cast(mModel.trans)->cleanUp(); - return true; - } - - std::vector& parameters() - { - return trans.getParams(); - } - private: - client_type trans; - client_type::ProcessModel mModel; - };//class - } //namespace wrapper -}//namespace fluid +#include +#include +#include +static InterfaceTable* ft; PluginLoad(OfflineFluidDecompositionUGens) { ft = inTable; - registerCommand(ft, "BufTransientSlice"); - fluid::wrapper::printCmd(ft,"BufTransientsSlice","FluidBufTransientSlice"); + using namespace fluid::client; + makeSCWrapper>>(ft, "BufTransientSlice"); + } diff --git a/src/FluidBufTransients/FluidBufTransients.cpp b/src/FluidBufTransients/FluidBufTransients.cpp index a83e861..1b2ae80 100644 --- a/src/FluidBufTransients/FluidBufTransients.cpp +++ b/src/FluidBufTransients/FluidBufTransients.cpp @@ -1,90 +1,11 @@ - // FD_BufNMF, an NRT buffer NMF Processor -// A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) - -//#include "clients/nrt/TransientNRTClient.hpp" -//#include "fdNRTBase.hpp" -//#include "data/FluidTensor.hpp" -//#include "clients/common/FluidParams.hpp" -//#include "SC_PlugIn.h" -//#include -//#include - #include #include - #include - static InterfaceTable *ft; -//namespace fluid { -// namespace wrapper{ -// -// class BufTransients: public NRTCommandBase -// { -// public: -// using client_type = client::TransientNRTClient; -// using NRTCommandBase::NRTCommandBase; -// -// ~BufTransients() {} -// -// void runCommand(World* world, void* replyAddr, char* completionMsgData, size_t completionMsgSize) -// { -// cmd(world, "/BufTransients", replyAddr, completionMsgData, completionMsgSize); -// } -// -// bool process(World* world) -// { -// //sanity check the parameters -// bool parametersOk; -// client_type::ProcessModel processModel; -// std::string whatHappened;//this will give us a message to pass back if param check fails -// std::tie(parametersOk,whatHappened,processModel) = trans.sanityCheck(); -// if(!parametersOk) -// { -// Print("fdTransients: %s \n", whatHappened.c_str()); -// return false; -// } -// trans.process(processModel); -// mModel = processModel; -// return true; -// } -// -// bool postProcess(World* world) -// { -// if(mModel.returnTransients) -// static_cast(mModel.trans)->assignToRT(world); -// if(mModel.returnResidual) -// static_cast(mModel.res)->assignToRT(world); -// return true; -// } -// -// bool postComplete(World*) -// { -// if(mModel.returnTransients) -// static_cast(mModel.trans)->cleanUp(); -// if(mModel.returnResidual) -// static_cast(mModel.res)->cleanUp(); -// return true; -// -// } -// std::vector& parameters() -// { -// return trans.getParams(); -// } -// private: -// client_type trans; -// client_type::ProcessModel mModel; -// };//class -// } //namespace wrapper -//}//namespace fluid - - PluginLoad(OfflineFluidDecompositionUGens) { ft = inTable; using namespace fluid::client; - makeSCWrapper, decltype(TransientParams), TransientParams>>(ft,"BufTransients"); - -// registerCommand(ft, "BufTransients"); -// fluid::wrapper::printCmd(ft,"BufTransients","FDTransients"); + makeSCWrapper>>(ft,"BufTransients"); } diff --git a/src/FluidSines/FluidSines.cpp b/src/FluidSines/FluidSines.cpp index 9f2f93a..bc268f5 100644 --- a/src/FluidSines/FluidSines.cpp +++ b/src/FluidSines/FluidSines.cpp @@ -1,131 +1,14 @@ // A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) - -#include "SC_PlugIn.hpp" -#include "data/FluidTensor.hpp" -#include "clients/rt/SinesClient.hpp" +#include +#include static InterfaceTable *ft; -namespace fluid { -namespace wrapper{ - class FDRTSines: public SCUnit - { - using AudioSignalWrapper = client::SinesClient::AudioSignal; - using SignalWrapper = client::SinesClient::Signal; - - // using SignalPointer = std::unique_ptr; - public: - FDRTSines() - { - //Order of args - //Window size, Hop size, FFT Size - - //Get the window size - - -// const float hfilter_size = in0(1); -// const float pfilter_size = in0(2); -// const float window_size = in0(3); -// const float hop_size = in0(4); -// const float fft_size = in0(5); -// - - //Oh NO! Heap allocation! Make client object - mClient = new client::SinesClient(65536); - setParams(true); - -// m_client->getParams()[0].setLong(pfilter_size); -// m_client->getParams()[1].setLong(hfilter_size); -// m_client->getParams()[2].setLong(window_size); -// m_client->getParams()[3].setLong(hop_size); -// m_client->getParams()[4].setLong(fft_size); - - bool isOK; - std::string feedback; - - std::tie(isOK, feedback) = mClient->sanityCheck(); - if(!isOK) - { - Print("fdRTHPSS Error: %s",feedback.c_str()); - return; - } - - - mClient->setHostBufferSize(bufferSize()); - mClient->reset(); - - //Work out what signals we need. For now keep it simple: - //in 0 => only audio - //out 0 => only audio - inputSignals[0] = new AudioSignalWrapper(); - outputSignals[0] = new AudioSignalWrapper(); - outputSignals[1] = new AudioSignalWrapper(); - - mCalcFunc = make_calc_function(); - Unit* unit = this; - ClearUnitOutputs(unit,1); - } - - ~FDRTSines() - { - delete inputSignals[0]; - delete outputSignals[0]; - delete outputSignals[1]; - delete mClient; - } - - private: - - void setParams(bool instantiation) - { - assert(mClient); - for(size_t i = 0; i < mClient->getParams().size(); ++i) - { - client::Instance& p = mClient->getParams()[i]; - - if(!instantiation && p.getDescriptor().instantiation()) - continue; - - switch(p.getDescriptor().getType()) - { - case client::Type::kLong: - p.setLong(in0(i + 1)); - p.checkRange(); - break; - case client::Type::kFloat: - p.setFloat(in0(i + 1)); - p.checkRange(); - break; - case client::Type::kBuffer: - // p.setBuffer( in0(i+1)); - break; - default: - break; - } - } - } - - - void next(int numsamples) - { - setParams(false); - const float* input = in(0); - const float inscalar = in0(0); - inputSignals[0]->set(const_cast(input), inscalar); - outputSignals[0]->set(out(0), out0(0)); - outputSignals[1]->set(out(1), out0(1)); - mClient->doProcess(std::begin(inputSignals),std::end(inputSignals),std::begin(outputSignals), std::end(outputSignals),numsamples,1,2); - } - client::SinesClient *mClient; - SignalWrapper *inputSignals[1]; - SignalWrapper *outputSignals[2]; - }; -} -} PluginLoad(FluidSTFTUGen) { ft = inTable; - registerUnit(ft, "FluidSines"); + using namespace fluid::client; + makeSCWrapper>(ft, "FluidSines"); } diff --git a/src/FluidTransientSlice/FluidTransientSlice.cpp b/src/FluidTransientSlice/FluidTransientSlice.cpp index 25e96fa..8058b57 100644 --- a/src/FluidTransientSlice/FluidTransientSlice.cpp +++ b/src/FluidTransientSlice/FluidTransientSlice.cpp @@ -1,107 +1,13 @@ // A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) -#include "SC_PlugIn.hpp" -#include "data/FluidTensor.hpp" -#include "clients/rt/TransientSlice.hpp" +#include +#include static InterfaceTable *ft; -namespace fluid { -namespace segmentation{ - class FluidSliceTransients: public SCUnit - { - using audio_client = client::TransientsSlice; - using AudioSignalWrapper = audio_client::AudioSignal; - using SignalWrapper = audio_client::Signal; - - // using SignalPointer = std::unique_ptr; - public: - FluidSliceTransients() - { - mClient = new audio_client(65536); - setParams(true); - bool isOK; - std::string feedback; - - std::tie(isOK, feedback) = mClient->sanityCheck(); - if(!isOK) - { - Print("FluidSliceTransients Error: %s",feedback.c_str()); - return; - } - - - mClient->setHostBufferSize(bufferSize()); - mClient->reset(); - - //Work out what signals we need. For now keep it simple: - //in 0 => only audio - //out 0 => only audio - inputSignals[0] = new AudioSignalWrapper(); - outputSignals[0] = new AudioSignalWrapper(); - - mCalcFunc = make_calc_function(); - Unit* unit = this; - ClearUnitOutputs(unit,1); - } - - ~FluidSliceTransients() - { - delete inputSignals[0]; - delete outputSignals[0]; - delete mClient; - } - - private: - - void setParams(bool instantiation) - { - assert(mClient); - for(size_t i = 0; i < mClient->getParams().size(); ++i) - { - client::Instance& p = mClient->getParams()[i]; - - if(!instantiation && p.getDescriptor().instantiation()) - continue; - - switch(p.getDescriptor().getType()) - { - case client::Type::kLong: - p.setLong(in0(i + 1)); - p.checkRange(); - break; - case client::Type::kFloat: - p.setFloat(in0(i + 1)); - p.checkRange(); - break; - case client::Type::kBuffer: - // p.setBuffer( in0(i+1)); - break; - default: - break; - } - } - } - - - void next(int numsamples) - { - setParams(false); - const float* input = in(0); - const float inscalar = in0(0); - inputSignals[0]->set(const_cast(input), inscalar); - outputSignals[0]->set(out(0), out0(0)); - mClient->doProcess(std::begin(inputSignals),std::end(inputSignals),std::begin(outputSignals), std::end(outputSignals),numsamples,1,1); - } - - audio_client *mClient; - SignalWrapper *inputSignals[1]; - SignalWrapper *outputSignals[1]; - }; -} -} PluginLoad(FluidSTFTUGen) { ft = inTable; - registerUnit(ft, "FluidTransientSlice"); + using namespace fluid::client; + makeSCWrapper>(ft, "FluidTransientSlice"); }