From e8d7216befd1d45c667ae70f5cff513a53e193c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 22 Oct 2024 18:09:44 -0400 Subject: [PATCH] [ranges] Domain & range improvements, allow value ports with ranges --- include/avnd/binding/ossia/port_setup.hpp | 58 +++++++++++++---------- include/avnd/concepts/control.hpp | 2 +- include/avnd/concepts/parameter.hpp | 8 +++- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/include/avnd/binding/ossia/port_setup.hpp b/include/avnd/binding/ossia/port_setup.hpp index cd952d5b..db053bf4 100644 --- a/include/avnd/binding/ossia/port_setup.hpp +++ b/include/avnd/binding/ossia/port_setup.hpp @@ -199,25 +199,33 @@ struct outlet_storage struct setup_value_port { - template - ossia::domain range_to_domain() + template + static ossia::domain range_to_domain() { static constexpr auto dom = avnd::get_range(); if constexpr(std::is_floating_point_v) return ossia::make_domain((float)dom.min, (float)dom.max); - if constexpr(std::is_same_v, bool>) - return ossia::domain_base{}; + + if constexpr(avnd::parameter_with_minmax_range) + { + if constexpr(std::is_same_v, bool>) + return ossia::domain_base{}; + else + return ossia::make_domain(dom.min, dom.max); + } else return ossia::make_domain(dom.min, dom.max); } + template - ossia::domain range_to_domain() + static ossia::domain range_to_domain() { + // FIXME return {}; } template - ossia::domain range_to_domain() + static ossia::domain range_to_domain() { ossia::domain_base d; #if !defined(_MSC_VER) @@ -228,7 +236,7 @@ struct setup_value_port } template - ossia::domain range_to_domain() + static ossia::domain range_to_domain() { if constexpr(avnd::has_range && requires { avnd::get_range().values; }) { @@ -269,7 +277,7 @@ struct setup_value_port template requires avnd::optional_ish - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { using concrete_val_type = std::remove_cvref_t().value)>; @@ -281,39 +289,39 @@ struct setup_value_port } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::INT; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::FLOAT; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::BOOL; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::STRING; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::STRING; @@ -321,23 +329,23 @@ struct setup_value_port } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::val_type::INT; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::cartesian_2d_u{}; - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::rgba_u{}; @@ -345,15 +353,15 @@ struct setup_value_port } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { setup_port_is_event(port); port.type = ossia::list_type(); - port.domain = this->range_to_domain(); + port.domain = setup_value_port::range_to_domain(); } template - void setup(ossia::value_port& port) + static void setup(ossia::value_port& port) { if constexpr(requires { bool(Field::event); }) port.is_event = Field::event; diff --git a/include/avnd/concepts/control.hpp b/include/avnd/concepts/control.hpp index d51505f2..b1978421 100644 --- a/include/avnd/concepts/control.hpp +++ b/include/avnd/concepts/control.hpp @@ -31,7 +31,7 @@ namespace avnd */ template concept control = /*(parameter || callback) &&*/ parameter - && (has_range || has_widget); + && (/*has_range || */ has_widget); // FIXME all this needs improving: they do not support callbacks. // Also messages are not handled. diff --git a/include/avnd/concepts/parameter.hpp b/include/avnd/concepts/parameter.hpp index 50e0c374..e6bf9b0f 100644 --- a/include/avnd/concepts/parameter.hpp +++ b/include/avnd/concepts/parameter.hpp @@ -105,8 +105,12 @@ template concept rgb_parameter = rgb_value; template -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 +concept parameter_with_minmax_range = parameter_with_minmax_range_ignore_init && AVND_REQUIREMENT_ON_MEMBER(C, range, init); template