Wrapper: workaround scsynth 32 char cmd length limit with extra dispatch layer

also avoids need for formerly truncated plugin names in some cases
nix
weefuzzy 4 years ago
parent 3b7e79ebac
commit 759066b574

@ -54,17 +54,10 @@ public:
template <size_t N, typename T> template <size_t N, typename T>
struct SetupMessageCmd struct SetupMessageCmd
{ {
void operator()(const T& message) void operator()(const T& message)
{ {
static std::string messageName = std::string{getName()} + '/' + message.name; static std::string messageName = std::string{getName()} + '/' + message.name;
FluidSCWrapper::registerMessage(messageName.c_str(),doMessage<N>);
if(messageName.size() >= 32u)
messageName = remove_vowel(messageName);
auto ft = getInterfaceTable();
if(!ft->fDefinePlugInCmd(messageName.c_str(), doMessage<N>,(void*)messageName.c_str()))
std::cout << "ERROR: failed to register command \"" << messageName << "\"\n";
} }
}; };

@ -20,6 +20,12 @@ namespace impl {
/// Non Real Time Processor /// Non Real Time Processor
using ServerCommandFn = void(*)(World* world, void*, struct sc_msg_iter* args,
void* replyAddr);
using CommandMap = std::unordered_map<std::string_view, ServerCommandFn>;
template <typename Client, typename Wrapper> template <typename Client, typename Wrapper>
class NonRealTime : public SCUnit class NonRealTime : public SCUnit
{ {
@ -829,8 +835,8 @@ private:
completionMsgData); completionMsgData);
if (completionMsgSize) ft->fRTFree(world, completionMsgData); if (completionMsgSize) ft->fRTFree(world, completionMsgData);
}; };
ft->fDefinePlugInCmd(Command::name(), commandRunner, nullptr); mCommandDispatchTable[Command::name()] = commandRunner;
} }
@ -1106,6 +1112,12 @@ private:
static constexpr bool IsModel = Client::isModelObject::value; static constexpr bool IsModel = Client::isModelObject::value;
public: public:
static void registerMessage(const char* name, ServerCommandFn f)
{
mCommandDispatchTable[name] = f;
}
static void setup(InterfaceTable* ft, const char*) static void setup(InterfaceTable* ft, const char*)
{ {
defineNRTCommand<CommandNew>(); defineNRTCommand<CommandNew>();
@ -1125,6 +1137,21 @@ public:
static std::string flushCmd = std::string(Wrapper::getName()) + "/flush"; static std::string flushCmd = std::string(Wrapper::getName()) + "/flush";
ft->fDefinePlugInCmd(
Wrapper::getName(),
[](World* w, void* inUserData, struct sc_msg_iter* msg, void* replyAddr)
{
const char* name = msg->gets();
auto cmd = mCommandDispatchTable.find(name);
if (cmd != mCommandDispatchTable.end())
cmd->second(w, inUserData ? inUserData : (void*)name, msg, replyAddr);
else
std::cout << "ERROR: message " << name << " not registered.";
}, nullptr);
ft->fDefinePlugInCmd( ft->fDefinePlugInCmd(
flushCmd.c_str(), flushCmd.c_str(),
[](World*, void*, struct sc_msg_iter*, void*) { mCache.clear(); }, [](World*, void*, struct sc_msg_iter*, void*) { mCache.clear(); },
@ -1176,14 +1203,21 @@ private:
index mPreviousTrigger{0}; index mPreviousTrigger{0};
bool mSynchronous{true}; bool mSynchronous{true};
Result mResult; Result mResult;
static CommandMap mCommandDispatchTable;
}; };
template <typename Client, typename Wrapper> template <typename Client, typename Wrapper>
World* NonRealTime<Client, Wrapper>::mWorld{nullptr}; World* NonRealTime<Client, Wrapper>::mWorld{nullptr};
template <typename Client, typename Wrapper> template <typename Client, typename Wrapper>
typename NonRealTime<Client, Wrapper>::Cache typename NonRealTime<Client, Wrapper>::Cache
NonRealTime<Client, Wrapper>::mCache{}; NonRealTime<Client, Wrapper>::mCache{};
template <typename Client, typename Wrapper>
CommandMap NonRealTime<Client, Wrapper>::mCommandDispatchTable{};
} // namespace impl } // namespace impl
} // namespace client } // namespace client

@ -1,9 +1,5 @@
FluidBufAudioTransport : FluidBufProcessor { FluidBufAudioTransport : FluidBufProcessor {
*objectClassName{
^\FluidBufAudioTransp
}
*kr { |sourceA, startFrameA = 0, numFramesA = -1, startChanA = 0, numChansA = -1, sourceB, startFrameB = 0, numFramesB = -1, startChanB = 0, numChansB = -1, destination, interpolation = 0.0, windowSize = 1024, hopSize = -1, fftSize = -1, trig = 1, blocking = 0| *kr { |sourceA, startFrameA = 0, numFramesA = -1, startChanA = 0, numChansA = -1, sourceB, startFrameB = 0, numFramesB = -1, startChanB = 0, numChansB = -1, destination, interpolation = 0.0, windowSize = 1024, hopSize = -1, fftSize = -1, trig = 1, blocking = 0|
var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize};

@ -1,9 +1,5 @@
FluidBufNoveltyFeature : FluidBufProcessor { FluidBufNoveltyFeature : FluidBufProcessor {
*objectClassName{
^\FluidBufNoveltyF
}
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, algorithm = 0, kernelSize = 3, filterSize = 1, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 0| *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, algorithm = 0, kernelSize = 3, filterSize = 1, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 0|
var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize};

@ -1,9 +1,5 @@
FluidBufSpectralShape : FluidBufProcessor { FluidBufSpectralShape : FluidBufProcessor {
*objectClassName{
^\FluidBufSpecShp
}
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, select, minFreq = 0, maxFreq = -1, rolloffPercent = 95, unit = 0, power = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 0| *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, select, minFreq = 0, maxFreq = -1, rolloffPercent = 95, unit = 0, power = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 0|
var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize};

@ -1,7 +1,5 @@
FluidBufTransientSlice : FluidBufProcessor { FluidBufTransientSlice : FluidBufProcessor {
*objectClassName{^\FluidBufTrSlice}
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, minSliceLength = 1000, trig = 1, blocking = 0| *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, minSliceLength = 1000, trig = 1, blocking = 0|
source = source.asUGenInput; source = source.asUGenInput;

@ -30,8 +30,7 @@ FluidServerObject
*newMsg{|id, params| *newMsg{|id, params|
params = params !? {params.collect(_.asUGenInput)}; params = params !? {params.collect(_.asUGenInput)};
// ("Newms"++params).postln; ^this.prMakeMsg(\new,id,*params);
^['/cmd',this.objectClassName ++ '/new',id] ++ params
} }
*new{ |server, id, params, action, callNew = true| *new{ |server, id, params, action, callNew = true|
@ -55,15 +54,13 @@ FluidServerObject
serverCaches[this.class].remove(server,id); serverCaches[this.class].remove(server,id);
} }
prMakeMsg{|msg,id...args| *prMakeMsg{|msg,id...args|
var commandName = "%/%".format(this.objectClassName,msg);
var commandName = "%/%".format(this.class.objectClassName,msg); ^['/cmd', this.objectClassName,commandName,id].addAll(args);
if(commandName.size >= 32) { commandName = commandName.select{|c|c.isVowel.not}};
^['/cmd',commandName,id].addAll(args);
} }
prMakeMsg{|msg,id...args| ^this.class.prMakeMsg(msg,id,*args) }
freeMsg { freeMsg {
var msg; var msg;
id ?? {" % already freed".format(this.class.name).warn; ^nil}; id ?? {" % already freed".format(this.class.name).warn; ^nil};

@ -17,5 +17,5 @@ PluginLoad(FluidSTFTUGen)
{ {
ft = inTable; ft = inTable;
using namespace fluid::client; using namespace fluid::client;
makeSCWrapper<NRTThreadedAudioTransportClient>("FluidBufAudioTransp",ft); makeSCWrapper<NRTThreadedAudioTransportClient>("FluidBufAudioTransport",ft);
} }

@ -17,5 +17,5 @@ static InterfaceTable *ft;
PluginLoad(OfflineFluidDecompositionUGens) { PluginLoad(OfflineFluidDecompositionUGens) {
ft = inTable; ft = inTable;
using namespace fluid::client; using namespace fluid::client;
makeSCWrapper<NRTThreadedNoveltyFeatureClient>("FluidBufNoveltyF", ft); makeSCWrapper<NRTThreadedNoveltyFeatureClient>("FluidBufNoveltyFeature", ft);
} }

@ -17,5 +17,5 @@ static InterfaceTable *ft;
PluginLoad(OfflineFluidDecompositionUGens) { PluginLoad(OfflineFluidDecompositionUGens) {
ft = inTable; ft = inTable;
using namespace fluid::client; using namespace fluid::client;
makeSCWrapper<NRTThreadedSpectralShapeClient>("FluidBufSpecShp", ft); makeSCWrapper<NRTThreadedSpectralShapeClient>("FluidBufSpectralShape", ft);
} }

@ -17,5 +17,5 @@ static InterfaceTable* ft;
PluginLoad(OfflineFluidDecompositionUGens) { PluginLoad(OfflineFluidDecompositionUGens) {
ft = inTable; ft = inTable;
using namespace fluid::client; using namespace fluid::client;
makeSCWrapper<NRTThreadedTransientSliceClient>("FluidBufTrSlice", ft); makeSCWrapper<NRTThreadedTransientSliceClient>("FluidBufTransientSlice", ft);
} }

Loading…
Cancel
Save