From 8c783e9764f2694eae9aca8213271a389de11440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Wed, 25 Sep 2024 12:00:26 -0400 Subject: [PATCH] [ci] More msvc fixes --- cmake/avendish.pd.cmake | 10 ++- include/avnd/binding/pd/configure.hpp | 28 +++--- include/avnd/binding/pd/outputs.hpp | 124 +++++++++++--------------- include/avnd/concepts/modules.hpp | 8 ++ 4 files changed, 80 insertions(+), 90 deletions(-) diff --git a/cmake/avendish.pd.cmake b/cmake/avendish.pd.cmake index e81815db..3cc9d0ca 100644 --- a/cmake/avendish.pd.cmake +++ b/cmake/avendish.pd.cmake @@ -86,10 +86,12 @@ function(avnd_make_pd) AVND_PUREDATA=1 ) - target_precompile_headers(${AVND_FX_TARGET} - REUSE_FROM - Avendish_pd_pch - ) + if(NOT MSVC) + target_precompile_headers(${AVND_FX_TARGET} + REUSE_FROM + Avendish_pd_pch + ) + endif() target_link_libraries( ${AVND_FX_TARGET} diff --git a/include/avnd/binding/pd/configure.hpp b/include/avnd/binding/pd/configure.hpp index 3ede54dd..1dae4e5a 100644 --- a/include/avnd/binding/pd/configure.hpp +++ b/include/avnd/binding/pd/configure.hpp @@ -18,38 +18,38 @@ struct logger template static void log(fmt::format_string fmt, T&&... args) { - post("%s", fmt::format(fmt, std::forward(args)...).c_str()); + ::post("%s", fmt::format(fmt, std::forward(args)...).c_str()); } template static void error(fmt::format_string fmt, T&&... args) { - error("%s", fmt::format(fmt, std::forward(args)...).c_str()); + ::error("%s", fmt::format(fmt, std::forward(args)...).c_str()); } template static void trace(fmt::format_string fmt, T&&... args) noexcept { - log(fmt, std::forward(args)...); + logger::log(fmt, std::forward(args)...); } template static void debug(fmt::format_string fmt, T&&... args) noexcept { - log(fmt, std::forward(args)...); + logger::log(fmt, std::forward(args)...); } template static void info(fmt::format_string fmt, T&&... args) noexcept { - log(fmt, std::forward(args)...); + logger::log(fmt, std::forward(args)...); } template static void warn(fmt::format_string fmt, T&&... args) noexcept { - error(fmt, std::forward(args)...); + logger::error(fmt, std::forward(args)...); } template static void critical(fmt::format_string fmt, T&&... args) noexcept { - error(fmt, std::forward(args)...); + logger::error(fmt, std::forward(args)...); } }; #else @@ -60,7 +60,7 @@ struct logger { std::ostringstream str; ((str << args), ...); - post("%s", str.str().c_str()); + ::post("%s", str.str().c_str()); } template @@ -68,33 +68,33 @@ struct logger { std::ostringstream str; ((str << args), ...); - error("%s", str.str().c_str()); + ::error("%s", str.str().c_str()); } template static void trace(T&&... args) noexcept { - log(std::forward(args)...); + logger::log(std::forward(args)...); } template static void debug(T&&... args) noexcept { - log(std::forward(args)...); + logger::log(std::forward(args)...); } template static void info(T&&... args) noexcept { - log(std::forward(args)...); + logger::log(std::forward(args)...); } template static void warn(T&&... args) noexcept { - error(std::forward(args)...); + logger::error(std::forward(args)...); } template static void critical(T&&... args) noexcept { - error(std::forward(args)...); + logger::error(std::forward(args)...); } }; #endif diff --git a/include/avnd/binding/pd/outputs.hpp b/include/avnd/binding/pd/outputs.hpp index 0bd822d2..24f5cbd4 100644 --- a/include/avnd/binding/pd/outputs.hpp +++ b/include/avnd/binding/pd/outputs.hpp @@ -39,7 +39,7 @@ inline void value_to_pd(t_atom& atom, const std::string& v) noexcept struct do_value_to_pd_typed { template - requires std::is_aggregate_v + requires (std::is_aggregate_v && !avnd::span_ish) void operator()(t_outlet* outlet, const T& v) { static constexpr int sz = avnd::pfr::tuple_size_v; @@ -49,34 +49,6 @@ struct do_value_to_pd_typed { outlet_bang(outlet); } - else if constexpr(vecf && sz == 2) - { - auto [x, y] = v; - t_atom arg[2]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}}; - outlet_list(outlet, &s_list, 2, arg); - } - else if constexpr(vecf && sz == 3) - { - auto [x, y, z] = v; - t_atom arg[3]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}, - {.a_type = A_FLOAT, .a_w = {.w_float = z}}}; - outlet_list(outlet, &s_list, 3, arg); - } - else if constexpr(vecf && sz == 4) - { - auto [x, y, z, w] = v; - t_atom arg[4]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}, - {.a_type = A_FLOAT, .a_w = {.w_float = z}}, - {.a_type = A_FLOAT, .a_w = {.w_float = w}}, - }; - outlet_list(outlet, &s_list, 4, arg); - } else { // FIXME for pd we need to flatten outputs as there @@ -109,8 +81,20 @@ struct do_value_to_pd_typed } template - requires avnd::array_ish - void operator()(t_outlet* outlet, const T& v) + void operator()(t_outlet* outlet, const std::array& v) + { + std::array atoms; + + for(int i = 0; i < N; i++) + { + value_to_pd(atoms[i], v[i]); + } + + outlet_list(outlet, &s_list, v.size(), atoms.data()); + } + + template + void operator()(t_outlet* outlet, const avnd::array_ish auto& v) { std::array atoms; @@ -228,7 +212,7 @@ struct do_value_to_pd_typed struct do_value_to_pd_anything { template - requires std::is_aggregate_v + requires (std::is_aggregate_v && !avnd::span_ish) void operator()(t_outlet* outlet, t_symbol* sym, const T& v) { static constexpr int sz = avnd::pfr::tuple_size_v; @@ -236,36 +220,7 @@ struct do_value_to_pd_anything if constexpr(sz == 0) { - t_atom arg[1]{.a_type = A_NULL}; - outlet_anything(outlet, &s_bang, 1, arg); - } - else if constexpr(vecf && sz == 2) - { - auto [x, y] = v; - t_atom arg[2]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}}; - outlet_anything(outlet, sym, 2, arg); - } - else if constexpr(vecf && sz == 3) - { - auto [x, y, z] = v; - t_atom arg[3]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}, - {.a_type = A_FLOAT, .a_w = {.w_float = z}}}; - outlet_anything(outlet, sym, 3, arg); - } - else if constexpr(vecf && sz == 4) - { - auto [x, y, z, w] = v; - t_atom arg[4]{ - {.a_type = A_FLOAT, .a_w = {.w_float = x}}, - {.a_type = A_FLOAT, .a_w = {.w_float = y}}, - {.a_type = A_FLOAT, .a_w = {.w_float = z}}, - {.a_type = A_FLOAT, .a_w = {.w_float = w}}, - }; - outlet_anything(outlet, sym, 4, arg); + outlet_anything(outlet, sym, 0, nullptr); } else { @@ -298,9 +253,22 @@ struct do_value_to_pd_anything outlet_anything(outlet, sym, v.size(), atoms.data()); } + // FIXME msvc isn't able to match the more generic template template - requires avnd::array_ish - void operator()(t_outlet* outlet, t_symbol* sym, const T& v) + void operator()(t_outlet* outlet, t_symbol* sym, const std::array& v) + { + std::array atoms; + + for(int i = 0; i < N; i++) + { + value_to_pd(atoms[i], v[i]); + } + + outlet_anything(outlet, sym, v.size(), atoms.data()); + } + + template + void operator()(t_outlet* outlet, t_symbol* sym, const avnd::array_ish auto& v) { std::array atoms; @@ -352,7 +320,7 @@ struct do_value_to_pd_anything void operator()(t_outlet* outlet, t_symbol* sym, const T& v) { using namespace std; - visit(v, [&](const auto& element) { (*this)(outlet, element); }); + visit(v, [&](const auto& element) { (*this)(outlet, sym, element); }); } template @@ -372,38 +340,50 @@ struct do_value_to_pd_anything void operator()(t_outlet* outlet, t_symbol* sym, const T& v) { if(v) - (*this)(outlet, *v); + (*this)(outlet, sym, *v); } inline void operator()(t_outlet* outlet, t_symbol* sym, std::integral auto v) noexcept { - outlet_float(outlet, v); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } inline void operator()(t_outlet* outlet, t_symbol* sym, std::floating_point auto v) noexcept { - outlet_float(outlet, v); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } inline void operator()(t_outlet* outlet, t_symbol* sym, bool v) noexcept { - outlet_float(outlet, v ? 1.f : 0.f); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } inline void operator()(t_outlet* outlet, t_symbol* sym, const char* v) noexcept { - outlet_symbol(outlet, gensym(v)); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } inline void operator()(t_outlet* outlet, t_symbol* sym, std::string_view v) noexcept { - outlet_symbol(outlet, gensym(v.data())); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } inline void operator()(t_outlet* outlet, t_symbol* sym, const std::string& v) noexcept { - outlet_symbol(outlet, gensym(v.c_str())); + t_atom atom; + value_to_pd(atom, v); + outlet_anything(outlet, sym, 1, &atom); } template diff --git a/include/avnd/concepts/modules.hpp b/include/avnd/concepts/modules.hpp index 5ea64baf..a3a9ea15 100644 --- a/include/avnd/concepts/modules.hpp +++ b/include/avnd/concepts/modules.hpp @@ -122,6 +122,14 @@ struct has_recursive_groups_impl is_recursive_group>::value; }; +// Quick fix to catch std::array which otherwise causes a compile error with MSVC +// instead of just making the concept return false +template class Arr> +struct has_recursive_groups_impl> +{ + static constexpr bool value = false; +}; + template concept has_recursive_groups = has_recursive_groups_impl>>::value;