From 8d7379095f4e65160389a533d954ec8b4ad875d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 25 Jun 2024 05:27:45 -0400 Subject: [PATCH] [ports] Improve conversion code for addresses with @[0] accessors --- 3rdparty/Servus | 2 +- src/ossia/dataflow/data.cpp | 39 ++++++++++++------- src/ossia/network/domain/domain_base_impl.hpp | 33 ++++++++-------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/3rdparty/Servus b/3rdparty/Servus index a2bfcd9d352..19492c2cf71 160000 --- a/3rdparty/Servus +++ b/3rdparty/Servus @@ -1 +1 @@ -Subproject commit a2bfcd9d352f2320e80b6aa61742238adb7ec7fb +Subproject commit 19492c2cf719c77cd8e305ee45bbbe7a2e3badf3 diff --git a/src/ossia/dataflow/data.cpp b/src/ossia/dataflow/data.cpp index 1f5066aa397..5c527d68913 100644 --- a/src/ossia/dataflow/data.cpp +++ b/src/ossia/dataflow/data.cpp @@ -12,6 +12,15 @@ namespace ossia { namespace { + +static inline ossia::complex_type +get_complex_type(const ossia::net::parameter_base& other) noexcept +{ + if(const auto u = other.get_unit()) + return u; + return other.get_value_type(); +} + // TODO we should take a visitor that takes (value, source_domain, sink_domain) // for each argument and does the right thing struct process_float_control_visitor @@ -291,11 +300,18 @@ static void filter_value( const ossia::destination_index& res_index, const ossia::complex_type& source_type, const ossia::complex_type& res_type) { - if(source_type && res_type && source_type != res_type) - source = ossia::convert(source, source_type, res_type); + // 1. Convert from source unit to destination unit + auto src_unit = source_type.target(); + auto tgt_unit = source_type.target(); + if(src_unit && tgt_unit && *src_unit != *tgt_unit) + { + source = ossia::convert(source, *src_unit, *tgt_unit); + } if(source.valid() && !res_index.empty()) + { source = get_value_at_index(source, res_index); + } } void value_port::add_local_value(const ossia::typed_value& other) @@ -317,15 +333,16 @@ void value_port::add_local_value(const ossia::typed_value& other) void value_port::add_global_values( const net::parameter_base& other, const value_vector& vec) { - const ossia::complex_type source_type = other.get_unit(); + const ossia::complex_type source_type = get_complex_type(other); if(index.empty() && (source_type == type || !source_type)) { - if(other.get_domain() && this->domain) + const auto& other_domain = other.get_domain(); + if(other_domain && this->domain) { for(ossia::value v : vec) { - map_value(v, index, other.get_domain(), this->domain); + map_value(v, index, other_domain, this->domain); write_value(std::move(v), 0); // TODO put correct timestamps here } } @@ -339,12 +356,13 @@ void value_port::add_global_values( } else { - if(other.get_domain() && this->domain) + const auto& other_domain = other.get_domain(); + if(other_domain && this->domain) { for(ossia::value v : vec) { filter_value(v, {}, index, source_type, type); - map_value(v, index, other.get_domain(), this->domain); + map_value(v, index, other_domain, this->domain); write_value(std::move(v), 0); } } @@ -359,13 +377,6 @@ void value_port::add_global_values( } } -ossia::complex_type get_complex_type(const ossia::net::parameter_base& other) -{ - if(other.get_unit()) - return other.get_unit(); - return other.get_value_type(); -} - void value_port::add_global_value( const ossia::net::parameter_base& other, ossia::value val) { diff --git a/src/ossia/network/domain/domain_base_impl.hpp b/src/ossia/network/domain/domain_base_impl.hpp index b28446270a9..8485d1944ea 100644 --- a/src/ossia/network/domain/domain_base_impl.hpp +++ b/src/ossia/network/domain/domain_base_impl.hpp @@ -36,7 +36,8 @@ struct OSSIA_EXPORT domain_base std::vector values; domain_base() noexcept { } - domain_base(const domain_base& other) noexcept + + domain_base(const domain_base& other) : min{other.min} , max{other.max} , values{other.values} @@ -66,29 +67,29 @@ struct OSSIA_EXPORT domain_base return *this; } - friend bool operator==(const domain_base& lhs, const domain_base& rhs) + friend bool operator==(const domain_base& lhs, const domain_base& rhs) noexcept { return lhs.min == rhs.min && lhs.max == rhs.max && lhs.values == rhs.values; } - friend bool operator!=(const domain_base& lhs, const domain_base& rhs) + friend bool operator!=(const domain_base& lhs, const domain_base& rhs) noexcept { return lhs.min != rhs.min || lhs.max != rhs.max || lhs.values != rhs.values; } - domain_base(value_type v1, value_type v2) - : min{v1} - , max{v2} + domain_base(value_type v1, value_type v2) noexcept + : min{std::move(v1)} + , max{std::move(v2)} { } domain_base(value_type v1, value_type v2, const ossia::flat_set& vals) - : min{v1} - , max{v2} + : min{std::move(v1)} + , max{std::move(v2)} , values{vals} { } - domain_base(value_type v1, value_type v2, ossia::flat_set&& vals) - : min{v1} - , max{v2} + domain_base(value_type v1, value_type v2, ossia::flat_set&& vals) noexcept + : min{std::move(v1)} + , max{std::move(v2)} , values{std::move(vals)} { } @@ -313,14 +314,14 @@ struct OSSIA_EXPORT domain_base std::vector values; domain_base() noexcept { } - domain_base(const domain_base& other) noexcept - : min{std::move(other.min)} - , max{std::move(other.max)} - , values{std::move(other.values)} + domain_base(const domain_base& other) noexcept + : min{other.min} + , max{other.max} + , values{other.values} { } - domain_base(domain_base&& other) noexcept + domain_base(domain_base&& other) noexcept : min{std::move(other.min)} , max{std::move(other.max)} , values{std::move(other.values)}