Skip to content

Commit

Permalink
[ci] More msvc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 25, 2024
1 parent 862e90c commit 8c783e9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 90 deletions.
10 changes: 6 additions & 4 deletions cmake/avendish.pd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
28 changes: 14 additions & 14 deletions include/avnd/binding/pd/configure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ struct logger
template <typename... T>
static void log(fmt::format_string<T...> fmt, T&&... args)
{
post("%s", fmt::format(fmt, std::forward<T>(args)...).c_str());
::post("%s", fmt::format(fmt, std::forward<T>(args)...).c_str());
}

template <typename... T>
static void error(fmt::format_string<T...> fmt, T&&... args)
{
error("%s", fmt::format(fmt, std::forward<T>(args)...).c_str());
::error("%s", fmt::format(fmt, std::forward<T>(args)...).c_str());
}
template <typename... T>
static void trace(fmt::format_string<T...> fmt, T&&... args) noexcept
{
log(fmt, std::forward<T>(args)...);
logger::log(fmt, std::forward<T>(args)...);
}
template <typename... T>
static void debug(fmt::format_string<T...> fmt, T&&... args) noexcept
{
log(fmt, std::forward<T>(args)...);
logger::log(fmt, std::forward<T>(args)...);
}
template <typename... T>
static void info(fmt::format_string<T...> fmt, T&&... args) noexcept
{
log(fmt, std::forward<T>(args)...);
logger::log(fmt, std::forward<T>(args)...);
}
template <typename... T>
static void warn(fmt::format_string<T...> fmt, T&&... args) noexcept
{
error(fmt, std::forward<T>(args)...);
logger::error(fmt, std::forward<T>(args)...);
}
template <typename... T>
static void critical(fmt::format_string<T...> fmt, T&&... args) noexcept
{
error(fmt, std::forward<T>(args)...);
logger::error(fmt, std::forward<T>(args)...);
}
};
#else
Expand All @@ -60,41 +60,41 @@ struct logger
{
std::ostringstream str;
((str << args), ...);
post("%s", str.str().c_str());
::post("%s", str.str().c_str());
}

template <typename... T>
static void error(T&&... args)
{
std::ostringstream str;
((str << args), ...);
error("%s", str.str().c_str());
::error("%s", str.str().c_str());
}

template <typename... T>
static void trace(T&&... args) noexcept
{
log(std::forward<T>(args)...);
logger::log(std::forward<T>(args)...);
}
template <typename... T>
static void debug(T&&... args) noexcept
{
log(std::forward<T>(args)...);
logger::log(std::forward<T>(args)...);
}
template <typename... T>
static void info(T&&... args) noexcept
{
log(std::forward<T>(args)...);
logger::log(std::forward<T>(args)...);
}
template <typename... T>
static void warn(T&&... args) noexcept
{
error(std::forward<T>(args)...);
logger::error(std::forward<T>(args)...);
}
template <typename... T>
static void critical(T&&... args) noexcept
{
error(std::forward<T>(args)...);
logger::error(std::forward<T>(args)...);
}
};
#endif
Expand Down
124 changes: 52 additions & 72 deletions include/avnd/binding/pd/outputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline void value_to_pd(t_atom& atom, const std::string& v) noexcept
struct do_value_to_pd_typed
{
template <typename T>
requires std::is_aggregate_v<T>
requires (std::is_aggregate_v<T> && !avnd::span_ish<T>)
void operator()(t_outlet* outlet, const T& v)
{
static constexpr int sz = avnd::pfr::tuple_size_v<T>;
Expand All @@ -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
Expand Down Expand Up @@ -109,8 +81,20 @@ struct do_value_to_pd_typed
}

template <typename T, std::size_t N>
requires avnd::array_ish<T, N>
void operator()(t_outlet* outlet, const T& v)
void operator()(t_outlet* outlet, const std::array<T, N>& v)
{
std::array<t_atom, N> 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 <std::size_t N>
void operator()(t_outlet* outlet, const avnd::array_ish<N> auto& v)
{
std::array<t_atom, N> atoms;

Expand Down Expand Up @@ -228,44 +212,15 @@ struct do_value_to_pd_typed
struct do_value_to_pd_anything
{
template <typename T>
requires std::is_aggregate_v<T>
requires (std::is_aggregate_v<T> && !avnd::span_ish<T>)
void operator()(t_outlet* outlet, t_symbol* sym, const T& v)
{
static constexpr int sz = avnd::pfr::tuple_size_v<T>;
static constexpr bool vecf = avnd::vecf_compatible<T>();

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
{
Expand Down Expand Up @@ -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 <typename T, std::size_t N>
requires avnd::array_ish<T, N>
void operator()(t_outlet* outlet, t_symbol* sym, const T& v)
void operator()(t_outlet* outlet, t_symbol* sym, const std::array<T, N>& v)
{
std::array<t_atom, N> atoms;

for(int i = 0; i < N; i++)
{
value_to_pd(atoms[i], v[i]);
}

outlet_anything(outlet, sym, v.size(), atoms.data());
}

template <std::size_t N>
void operator()(t_outlet* outlet, t_symbol* sym, const avnd::array_ish<N> auto& v)
{
std::array<t_atom, N> atoms;

Expand Down Expand Up @@ -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 <typename T>
Expand All @@ -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 <typename... Args>
Expand Down
8 changes: 8 additions & 0 deletions include/avnd/concepts/modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, std::size_t N, template<typename TT, std::size_t NN> class Arr>
struct has_recursive_groups_impl<Arr<T,N>>
{
static constexpr bool value = false;
};

template <typename T>
concept has_recursive_groups
= has_recursive_groups_impl<std::remove_reference_t<std::remove_const_t<T>>>::value;
Expand Down

0 comments on commit 8c783e9

Please sign in to comment.