Skip to content

Commit

Permalink
[max/pd] Handle even more types
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 30, 2024
1 parent ab4b37c commit 55ddd8c
Show file tree
Hide file tree
Showing 13 changed files with 553 additions and 138 deletions.
127 changes: 121 additions & 6 deletions examples/Raw/AllPortsTypes.hpp

Large diffs are not rendered by default.

56 changes: 53 additions & 3 deletions include/avnd/binding/max/attributes_setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,70 @@ struct attribute_object_register<Processor, T>
template<typename F, std::size_t I>
void operator()(F& field, avnd::predicate_index<I>)
{
using value_type = std::remove_cvref_t<decltype(F::value)>;
static const auto attr_name = max::symbol_from_name<F>();

if constexpr(std::is_integral_v<decltype(F::value)>)
if constexpr(std::is_integral_v<value_type>)
{
object_attr_setlong(o, attr_name, field.value);
}
else if constexpr(std::is_floating_point_v<decltype(F::value)>)
else if constexpr(std::is_floating_point_v<value_type>)
{
object_attr_setfloat(o, attr_name, field.value);
}
else if constexpr(avnd::string_ish<decltype(F::value)>)
else if constexpr(avnd::string_ish<value_type>)
{
object_attr_setsym(o, attr_name, gensym(field.value.data()));
}
else if constexpr(std::is_enum_v<value_type>)
{
object_attr_setsym(
o, attr_name, gensym(magic_enum::enum_name(field.value).data()));
}
else if constexpr(avnd::iterable_ish<value_type>)
{
using span_val_type = typename value_type::value_type;

if constexpr(std::is_integral_v<span_val_type>)
{
using namespace std;
boost::container::small_vector<t_atom_long, 512> vec;
vec.assign(begin(field.value), end(field.value));
object_attr_setlong_array(o, attr_name, vec.size(), vec.data());
}
else if constexpr(std::is_same_v<float, span_val_type>)
{
using namespace std;
boost::container::small_vector<float, 512> vec;
vec.assign(begin(field.value), end(field.value));
object_attr_setfloat_array(o, attr_name, vec.size(), vec.data());
}
else if constexpr(std::is_floating_point_v<span_val_type>)
{
using namespace std;
boost::container::small_vector<double, 512> vec;
vec.assign(begin(field.value), end(field.value));
object_attr_setdouble_array(o, attr_name, vec.size(), vec.data());
}
else if constexpr(avnd::string_ish<span_val_type>)
{
boost::container::small_vector<t_symbol*, 512> vec;
for(auto& v : field.value)
vec.push_back(gensym(v.data()));
object_attr_setsym_array(o, attr_name, vec.size(), vec.data());
}
else if constexpr(std::is_enum_v<span_val_type>)
{
boost::container::small_vector<t_symbol*, 512> vec;
for(auto& v : field.value)
vec.push_back(gensym(magic_enum::enum_name(v).data()));
object_attr_setsym_array(o, attr_name, vec.size(), vec.data());
}
else
{
static_assert(F::error_in_attribute, "Unhandled attribute type");
}
}
else
{
static_assert(F::error_in_attribute, "Unhandled attribute type");
Expand Down
20 changes: 18 additions & 2 deletions include/avnd/binding/max/from_atoms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct from_atom
requires std::is_aggregate_v<T>
bool operator()(T& v) const noexcept = delete;

bool operator()(avnd::span_ish auto& v) const noexcept = delete;
bool operator()(avnd::iterable_ish auto& v) const noexcept = delete;
bool operator()(avnd::pair_ish auto& v) const noexcept = delete;
bool operator()(avnd::tuple_ish auto& v) const noexcept = delete;
bool operator()(avnd::map_ish auto& v) const noexcept = delete;
Expand Down Expand Up @@ -156,6 +156,20 @@ struct from_atoms
return res;
}

template <avnd::list_ish T>
bool operator()(T& v) const noexcept
{
v.clear();

for(int i = 0; i < ac; i++)
{
typename T::value_type item;
from_atom{av[i]}(item);
v.push_back(std::move(item));
}
return true;
}

bool operator()(avnd::vector_ish auto& v) const noexcept
{
v.clear();
Expand Down Expand Up @@ -308,7 +322,9 @@ struct from_atoms
}

template <typename T>
requires(std::is_aggregate_v<T> && !avnd::span_ish<T> && avnd::pfr::tuple_size_v<T> > 0)
requires(
std::is_aggregate_v<T> && !avnd::iterable_ish<T>
&& avnd::pfr::tuple_size_v<T> > 0)
bool operator()(T& v) const noexcept
{
avnd::for_each_field_ref(v, [this, i = 0] <typename F> (F& field) mutable {
Expand Down
7 changes: 5 additions & 2 deletions include/avnd/binding/max/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ concept convertible_to_fundamental_value_type
template<typename T>
struct convertible_to_fundamental_value_type_pred : std::bool_constant<convertible_to_fundamental_value_type<T>>{};

// clang-format off
template <typename T>
concept convertible_to_atom_list_statically_impl
= convertible_to_fundamental_value_type<T> ||
(avnd::bitset_ish<T>) ||
(avnd::span_ish<T> && convertible_to_fundamental_value_type<typename T::value_type>) ||
(avnd::iterable_ish<T> && convertible_to_fundamental_value_type<typename T::value_type>) ||
(avnd::pair_ish<T> && convertible_to_fundamental_value_type<typename T::first_type> && convertible_to_fundamental_value_type<typename T::second_type>) ||
(avnd::set_ish<T> && convertible_to_fundamental_value_type<typename T::value_type> && convertible_to_fundamental_value_type<typename T::mapped_type>) ||
(avnd::map_ish<T> && convertible_to_fundamental_value_type<typename T::key_type> && convertible_to_fundamental_value_type<typename T::mapped_type>) ||
(avnd::optional_ish<T> && convertible_to_fundamental_value_type<typename T::value_type>) ||
(avnd::variant_ish<T> && boost::mp11::mp_all_of<T, convertible_to_fundamental_value_type_pred>::value) ||
(avnd::tuple_ish<T> && boost::mp11::mp_all_of<T, convertible_to_fundamental_value_type_pred>::value) ||
(std::is_aggregate_v<T> && !avnd::span_ish<T> && boost::mp11::mp_all_of<avnd::as_typelist<T>, convertible_to_fundamental_value_type_pred>::value)
(std::is_aggregate_v<T> && !avnd::iterable_ish<T> && boost::mp11::mp_all_of<avnd::as_typelist<T>, convertible_to_fundamental_value_type_pred>::value)
;
// clang-format on
template <typename T>
concept convertible_to_atom_list_statically
= convertible_to_atom_list_statically_impl<std::remove_cvref_t<T>>;
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/max/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct init_arguments
call_vec(implementation, name, argc, argv);
return;
}
else if constexpr(avnd::span_ish<main_arg_type>)
else if constexpr(avnd::iterable_ish<main_arg_type>)
{
call_span(implementation, name, argc, argv);
return;
Expand Down
Loading

0 comments on commit 55ddd8c

Please sign in to comment.