Skip to content

Commit

Permalink
[net] Add a more optimized device_parameter implementation when we kn…
Browse files Browse the repository at this point in the history
…ow the type beforehand
  • Loading branch information
jcelerier committed Aug 14, 2024
1 parent 504dd19 commit f48994c
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ossia/detail/triple_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class triple_buffer
std::atomic_flag stale;

public:
triple_buffer(T init)
explicit triple_buffer(T init)
{
// Store the initial data in the "ready" buffer:
data[1] = std::move(init);
Expand Down Expand Up @@ -53,6 +53,8 @@ class triple_buffer
res = std::move(*p);
return true;
}

auto& get_data() noexcept { return this->data; }
};

}
2 changes: 0 additions & 2 deletions src/ossia/network/common/device_parameter.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#pragma once

#include <ossia/network/base/node.hpp>
Expand All @@ -13,7 +12,6 @@ namespace ossia::net

class OSSIA_EXPORT device_parameter : public ossia::net::parameter_base
{

public:
device_parameter(
ossia::net::node_base& node, const ossia::val_type type,
Expand Down
109 changes: 109 additions & 0 deletions src/ossia/network/common/device_parameter_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once

#include <ossia/network/base/node.hpp>
#include <ossia/network/base/protocol.hpp>
#include <ossia/network/common/complex_type.hpp>
#include <ossia/network/domain/domain.hpp>
#include <ossia/network/oscquery/oscquery_server.hpp>
#include <ossia/network/value/value.hpp>

namespace ossia::net
{
template <typename T>
class device_parameter_t : public ossia::net::parameter_base
{
public:
explicit device_parameter_t(net::node_base& node)
: net::parameter_base{node}
, m_current_value{}
{
set_repetition_filter(repetition_filter::ON);
}

~device_parameter_t() = default;

void device_value_change_event(const ossia::value& val)
{
if(val.valid())
{
m_current_value = val;
get_protocol().push(*this);
}
}

void pull_value() override { get_protocol().pull(*this); }

ossia::value value() const override { return m_current_value; }

net::parameter_base& push_value(const ossia::value& val) override
{
set_value(val);
get_protocol().push(*this);
return *this;
}

net::parameter_base& push_value(ossia::value&& val) override
{
return push_value(val);
}

net::parameter_base& push_value() override
{
get_protocol().push(*this);
return *this;
}

ossia::value set_value(const ossia::value& val) override
{
if(val.valid())
{
m_current_value = ossia::convert<T>(val);
send(val);
device_update_value();
}

return m_current_value;
}

ossia::value set_value(ossia::value&& val) override { return set_value(val); }

ossia::val_type get_value_type() const noexcept override
{
return ossia::value_trait<T>::ossia_enum;
}

ossia::net::parameter_base& set_value_type(ossia::val_type) override { return *this; }

ossia::access_mode get_access() const noexcept override
{
return ossia::access_mode::SET;
}
ossia::net::parameter_base& set_access(ossia::access_mode) override { return *this; }

const domain& get_domain() const noexcept override
{
static const thread_local ossia::domain dom;
return dom;
}

ossia::bounding_mode get_bounding() const noexcept override
{
return ossia::bounding_mode::CLIP;
}
ossia::net::parameter_base& set_bounding(ossia::bounding_mode) override
{
return *this;
}

ossia::net::parameter_base& set_domain(const ossia::domain&) override { return *this; }

protected:
virtual void device_update_value()
{
// Here should be the code that actually make the hardware update to
// current value
}

T m_current_value;
};
}
1 change: 1 addition & 0 deletions src/ossia_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ set(API_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/common/path.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/common/complex_type.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/common/device_parameter.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/common/device_parameter_t.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/generic/generic_parameter.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/generic/generic_device.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/network/generic/generic_node.hpp"
Expand Down

0 comments on commit f48994c

Please sign in to comment.