GetProperty.hpp
1 #pragma once
2 #include <Process/TypeConversion.hpp>
3 
4 #include <LocalTree/BaseCallbackWrapper.hpp>
5 
6 #include <score/tools/Debug.hpp>
7 
8 #include <ossia/network/base/node.hpp>
9 
10 #include <QObject>
11 
12 namespace LocalTree
13 {
14 
15 template <typename Property>
16 struct GetPropertyWrapper final : public BaseProperty
17 {
18  using model_t = typename Property::model_type;
19  using param_t = typename Property::param_type;
20  model_t& m_model;
21  using converter_t = ossia::qt_property_converter<typename Property::param_type>;
22 
24  ossia::net::parameter_base& param_addr, model_t& obj, QObject* context)
25  : BaseProperty{param_addr}
26  , m_model{obj}
27  {
28  QObject::connect(
29  &m_model, Property::notify, context,
30  [&m = m_model, &addr = addr] {
31  auto newVal = converter_t::convert((m.*Property::get)());
32  try
33  {
34  auto res = addr.value();
35 
36  if(newVal != res)
37  {
38  addr.push_value(newVal);
39  }
40  }
41  catch(...)
42  {
43  }
44  },
45  Qt::QueuedConnection);
46 
47  addr.set_value(converter_t::convert((m_model.*Property::get)()));
48  }
49 };
50 
51 template <typename Property, typename Object>
52 auto add_getProperty(ossia::net::node_base& n, Object& obj, QObject* context)
53 {
54  constexpr const auto t
55  = ossia::qt_property_converter<typename Property::param_type>::val;
56  auto node = n.create_child(Property::name);
57  SCORE_ASSERT(node);
58 
59  auto addr = node->create_parameter(t);
60  SCORE_ASSERT(addr);
61 
62  addr->set_access(ossia::access_mode::GET);
63 
64  return std::make_unique<GetPropertyWrapper<Property>>(*addr, obj, context);
65 }
66 }
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition: BaseCallbackWrapper.hpp:9
Definition: BaseProperty.hpp:12
Definition: GetProperty.hpp:17