2#include <State/Value.hpp>
3#include <State/ValueConversion.hpp>
5#include <Process/TypeConversion.hpp>
7#include <LocalTree/BaseCallbackWrapper.hpp>
9#include <score/tools/Debug.hpp>
10#include <score/tools/std/Invoke.hpp>
12#include <ossia/network/base/node.hpp>
14#include <QApplication>
18using qt_property_converter_T
19 = ossia::qt_property_converter<std::remove_const_t<std::remove_reference_t<T>>>;
21template <
typename Property>
24 using model_t =
typename Property::model_type;
25 using param_t =
typename Property::param_type;
30 bool in_push_from_qt{};
31 bool in_push_from_ossia{};
32 auto push_from_qt()
noexcept
40 self.in_push_from_qt =
true;
42 ~res() { self.in_push_from_qt =
false; }
46 auto push_from_ossia()
noexcept
54 self.in_push_from_ossia =
true;
56 ~res() { self.in_push_from_ossia =
false; }
62 std::shared_ptr<shared_state> state
63 = std::make_shared<shared_state>(
shared_state{.active =
true});
64 using converter_t = ossia::qt_property_converter<typename Property::param_type>;
65 PropertyWrapper(ossia::net::parameter_base& param_addr, model_t& obj, QObject* context)
70 = QObject::connect(&m_model, Property::notify, context, [
this, state = state] {
73 if(state->in_push_from_qt)
75 if(state->in_push_from_ossia)
77 auto push = state->push_from_qt();
79 auto newVal = converter_t::convert((m_model.*Property::get)());
82 auto res = addr.value();
86 addr.push_value(newVal);
92 }, Qt::QueuedConnection);
94 addr.set_value(converter_t::convert((m_model.*Property::get)()));
95 callbackIt = addr.add_callback(
96 [=, m = QPointer<model_t>{&m_model}, state = state](
const ossia::value& v) {
99 if(state->in_push_from_qt)
101 if(state->in_push_from_ossia)
103 auto push = state->push_from_ossia();
104 ossia::qt::run_async(qApp, [m, v] {
106 ((*m).*Property::set)(::State::convert::value<param_t>(v));
114 state->active =
false;
115 auto& node = this->addr.get_node();
116 auto par = node.get_parent();
118 par->remove_child(node);
122template <
typename Property,
typename Object>
123auto add_property(ossia::net::node_base& n, Object& obj, QObject* context)
125 SCORE_ASSERT(!std::string_view(Property::name).empty());
126 constexpr const auto t
127 = ossia::qt_property_converter<typename Property::param_type>::val;
128 auto node = n.create_child(Property::name);
131 auto addr = node->create_parameter(t);
134 addr->set_access(ossia::access_mode::BI);
135 return std::make_unique<PropertyWrapper<Property>>(*addr, obj, context);
138template <
typename Property,
typename Object>
140 ossia::net::node_base& n, Object& obj,
const std::string& name, QObject* context)
142 SCORE_ASSERT(!name.empty());
143 constexpr const auto t
144 = ossia::qt_property_converter<typename Property::param_type>::val;
145 auto node = n.create_child(name);
148 auto addr = node->create_parameter(t);
151 addr->set_access(ossia::access_mode::BI);
152 return std::make_unique<PropertyWrapper<Property>>(*addr, obj, context);
Definition BaseCallbackWrapper.hpp:11
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition BaseCallbackWrapper.hpp:9
Definition Property.hpp:28
Definition Property.hpp:23