OSSIA
Open Scenario System for Interactive Application
ossia-cpp98.hpp
Go to the documentation of this file.
1 #ifndef OSSIA_CPP98_HPP_2017_07_07
2 #define OSSIA_CPP98_HPP_2017_07_07
3 #include <ossia_export.h>
4 
5 #include <cstddef>
6 #include <string>
7 #include <vector>
8 #if(__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
9 #define OSSIA_CPP_CXX11
10 #endif
11 
12 namespace ossia
13 {
14 class value;
15 namespace net
16 {
17 class node_base;
18 class parameter_base;
19 class device_base;
20 class value;
21 struct parameter_data;
22 }
23 }
57 namespace opp
58 {
66 {
67  Get,
68  Set,
69  Bi
70 };
75 {
76  Free,
77  Clip,
78  Wrap,
79  Fold,
80  Low,
81  High
82 };
83 
84 class node;
85 class oscquery_server;
86 class oscquery_mirror;
87 
88 //**************************************//
89 // value //
90 //*************************************//
91 
102 class OSSIA_EXPORT value
103 {
104 public:
109  struct vec2f
110  {
111  float data[2];
112  float& operator[](int i) { return data[i]; }
113  };
118  struct vec3f
119  {
120  float data[3];
121  float& operator[](int i) { return data[i]; }
122  };
126  struct vec4f
127  {
128  float data[4];
129  float& operator[](int i) { return data[i]; }
130  };
131 
136  struct impulse
137  {
138  };
139 
140  //*********************//
141  // Constructors //
142  //*********************//
143 
147  value();
151  ~value();
156  value(const value& v);
162  value(char v);
168  value(int v);
173  value(bool v);
178  value(float v);
183  value(double v);
188  value(const vec2f);
193  value(const vec3f);
198  value(const vec4f);
203  value(std::vector<opp::value> v);
208  value(std::string v);
213  value(const char* v);
218  value(impulse p);
219 
220  //*********************//
221  // Type tests //
222  //*********************//
223 
228  bool is_impulse() const;
233  bool is_int() const;
238  bool is_float() const;
243  bool is_bool() const;
248  bool is_vec2f() const;
253  bool is_vec3f() const;
258  bool is_vec4f() const;
263  bool is_list() const;
268  bool is_string() const;
269 
270  //*********************//
271  // Convertors //
272  //*********************//
273 
278  char to_char() const;
283  int to_int() const;
288  float to_float() const;
293  bool to_bool() const;
298  vec2f to_vec2f() const;
303  vec3f to_vec3f() const;
308  vec4f to_vec4f() const;
313  std::vector<opp::value> to_list() const;
318  std::string to_string() const;
319 
320  //*********************//
321  // Assignment Operators //
322  //*********************//
323 
329  value& operator=(const value& v);
335  value& operator=(char v);
341  value& operator=(int v);
347  value& operator=(float v);
353  value& operator=(bool v);
359  value& operator=(vec2f v);
365  value& operator=(vec3f v);
371  value& operator=(vec4f v);
377  value& operator=(std::vector<opp::value> v);
383  value& operator=(std::string v);
384 
390  bool operator==(const opp::value& v) const;
391 
397  bool operator!=(const opp::value& v) const;
401  void set_impulse();
406  void set_int(int v);
411  void set_float(float v);
416  void set_bool(bool v);
421  void set_vec2f(vec2f v);
426  void set_vec3f(vec3f v);
431  void set_vec4f(vec4f v);
436  void set_list(std::vector<opp::value> v);
441  void set_string(std::string v);
442 
443 #if defined(OSSIA_CPP_CXX11)
444  value(value&& v) noexcept;
445  value& operator=(value&& v) noexcept;
446 #endif
447 
455  {
456  return m_val;
457  }
458 
459 private:
460  friend class node;
461  friend class oscquery_mirror; // needed to build an opp::value from a const
462  // ossia::value& in
463  // oscquery_mirror::on_unhandled_message_callback()
464  value(const ossia::value& v);
465  template <typename T>
466  value(const T* v);
467  ossia::value* m_val;
468 };
469 
474 typedef void (*value_callback)(void*, const opp::value&);
478 typedef void (*connection_callback)(void*, const std::string&);
482 typedef void (*disconnection_callback)(void*, const std::string&);
485 typedef void (*parameter_callback)(void*, const opp::node&);
488 typedef void (*node_callback)(void*, const opp::node&);
491 typedef void (*node_rn_callback)(void*, const opp::node&, std::string);
494 typedef void (*message_callback)(void*, const opp::node&);
497 typedef void (*unhandled_message_callback)(void*, const std::string&, const opp::value&);
500 typedef void (*attribute_modified_callback)(void*, const opp::node&, const std::string&);
504 typedef bool (*rename_node_callback)(void*, const std::string&, const std::string&);
508 typedef bool (*remove_node_callback)(void*, const std::string&);
512 typedef bool (*add_node_callback)(void*, const std::string&, const std::string&);
513 
522 struct OSSIA_EXPORT callback_index
523 {
524  callback_index();
525  ~callback_index();
527  callback_index& operator=(const callback_index&);
528  operator bool() const;
529 
530 private:
531  friend class node;
532 
533  struct impl;
534  impl* index;
535 };
536 
551 class OSSIA_EXPORT node
552 {
553 public:
554  //*********************//
555  // Constructors //
556  //*********************//
557 
561  node();
565  node(const node&);
570  node& operator=(const node&);
571 
575  ~node();
576 
581  operator bool() const;
582 
586  node parent() const;
587 
592  void request_add_child(const std::string&);
593 
598  void request_remove_child(const std::string&);
599 
604  void request_rename_child(const std::string&, const std::string&);
605 
610  std::string get_name() const;
615  void set_name(std::string s);
616 
621  bool has_parameter() const;
622 
627  std::string get_address() const;
632  std::vector<node> get_namespace() const;
637  std::vector<node> get_children() const;
643  node find_child(std::string addr) const;
644 
650  std::vector<node> find_children(std::string pattern) const;
651 
656  void remove_child(std::string addr);
660  void remove_children();
661 
662  //*********************//
663  // Create Nodes //
664  //*********************//
665 
673  node create_child(std::string addr);
674 
675  //*********************//
676  // Add parameters //
677  //*********************//
678 
683  void set_impulse();
688  void set_char();
693  void set_int();
698  void set_float();
703  void set_bool();
708  void set_vec2f();
713  void set_vec3f();
718  void set_vec4f();
723  void set_list();
728  void set_string();
733  void set_buffer();
739  void set_filepath();
745  void set_rgb();
751  void set_rgba();
757  void set_argb();
763  void set_argb8();
769  void set_rgba8();
775  void set_hsv();
780  void set_cart2D();
785  void set_cart3D();
792  void set_opengl();
798  void set_polar();
805  void set_spherical();
812  void set_cylindrical();
817  void set_angle_radian();
822  void set_angle_degree();
829  void set_quaternion();
836  void set_euler();
842  void set_axis();
849  void set_decibel();
855  void set_midigain();
860  void set_linear();
865  void set_frequency();
870  void set_midi_pitch();
875  void set_bpm();
876 
877  //************************************//
878  // Create Nodes with parameters //
879  //************************************//
880 
887  node create_void(std::string addr);
894  node create_impulse(std::string addr);
901  node create_int(std::string addr);
908  node create_float(std::string addr);
915  node create_bool(std::string addr);
922  node create_vec2f(std::string addr);
929  node create_vec3f(std::string addr);
936  node create_vec4f(std::string addr);
943  node create_list(std::string addr);
950  node create_string(std::string addr);
957  node create_buffer(std::string addr);
965  node create_filepath(std::string addr);
974  node create_rgb(std::string addr);
983  node create_rgba(std::string addr);
992  node create_rgba8(std::string addr);
1001  node create_argb(std::string addr);
1010  node create_argb8(std::string addr);
1019  node create_hsv(std::string addr);
1027  node create_cart2D(std::string addr);
1035  node create_cart3D(std::string addr);
1044  node create_opengl(std::string addr);
1053  node create_polar(std::string addr);
1062  node create_spherical(std::string addr);
1071  node create_cylindrical(std::string addr);
1072 
1080  node create_angle_radian(std::string addr);
1088  node create_angle_degree(std::string addr);
1089 
1098  node create_quaternion(std::string addr);
1107  node create_euler(std::string addr);
1116  node create_axis(std::string addr);
1126  node create_decibel(std::string addr);
1135  node create_midigain(std::string addr);
1143  node create_linear(std::string addr);
1151  node create_frequency(std::string addr);
1159  node create_midi_pitch(std::string addr);
1167  node create_bpm(std::string addr);
1168 
1169  //************************************//
1170  // Manage values //
1171  //************************************//
1172 
1179  node& set_value(opp::value v);
1184  opp::value get_value() const;
1190  opp::value fetch_value() const;
1191 
1203  callback_index set_value_callback(value_callback c, void* ctx);
1209  void remove_value_callback(callback_index idx);
1210 
1211  //************************************//
1212  // Manage attributes //
1213  //************************************//
1214 
1215  //********* Access mode: ************//
1216 
1233  node& set_access(access_mode v);
1239  access_mode get_access() const;
1240 
1241  //********* Domain: ************//
1242 
1254  node& set_min(opp::value min);
1261  opp::value get_min() const;
1273  node& set_max(opp::value max);
1280  opp::value get_max() const;
1292  node& set_accepted_values(std::vector<opp::value> v);
1301  std::vector<opp::value> get_accepted_values() const;
1302 
1303  //********* Bounding mode: ************//
1304 
1322  node& set_bounding(bounding_mode v);
1327  bounding_mode get_bounding() const;
1328 
1329  //********* Units: ************//
1330 
1349  node& set_unit(std::string v);
1473  std::string get_unit() const;
1474 
1475  //********* Other value management attributes: ************//
1476 
1484  node& set_default_value(value v);
1489  value get_default_value();
1490 
1498  node& set_repetition_filter(bool v);
1503  bool get_repetition_filter() const;
1504 
1511  node& set_refresh_rate(int v);
1516  node& unset_refresh_rate();
1521  int get_refresh_rate();
1522 
1530  node& set_value_step_size(double v);
1535  node& unset_value_step_size();
1540  double get_value_step_size();
1541 
1549  node& set_priority(float v);
1554  node& unset_priority();
1560  float get_priority();
1561 
1569  node& set_disabled(bool v);
1574  bool get_disabled() const;
1575 
1583  node& set_muted(bool v);
1588  bool get_muted() const;
1589 
1598  node& set_critical(bool v);
1603  bool get_critical() const;
1604 
1605  //********* Other informative attributes: ************//
1606 
1613  node& set_description(std::string v);
1618  std::string get_description() const;
1619 
1626  node& set_tags(std::vector<std::string> v);
1631  std::vector<std::string> get_tags() const;
1632 
1642  node& set_instance_bounds(int min, int max);
1647  node& unset_instance_bounds();
1653  std::pair<int, int> get_instance_bounds() const;
1654 
1661  node& set_hidden(bool v);
1666  bool get_hidden() const;
1667 
1675  bool get_zombie() const;
1676 
1677  /***********/
1678  /* PRESETS */
1679  /***********/
1680 
1685  void load_preset(const std::string& filename);
1686 
1691  void save_preset(const std::string& filename);
1692 
1693 #if defined(OSSIA_CPP_CXX11)
1694  node(node&&) noexcept;
1695  node& operator=(node&&) noexcept;
1696 #endif
1697 
1705  {
1706  return m_node;
1707  }
1708 
1709 private:
1710  friend class oscquery_mirror;
1711  friend class oscquery_server;
1714  void init();
1715  void cleanup(const ossia::net::node_base&);
1716  void cleanup_parameter(const ossia::net::parameter_base&);
1717 
1718  ossia::net::node_base* m_node;
1719  ossia::net::parameter_base* m_param;
1720 };
1721 
1736 class OSSIA_EXPORT oscquery_server
1737 {
1738 public:
1744  oscquery_server();
1753  oscquery_server(std::string name, int oscPort = 1234, int wsPort = 5678);
1757  ~oscquery_server();
1767  void setup(std::string name, int oscPort = 1234, int wsPort = 5678);
1768 
1775  node get_root_node() const;
1776 
1782  void set_echo(bool echo);
1783 
1790  bool get_echo();
1791 
1797  void set_connection_callback(connection_callback c, void* ctx);
1801  void remove_connection_callback();
1802 
1808  void set_disconnection_callback(disconnection_callback c, void* ctx);
1812  void remove_disconnection_callback();
1813 
1819  void set_add_node_callback(add_node_callback c, void* ctx);
1820  void remove_add_node_callback();
1821 
1827  void set_remove_node_callback(remove_node_callback c, void* ctx);
1828  void remove_remove_node_callback();
1829 
1835  void set_rename_node_callback(rename_node_callback c, void* ctx);
1836  void remove_rename_node_callback();
1837 
1841  bool connected() const;
1842 
1851 
1852 private:
1853  void on_connection(const std::string&);
1854  void on_disconnection(const std::string&);
1855  void on_add_node_request(
1856  const std::string& parent, const ossia::net::parameter_data& param);
1857  void on_remove_node_request(const std::string& parent, const std::string& node);
1858  void
1859  on_rename_node_request(const std::string& node_to_rename, const std::string& new_name);
1860  ossia::net::device_base* m_dev;
1861 
1862  connection_callback m_con;
1863  void* m_con_ctx;
1864 
1865  disconnection_callback m_discon;
1866  void* m_discon_ctx;
1867 
1868  add_node_callback m_add_node_cb;
1869  void* m_add_node_ctx;
1870 
1871  remove_node_callback m_remove_node_cb;
1872  void* m_remove_node_ctx;
1873 
1874  rename_node_callback m_rename_node_cb;
1875  void* m_rename_node_ctx;
1876 };
1877 
1886 class OSSIA_EXPORT oscquery_mirror
1887 {
1888 public:
1900  oscquery_mirror(std::string name, std::string host = "ws://127.0.0.1:5678");
1904  ~oscquery_mirror();
1905 
1912  node get_root_node() const;
1913 
1919  void refresh();
1920 
1925  void update();
1926 
1934  void reconnect(std::string name = "", std::string host = "");
1935 
1940  bool is_connected() const { return m_dev != nullptr; }
1941 
1947  void set_parameter_created_callback(parameter_callback c, void* ctx);
1951  void remove_parameter_created_callback();
1952 
1958  void set_parameter_removed_callback(parameter_callback c, void* ctx);
1962  void remove_parameter_removed_callback();
1963 
1969  void set_node_created_callback(node_callback c, void* ctx);
1973  void remove_node_created_callback();
1974 
1980  void set_node_removed_callback(node_callback c, void* ctx);
1984  void remove_node_removed_callback();
1985 
1991  void set_node_renamed_callback(node_rn_callback c, void* ctx);
1995  void remove_node_renamed_callback();
1996 
2002  void set_message_callback(message_callback c, void* ctx);
2006  void remove_message_callback();
2007 
2013  void set_unhandled_message_callback(unhandled_message_callback c, void* ctx);
2017  void remove_unhandled_message_callback();
2018 
2024  void set_attribute_modified_callback(attribute_modified_callback c, void* ctx);
2025 
2029  void remove_attribute_modified_callback();
2030 
2035  void set_zombie_on_remove(bool b);
2036 
2041  bool get_zombie_on_remove() const;
2042 
2048  void request_add_node(node parent, const std::string& name);
2049 
2054  void request_remove_node(node node_to_be_removed);
2055 
2061  void request_rename_node(node node, std::string new_name);
2062 
2071 
2072 private:
2073  void on_parameter_created(const ossia::net::parameter_base&);
2074  void on_parameter_removed(const ossia::net::parameter_base&);
2075 
2076  void on_node_created(ossia::net::node_base&);
2077  void on_node_removed(ossia::net::node_base&);
2078  void on_node_renamed(ossia::net::node_base&, std::string);
2079 
2080  void on_message(const ossia::net::parameter_base&);
2081  void on_unhandled_message(const std::string&, const ossia::value&);
2082  void on_attribute_modified(ossia::net::node_base&, const std::string&);
2083 
2084  ossia::net::device_base* m_dev;
2085  parameter_callback m_param_cb;
2086  void* m_param_ctx;
2087 
2088  parameter_callback m_rm_param_cb;
2089  void* m_rm_param_ctx;
2090 
2091  node_callback m_node_cb;
2092  void* m_node_ctx;
2093 
2094  node_callback m_rm_node_cb;
2095  void* m_rm_node_ctx;
2096 
2097  node_rn_callback m_rn_node_cb;
2098  void* m_rn_node_ctx;
2099 
2100  message_callback m_message_cb;
2101  void* m_message_ctx;
2102 
2103  unhandled_message_callback m_unhandled_message_cb;
2104  void* m_unhandled_message_ctx;
2105 
2106  attribute_modified_callback m_attribute_modified_cb;
2107  void* m_attribute_modified_ctx;
2108 
2109  std::string m_name;
2110  std::string m_host;
2111 };
2112 }
2113 
2116 #endif
The node class holds all ossia nodes and their std::optional parameters.
Definition: ossia-cpp98.hpp:552
ossia::net::node_base * get_raw_node_pointer()
Get the raw node pointer.
Definition: ossia-cpp98.hpp:1704
void set_char()
adds a char parameter to the current node
The oscquery_mirror class allows to create a mirror image of a remote OSCQuery server.
Definition: ossia-cpp98.hpp:1887
ossia::net::device_base * get_raw_device_pointer()
Get the raw device pointer.
Definition: ossia-cpp98.hpp:2070
bool is_connected() const
is_connected
Definition: ossia-cpp98.hpp:1940
The oscquery_server class allows to create a local OSCQuery server.
Definition: ossia-cpp98.hpp:1737
ossia::net::device_base * get_raw_device_pointer()
Get the raw device pointer.
Definition: ossia-cpp98.hpp:1850
The value class holds all ossia parameters typed values.
Definition: ossia-cpp98.hpp:103
ossia::value * get_raw_value_pointer()
Get the raw value pointer.
Definition: ossia-cpp98.hpp:454
Root of a device tree.
Definition: ossia/network/base/device.hpp:58
The node_base class.
Definition: node.hpp:48
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
The value class.
Definition: value.hpp:173
Definition: ossia-cpp98.cpp:25
bool(* remove_node_callback)(void *, const std::string &)
container for a node remove request callback should return true if node could be remove
Definition: ossia-cpp98.hpp:508
void(* message_callback)(void *, const opp::node &)
container for a message callback
Definition: ossia-cpp98.hpp:494
void(* parameter_callback)(void *, const opp::node &)
container for a parameter creation/deletion callback
Definition: ossia-cpp98.hpp:485
bool(* rename_node_callback)(void *, const std::string &, const std::string &)
container for a node rename request callback should return true if node could be renamed
Definition: ossia-cpp98.hpp:504
void(* unhandled_message_callback)(void *, const std::string &, const opp::value &)
container for an unhandled message callback
Definition: ossia-cpp98.hpp:497
access_mode
Defines Write (Set), Read (Get) or Read/Write (Bi) access to the parameter's value.
Definition: ossia-cpp98.hpp:66
@ Set
Definition: ossia-cpp98.hpp:68
@ Bi
Definition: ossia-cpp98.hpp:69
@ Get
Definition: ossia-cpp98.hpp:67
bounding_mode
Behaviour at the bounds of the value.
Definition: ossia-cpp98.hpp:75
@ Low
Definition: ossia-cpp98.hpp:80
@ Fold
Definition: ossia-cpp98.hpp:79
@ High
Definition: ossia-cpp98.hpp:81
@ Wrap
Definition: ossia-cpp98.hpp:78
@ Clip
Definition: ossia-cpp98.hpp:77
@ Free
Definition: ossia-cpp98.hpp:76
void(* connection_callback)(void *, const std::string &)
container for a connection callback
Definition: ossia-cpp98.hpp:478
void(* node_rn_callback)(void *, const opp::node &, std::string)
container for a node renamed callback
Definition: ossia-cpp98.hpp:491
void(* node_callback)(void *, const opp::node &)
container for a node creation/deletion callback
Definition: ossia-cpp98.hpp:488
void(* disconnection_callback)(void *, const std::string &)
container for a disconnection callback
Definition: ossia-cpp98.hpp:482
bool(* add_node_callback)(void *, const std::string &, const std::string &)
container for a node creation request callback should return true if node could be created
Definition: ossia-cpp98.hpp:512
void(* attribute_modified_callback)(void *, const opp::node &, const std::string &)
container for an attribute modified callback
Definition: ossia-cpp98.hpp:500
void(* value_callback)(void *, const opp::value &)
container for a value callback
Definition: ossia-cpp98.hpp:474
Definition: git_info.h:7
constexpr OSSIA_INLINE auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition: math.hpp:125
constexpr OSSIA_INLINE auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition: math.hpp:96
The callback_index struct holds callbacks for adding listeners to parameters' values.
Definition: ossia-cpp98.hpp:523
Definition: ossia-cpp98.hpp:137
container for a vector of 2 floats
Definition: ossia-cpp98.hpp:110
container for a vector of 3 floats
Definition: ossia-cpp98.hpp:119
container for a vector of 4 floats
Definition: ossia-cpp98.hpp:127
The data that can be found inside a parameter.
Definition: parameter_data.hpp:21