-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathOSCQuery_exploration.cpp
99 lines (80 loc) · 2.82 KB
/
OSCQuery_exploration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/*!
* \file exploration.cpp
*
* \author Clément Bossut
* \author Théo de la Hogue
*
* This code is licensed under the terms of the "CeCILL-C"
* http://www.cecill.info
*/
#include <ossia/detail/config.hpp>
#include <ossia/network/base/osc_address.hpp>
#include <ossia/network/base/parameter_data.hpp>
#include <ossia/network/common/debug.hpp>
#include <ossia/network/domain/domain.hpp>
#include <ossia/network/generic/generic_device.hpp>
#include <ossia/network/http/http_client.hpp>
#include <ossia/network/oscquery/oscquery_mirror.hpp>
#include <functional>
#include <iostream>
#include <memory>
using namespace ossia;
using namespace ossia::net;
using namespace std;
void explore(const node_base& node);
void printDomain(const domain& d);
void printValueCallback(const value& v);
int main()
{
// Create a protocol that will connect to the given websocket address
auto protocol = new ossia::oscquery::oscquery_mirror_protocol{"ws://127.0.0.1:5678"};
protocol->set_logger(network_logger{ossia::logger_ptr(), ossia::logger_ptr()});
// Create a device that will attach to this protocol
ossia::net::generic_device device{std::unique_ptr<protocol_base>(protocol), "B"};
// Explore the tree of B
std::cerr << "update: " << device.get_protocol().update(device) << std::endl;
// Display the tree in console
explore(device.get_root_node());
while(true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
protocol->run_commands();
}
ossia::net::find_node(device, "/test/my_string")
->get_parameter()
->push_value("fheakoezp");
auto node = ossia::net::find_node(device, "/test/my_float");
// Request to add an instance :
protocol->request_add_node(*node, parameter_data{"layer"});
// Again : (will become layer.1)
protocol->request_add_node(*node, parameter_data{"layer"});
// Wait a bit to get a reply
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// This will apply the changes to the tree.
protocol->run_commands();
// Wait a bit
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Display the tree with the new nodes
explore(device.get_root_node());
}
void explore(const ossia::net::node_base& node)
{
for(const auto& child : node.children_copy())
{
if(auto addr = child->get_parameter())
{
// attach to callback to display value update
addr->add_callback([=](const value& v) {
std::cerr << "[message] " << osc_parameter_string(*addr) << " <- "
<< value_to_pretty_string(v) << std::endl;
});
// update the value
addr->pull_value();
}
using namespace fmt;
fmt::print(stderr, "{}\n", *child);
explore(*child);
}
}