Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
################################################################################
# Paths
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "")
Expand Down Expand Up @@ -89,7 +89,7 @@ include(flucoma-buildtools)
include(flucoma-buildtype)
# endif()

option(DOCS "Generate scdocs" OFF)
option(DOCS "Generate scdocs" ON)
set(FLUID_DOCS_PATH "" CACHE PATH "Optional path to flucoma-docs (needed for docs); will download if absent")

if(DOCS)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Note that on macOS you may need to [dequarantine](https://learn.flucoma.org/inst
## Pre-requisites


* C++14 compliant compiler (clang, GCC or MSVC)
* C++17 compliant compiler (clang, GCC or MSVC)
* cmake
* make (or Ninja or XCode or VisualStudio)
* git
Expand Down
7 changes: 4 additions & 3 deletions include/FluidSCWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase<C>

}

static auto& setParams(Unit* x, ParamSetType& p,
FloatControlsIter& inputs, bool constrain = false, bool initialized = true)
static auto& setParams(Unit* x, ParamSetType& p, FloatControlsIter& inputs,
Allocator& alloc, bool constrain = false,
bool initialized = true)
{
bool verbose = x->mWorld->mVerbosity > 0;

using Reportage = decltype(static_cast<FluidSCWrapper*>(x)->mReportage);

Reportage* reportage = initialized ? &(static_cast<FluidSCWrapper*>(x)->mReportage) : new Reportage();

p.template setParameterValuesRT<ControlSetter>(verbose ? reportage: nullptr , x, inputs);
p.template setParameterValuesRT<ControlSetter>(verbose ? reportage: nullptr , x, inputs, alloc);
if (constrain) p.constrainParameterValuesRT(verbose ? reportage : nullptr);
if(verbose)
{
Expand Down
4 changes: 2 additions & 2 deletions include/clients/rt/FluidDataSetWr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class DataSetWriterClient : public FluidBaseClient, OfflineIn, OfflineOut {

static constexpr auto &getParameterDescriptors() { return DataSetWrParams; }

DataSetWriterClient(ParamSetViewType &p) : mParams(p) {}
DataSetWriterClient(ParamSetViewType &p, FluidContext&) : mParams(p) {}

template <typename T> Result process(FluidContext &) {
auto dataset = get<kDataSet>().get();
if (auto datasetPtr = dataset.lock()) {
std::string &idPrefix = get<kIDPrefix>();
std::string idPrefix = std::string(get<kIDPrefix>());
auto &idNumberArr = get<kIDNumber>();
if (idNumberArr.size() != 2)
return {Result::Status::kError, "ID number malformed"};
Expand Down
35 changes: 25 additions & 10 deletions include/wrapper/ArgsFromClient.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "Meta.hpp"
#include <data/FluidMemory.hpp>
#include <fmt/format.h>

namespace fluid {
namespace client {
Expand Down Expand Up @@ -40,7 +42,11 @@ struct ParamReader<impl::FloatControlsIter>

using Controls = impl::FloatControlsIter;

static auto fromArgs(Unit* /*x*/, Controls& args, std::string, int)
/// todo: fix std::string to use a specialisation with RT alloc
template <typename Alloc>
static auto
fromArgs(Unit* /*x*/, Controls& args,
std::basic_string<char, std::char_traits<char>, Alloc> const&, int)
{
// first is string size, then chars
index size = static_cast<index>(args.next());
Expand All @@ -50,14 +56,15 @@ struct ParamReader<impl::FloatControlsIter>
res[asUnsigned(i)] = static_cast<char>(args.next());
return res;
}

static auto fromArgs(Unit*, Controls& args,typename LongArrayT::type&, int)
{
//first is array size, then items
using Container = typename LongArrayT::type;
using Value = typename Container::type;
index size = static_cast<index>(args.next());
Container res(size);
/// todo: fix allocator
Container res(size, FluidDefaultAllocator());
for (index i = 0; i < size; ++i)
res[i] = static_cast<Value>(args.next());
return res;
Expand Down Expand Up @@ -225,7 +232,8 @@ struct ParamReader<sc_msg_iter>
return argTypeOK(T{},tag);
}

static auto fromArgs(World*, sc_msg_iter& args, std::string, int)
template<typename Alloc>
static auto fromArgs(World*, sc_msg_iter& args, std::basic_string<char,std::char_traits<char>,Alloc> const&, int)
{
const char* recv = args.gets("");

Expand Down Expand Up @@ -285,7 +293,7 @@ struct ParamReader<sc_msg_iter>
using Container = typename LongArrayT::type;
using Value = typename Container::type;
index size = static_cast<index>(args.geti());
Container res(size);
Container res(size, FluidDefaultAllocator());
for (index i = 0; i < size; ++i)
res[i] = static_cast<Value>(args.geti());
return res;
Expand Down Expand Up @@ -325,14 +333,14 @@ struct ClientParams{

template<typename Context, typename Client = typename Wrapper::Client, size_t Number = N>
std::enable_if_t<!impl::IsNamedShared_v<Client> || Number!=0, typename T::type>
operator()(Context* x, ArgType& args)
operator()(Context* x, ArgType& args, Allocator& alloc)
{
// Just return default if there's nothing left to grab
if (args.remain() == 0)
{
std::cout << "WARNING: " << Wrapper::getName()
<< " received fewer parameters than expected\n";
return Wrapper::Client::getParameterDescriptors().template makeValue<N>();
return Wrapper::Client::getParameterDescriptors().template makeValue<N>(alloc);
}

ParamLiteralConvertor<T, argSize> a;
Expand All @@ -348,18 +356,25 @@ struct ClientParams{

template<typename Context, typename Client = typename Wrapper::Client, size_t Number = N>
std::enable_if_t<impl::IsNamedShared_v<Client> && Number==0, typename T::type>
operator()(Context* x, ArgType& args)
operator()(Context* x, ArgType& args, Allocator& alloc)
{
// Just return default if there's nothing left to grab
if (args.remain() == 0)
{
std::cout << "WARNING: " << Wrapper::getName()
<< " received fewer parameters than expected\n";
return Wrapper::Client::getParameterDescriptors().template makeValue<N>();
return Wrapper::Client::getParameterDescriptors().template makeValue<N>(alloc);
}

index id = ParamReader<ArgType>::fromArgs(x,args,index{},0);
return std::to_string(id);
using StdAlloc = foonathan::memory::std_allocator<char, Allocator>;
using fmt_memory_buffer =
fmt::basic_memory_buffer<char, fmt::inline_buffer_size, StdAlloc>;
auto buf = fmt_memory_buffer(alloc);
std::string_view fmt_string("{}");
fmt::vformat_to(std::back_inserter(buf), fmt_string,
fmt::make_format_args(id));
return rt::string(buf.data(), buf.size(), alloc);
}
};

Expand Down
43 changes: 28 additions & 15 deletions include/wrapper/ArgsToClient.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <data/FluidMemory.hpp>

namespace fluid {
namespace client {

Expand All @@ -15,20 +17,20 @@ namespace client {
return 1;
}

static index allocSize(std::string s)
static index allocSize(std::string const& s)
{
return asSigned(s.size()) + 1;
} // put null char at end when we send

static index allocSize(FluidTensor<std::string, 1> s)
static index allocSize(FluidTensor<std::string, 1> const& s)
{
index count = 0;
for (auto& str : s) count += (str.size() + 1);
return count;
}

template <typename T>
static index allocSize(FluidTensor<T, 1> s)
static index allocSize(FluidTensor<T, 1> const& s)
{
return s.size();
}
Expand Down Expand Up @@ -68,12 +70,12 @@ namespace client {
f[0] = static_cast<float>(x);
}

static void convert(float* f, std::string s)
static void convert(float* f, std::string const& s)
{
std::copy(s.begin(), s.end(), f);
f[s.size()] = 0; // terminate
}
static void convert(float* f, FluidTensor<std::string, 1> s)
static void convert(float* f, FluidTensor<std::string, 1> const& s)
{
for (auto& str : s)
{
Expand All @@ -83,7 +85,7 @@ namespace client {
}
}
template <typename T>
static void convert(float* f, FluidTensor<T, 1> s)
static void convert(float* f, FluidTensor<T, 1> const& s)
{
static_assert(std::is_convertible<T, float>::value,
"Can't convert this to float output");
Expand Down Expand Up @@ -114,19 +116,24 @@ namespace client {
return 1;
}

static index numTags(std::string)
static index numTags(rt::string const&)
{
return 1;;
}

static index numTags(std::string const&)
{
return 1;;
}

template <typename T>
static index numTags(FluidTensor<T, 1> s)
static index numTags(FluidTensor<T, 1> const& s)
{
return s.size();
}

template <typename... Ts>
static index numTags(std::tuple<Ts...>&& t)
static index numTags(std::tuple<Ts...> const& t)
{
index count = 0;
ForEach(t,[&count](auto& x){ count += numTags(x);});
Expand All @@ -143,18 +150,19 @@ namespace client {
static std::enable_if_t<std::is_floating_point<std::decay_t<T>>::value>
getTag(Packet& p, T&&) { p.addtag('f'); }

static void getTag (Packet& p, std::string) { p.addtag('s'); }
static void getTag (Packet& p, std::string const&) { p.addtag('s'); }
static void getTag (Packet& p, rt::string const&) { p.addtag('s'); }

template <typename T>
static void getTag(Packet& p, FluidTensor<T, 1> x)
static void getTag(Packet& p, FluidTensor<T, 1> const& x)
{
T dummy{};
for (int i = 0; i < x.rows(); i++)
getTag(p, dummy);
}

template <typename... Ts>
static void getTag(Packet& p, std::tuple<Ts...>&& t)
static void getTag(Packet& p, std::tuple<Ts...> const& t)
{
ForEach(t,[&p](auto& x){getTag(p,x);});
}
Expand All @@ -179,19 +187,24 @@ namespace client {
p.addf(static_cast<float>(x));
}

static void convert(Packet& p, std::string s)
static void convert(Packet& p, std::string const& s)
{
p.adds(s.c_str());
}

static void convert(Packet& p, rt::string const& s)
{
p.adds(s.c_str());
}

template <typename T>
static void convert(Packet& p, FluidTensor<T, 1> s)
static void convert(Packet& p, FluidTensor<T, 1> const& s)
{
for(auto& x: s) convert(p,x);
}

template <typename... Ts>
static void convert(Packet& p, std::tuple<Ts...>&& t)
static void convert(Packet& p, std::tuple<Ts...> const& t)
{
ForEach(t,[&p](auto& x){ convert(p,x);});
}
Expand Down
12 changes: 5 additions & 7 deletions include/wrapper/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct FluidSCMessaging{

static void refreshParams(Params& p, MessageResult<ParamValues>& r)
{
p.fromTuple(ParamValues(r));
p.fromTuple(r.value());
}

template<typename T>
Expand Down Expand Up @@ -253,7 +253,7 @@ struct FluidSCMessaging{
template <typename T> // call from RT
static void messageOutput(const std::string& s, index id, MessageResult<T>& result, void* replyAddr)
{
index numTags = ToOSCTypes<small_scpacket>::numTags(static_cast<T>(result));
index numTags = ToOSCTypes<small_scpacket>::numTags(result.value());
if(numTags > 2048)
{
std::cout << "ERROR: Message response too big to send (" << asUnsigned(numTags) * sizeof(float) << " bytes)." << std::endl;
Expand Down Expand Up @@ -290,9 +290,7 @@ struct FluidSCMessaging{
template <typename... Ts>
static void messageOutput(const std::string& s, index id, MessageResult<std::tuple<Ts...>>& result, void* replyAddr)
{
using T = std::tuple<Ts...>;

index numTags = ToOSCTypes<small_scpacket>::numTags(static_cast<T>(result));
index numTags = ToOSCTypes<small_scpacket>::numTags(result.value());
if(numTags > 2048)
{
std::cout << "ERROR: Message response too big to send (" << asUnsigned(numTags) * sizeof(float) << " bytes)." << std::endl;
Expand All @@ -304,10 +302,10 @@ struct FluidSCMessaging{
packet.maketags(static_cast<int>(numTags + 2));
packet.addtag(',');
packet.addtag('i');
ToOSCTypes<small_scpacket>::getTag(packet,static_cast<T>(result));
ToOSCTypes<small_scpacket>::getTag(packet,result.value());

packet.addi(static_cast<int>(id));
ToOSCTypes<small_scpacket>::convert(packet, static_cast<T>(result));
ToOSCTypes<small_scpacket>::convert(packet, result.value());

if(replyAddr)
SendReply(replyAddr,packet.data(),static_cast<int>(packet.size()));
Expand Down
Loading