Skip to content

Commit

Permalink
[ranges] Domain & range improvements, allow value ports with ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Oct 22, 2024
1 parent 7e237ee commit e8d7216
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
58 changes: 33 additions & 25 deletions include/avnd/binding/ossia/port_setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,33 @@ struct outlet_storage

struct setup_value_port
{
template <avnd::parameter_with_minmax_range T>
ossia::domain range_to_domain()
template <avnd::parameter_with_minmax_range_ignore_init T>
static ossia::domain range_to_domain()
{
static constexpr auto dom = avnd::get_range<T>();
if constexpr(std::is_floating_point_v<decltype(dom.min)>)
return ossia::make_domain((float)dom.min, (float)dom.max);
if constexpr(std::is_same_v<std::decay_t<decltype(dom.init)>, bool>)
return ossia::domain_base<bool>{};

if constexpr(avnd::parameter_with_minmax_range<T>)
{
if constexpr(std::is_same_v<std::decay_t<decltype(dom.init)>, bool>)
return ossia::domain_base<bool>{};
else
return ossia::make_domain(dom.min, dom.max);
}
else
return ossia::make_domain(dom.min, dom.max);
}

template <avnd::string_parameter T>
ossia::domain range_to_domain()
static ossia::domain range_to_domain()
{
// FIXME
return {};
}

template <avnd::enum_parameter T>
ossia::domain range_to_domain()
static ossia::domain range_to_domain()
{
ossia::domain_base<std::string> d;
#if !defined(_MSC_VER)
Expand All @@ -228,7 +236,7 @@ struct setup_value_port
}

template <typename T>
ossia::domain range_to_domain()
static ossia::domain range_to_domain()
{
if constexpr(avnd::has_range<T> && requires { avnd::get_range<T>().values; })
{
Expand Down Expand Up @@ -269,7 +277,7 @@ struct setup_value_port

template <typename Field>
requires avnd::optional_ish<decltype(Field::value)>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
using concrete_val_type
= std::remove_cvref_t<decltype(*std::declval<Field>().value)>;
Expand All @@ -281,79 +289,79 @@ struct setup_value_port
}

template <avnd::int_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::INT;
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::float_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::FLOAT;
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::bool_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::BOOL;
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::string_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::STRING;
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::soundfile_port Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::STRING;
port.domain = ossia::domain{};
}

template <avnd::enum_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::val_type::INT;
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::xy_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::cartesian_2d_u{};
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <avnd::rgb_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::rgba_u{};
port.domain = {};
}

template <avnd::span_parameter Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
setup_port_is_event<Field>(port);
port.type = ossia::list_type();
port.domain = this->range_to_domain<Field>();
port.domain = setup_value_port::range_to_domain<Field>();
}

template <typename Field>
void setup(ossia::value_port& port)
static void setup(ossia::value_port& port)
{
if constexpr(requires { bool(Field::event); })
port.is_event = Field::event;
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/concepts/control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace avnd
*/
template <typename T>
concept control = /*(parameter<T> || callback<T>) &&*/ parameter<T>
&& (has_range<T> || has_widget<T>);
&& (/*has_range<T> || */ has_widget<T>);

// FIXME all this needs improving: they do not support callbacks.
// Also messages are not handled.
Expand Down
8 changes: 6 additions & 2 deletions include/avnd/concepts/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ template <typename T>
concept rgb_parameter = rgb_value<decltype(T::value)>;

template <typename C>
concept parameter_with_minmax_range = AVND_REQUIREMENT_ON_MEMBER(C, range, min)
&& AVND_REQUIREMENT_ON_MEMBER(C, range, max)
concept parameter_with_minmax_range_ignore_init
= AVND_REQUIREMENT_ON_MEMBER(C, range, min)
&& AVND_REQUIREMENT_ON_MEMBER(C, range, max);

template <typename C>
concept parameter_with_minmax_range = parameter_with_minmax_range_ignore_init<C>
&& AVND_REQUIREMENT_ON_MEMBER(C, range, init);

template <typename C>
Expand Down

0 comments on commit e8d7216

Please sign in to comment.