diff --git a/include/flucoma/clients/common/FluidBaseClient.hpp b/include/flucoma/clients/common/FluidBaseClient.hpp index ea7ac98f..3aeeb3f9 100644 --- a/include/flucoma/clients/common/FluidBaseClient.hpp +++ b/include/flucoma/clients/common/FluidBaseClient.hpp @@ -20,6 +20,8 @@ under the European Union’s Horizon 2020 research and innovation programme #include "TupleUtilities.hpp" #include "../../data/FluidIndex.hpp" #include "../../data/FluidMeta.hpp" +#include +#include #include namespace fluid { @@ -29,6 +31,18 @@ namespace client { struct ModelObject {}; +// Mixin for shared clients that want to know the name they are registered +// under (e.g. for printing). The name is not a parameter: it is owned by +// NRTSharedInstanceAdaptor, which keeps this copy up to date. +struct NamedObject +{ + void setName(std::string_view name) { mName = name; } + const std::string& name() const { return mName; } + +private: + std::string mName; +}; + enum ProcessState { kNoProcess, kProcessing, kDone, kDoneStillProcessing }; struct ControlChannel { diff --git a/include/flucoma/clients/common/MessageSet.hpp b/include/flucoma/clients/common/MessageSet.hpp index 1ffa090d..51065d45 100644 --- a/include/flucoma/clients/common/MessageSet.hpp +++ b/include/flucoma/clients/common/MessageSet.hpp @@ -162,6 +162,9 @@ class MessageSet> return std::get(mMessages)(std::forward(us)...); } + /// The underlying tuple of message descriptors, e.g. for concatenating sets + const MessagesType& messages() const noexcept { return mMessages; } + private: MessagesType mMessages; @@ -184,5 +187,18 @@ MessageSet> defineMessages(Args&&... args) inline auto NoMessages = defineMessages(); +/// The tuple type held by a MessageSet +template +struct MessageTuple; + +template +struct MessageTuple>> +{ + using type = std::tuple; +}; + +template +using MessageTuple_t = typename MessageTuple::type; + } // namespace client } // namespace fluid diff --git a/include/flucoma/clients/nrt/CorpusClient.hpp b/include/flucoma/clients/nrt/CorpusClient.hpp index dd700f32..fbd4c474 100644 --- a/include/flucoma/clients/nrt/CorpusClient.hpp +++ b/include/flucoma/clients/nrt/CorpusClient.hpp @@ -30,12 +30,14 @@ namespace fluid { namespace client { namespace corpus { -enum { kName }; constexpr auto CorpusParams = - defineParameters(StringParam>("name", "Corpus name")); + defineParameters(); -class CorpusClient : public FluidBaseClient, public OfflineIn, public OfflineOut +class CorpusClient : public FluidBaseClient, + public OfflineIn, + public OfflineOut, + public NamedObject { using string = std::string; using Buffer = typename BufferT::type; @@ -72,8 +74,6 @@ class CorpusClient : public FluidBaseClient, public OfflineIn, public OfflineOut return {}; } - std::string name() const { return get(); } - MessageResult addPoint(string label, Buffer buffer, size_t offset, int length) { diff --git a/include/flucoma/clients/nrt/DataClient.hpp b/include/flucoma/clients/nrt/DataClient.hpp index 292afd40..537fa6a2 100644 --- a/include/flucoma/clients/nrt/DataClient.hpp +++ b/include/flucoma/clients/nrt/DataClient.hpp @@ -37,7 +37,6 @@ class DataClient return OK(); } - MessageResult write(string fileName) { auto file = JSONFile(fileName, "w"); diff --git a/include/flucoma/clients/nrt/DataSetClient.hpp b/include/flucoma/clients/nrt/DataSetClient.hpp index 70a96f1c..1d7c4741 100644 --- a/include/flucoma/clients/nrt/DataSetClient.hpp +++ b/include/flucoma/clients/nrt/DataSetClient.hpp @@ -22,10 +22,9 @@ namespace fluid { namespace client { namespace dataset { -enum { kName }; constexpr auto DataSetParams = - defineParameters(StringParam>("name", "Name of the DataSet")); + defineParameters(); template double distance(FluidTensorView point1, FluidTensorView point2) @@ -53,6 +52,7 @@ auto sortedDistances(FluidTensorView x, FluidTensorView Y, class DataSetClient : public FluidBaseClient, OfflineIn, OfflineOut, + public NamedObject, public DataClient> { public: @@ -306,7 +306,7 @@ class DataSetClient : public FluidBaseClient, MessageResult print() { - return "DataSet " + std::string(get()) + ": " + mAlgorithm.print(); + return "DataSet " + name() + ": " + mAlgorithm.print(); } const DataSet& getDataSet() const { return mAlgorithm; } diff --git a/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp b/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp index 8c575b41..36580131 100644 --- a/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp +++ b/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp @@ -18,13 +18,19 @@ under the European Union’s Horizon 2020 research and innovation programme #include "../../data/FluidTensor.hpp" #include "../../data/TensorTypes.hpp" #include "../../data/FluidMemory.hpp" +#include #include #include +#include #include +#include namespace fluid { namespace client { +template +class NRTSharedInstanceAdaptor; + template class ParamAliasAdaptor; @@ -45,6 +51,7 @@ class ParamAliasAdaptor> ParamSetType params{ClientWrapper::getParameterDescriptors(), FluidDefaultAllocator()}; ListenersArray listeners; + rt::string name; // key in the lookup tables; shared by all aliases std::shared_ptr getShared() { return shared_from_this(); }; }; @@ -61,136 +68,178 @@ class ParamAliasAdaptor> using ValueTuple = typename ParamSetType::ValueTuple; ParamAliasAdaptor(typename NRTClient::ParamDescType&, Allocator&) - : mParams{std::make_shared()} - {} + : mBinding{std::make_shared()} + { + mBinding->data = std::make_shared(); + } ~ParamAliasAdaptor() { - if (mParams && - mParams.use_count() == 1) // is this the last remaining user of this - // Corpus, except the hash table? - { - auto name = mParams->params.template get<0>(); - mParamsTable.erase(name); // then remove it from the universe - } + // Copies of a ParamAliasAdaptor share one Binding: only the last copy of + // this object, if it is also the last user of the shared data (except the + // hash table), removes the data from the universe + if (mBinding && mBinding.use_count() == 1 && data() && + data().use_count() == 1) + eraseEntryFor(data()); } - typename WrappedClient::ParamSetType& instance() { return mParams->params; } + typename WrappedClient::ParamSetType& instance() { return data()->params; } auto keepConstrained(bool keep) { - return mParams->params.keepConstrained(keep); + return data()->params.keepConstrained(keep); } std::array constrainParameterValues() { - return mParams->params.constrainParameterValues(); + return data()->params.constrainParameterValues(); } template