OSSIA
Open Scenario System for Interactive Application
ossia-pd/src/object_base.hpp
1 #pragma once
3 #include <ossia/detail/optional.hpp>
4 #include <ossia/detail/safe_vec.hpp>
6 #include <ossia/network/base/value_callback.hpp>
7 #include <ossia/network/common/path.hpp>
8 #include <ossia/network/dataspace/dataspace.hpp>
9 
10 #include <map>
11 
12 extern "C" {
13 #include <cicm_wrapper.h>
14 }
15 #include <readerwriterqueue.h>
16 
17 #define OSSIA_PD_MAX_ATTR_SIZE 256
18 
19 namespace ossia
20 {
21 namespace net
22 {
23 class node_base;
24 class parameter_base;
25 class device_base;
26 class generic_device;
27 }
28 namespace pd
29 {
30 
31 enum class object_class
32 {
33  root = 0,
34  attribute,
35  param,
36  remote,
37  model,
38  view,
39  device,
40  client
41 };
42 
43 class object_base;
44 
45 class t_select_clock
46 {
47 public:
48  t_select_clock(t_canvas* canvas, object_base* obj);
49  ~t_select_clock();
50 
51  static void deselect(t_select_clock* x);
52 
53 private:
54  t_clock* m_clock{};
55  object_base* m_obj{};
56  t_canvas* m_canvas{};
57 };
58 
59 class t_matcher
60 {
61 public:
62  t_matcher(ossia::net::node_base* n, object_base* p); // constructor
63  ~t_matcher();
64  t_matcher(const t_matcher&) = delete;
65  t_matcher(t_matcher&& other) noexcept;
66  t_matcher& operator=(const t_matcher&) = delete;
67  t_matcher& operator=(t_matcher&& other) noexcept;
68 
69  void enqueue_value(ossia::value v);
70  void output_value();
71  auto get_node() const { return node; }
72  auto get_owner() const { return owner; }
73  t_atom* get_atom_addr_ptr() { return &m_addr; }
74  void set_owner_addr();
75 
76  inline bool operator==(const t_matcher& rhs) const noexcept
77  {
78  return (this->node == rhs.node);
79  }
80  inline bool operator!=(const t_matcher& rhs) const noexcept
81  {
82  return (this->node != rhs.node);
83  }
84 
85  std::vector<ossia::value> m_set_pool;
86 
87 private:
88  ossia::net::node_base* node{};
89  object_base* owner{};
90 
91  std::optional<ossia::callback_container<ossia::value_callback>::iterator> callbackit
92  = std::nullopt;
93 
94  moodycamel::ReaderWriterQueue<ossia::value, 64> m_queue_list;
95 
96  t_atom m_addr{};
97 };
98 
99 class object_base
100 {
101 
102 public:
103  t_eobj m_obj; // should be the first element
104 
105  t_outlet* m_setout{};
106  t_outlet* m_dataout{};
107  t_outlet* m_dumpout{};
108 
109  object_class m_otype{};
110  t_symbol* m_name{};
111  ossia::net::address_scope m_addr_scope{};
112  bool m_is_pattern{}; // whether the address is a pattern or not
113  bool m_dead{false}; // whether this object is being deleted or not
114  bool m_is_deleted{false}; // true during the is_deleted callback method
115  unsigned int m_queue_length{64};
116  int m_recall_safe{0};
117 
118  t_clock* m_clock{}; // multi-purpose clock
119  std::chrono::milliseconds m_last_click{};
120 
121  t_clock* m_poll_clock{}; // value or message polling clock
122  float m_rate{10};
123 
124  ossia::net::generic_device* m_device{};
125 
126  // TODO m_parent_nodes should be a vector
127  // since we may use pattern matching in view and model
128  ossia::net::node_base* m_parent_node{};
129  std::vector<t_matcher> m_matchers{};
130  std::vector<t_matcher*> m_node_selection{};
131  std::optional<ossia::traversal::path> m_selection_path{};
132  std::vector<t_canvas*> m_patcher_hierarchy; // canvas hierarchy in ascending order
133  // starting at current canvas
134 
135  static void class_setup(t_eclass* c);
136 
137  void fill_selection();
138  void update_path();
139 
140  void set_description();
141  void set_tags();
142  void set_priority();
143  void set_hidden();
144  void set_recall_safe();
145 
146  static void get_mess_cb(object_base* x, t_symbol* s);
147  static t_pd_err
148  notify(object_base* x, t_symbol* s, t_symbol* msg, void* sender, void* data);
149  static void print_hierarchy(object_base* x);
150 
151  static void get_description(object_base* x, std::vector<t_matcher*> nodes);
152  static void get_tags(object_base* x, std::vector<t_matcher*> nodes);
153  static void get_priority(object_base* x, std::vector<t_matcher*> nodes);
154  static void get_hidden(object_base* x, std::vector<t_matcher*> nodes);
155  static void get_recall_safe(object_base* x, std::vector<t_matcher*> nodes);
156  static void get_zombie(object_base* x, std::vector<t_matcher*> nodes);
157  static void loadbang(object_base* x, t_float flag);
158 
159  t_atom m_tags[OSSIA_PD_MAX_ATTR_SIZE] = {{}};
160  t_atom m_description[OSSIA_PD_MAX_ATTR_SIZE] = {{}};
161  int m_priority{};
162  bool m_hidden{};
163 
164  long m_tags_size{};
165  long m_description_size{};
166 
167  // con/destructor
168  object_base(t_eclass* c);
169  ~object_base();
170 
171  static void update_attribute(
172  object_base* x, ossia::string_view attribute,
173  const ossia::net::node_base* node = nullptr);
174  void is_deleted(const ossia::net::node_base& n);
175 
182  static bool find_and_display_friend(object_base* x);
183 
188  static void get_address(object_base* x, std::vector<t_matcher*> nodes);
189 
190  static void select_mess_cb(object_base* x, t_symbol* s, int argc, t_atom* argv);
191 
192 protected:
193  std::optional<ossia::traversal::path> m_path;
194  std::map<std::string_view, ossia::value> m_value_map;
195 };
196 
197 }
198 } // namespace
The node_base class.
Definition: network/base/node.hpp:48
The value class.
Definition: value.hpp:173
Definition: git_info.h:7