Skip to content

Commit

Permalink
[ports] Improve conversion code for addresses with @[0] accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 25, 2024
1 parent e1d0c9e commit 8d73790
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/Servus
Submodule Servus updated 1 files
+1 −1 servus/avahi/servus.h
39 changes: 25 additions & 14 deletions src/ossia/dataflow/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ossia::unit_t>();
auto tgt_unit = source_type.target<ossia::unit_t>();
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)
Expand All @@ -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<ossia::value>& 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
}
}
Expand All @@ -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);
}
}
Expand All @@ -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)
{
Expand Down
33 changes: 17 additions & 16 deletions src/ossia/network/domain/domain_base_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct OSSIA_EXPORT domain_base
std::vector<value_type> 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}
Expand Down Expand Up @@ -66,29 +67,29 @@ struct OSSIA_EXPORT domain_base
return *this;
}

friend bool operator==(const domain_base<T>& lhs, const domain_base<T>& rhs)
friend bool operator==(const domain_base<T>& lhs, const domain_base<T>& rhs) noexcept
{
return lhs.min == rhs.min && lhs.max == rhs.max && lhs.values == rhs.values;
}
friend bool operator!=(const domain_base<T>& lhs, const domain_base<T>& rhs)
friend bool operator!=(const domain_base<T>& lhs, const domain_base<T>& 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<value_type>& 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<value_type>&& vals)
: min{v1}
, max{v2}
domain_base(value_type v1, value_type v2, ossia::flat_set<value_type>&& vals) noexcept
: min{std::move(v1)}
, max{std::move(v2)}
, values{std::move(vals)}
{
}
Expand Down Expand Up @@ -313,14 +314,14 @@ struct OSSIA_EXPORT domain_base<ossia::value>
std::vector<value_type> values;

domain_base() noexcept { }
domain_base(const domain_base<value_type>& 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<value_type>&& other) noexcept
domain_base(domain_base&& other) noexcept
: min{std::move(other.min)}
, max{std::move(other.max)}
, values{std::move(other.values)}
Expand Down

0 comments on commit 8d73790

Please sign in to comment.