From 9ac0e7f9b4e9e0b68cc4a3c9de64de3fd113de16 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 27 Mar 2017 16:54:14 +0200 Subject: [PATCH 001/363] data/ssr.conf.example: Adding networking configuration. --- data/ssr.conf.example | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index eca99e30..67478ec4 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -95,6 +95,20 @@ # carriage return: 13) #END_OF_MESSAGE_CHARACTER = 10 +############################ Networking configuration ########################## + +# networking mode (client|server|off) +#NETWORK_MODE = server + +# networking port for sending (default: 50001) +#NETWORK_PORT_SEND = 50001 + +# networking port for receiving (default: 50002) +#NETWORK_PORT_RECEIVE = 50002 + +# networking clients by hostname:port +#NETWORK_CLIENTS = "test:50002 test:50002" + ############################## Verbosity Level ################################# # Set the level of system information From 2c753177501b45e99604b7d2a3ff30ab867c68b8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 27 Mar 2017 16:55:05 +0200 Subject: [PATCH 002/363] src/configuration.h: Adding struct members for networking mode. --- src/configuration.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 18b0b030..6da09c27 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,6 +57,10 @@ struct conf_struct std::string output_port_prefix; ///< e.g. "alsa_pcm:playback" std::string path_to_gui_images; ///< dto. std::string path_to_scene_menu; ///< path to scene_menu.conf + std::string network_mode; ///< network mode (client or server) + std::string network_clients; ///< list of network clients and ports + int network_port_send; ///< network sending port + int network_port_receive; ///< network receiving port int end_of_message_character; ///< ASCII bool auto_rotate_sources; ///< Automatic orientation of sources From 623929c3be4d10e1e7fd0f0aa35a3d8066944031 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 27 Mar 2017 17:09:22 +0200 Subject: [PATCH 003/363] .gitignore: Adding entries for local build, ctags and compile_commands. --- .gitignore | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.gitignore b/.gitignore index 66e82732..30f5be28 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,55 @@ ssr_scene_autosave.asd +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +autotools/ +compile_commands.json +config.log +config.status +configure +configure.orig +data/MacOSX/DMG-Layout.applescript +data/MacOSX/Info.plist +data/MacOSX/Makefile +data/MacOSX/Makefile.in +data/MacOSX/dylibbundler/src/.deps/ +data/Makefile +data/Makefile.in +data/ssr-aap +data/ssr-binaural +data/ssr-brs +data/ssr-generic +data/ssr-nfc-hoa +data/ssr-vbap +data/ssr-wfs +doc/*.pdf +doc/doxygen/ +doc/manual/_build/ +libtool +man/ +src/.deps/ +src/Makefile +src/Makefile.in +src/config.h* +src/gui/.deps/ +src/gui/.dirstamp +src/gui/*.o +src/gui/*_moc.cpp +src/network/.deps/ +src/network/.dirstamp +src/network/*.o +src/razor-ahrs/.deps/ +src/razor-ahrs/.dirstamp +src/razor-ahrs/RazorAHRS.o +src/ssr-aap +src/ssr-binaural +src/ssr-brs +src/ssr-generic +src/ssr-nfc-hoa +src/ssr-vbap +src/ssr-wfs +src/*.o +src/stamp-h1 +ssr-qt4.patch +tags From 6d2a994303e6904e6b5290fb55f714972d563a57 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:30:55 +0200 Subject: [PATCH 004/363] src/configuration.h: Turning network_clients field into a multimap to have unique keys. --- src/configuration.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/configuration.h b/src/configuration.h index 6da09c27..a22e15ee 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -30,6 +30,7 @@ #ifndef SSR_CONFIGURATION_H #define SSR_CONFIGURATION_H +#include #include #include "apf/parameter_map.h" @@ -58,7 +59,8 @@ struct conf_struct std::string path_to_gui_images; ///< dto. std::string path_to_scene_menu; ///< path to scene_menu.conf std::string network_mode; ///< network mode (client or server) - std::string network_clients; ///< list of network clients and ports + ///< list of network clients and ports + std::multimap network_clients; int network_port_send; ///< network sending port int network_port_receive; ///< network receiving port int end_of_message_character; ///< ASCII From c338df7779bfec29508ae2e8b4b58988b420e09e Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:35:07 +0200 Subject: [PATCH 005/363] src/configuration.cpp: First version of functionality to parse network clients and ports from flag or configuration file. Adding flags for network-mode, network-port-receive, network-port-send and network-clients. --- src/configuration.cpp | 121 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index d9ad17e0..8f2b51ca 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -39,6 +39,7 @@ #include // for getenv(), ... #include #include +#include // for parse_network_clients #include "configuration.h" #include "posixpathtools.h" #include "apf/stringtools.h" @@ -108,6 +109,55 @@ namespace // anonymous } } +/* This function removes all whitespaces from a string. + * If the string is " " it will return an empty string. + */ +std::string trim(const std::string& str) +{ + if (str == " ") return ""; + size_t first = str.find_first_not_of(' '); + if (std::string::npos == first) + { + return str; + } + size_t last = str.find_last_not_of(' '); + return str.substr(first, (last - first + 1)); +} + +/* This function retrieves tuples of key value pairs from a comma-separated + * string and stores it in a multimap. + */ +static int parse_network_clients(const char *input, + std::multimap clients){ + std::istringstream iss(input); + std::string name; + int port; + std::string token; + + while (std::getline(iss, token, ',')) { + size_t pos = token.find(':'); + std::string port_temp = trim(token.substr(pos+1)); + name = trim(token.substr(0, pos)); + + if (!name.empty()) + { + std::cout << name << "(" << name.length() << ")" << std::endl; + std::cout << port_temp << "(" << port_temp.length() << ")" << std::endl; + // if no port supplied, insert standard + if ( port_temp.empty() || port_temp == name ) + { + port = 50002; + } + else + { + port = std::stoi(port_temp); + } + clients.insert(make_pair(name, port)); + } + } + return CONFIG_SUCCESS; +} + /** parse command line options and configuration file(s) * @param argc number of command line arguments. * @param argv the arguments themselves. @@ -154,6 +204,11 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.path_to_scene_menu = "./scene_menu.conf"; conf.end_of_message_character = 0; // default: binary zero + // default network settings, also stated in data/ssr.conf.example + conf.network_mode = "client"; + conf.network_port_send = 50001; + conf.network_port_receive = 50002; + conf.renderer_params.set("decay_exponent", 1); // 1 / r^1 conf.renderer_params.set("amplitude_reference_distance", 3); // meters @@ -240,6 +295,16 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) " --no-auto-rotation\n" " Don't auto-rotate sound sources' orientation toward " "the reference\n" +" -N --network_mode=VALUE\n" +" Which network mode to use: client or server " + "(default: client)\n" +" -C --network_clients=VALUE\n" +" List of network clients and their ports (e.g. " + "client1:50002 client2:50002)\n" +" -P --network_port_send=VALUE\n" +" Port to send OSC messages from (default: 50001)\n" +" -p --network_port_receive=VALUE\n" +" Port to receive OSC messages on (default: 50002)\n" #ifdef ENABLE_IP_INTERFACE " -i, --ip-server[=PORT]\n" @@ -323,6 +388,10 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) {"master-volume-correction", required_argument, nullptr, 0}, {"auto-rotation", no_argument, nullptr, 0 }, {"no-auto-rotation", no_argument, nullptr, 0 }, + {"network-mode", required_argument, nullptr, 'N'}, + {"network-clients", required_argument, nullptr, 'C'}, + {"network-port-send", required_argument, nullptr, 'P'}, + {"network-port-receive", required_argument, nullptr, 'p'}, {"ip-server", optional_argument, nullptr, 'i'}, {"no-ip-server", no_argument, nullptr, 'I'}, {"end-of-message-character", required_argument, nullptr, 0}, @@ -341,7 +410,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) }; // one colon: required argument; two colons: optional argument // if first character is '-', non-option arguments return 1 (see case 1 below) - const char *optstring = "-c:fgGhi::In:o:r:s:t:TvV?"; + const char *optstring = "-c:C:fgGhi::IN:n:o:P:p:r:s:t:TvV?"; int opt; int longindex = 0; @@ -441,6 +510,9 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) + std::string(optarg) + "\"!"); } break; + case 'C': + parse_network_clients(optarg, conf.network_clients); + break; case 'f': conf.freewheeling = true; @@ -478,6 +550,16 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.ip_server = false; break; + case 'N': + //TODO: check if correct string + if (!strcasecmp(optarg, "client") || !strcasecmp(optarg, "server")) + { + conf.network_mode = optarg; + } + else { + ERROR("'"<< optarg << "' is not understood as option for network-mode."); + } + break; case 'n': conf.renderer_params.set("name", optarg); break; @@ -485,6 +567,20 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) case 'o': conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; + case 'P': + //TODO: check if in port range + if (!S2A(optarg, conf.network_port_send)) + { + ERROR("Invalid port for network send specified!"); + } + break; + case 'p': + //TODO: check if in port range + if (!S2A(optarg, conf.network_port_receive)) + { + ERROR("Invalid port for network receive specified!"); + } + break; case 'r': conf.audio_recorder_file_name = optarg; @@ -558,6 +654,7 @@ static int is_comment_or_empty(const char *line){ return (*line == '#') || (!*line); } + /******************************************************************************/ /* This function takes a line from the configuration file and splits @@ -790,6 +887,28 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ if (!strcasecmp(value, "on")) conf.gui = true; else conf.gui = false; } + else if (!strcmp(key, "NETWORK_MODE")) + { + if (!strcasecmp(value, "client") || !strcasecmp(value, "server")) + { + conf.network_mode = value; + } + else { + ERROR("'"<< value << "' is not understood as option for network-mode."); + } + } + else if (!strcmp(key, "NETWORK_CLIENTS")) + { + parse_network_clients(value, conf.network_clients); + } + else if (!strcmp(key, "NETWORK_PORT_SEND")) + { + conf.network_port_send = atoi(value); + } + else if (!strcmp(key, "NETWORK_PORT_RECEIVE")) + { + conf.network_port_receive = atoi(value); + } else if (!strcmp(key, "NETWORK_INTERFACE")) { #ifdef ENABLE_IP_INTERFACE From a9f691d9bf56622d4d7e60dde3125a1aa1052c6a Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:57:15 +0200 Subject: [PATCH 006/363] src/configuration.cpp: Renaming trim to remove_whitespace. Moving curly bracket to next line in parse_network_clients. --- src/configuration.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 8f2b51ca..2df63b47 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -112,7 +112,7 @@ namespace // anonymous /* This function removes all whitespaces from a string. * If the string is " " it will return an empty string. */ -std::string trim(const std::string& str) +std::string remove_whitespace(const std::string& str) { if (str == " ") return ""; size_t first = str.find_first_not_of(' '); @@ -128,7 +128,8 @@ std::string trim(const std::string& str) * string and stores it in a multimap. */ static int parse_network_clients(const char *input, - std::multimap clients){ + std::multimap clients) +{ std::istringstream iss(input); std::string name; int port; @@ -136,8 +137,8 @@ static int parse_network_clients(const char *input, while (std::getline(iss, token, ',')) { size_t pos = token.find(':'); - std::string port_temp = trim(token.substr(pos+1)); - name = trim(token.substr(0, pos)); + std::string port_temp = remove_whitespace(token.substr(pos+1)); + name = remove_whitespace(token.substr(0, pos)); if (!name.empty()) { From 8e13c3fea64a03f8ac47a290e2ce32390e923eb0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 18:25:24 +0200 Subject: [PATCH 007/363] src/configuration.cpp: parse_network_clients removing printouts of names, adding VERBOSE2 messages about which clients are added. Moving remove_whitespace to ssr namespace. src/configuration.h: Defining remove_whitespace in ssr namespace. --- src/configuration.cpp | 12 +++++++----- src/configuration.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 2df63b47..acfa725e 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -112,7 +112,7 @@ namespace // anonymous /* This function removes all whitespaces from a string. * If the string is " " it will return an empty string. */ -std::string remove_whitespace(const std::string& str) +std::string ssr::remove_whitespace(const std::string& str) { if (str == " ") return ""; size_t first = str.find_first_not_of(' '); @@ -137,13 +137,11 @@ static int parse_network_clients(const char *input, while (std::getline(iss, token, ',')) { size_t pos = token.find(':'); - std::string port_temp = remove_whitespace(token.substr(pos+1)); - name = remove_whitespace(token.substr(0, pos)); + std::string port_temp = ssr::remove_whitespace(token.substr(pos+1)); + name = ssr::remove_whitespace(token.substr(0, pos)); if (!name.empty()) { - std::cout << name << "(" << name.length() << ")" << std::endl; - std::cout << port_temp << "(" << port_temp.length() << ")" << std::endl; // if no port supplied, insert standard if ( port_temp.empty() || port_temp == name ) { @@ -156,6 +154,10 @@ static int parse_network_clients(const char *input, clients.insert(make_pair(name, port)); } } + VERBOSE2("Using the following network clients:"); + for (const auto& client: clients) { + VERBOSE2(client.first << ":" << client.second); + } return CONFIG_SUCCESS; } diff --git a/src/configuration.h b/src/configuration.h index a22e15ee..7a488ffe 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -85,6 +85,8 @@ conf_struct configuration(int& argc, char* argv[]); // static int parse(const char *line, char *key, char *value); // static int is_comment_or_empty(const char *line); int load_config_file(const char *filename, conf_struct& conf); +std::string remove_whitespace(const std::string& str); + } // namespace ssr From df314bf4990343dcae85082ff7dcaf560630f45f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 29 Mar 2017 23:28:38 +0200 Subject: [PATCH 008/363] src/networking/oschandler.*: Adding first attempt of OSC network interface. --- src/networking/oschandler.cpp | 15 ++++++++++++ src/networking/oschandler.h | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/networking/oschandler.cpp create mode 100644 src/networking/oschandler.h diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp new file mode 100644 index 00000000..0356a864 --- /dev/null +++ b/src/networking/oschandler.cpp @@ -0,0 +1,15 @@ +#include "oschandler.h" + +ssr::OscHandler::OscHandler(Publisher& controller, int port) + : _controller(controller), + , _serverThread(port), + , _serverAddress(port) +{} + +ssr::OscHandler::~OscHandler() +{} + +//ssr::OscHandler::setPort(int port) +//{ +// +//} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h new file mode 100644 index 00000000..4f16cbd3 --- /dev/null +++ b/src/networking/oschandler.h @@ -0,0 +1,44 @@ +#ifndef OSC_HANDLER_H +#define OSC_HANDLER_H + +#include // for ENABLE_* +#include +#include +#include +#include + +namespace ssr +{ +/* + * \class OscHandler + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscHandler +{ + private: + int _port; + lo::ServerThread *_serverThread; + lo::Address _serverAddress; + Publisher& _controller; + OscReceiver _oscReceiver; + OscSender _oscSender; + + public: + OscHandler(Publisher& controller, int port); + ~OscHandler(); + void setPort(int port); + int getPort(); + void start(); + void stop(); +}; + +} From e837cb38b4699126d4bdd373d0914225f850d881 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:47:34 +0200 Subject: [PATCH 009/363] src/networking/*: Adding current stage of work. Added class for sending and receiving. --- src/networking/oschandler.cpp | 51 ++++- src/networking/oschandler.h | 42 +++- src/networking/oscreceiver.cpp | 387 +++++++++++++++++++++++++++++++++ src/networking/oscreceiver.h | 61 ++++++ src/networking/oscsender.cpp | 33 +++ src/networking/oscsender.h | 105 +++++++++ 6 files changed, 661 insertions(+), 18 deletions(-) create mode 100644 src/networking/oscreceiver.cpp create mode 100644 src/networking/oscreceiver.h create mode 100644 src/networking/oscsender.cpp create mode 100644 src/networking/oscsender.h diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0356a864..2a4a87c6 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -1,15 +1,52 @@ #include "oschandler.h" +#include -ssr::OscHandler::OscHandler(Publisher& controller, int port) +// client ctor +ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int + port_out, std::string mode) : _controller(controller), - , _serverThread(port), - , _serverAddress(port) + , _osc_receiver(controller, *this, port_in) + , _osc_sender(*this, port_out) + , _mode(mode) {} +// server ctor +ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, + std::string mode, std::multimap + clients) + : _controller(controller), + , _osc_receiver(controller, *this, port_in) + , _mode(mode) +{ + std::vector new_clients; + for (const auto& hostname: clients) + { + new_clients.push_back(new lo::Address(hostname.first, + std::to_string(hostname.second))); + } + _osc_sender(*this, port_out, new_clients); +} + ssr::OscHandler::~OscHandler() {} -//ssr::OscHandler::setPort(int port) -//{ -// -//} +ssr::OscHandler::start() +{ + _oscReceiver.start(); +} + +/** Implementation of friend function to set the OscSender's server_address + * @param OscHandler holding both OscReceiver and OscSender + * @param Hostname to be set + * @param Port to be set + */ +void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address + server_address) +{ + self->_osc_sender->set_server_address(server_address); +} + +lo::Address OscReceiver::server_address(OscHandler& self) +{ + return self->_osc_sender.server_address; +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 4f16cbd3..880a99cc 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -1,21 +1,32 @@ #ifndef OSC_HANDLER_H #define OSC_HANDLER_H +#endif +#ifdef HAVE_CONFIG_H #include // for ENABLE_* +#endif + +#include #include #include -#include -#include + +#include "oscreceiver.h" +#include "oscsender.h" namespace ssr { + +struct Publisher; + /* * \class OscHandler * \brief Class holding Publisher and Subscriber implementation, while being responsible for * sending and receiving OSC messages. * This class holds a Publisher implementation (OscReceiver), which turns * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which + * It also holds an implementation of Subscriber (OscSender), which turns + * Publisher functionality into outgoing OSC messages + * * \author David Runge * \version $Revision: 0.1 $ * \date $Date: 2017/03/29 @@ -25,20 +36,29 @@ namespace ssr class OscHandler { private: - int _port; - lo::ServerThread *_serverThread; - lo::Address _serverAddress; + // mode: client|server + std::string _mode; Publisher& _controller; - OscReceiver _oscReceiver; - OscSender _oscSender; + OscReceiver _osc_receiver; + OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port); + // client ctor + OscHandler(Publisher& controller, int port_in, int port_out, std::string + mode); + // server ctor + OscHandler(Publisher& controller, int port_in, int port_out, std::string + mode, std::multimap clients); ~OscHandler(); - void setPort(int port); - int getPort(); void start(); void stop(); + + //declare set_server_for_client() as friend of class OscReceiver + friend void OscReceiver::set_server_for_client(OscHandler& self, + lo::Address server_address); + //declare set_server_for_client() as friend of class OscReceiver + friend lo::Address OscReceiver::server_address(OscHandler& self); + }; } diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp new file mode 100644 index 00000000..ff5d15c4 --- /dev/null +++ b/src/networking/oscreceiver.cpp @@ -0,0 +1,387 @@ +#include "oscreiver.h" +#include "oschandler.h" +#include "publisher.h" +#include "apf/stringtools.h" +#include "apf/math.h" + +using namespace apf::str; + +ssr::OscReceiver::OscReceiver(Publisher& controller, int port) + : _controller(controller) + //TODO: add error handler here + , _receiver(port) +{} + +ssr::OscReceiver::~OscReceiver() +{ + _receiver.stop(); +} + + +void ssr::OscReceiver::start() +{ + // add method handlers for received messages + if (_mode == "server") + { + add_client_to_server_methods(); + } + else if (_mode == "client") + { + add_server_to_client_methods(); + } + // start server thread + _receiver.start(); + +// _controller.subscribe(&_subscriber); + +} + +lo::Address server_address(OscHandler& handler) +{ + return handler.server_address(handler->_osc_sender); +} + +/** Add callback handlers for OSC messages received from clients. + * + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + */ +void add_client_to_server_methods() +{ +//TODO: implement! +} + +/** Add callback handlers for OSC messages received from a server. + * + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + */ +void add_server_to_client_methods() +{ + // set _server_address for OscSender through OscHandler, depending on, if + // polled from given server before + _receiver.add_method("poll", NULL, [](lo_arg **argv, int, lo::Message + message) + { + lo::Address server = server_address(&_handler); + lo::Address from(message.source()); + if(server.hostname() != from.hostname() && server.port() != from.port()) + { + set_server_address(from); + } + } + ): + + // set source position: "source/position, iff, id, x, y" + _receiver.add_method("source/position", "iff", [](lo_arg **argv, int) + { + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f); + VERBOSE2("set source position: id = " << argv[0]->i << ", " << + Position(argv[1]->f, argv[2]->f)); + } + ); + + // set source fixed: "source/position_fixed, iT, id, true" + _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) + { + _controller.set_source_position_fixed(argv[0]->i, argv[1]->T); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " + << argv[1]->T); + } + ); + + // set source fixed: "source/position_fixed, iF, id, false" + _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) + { + _controller.set_source_position_fixed(argv[0]->i, argv[1]->F); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " + << argv[1]->F); + } + ); + + // set source orientation: "source/orientation, if, id, azimuth" + _receiver.add_method("source/orientation", "if", [](lo_arg **argv, int) + { + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + VERBOSE2("set source orientation: id = " << argv[0]->i << ", " + << Orientation(argv[1]->f)); + } + ); + + // set source volume: "source/volume, if, id, volume" + _receiver.add_method("source/volume", "if", [](lo_arg **argv, int) + { + _controller.set_source_gain(argv[0]->i, dB2linear(argv[1]->f)); + VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << + dB2linear(argv[1]->f)); + } + ); + + // set source mute: "source/mute, iT, id, true" + _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) + { + _controller.set_source_mute(argv[0]->i, argv[1]->T); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << + dB2linear(argv[1]->T)); + } + ); + + // set source mute: "source/mute, iF, id, false" + _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) + { + _controller.set_source_mute(argv[0]->i, argv[1]->F); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << + dB2linear(argv[1]->F)); + } + ); + + // set source name: "source/name, is, id, name" + _receiver.add_method("source/name", "is", [](lo_arg **argv, int) + { + _controller.set_source_name(argv[0]->i, argv[1]->s); + VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << + argv[1]->s); + } + ); + + // set source file: "source/file, is, id, file" + _receiver.add_method("source/file", "is", [](lo_arg **argv, int) + { + _controller.set_source_properties_file(argv[0]->i, argv[1]->s); + VERBOSE2("set source properties file name: id = " << argv[0]->i << ", + file = " << argv[1]->s); + } + ); + + // set source model: "source/model, is, id, model" + _receiver.add_method("source/model", "is", [](lo_arg **argv, int) + { + _controller.set_source_model(argv[0]->i, argv[1]->s); + VERBOSE2("set source model: id = " << argv[0]->i << ", + model = " << argv[1]->s); + } + ); + + // set source port name: "source/port_name, is, id, port_name" + _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) + { + _controller.set_source_port_name(argv[0]->i, argv[1]->s); + VERBOSE2("set source port name: id = " << argv[0]->i << ", + port = " << argv[1]->s); + } + ); + + //FIXME: spezialize with TF types + + // create new source: "source/new, sssffbfbfb, name, model, port_name, x, y, + // position_fixed, orientation, orientation_fixed, volume, muted" + _receiver.add_method("source/new", "sssffbfbfb", [](lo_arg **argv, int) + { + _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, + Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, + argv[8]->f, argv[9]->b, ""); + VERBOSE2("Creating source with following properties:" + "\nname: " << argv[0]->s << + "\nmodel: " << argv[1]->s << + "\nfile_or_port_name: " << argv[2]->s << + "\nchannel: 0" << + "\nposition: " << Position(argv[3]->f, argv[4]->f) << + "\nposition_fixed: " << argv[5]->b << + "\norientation: " << argv[6]->f << + "\norientation_fixed: " << argv[7]->b << + "\nvolume (linear): " << argv[8]->f << + "\nmuted: " << argv[9]->b << + "\nproperties_file: " << + "\n"); + } + ); + + // create new source: "source/new, sssiffbfbfbs, name, model, file, channel, + // x, y, position_fixed, orientation, orientation_fixed, volume, muted, + // properties_file" + _receiver.add_method("source/new", "sssiffbfbfbs", [](lo_arg **argv, int) + { + _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, + Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, + argv[8]->f, argv[9]->b, ""); + VERBOSE2("Creating source with following properties:" + "\nname: " << argv[0]->s << + "\nmodel: " << argv[1]->s << + "\nfile_or_port_name: " << argv[2]->s << + "\nchannel: " << argv[3]->i << + "\nposition: " << Position(argv[4]->f, argv[5]->f) << + "\nposition_fixed: " << argv[6]->b << + "\norientation: " << argv[7]->f << + "\norientation_fixed: " << argv[8]->b << + "\nvolume (linear): " << argv[9]->f << + "\nmuted: " << argv[10]->b << + "\nproperties_file: " << argv[11]->s << + "\n"); + } + ); + + // delete source: "source/delete, i, id" + // special case: i == 0 deletes all sources! + _receiver.add_method("source/delete", "i", [](lo_arg **argv, int) + { + if (argv[0]->i == 0) + { + _controller.delete_all_sources(); + VERBOSE2("delete all sources"); + } + else + { + _controller.delete_source(argv[0]->i); + VERBOSE2("delete source with id = " << argv[0]->i); + } + } + ); + + // set reference position: "reference/position, ff, x, y" + _receiver.add_method("reference/position", "ff", [](lo_arg **argv, int) + { + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f); + VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); + } + ); + + // set reference orientation: "reference/orientation, f, azimuth" + _receiver.add_method("reference/position", "f", [](lo_arg **argv, int) + { + _controller.set_reference_orientation(Orientation(argv[0]->f)); + VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); + } + ); + + // set reference offset position: "reference_offset/position, ff, x, y" + _receiver.add_method("reference_offset/position", "ff" + , [](lo_arg **argv, int) + { + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f); + VERBOSE2("set reference offset position: " << Position(argv[0]->f, + argv[1]->f)); + } + ); + + // set reference offset orientation: "reference_offset/orientation, f, + // azimuth" + _receiver.add_method("reference_offset/position", "f" + , [](lo_arg **argv, int) + { + _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + VERBOSE2("set reference offset orientation: " << + Orientation(argv[0]->f)); + } + ); + + // save scene to file: "scene/save, s, file" + _receiver.add_method("scene/save", "s" + , [](lo_arg **argv, int) + { + _controller.save_scene_as_XML(argv[0]->s); + VERBOSE2("saving theme as: " << argv[0]->s); + } + ); + + // load scene from file: "scene/load, s, file" + _receiver.add_method("scene/load", "s" + , [](lo_arg **argv, int) + { + _controller.load_scene(argv[0]->s); + VERBOSE2("loading scene: " << argv[0]->s); + } + ); + + // set master volume: "scene/volume, f, volume" + _receiver.add_method("scene/volume", "f" + , [](lo_arg **argv, int) + { + _controller.set_master_volume(dB2linear(argv[0]->f)); + VERBOSE2("set master volume: " << dB2linear(argv[0]->f) << " dB"); } + ); + + // clear scene: "scene/clear" + _receiver.add_method("scene/load", NULL + , [](lo_arg **argv, int) + { + _controller.delete_all_sources(); + VERBOSE2("clearing scene."); + } + ); + + // set processing state: "state/processing, T, true" + _receiver.add_method("state/processing", "T" + , [](lo_arg **argv, int) + { + _controller.start_processing(); + VERBOSE2("start processing."); + } + ); + + // set processing state: "state/processing, F, false" + _receiver.add_method("state/processing", "F" + , [](lo_arg **argv, int) + { + _controller.stop_processing(); + VERBOSE2("stop processing."); + } + ); + + // set transport state: "state/transport, T, true" + _receiver.add_method("state/transport", "T" + , [](lo_arg **argv, int) + { + _controller.transport_start(); + VERBOSE2("start transport."); + } + ); + + // set transport state: "state/transport, F, false" + _receiver.add_method("state/transport", "F" + , [](lo_arg **argv, int) + { + _controller.transport_stop(); + VERBOSE2("stop transport."); + } + ); + + // rewind transport state: "state/transport/rewind" + _receiver.add_method("state/transport/rewind", NULL + , [](lo_arg **argv, int) + { + _controller.transport_locate(0); + VERBOSE2("rewind transport."); + } + ); + + // seek transport state: "state/transport/seek, s, time" + _receiver.add_method("state/transport/seek", "s" + , [](lo_arg **argv, int) + { + float time; + if(string2time(argv[0]->s, time)) + { + _controller.transport_locate(time); + VERBOSE2("Seek transport to: " << time); + } + else + { + ERROR("Couldn't get the time out of the \"seek\" attribute (\"" + << argv[0]->s << "\")."); + } + } + ); + + // reset tracker: "tracker/reset" + _receiver.add_method("tracker/reset", NULL + , [](lo_arg **argv, int) + { + _controller.calibrate_client(); + VERBOSE2("calibrate tracker."); + } + ); + + +} diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h new file mode 100644 index 00000000..2fdc3e88 --- /dev/null +++ b/src/networking/oscreceiver.h @@ -0,0 +1,61 @@ +/** + * \file oscreceiver.h + * \brief Header for OscReceiver, defining a class, responsible for evaluating + * received OSC messages and interfacing the SSR's controller + */ + +#ifndef OSC_RECEIVER_H +#define OSC_RECEIVER_H +#endif + + +#ifdef HAVE_CONFIG_H +#include // for ENABLE_* +#endif + +#include +#include + +#include "ssr_global.h" + +namespace ssr +{ + +struct Publisher; + +// forward declaration for OscHandler friend functions +class OscHandler; + +/** OscReceiver + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscReceiver +{ + private: + lo::ServerThread _receiver; + Publisher& _controller; + ssr::OscHandler& _handler; + std::string _mode; + void add_client_to_server_methods(); + void add_server_to_client_methods(); + public: + OscReceiver(Publisher& controller, OscHandler& handler, int port); + ~OscReceiver(); + void start(); + void stop(); + + void set_server_for_client(OscHandler& handler, lo::Address + server_address); + lo::Address server_address(OscHandler& handler); +}; + +} // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp new file mode 100644 index 00000000..defcf0db --- /dev/null +++ b/src/networking/oscsender.cpp @@ -0,0 +1,33 @@ +#include "oschandler.h" +#include "oscsender.h" + +// client ctor +ssr::OscSender::OscSender(OscHandler& handler, int port_out) + : _handler(handler) + , _send_from(lo::ServerThread(port_out)) +{} + +// server ctor +ssr::OscSender::OscSender(OscHandler& handler, int port_out, + std::vector client_addresses) + : _handler(handler) + , _send_from(lo::ServerThread(port_out)) + , _client_addresses(client_addresses) +{} + +/** Implementation of function to return OscSender's _server_address + * @return _server_address + */ +lo::Address server_address() +{ + return this->_server_address; +} + +/** Implementation of function to set OscSender's _server_address + * @return _server_address + */ +void set_server_address(lo::Address server_address) +{ + this->_server_address = server_address; +} + diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h new file mode 100644 index 00000000..e6d17af8 --- /dev/null +++ b/src/networking/oscsender.h @@ -0,0 +1,105 @@ +#ifndef OSC_SENDER_H +#define OSC_SENDER_H +#endif + +#ifdef HAVE_CONFIG_H +#include // for ENABLE_* +#endif + +#include +#include +#include + +#include "ssr_global.h" +#include "subscriber.h" + +namespace ssr +{ + +/** OscSender + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscSender : public Subscriber +{ + private: + // address of server (only used for client -> server connection) + lo::Address _server_address; + // ServerThread to send from specific port (client <-> server) + lo::ServerThread _send_from; + // vector of client address objects (only for server -> clients) + std::vector _client_addresses; + // reference to handler + OscHandler& _handler; + + public: + OscSender(OscHandler& handler, int port); + OscSender(int port); + ~OscSender(); + void start(); + void stop(); + + // server -> clients + void poll_clients(); // poll the list of clients + + + void update_all_clients(std::string str); + void send_levels(); + + // Subscriber Interface + virtual void set_loudspeakers(const Loudspeaker::container_t& + loudspeakers); + virtual void new_source(id_t id); + virtual void delete_source(id_t id); + virtual void delete_all_sources(); + virtual bool set_source_position(id_t id, const Position& position); + virtual bool set_source_position_fixed(id_t id, const bool& fix); + virtual bool set_source_orientation(id_t id, const Orientation& + orientation); + virtual bool set_source_gain(id_t id, const float& gain); + virtual bool set_source_mute(id_t id, const bool& mute); + virtual bool set_source_name(id_t id, const std::string& name); + virtual bool set_source_properties_file(id_t id, const std::string& name); + virtual bool set_source_model(id_t id, const Source::model_t& model); + virtual bool set_source_port_name(id_t id, const std::string& port_name); + virtual bool set_source_file_name(id_t id, const std::string& file_name); + virtual bool set_source_file_channel(id_t id, const int& file_channel); + virtual bool set_source_file_length(id_t id, const long int& length); + virtual void set_reference_position(const Position& position); + virtual void set_reference_orientation(const Orientation& orientation); + virtual void set_reference_offset_position(const Position& position); + virtual void set_reference_offset_orientation(const Orientation& + orientation); + virtual void set_master_volume(float volume); + virtual void set_source_output_levels(id_t id, float* first, float* last); + virtual void set_processing_state(bool state); + virtual void set_transport_state( + const std::pair& state); + virtual void set_auto_rotation(bool auto_rotate_sources); + virtual void set_decay_exponent(float exponent); + virtual void set_amplitude_reference_distance(float distance); + virtual void set_master_signal_level(float level); + virtual void set_cpu_load(float load); + virtual void set_sample_rate(int sample_rate); + virtual bool set_source_signal_level(const id_t id, const float& level); + +// // declare set_server_address() as friend of class OscHandler +// friend void OscHandler::set_server_address(OscSender& self, lo::Address +// server_address); +// // declare server_address() as friend of class OscHandler +// friend lo::Address OscHandler::server_address(OscSender& self); + // declare set_server_address() as friend of class OscHandler + void set_server_address(lo::Address server_address); + // declare server_address() as friend of class OscHandler + lo::Address server_address(); +}; + +} // namespace ssr From 517ec3a787cd0e797ca9cdca26a753da8c05d24d Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:47:59 +0200 Subject: [PATCH 010/363] configure.ac: Adding check for liblo headers. --- configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configure.ac b/configure.ac index 7da7b5fc..78ba3df4 100644 --- a/configure.ac +++ b/configure.ac @@ -521,6 +521,14 @@ ENABLE_EXPLICIT([floating-control-panel], [separate control window], [ AS_IF([test x$have_gui = xno], [have_floating_control_panel=no]) ]) +dnl check for liblo +ENABLE_FORCED([osc-interface], [OSC interface], + [ + AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) + AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) + AC_MSG_RESULT([$have_osc_interface]) + ] +) ENABLE_FORCED([ip-interface], [network (TCP/IP) interface], [ @@ -770,6 +778,7 @@ echo "| VRPN ................................ : $have_vrpn" echo "|" echo "| Build with Ecasound support ............ : $have_ecasound" echo "| Build with IP interface ................ : $have_ip_interface" +echo "| Build with OSC interface ............... : $have_osc_interface" echo "| Build with GUI ......................... : $gui_string" echo "|" echo "| Enable debugging/optimization .......... : $have_debugging/$have_optimization" From 06837d573cefe55dd2dd65d08db1f002e12a9635 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:48:27 +0200 Subject: [PATCH 011/363] src/Makefile.am: Adding files in src/networking. --- src/Makefile.am | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 821b4bc8..4d37deb1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -178,6 +178,18 @@ SSRSOURCES += \ network/server.h endif +if ENABLE_OSC_INTERFACE +AM_CPPFLAGS += -I$(srcdir)/networking + +SSRSOURCES += \ + networking/oschandler.cpp \ + networking/oschandler.h \ + networking/oscreceiver.cpp \ + networking/oscreceiver.h \ + networking/oscsender.cpp \ + networking/oscsender.h +endif + if ENABLE_GUI AM_CPPFLAGS += -I$(srcdir)/gui From ccb1953e4d969085ad2a3831f64ae2b03753df56 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:49:28 +0200 Subject: [PATCH 012/363] src/controller.h: Adding first batch of conditionals for osc interface. --- src/controller.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/controller.h b/src/controller.h index 44165496..ecae2393 100644 --- a/src/controller.h +++ b/src/controller.h @@ -61,6 +61,10 @@ #include "server.h" #endif +#ifdef ENABLE_OSC_INTERFACE +#include "oschandler.h" +#endif + #include "tracker.h" #ifdef ENABLE_INTERSENSE #include "trackerintersense.h" @@ -253,6 +257,11 @@ class Controller : public Publisher #ifdef ENABLE_IP_INTERFACE std::unique_ptr _network_interface; #endif + +#ifdef ENABLE_OSC_INTERFACE + std::unique_ptr _osc_interface; +#endif + std::unique_ptr _tracker; /// check if audio player is running and start it if necessary @@ -331,6 +340,16 @@ Controller::Controller(int argc, char* argv[]) } #endif +// throw error, if OSC interface is about to be used, but not compiled in +#ifndef ENABLE_OSC_INTERFACE + if (_conf.network_mode == "client" || _conf.network_mode == "server") + { + throw std::logic_error(_conf.exec_name + + " was compiled without OSC support!\n" + "Type '" + _conf.exec_name + " --help' for more information."); + } +#endif + #ifndef ENABLE_GUI if (_conf.gui) { @@ -403,6 +422,18 @@ Controller::Controller(int argc, char* argv[]) _network_interface->start(); } #endif // ENABLE_IP_INTERFACE + +// if OSC is compiled in and network-mode set, start OSC handler +#ifdef ENABLE_OSC_INTERFACE + if (_conf.network_mode == "client" || _conf.network_mode == "server") + { + VERBOSE("Starting OSC server on port " << _conf.network_port_receive << + "."); + _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, + _conf.network_mode)); + _osc_interface->start(); + } +#endif } template From b8bacc825f2f66daecf6e0d5758ae822e3ee5db3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:22:43 +0200 Subject: [PATCH 013/363] src/networking/oscsender.h: Added reference to controller as private member and to client/server constructor. --- src/networking/oscsender.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index e6d17af8..7c96bc22 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -39,10 +39,13 @@ class OscSender : public Subscriber std::vector _client_addresses; // reference to handler OscHandler& _handler; + // reference to controller + Publisher& _controller; + bool _is_subscribed; public: - OscSender(OscHandler& handler, int port); - OscSender(int port); + OscSender(Publisher& controller, OscHandler& handler, int port); + OscSender(Publisher& controller, int port); ~OscSender(); void start(); void stop(); From b3586d26181014ae2a46752947686015ebd7f4d9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:26:01 +0200 Subject: [PATCH 014/363] src/networking/oschandler.cpp: Adding controller to initializer list for initializing OscSender. --- src/networking/oschandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2a4a87c6..ebd0a9ee 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -6,7 +6,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode) : _controller(controller), , _osc_receiver(controller, *this, port_in) - , _osc_sender(*this, port_out) + , _osc_sender(controller, *this, port_out) , _mode(mode) {} @@ -16,6 +16,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) + , _osc_sender(controller, *this, port_out) , _mode(mode) { std::vector new_clients; From ff9326e38b59e60f351ff5072bca45a096147d26 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:28:59 +0200 Subject: [PATCH 015/363] src/networking/oscreceiver.cpp: Unifying callback function for creating new source. Implementing proper use of LO_TRUE and LO_FALSE types in all callback functions. Minor fixes to some VERBOSE2 output in callback functions. --- src/networking/oscreceiver.cpp | 223 ++++++++++++++++++++++++--------- 1 file changed, 166 insertions(+), 57 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index ff5d15c4..a1036208 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -68,6 +68,7 @@ void add_server_to_client_methods() if(server.hostname() != from.hostname() && server.port() != from.port()) { set_server_address(from); + // TODO: send reply to subscribed server } } ): @@ -85,18 +86,18 @@ void add_server_to_client_methods() // set source fixed: "source/position_fixed, iT, id, true" _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) { - _controller.set_source_position_fixed(argv[0]->i, argv[1]->T); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " - << argv[1]->T); + _controller.set_source_position_fixed(argv[0]->i, true); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + true"); } ); // set source fixed: "source/position_fixed, iF, id, false" _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) { - _controller.set_source_position_fixed(argv[0]->i, argv[1]->F); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " - << argv[1]->F); + _controller.set_source_position_fixed(argv[0]->i, false); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + false"); } ); @@ -121,18 +122,16 @@ void add_server_to_client_methods() // set source mute: "source/mute, iT, id, true" _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) { - _controller.set_source_mute(argv[0]->i, argv[1]->T); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << - dB2linear(argv[1]->T)); + _controller.set_source_mute(argv[0]->i, true); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); } ); // set source mute: "source/mute, iF, id, false" _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) { - _controller.set_source_mute(argv[0]->i, argv[1]->F); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << - dB2linear(argv[1]->F)); + _controller.set_source_mute(argv[0]->i, false); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); } ); @@ -172,52 +171,162 @@ void add_server_to_client_methods() } ); - //FIXME: spezialize with TF types - - // create new source: "source/new, sssffbfbfb, name, model, port_name, x, y, - // position_fixed, orientation, orientation_fixed, volume, muted" - _receiver.add_method("source/new", "sssffbfbfb", [](lo_arg **argv, int) - { - _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, - Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, - argv[8]->f, argv[9]->b, ""); - VERBOSE2("Creating source with following properties:" - "\nname: " << argv[0]->s << - "\nmodel: " << argv[1]->s << - "\nfile_or_port_name: " << argv[2]->s << - "\nchannel: 0" << - "\nposition: " << Position(argv[3]->f, argv[4]->f) << - "\nposition_fixed: " << argv[5]->b << - "\norientation: " << argv[6]->f << - "\norientation_fixed: " << argv[7]->b << - "\nvolume (linear): " << argv[8]->f << - "\nmuted: " << argv[9]->b << - "\nproperties_file: " << - "\n"); - } - ); - - // create new source: "source/new, sssiffbfbfbs, name, model, file, channel, - // x, y, position_fixed, orientation, orientation_fixed, volume, muted, - // properties_file" - _receiver.add_method("source/new", "sssiffbfbfbs", [](lo_arg **argv, int) + // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // port_name, x, y, orientation, volume, position_fixed, orientation_fixed, + // muted" + // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // port_name, x, y, orientation, volume, channel, properties_file, + // position_fixed, orientation_fixed, muted" + _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, + lo::Message message) { - _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, - Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, - argv[8]->f, argv[9]->b, ""); - VERBOSE2("Creating source with following properties:" - "\nname: " << argv[0]->s << - "\nmodel: " << argv[1]->s << - "\nfile_or_port_name: " << argv[2]->s << - "\nchannel: " << argv[3]->i << - "\nposition: " << Position(argv[4]->f, argv[5]->f) << - "\nposition_fixed: " << argv[6]->b << - "\norientation: " << argv[7]->f << - "\norientation_fixed: " << argv[8]->b << - "\nvolume (linear): " << argv[9]->f << - "\nmuted: " << argv[10]->b << - "\nproperties_file: " << argv[11]->s << - "\n"); + std::string name(argv[0]->s); + std::string model(argv[1]->s); + std::string file_or_portname(argv[2]->s); + float x(argv[3]->f); + float y(argv[4]->f); + float orientation(argv[5]->f); + float volume(argv[6]->f); + int channel = 0; + std::string properties_file = ""; + bool position_fixed; + bool orientation_fixed; + bool muted; + bool setup = false; + switch (message.types()) + { + case "sssffffTTT": + position_fixed = true; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffTTF": + position_fixed = true; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffTFF": + position_fixed = true; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffFFF": + position_fixed = false; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffTFT": + position_fixed = true; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffFTF": + position_fixed = false; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffFTT": + position_fixed = false; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffFFT": + position_fixed = false; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffisTTT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffisTTF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffisTFF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffisFFF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffisTFT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffisFTF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffisFTT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffisFFT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = false; + muted = true; + setup = true; + break; + } + if (setup) + { + _controller.new_source(name, model, file_or_port_name, channel, + Position(x, y), position_fixed, orientation, orientation_fixed, + volume, muted, properties_file); + VERBOSE2("Creating source with following properties:" + "\nname: " << name << + "\nmodel: " << model << + "\nfile_or_port_name: " << file_or_port_name << + "\nchannel: " << channel << + "\nposition: " << Position(x, y) << + "\nposition_fixed: " << position_fixed << + "\norientation: " << orientation << + "\norientation_fixed: " << orientation_fixed << + "\nvolume (linear): " << volume << + "\nmuted: " << muted << + "\nproperties_file: " << properties_file << + "\n"); + } } ); From 1d1e812af4272c985567bffe050ec9859879cfd6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:31:12 +0200 Subject: [PATCH 016/363] src/networking/oscsender.cpp: Adding reference to controller and handler to OscSender constructors. Adding start/stop functionality that subscribes/unsubscribes OscSender with/from the controller. --- src/networking/oscsender.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index defcf0db..0f3739ad 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -2,19 +2,36 @@ #include "oscsender.h" // client ctor -ssr::OscSender::OscSender(OscHandler& handler, int port_out) - : _handler(handler) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int + port_out) + : _controller(controller) + , _handler(handler) , _send_from(lo::ServerThread(port_out)) + , _is_subscribed(false) {} // server ctor -ssr::OscSender::OscSender(OscHandler& handler, int port_out, - std::vector client_addresses) - : _handler(handler) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int + port_out, std::vector client_addresses) + : _controller(controller) + , _handler(handler) , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) + , _is_subscribed(false) {} +ssr::OscSender::start() +{ + _controller.subscribe(*this); + _is_subscribed = true; +} + +ssr::OscSender::stop() +{ + _controller.unsubscribe(*this); + _is_subscribed = false; +} + /** Implementation of function to return OscSender's _server_address * @return _server_address */ From 2cfcfb7cf7de2277e17664127f3e3bd86a1334fc Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:52:08 +0200 Subject: [PATCH 017/363] src/controller.h: Extending messages for starting OSC interface by port numbers in use. --- src/controller.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controller.h b/src/controller.h index ecae2393..cc5ee2ac 100644 --- a/src/controller.h +++ b/src/controller.h @@ -427,8 +427,9 @@ Controller::Controller(int argc, char* argv[]) #ifdef ENABLE_OSC_INTERFACE if (_conf.network_mode == "client" || _conf.network_mode == "server") { - VERBOSE("Starting OSC server on port " << _conf.network_port_receive << - "."); + VERBOSE2("Starting OSC interface.\nReceiving on port " << + std::to_string(_conf.network_port_receive) << ".\nSending on port " << + std::to_string(_conf.network_port_send) << "."); _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, _conf.network_mode)); _osc_interface->start(); From 7940d223248e002a533df66a21e8abb3b3e8f3c5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:55:13 +0200 Subject: [PATCH 018/363] src/networking/oschandler.cpp: Adding documentation. Adding stop() and mode() methods. --- src/networking/oschandler.cpp | 64 +++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index ebd0a9ee..068ca258 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -1,7 +1,20 @@ +/** + * Implementation of oschandler.h + * @file oschandler.cpp + */ + #include "oschandler.h" #include -// client ctor +/** + * Constructor used to create client objects + * @param controller reference to a Publisher object + * @param port_in an integer describing the port number used for incoming + * traffic + * @param port_out an integer describing the port number used for outgoing + * traffic + * @param mode a string defining the mode (client|server) + */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode) : _controller(controller), @@ -10,13 +23,21 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int , _mode(mode) {} -// server ctor +/** + * Constructor used to create server objects + * @param controller reference to a Publisher object + * @param port_in an integer describing the port number used for incoming + * traffic + * @param port_out an integer describing the port number used for outgoing + * traffic + * @param mode a string defining the mode (client|server) + * @param clients a multimap holding hostname, port pairs + */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) , _mode(mode) { std::vector new_clients; @@ -28,18 +49,34 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, _osc_sender(*this, port_out, new_clients); } +/** + * Destructor + */ ssr::OscHandler::~OscHandler() {} +/** + * Stop this OscHandler by stopping its OscReceiver and OscSender + */ +ssr::OscHandler::stop() +{ + _oscSender.stop(); + _oscReceiver.stop(); +} + +/** + * Start this OscHandler by starting its OscReceiver and OscSender + */ ssr::OscHandler::start() { _oscReceiver.start(); + _oscSender.start(); } -/** Implementation of friend function to set the OscSender's server_address - * @param OscHandler holding both OscReceiver and OscSender - * @param Hostname to be set - * @param Port to be set +/** + * OscHandler's friend function to set the OscSender's server_address + * @param self reference to OscHandler holding OscSender + * @param server_address lo::Address object to be used for OscSender */ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address) @@ -47,7 +84,20 @@ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address self->_osc_sender->set_server_address(server_address); } +/** + * OscHandler's friend function return OscSender's server_address + * @param self reference to OscHandler holding the OscSender + * @return lo::Address server_address of OscSender + */ lo::Address OscReceiver::server_address(OscHandler& self) { return self->_osc_sender.server_address; } + +/** + * This function returns the OscHandler's mode + */ +std::string mode() +{ + return *this->_mode; +} From a2706adff07edd1a66411184d41dd2f454a57ed9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:56:09 +0200 Subject: [PATCH 019/363] src/networking/oschandler.h: Updating documentation. Adding mode() declaration. --- src/networking/oschandler.h | 40 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 880a99cc..11c90474 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -1,3 +1,9 @@ +/** + * Header for OscHandler, defining a class, responsible for sending OSC messages + * and subscribing to the SSR's Publisher. + * @file oschandler.h + */ + #ifndef OSC_HANDLER_H #define OSC_HANDLER_H #endif @@ -18,47 +24,33 @@ namespace ssr struct Publisher; -/* - * \class OscHandler - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which turns - * Publisher functionality into outgoing OSC messages - * - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscHandler + * This class holds a Subscriber derivate (OscSender), which turns actions of + * the referenced Publisher into OSC messages to clients or a server and an + * OscReceiver, responsible for callbacks on arriving OSC messages, that are + * delegated to the Publisher reference. */ class OscHandler { private: - // mode: client|server - std::string _mode; - Publisher& _controller; + std::string _mode; //< mode: client|server + Publisher& _controller; //< reference to Publisher object OscReceiver _osc_receiver; OscSender _osc_sender; public: - // client ctor OscHandler(Publisher& controller, int port_in, int port_out, std::string mode); - // server ctor OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients); ~OscHandler(); void start(); void stop(); - - //declare set_server_for_client() as friend of class OscReceiver + std::string mode(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); - //declare set_server_for_client() as friend of class OscReceiver friend lo::Address OscReceiver::server_address(OscHandler& self); - }; -} +} // namespace ssr From db19698887186433e9f38fa56c049aad5cec2d4d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:58:54 +0200 Subject: [PATCH 020/363] src/networking/oscreceiver.cpp: Removing superfluous implementations. Adding/updating documentation. --- src/networking/oscreceiver.cpp | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index a1036208..94458aef 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -1,3 +1,8 @@ +/** + * Implementation of oscreceiver.h + * @file oscreceiver.cpp + */ + #include "oscreiver.h" #include "oschandler.h" #include "publisher.h" @@ -6,18 +11,30 @@ using namespace apf::str; +/** + * Constructor + * @param controller reference to a Publisher object + * @param port integer representing a port to used for incoming OSC messages + * @todo add error handler for ServerThread + */ ssr::OscReceiver::OscReceiver(Publisher& controller, int port) : _controller(controller) - //TODO: add error handler here , _receiver(port) {} +/** + * Destructor + * Stops the lo::ServerThread, used for listening for OSC messages + */ ssr::OscReceiver::~OscReceiver() { _receiver.stop(); } - +/** + * Starts the OscReceiver, by adding client|server callback functions and + * starting the lo::ServerThread used for listening to OSC messages. + */ void ssr::OscReceiver::start() { // add method handlers for received messages @@ -31,18 +48,10 @@ void ssr::OscReceiver::start() } // start server thread _receiver.start(); - -// _controller.subscribe(&_subscriber); - -} - -lo::Address server_address(OscHandler& handler) -{ - return handler.server_address(handler->_osc_sender); } -/** Add callback handlers for OSC messages received from clients. - * +/** + * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ @@ -51,8 +60,8 @@ void add_client_to_server_methods() //TODO: implement! } -/** Add callback handlers for OSC messages received from a server. - * +/** + * Adds callback handlers for OSC messages received from a server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ From 3ddfbdf3693cff6cf112c002ed61b485a38e01b0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:59:27 +0200 Subject: [PATCH 021/363] src/networking/oscreceiver.h: Updating documentation. --- src/networking/oscreceiver.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 2fdc3e88..3c2c503f 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -1,7 +1,7 @@ /** - * \file oscreceiver.h - * \brief Header for OscReceiver, defining a class, responsible for evaluating - * received OSC messages and interfacing the SSR's controller + * @file oscreceiver.h + * Header for OscReceiver, declaring a class, responsible for evaluating + * received OSC messages and interfacing the SSR's controller. */ #ifndef OSC_RECEIVER_H @@ -26,17 +26,11 @@ struct Publisher; // forward declaration for OscHandler friend functions class OscHandler; -/** OscReceiver - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscReceiver + * This class holds a Publisher and an OscHandler reference. + * It is responsible for all incoming OSC messages and using callback functions + * to trigger functionality in the Publisher. */ class OscReceiver { @@ -52,7 +46,6 @@ class OscReceiver ~OscReceiver(); void start(); void stop(); - void set_server_for_client(OscHandler& handler, lo::Address server_address); lo::Address server_address(OscHandler& handler); From 2d10c07d3f11171c7407d0126860bf1eab5e93e3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 19:00:27 +0200 Subject: [PATCH 022/363] src/networking/oscsender.cpp: Updating documentation. Implementing poll_clients(), send_to_server() methods. --- src/networking/oscsender.cpp | 98 +++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0f3739ad..ea876e0e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1,16 +1,36 @@ +/** + * Implementation of oscsender.h + * @file oscsender.cpp + */ + #include "oschandler.h" #include "oscsender.h" -// client ctor +/** + * Constructor used to create client objects + * @param controller reference to a Publisher object + * @param handler reference to an OscHandler object + * @param port_out an integer describing the port number to be used + * for outgoing traffic + */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out) : _controller(controller) , _handler(handler) , _send_from(lo::ServerThread(port_out)) , _is_subscribed(false) + , _mode(handler.mode()) {} -// server ctor +/** + * Constructor used to create server objects + * @param controller reference to a Publisher object + * @param handler reference to an OscHandler object + * @param port_out an integer describing the port number to be used + * for outgoing traffic + * @param client_addresses vector of lo::Address objects representing + * clients to this server + */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out, std::vector client_addresses) : _controller(controller) @@ -18,33 +38,95 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) , _is_subscribed(false) + , _mode(handler.mode()) {} -ssr::OscSender::start() +/** + * Destructor + */ +~OscSender(); + +/** Function to start the OscSender object + * This subscribes the OscSender to the Publisher and starts the + * lo::ServerThread to send from + */ +void ssr::OscSender::start() { _controller.subscribe(*this); _is_subscribed = true; + // check if lo::ServerThread is valid + if (!_send_from.is_valid()) { + ERROR("OSC ServerThread to send from could not be started!"); + return 1; + } + _send_from.set_callbacks([&_send_from]() + { + VERBOSE2("OSC ServerThread init: "<<&_send_from <<"."); + }, + []() + { + VERBOSE2("OSC ServerThread cleanup."); + } + ); + VERBOSE("OSC URL: " << _send_from.url()<<"."); + _send_from.start(); } -ssr::OscSender::stop() +/** + * Function to stop the OscSender object + * This unsubscribes the OscSender from the Publisher + */ +void ssr::OscSender::stop() { _controller.unsubscribe(*this); _is_subscribed = false; } -/** Implementation of function to return OscSender's _server_address - * @return _server_address +/** + * Function to return OscSender's _server_address + * @return a lo::Address object representing the current server for this client */ lo::Address server_address() { return this->_server_address; } -/** Implementation of function to set OscSender's _server_address - * @return _server_address +/** + * Function to set OscSender's _server_address + * @param server_address a lo::Address to be used as _server_address */ void set_server_address(lo::Address server_address) { this->_server_address = server_address; } +/** + * Function to send /poll OSC message to all clients + */ +void poll_clients() +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, "poll"); + } +} + +/** + * Function to send a lo::Message to the lo:Address setup as server + * @param message a predefined lo::Messge object to be sent + */ +void send_to_server(lo::Message message) +{ + _server_address.send_from(_send_from, msg); +} + +/** + * Function to send a lo::Bundle to the lo:Address setup as server + * @param bundle a predefined lo::Bundle object to be sent + */ +void send_to_server(lo::Bundle bundle) +{ + _server_address.send_from(_send_from, bundle); +} + + From b330b1ac5d2ba4b5acdb4e3cbfc790e3ab87c5ac Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 19:04:39 +0200 Subject: [PATCH 023/363] src/networking/oscsender.h: Updating documentation. Adding declaration for send_to_server(), _mode string, _source_level and _master_level. Updating server constructor to include OscHandler reference and client_addresses vector. --- src/networking/oscsender.h | 59 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 7c96bc22..41a960d6 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -1,3 +1,9 @@ +/** + * Header for OscSender, declaring a class, responsible for sending OSC + * messages and subscribing to the SSR's Publisher. + * @file oscsender.h + */ + #ifndef OSC_SENDER_H #define OSC_SENDER_H #endif @@ -16,43 +22,45 @@ namespace ssr { -/** OscSender - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscSender + * This class holds a Publisher and an OscHandler reference, while implementing + * the Subscriber interface. + * The Publisher is subscribed to, using its interface to send out OSC messages + * on all events it emmits. */ class OscSender : public Subscriber { private: - // address of server (only used for client -> server connection) + // address of server (client) lo::Address _server_address; - // ServerThread to send from specific port (client <-> server) + // ServerThread to send from specific port (client|server) lo::ServerThread _send_from; - // vector of client address objects (only for server -> clients) + // vector of client address objects (server) std::vector _client_addresses; // reference to handler - OscHandler& _handler; + OscHandler& _handler; // TODO: really needed? // reference to controller Publisher& _controller; bool _is_subscribed; + std::string _mode; + typedef std::map source_level_map_t; + source_level_map_t _source_levels; + float _master_level; public: - OscSender(Publisher& controller, OscHandler& handler, int port); - OscSender(Publisher& controller, int port); + OscSender(Publisher& controller, OscHandler& handler, int port_out); + OscSender(Publisher& controller, OscHandler& handler, int port_out, + std::vector client_addresses); ~OscSender(); + void start(); void stop(); - - // server -> clients - void poll_clients(); // poll the list of clients - + void set_server_address(lo::Address server_address); + lo::Address server_address(); + void poll_clients(); + void send_to_server(lo::Message message); + void send_to_server(lo::Bundle bundle); void update_all_clients(std::string str); void send_levels(); @@ -94,15 +102,6 @@ class OscSender : public Subscriber virtual void set_sample_rate(int sample_rate); virtual bool set_source_signal_level(const id_t id, const float& level); -// // declare set_server_address() as friend of class OscHandler -// friend void OscHandler::set_server_address(OscSender& self, lo::Address -// server_address); -// // declare server_address() as friend of class OscHandler -// friend lo::Address OscHandler::server_address(OscSender& self); - // declare set_server_address() as friend of class OscHandler - void set_server_address(lo::Address server_address); - // declare server_address() as friend of class OscHandler - lo::Address server_address(); }; } // namespace ssr From 7e04615236dfcf450590e60d9fb547213ed691c9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:19:37 +0200 Subject: [PATCH 024/363] src/controller.h: Updating VERBOSE2 messages for starting osc interface. Updating call to constructor of OSCHandler to include _conf.network_clients and _conf.network_port_send. --- src/controller.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controller.h b/src/controller.h index cc5ee2ac..367e8036 100644 --- a/src/controller.h +++ b/src/controller.h @@ -427,11 +427,13 @@ Controller::Controller(int argc, char* argv[]) #ifdef ENABLE_OSC_INTERFACE if (_conf.network_mode == "client" || _conf.network_mode == "server") { - VERBOSE2("Starting OSC interface.\nReceiving on port " << - std::to_string(_conf.network_port_receive) << ".\nSending on port " << + VERBOSE2("Starting OSC interface as "<< _conf.network_mode << + ".\nReceiving messages on port " << + std::to_string(_conf.network_port_receive) << + ".\nSending messages from port " << std::to_string(_conf.network_port_send) << "."); _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, - _conf.network_mode)); + _conf.network_port_send, _conf.network_mode, _conf.network_clients)); _osc_interface->start(); } #endif From 847fa52cb6714f63a24822e780baf9520994026c Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:28:20 +0200 Subject: [PATCH 025/363] src/networking/oscreceiver.cpp: Updating OSCReceiver methods to be part of namespace ssr. Changing constructor to be more explicit. --- src/networking/oscreceiver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 94458aef..e29aa376 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -14,12 +14,12 @@ using namespace apf::str; /** * Constructor * @param controller reference to a Publisher object - * @param port integer representing a port to used for incoming OSC messages + * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, int port) +ssr::OscReceiver::OscReceiver(Publisher& controller, int port_in) : _controller(controller) - , _receiver(port) + , _receiver(port_in) {} /** @@ -55,7 +55,7 @@ void ssr::OscReceiver::start() * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void add_client_to_server_methods() +void ssr::OscReceiver::add_client_to_server_methods() { //TODO: implement! } @@ -65,7 +65,7 @@ void add_client_to_server_methods() * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void add_server_to_client_methods() +void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before From ef3c556d775f62dcbbdf0369503875f3630d318b Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:29:41 +0200 Subject: [PATCH 026/363] src/networking/oscreceiver.h: Changing constructor parameters to be more explicit. Adding friend functions to be able to send lo::Messages and lo::Bundles to clients/server in callbacks. --- src/networking/oscreceiver.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3c2c503f..56867ac3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -42,13 +42,21 @@ class OscReceiver void add_client_to_server_methods(); void add_server_to_client_methods(); public: - OscReceiver(Publisher& controller, OscHandler& handler, int port); + OscReceiver(Publisher& controller, OscHandler& handler, int port_in); ~OscReceiver(); void start(); void stop(); void set_server_for_client(OscHandler& handler, lo::Address server_address); lo::Address server_address(OscHandler& handler); + void send_to_client(OscHandler& self, lo::Address client_address, + std::string path, lo::Message message); + void send_to_client(OscHandler& self, lo::Address client_address, + lo::Bundle bundle); + void send_to_all_clients(OscHandler& self, std::string path, lo::Message message); + void send_to_all_clients(OscHandler& self, lo::Bundle bundle); + void send_to_server(OscHandler& self, std::string path, lo::Message message); + void send_to_server(OscHandler& self, lo::Bundle bundle); }; } // namespace ssr From cb87a801c1f237fb19fdca987881e7ade869d422 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:36:31 +0200 Subject: [PATCH 027/363] src/networking/oscsender.cpp: Adding methods for sending OSC messages to all clients, server or specific client. Fixing all send methods to use a path std::string, where needed. Making all methods part of namespace ssr. Adding poll_all_clients method to send periodical '/poll' messages to all clients to make them subscribe to the server. Adding std::thread poll_thread to call poll_all_clients in a thread. --- src/networking/oscsender.cpp | 111 ++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 15 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index ea876e0e..9b9871b6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -3,6 +3,7 @@ * @file oscsender.cpp */ +#include #include "oschandler.h" #include "oscsender.h" @@ -38,7 +39,9 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) , _is_subscribed(false) + , _poll_all_clients(false) , _mode(handler.mode()) + , _poll_thread(0) {} /** @@ -70,23 +73,47 @@ void ssr::OscSender::start() ); VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); + _poll_all_clients = true; + _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients(), this); } /** * Function to stop the OscSender object - * This unsubscribes the OscSender from the Publisher + * This unsubscribes the OscSender from the Publisher and stops the client + * polling thread */ void ssr::OscSender::stop() { _controller.unsubscribe(*this); _is_subscribed = false; + VERBOSE2("Stopping client polling thread ..."); + _poll_all_clients = false; + if (_poll_thread) + { + _poll_thread->join(); + } + VERBOSE2("Client polling thread stopped."); +} + +/** + * Sends a '/poll' message to all client instances listed in _client_addresses, + * then makes the thread calling this function sleep for 1000 milliseconds + */ +void ssr::OscSender::poll_all_clients() +{ + while(_poll_all_clients) + { + send_to_all_clients("poll", lo::Message()); + //TODO find better solution to compensate for execution time + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } } /** * Function to return OscSender's _server_address * @return a lo::Address object representing the current server for this client */ -lo::Address server_address() +lo::Address ssr::OscSender::server_address() { return this->_server_address; } @@ -95,38 +122,92 @@ lo::Address server_address() * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address */ -void set_server_address(lo::Address server_address) +void ssr::OscSender::set_server_address(lo::Address server_address) { this->_server_address = server_address; } /** - * Function to send /poll OSC message to all clients + * Function to send a lo::Message to the lo:Address setup as server using a + * predefined path + * @param path a std::string defining the path to send to + * @param message a predefined lo::Messge object to be sent */ -void poll_clients() +void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - for (const auto& client_address: _client_addresses) - { - client_address.send_from(_send_from, "poll"); - } + _server_address.send_from(_send_from, path, message); +} + +/** + * Function to send a lo::Bundle to the lo:Address setup as server + * @param bundle a predefined lo::Bundle object to be sent + */ +void ssr::OscSender::send_to_server(lo::Bundle bundle) +{ + _server_address.send_from(_send_from, bundle); } /** - * Function to send a lo::Message to the lo:Address setup as server + * Function to send a lo::Message to a client. + * @param address a lo:Address that will be sent to, when found in + * _client_addresses. + * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ -void send_to_server(lo::Message message) +void ssr::OscSender::send_to_client(lo::Address address, std::string path, + lo::Message message) { - _server_address.send_from(_send_from, msg); + for (const auto& client _client_addresses) + { + if(client.hostname() == address.hostname() && client.port() == + address.port()) + { + client.send_from(_send_from, path, message); + } + } } /** - * Function to send a lo::Bundle to the lo:Address setup as server + * Function to send a lo::Bundle to a client. + * @param address a lo:Address that will be sent to, when found in + * _client_addresses. * @param bundle a predefined lo::Bundle object to be sent */ -void send_to_server(lo::Bundle bundle) +void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - _server_address.send_from(_send_from, bundle); + for (const auto& client _client_addresses) + { + if(client.hostname() == address.hostname() && client.port() == + address.port()) + { + client.send_from(_send_from, bundle); + } + } } +/** + * Function to send a lo::Message to all clients setup in _client_addresses + * vector. + * @param path a std::string defining the path to send to + * @param message a predefined lo::Messge object to be sent + */ +void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, path, message); + } +} +/** + * Function to send a lo::Bundle to all clients setup in _client_addresses + * vector. + * @param bundle a predefined lo::Bundle object to be sent + */ +void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, bundle); + } +} From b3907bf5d45874d723c43691c66fa870c2c25a43 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:40:24 +0200 Subject: [PATCH 028/363] src/networking/oscsender.h: Adding bool and thread include for poll_all_clients method. Adding send_to_client and send_to_all_clients public methods. --- src/networking/oscsender.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 41a960d6..c922e382 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -13,6 +13,7 @@ #endif #include +#include #include #include @@ -42,11 +43,15 @@ class OscSender : public Subscriber OscHandler& _handler; // TODO: really needed? // reference to controller Publisher& _controller; + // thread used for calling poll_all_clients continuously + std::thread *_poll_thread; bool _is_subscribed; + bool _poll_all_clients; std::string _mode; typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; + void poll_all_clients(); public: OscSender(Publisher& controller, OscHandler& handler, int port_out); @@ -59,8 +64,13 @@ class OscSender : public Subscriber void set_server_address(lo::Address server_address); lo::Address server_address(); void poll_clients(); - void send_to_server(lo::Message message); + void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); + void send_to_client(lo::Address address, std::string path, lo::Message + message); + void send_to_client(lo::Address address, lo::Bundle bundle); + void send_to_all_client(std::string path, lo::Message message); + void send_to_all_client(lo::Bundle bundle); void update_all_clients(std::string str); void send_levels(); From d2caac9d1ed323ada6d751719d9ffe62f43e7079 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:42:42 +0200 Subject: [PATCH 029/363] src/networking/oschandler.cpp: Merging client and server constructor. Initializing _osc_sender in body instead of initializer list. Fixing call to set_server_address in friend function. Adding friend functions for sending to client(s) and server for OscReceiver. --- src/networking/oschandler.cpp | 140 +++++++++++++++++++++++++++------- 1 file changed, 113 insertions(+), 27 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 068ca258..fb5c044e 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -7,46 +7,36 @@ #include /** - * Constructor used to create client objects + * Constructor * @param controller reference to a Publisher object * @param port_in an integer describing the port number used for incoming * traffic * @param port_out an integer describing the port number used for outgoing * traffic * @param mode a string defining the mode (client|server) - */ -ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int - port_out, std::string mode) - : _controller(controller), - , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) - , _mode(mode) -{} - -/** - * Constructor used to create server objects - * @param controller reference to a Publisher object - * @param port_in an integer describing the port number used for incoming - * traffic - * @param port_out an integer describing the port number used for outgoing - * traffic - * @param mode a string defining the mode (client|server) - * @param clients a multimap holding hostname, port pairs + * @param clients a multimap holding hostname, port pairs (only used for + * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap - clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) { - std::vector new_clients; - for (const auto& hostname: clients) + if (mode == "server") + { + std::vector new_clients; + for (const auto& hostname: clients) + { + new_clients.push_back(new lo::Address(hostname.first, + std::to_string(hostname.second))); + } + _osc_sender(controller, *this, port_out, new_clients); + } + else if(mode == "client") { - new_clients.push_back(new lo::Address(hostname.first, - std::to_string(hostname.second))); + _osc_sender(controller, *this, port_out); } - _osc_sender(*this, port_out, new_clients); } /** @@ -81,7 +71,7 @@ ssr::OscHandler::start() void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address) { - self->_osc_sender->set_server_address(server_address); + self->_osc_sender.set_server_address(server_address); } /** @@ -94,6 +84,102 @@ lo::Address OscReceiver::server_address(OscHandler& self) return self->_osc_sender.server_address; } +/** + * OscHandler's friend function to send an OSC message to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, std::string path, lo::Message message) +{ + self->_osc_sender.send_to_client(client_address, path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, lo::Bundle bundle) +{ + self->_osc_sender.send_to_client(client_address, bundle); +} + +/** + * OscHandler's friend function to send an OSC message to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_all_clients(bundle); +} + +/** + * OscHandler's friend function to send an OSC message to all clients, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to all clients, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_all_clients(bundle); +} + +/** + * OscHandler's friend function to send an OSC message to the server, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to the server, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_server(bundle); +} + /** * This function returns the OscHandler's mode */ From 72fc432f89d37d17c7e66ebe26fb2a5f622843e7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:43:36 +0200 Subject: [PATCH 030/363] src/networking/oschandler.h: Removing explicit client constructor for OscHandler. Adding friend functions for OscReceiver to send messages/bundles to server and client(s). --- src/networking/oschandler.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 11c90474..756074e8 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -40,8 +40,6 @@ class OscHandler OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port_in, int port_out, std::string - mode); OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients); ~OscHandler(); @@ -51,6 +49,18 @@ class OscHandler friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); + friend void OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, std::string path, lo::Message message); + friend void OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, lo::Bundle bundle); + friend void OscReceiver::send_to_all_clients(OscHandler& self, std::string + path, lo::Message message); + friend void OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle + bundle); + friend void OscReceiver::send_to_server(OscHandler& self, std::string path, + lo::Message message); + friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle + bundle); }; } // namespace ssr From bfdc146fdd523044d21b866679d26afc484e9364 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:04:37 +0200 Subject: [PATCH 031/363] src/networking/oscreceiver.cpp: Be more specific about the naming of OSC messages (especially source/properties_file) and the naming of variables (especially file_name_or_port_number). Fixing typo in OSC message for reference/orientation and reference_offset/orientation. --- src/networking/oscreceiver.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e29aa376..14f8805b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -153,8 +153,8 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); - // set source file: "source/file, is, id, file" - _receiver.add_method("source/file", "is", [](lo_arg **argv, int) + // set source file: "source/properties_file, is, id, properties_file" + _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, argv[1]->s); VERBOSE2("set source properties file name: id = " << argv[0]->i << ", @@ -181,17 +181,17 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, - // port_name, x, y, orientation, volume, position_fixed, orientation_fixed, - // muted" + // file_name_or_port_number, x, y, orientation, volume, position_fixed, + // orientation_fixed, muted" // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // port_name, x, y, orientation, volume, channel, properties_file, - // position_fixed, orientation_fixed, muted" + // file_name_or_port_number, x, y, orientation, volume, channel, + // properties_file, position_fixed, orientation_fixed, muted" _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, lo::Message message) { std::string name(argv[0]->s); std::string model(argv[1]->s); - std::string file_or_portname(argv[2]->s); + std::string file_name_or_portname(argv[2]->s); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); @@ -319,13 +319,13 @@ void ssr::OscReceiver::add_server_to_client_methods() } if (setup) { - _controller.new_source(name, model, file_or_port_name, channel, + _controller.new_source(name, model, file_name_or_port_number, channel, Position(x, y), position_fixed, orientation, orientation_fixed, volume, muted, properties_file); VERBOSE2("Creating source with following properties:" "\nname: " << name << "\nmodel: " << model << - "\nfile_or_port_name: " << file_or_port_name << + "\nfile_name_or_port_number: " << file_name_or_port_number << "\nchannel: " << channel << "\nposition: " << Position(x, y) << "\nposition_fixed: " << position_fixed << @@ -365,7 +365,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/position", "f", [](lo_arg **argv, int) + _receiver.add_method("reference/orientation", "f", [](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -385,7 +385,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/position", "f" + _receiver.add_method("reference_offset/orientation", "f" , [](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); From c7c7041539d35c58879fb379d94badc8cf556e5d Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:07:03 +0200 Subject: [PATCH 032/363] src/networking/oscsender.h: Adding new private functions is_client, is_server, is_new_source, is_complete_source, send_new_source_message_from_id and a map for the collection of source message parts (_new_sources), requiring the adding of apf/parameter_map.h. --- src/networking/oscsender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index c922e382..cdf32f50 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -13,12 +13,14 @@ #endif #include +#include #include #include #include #include "ssr_global.h" #include "subscriber.h" +#include "apf/parameter_map.h" namespace ssr { @@ -39,6 +41,8 @@ class OscSender : public Subscriber lo::ServerThread _send_from; // vector of client address objects (server) std::vector _client_addresses; + // map of id/parameter_map pairs for new sources (server) + std::map _new_sources; // reference to handler OscHandler& _handler; // TODO: really needed? // reference to controller @@ -51,7 +55,13 @@ class OscSender : public Subscriber typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; + + bool is_client(); + bool is_server(); + bool is_new_source(id_t id); //< check, if source id is in _new_sources + bool is_complete_source(id_t id); //< check, if source is complete void poll_all_clients(); + void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: OscSender(Publisher& controller, OscHandler& handler, int port_out); From c14987503ca19386138aaed123403677020d5944 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:11:30 +0200 Subject: [PATCH 033/363] src/networking/oscsender.cpp: Adding implementation for is_client, is_server and all Subscriber interface functions. --- src/networking/oscsender.cpp | 1069 +++++++++++++++++++++++++++++++++- 1 file changed, 1067 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 9b9871b6..d22bd18e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -95,6 +95,38 @@ void ssr::OscSender::stop() VERBOSE2("Client polling thread stopped."); } +/** + * Returns true, if the instance of OscHandler is a 'client', false otherwise. + * @return true, if _oschandler.mode() returns 'client', false otherwise. + */ +bool ssr::OscSender::is_client() +{ + if(_oschandler.mode() == "client") + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the instance of OscHandler is a 'server', false otherwise. + * @return true, if _oschandler.mode() returns 'server', false otherwise. + */ +bool ssr::OscSender::is_server() +{ + if(_oschandler.mode() == "server") + { + return true; + } + else + { + return false; + } +} + /** * Sends a '/poll' message to all client instances listed in _client_addresses, * then makes the thread calling this function sleep for 1000 milliseconds @@ -200,8 +232,7 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) } /** - * Function to send a lo::Bundle to all clients setup in _client_addresses - * vector. + * Sends a lo::Bundle to all clients setup in _client_addresses vector. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) @@ -211,3 +242,1037 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) client_address.send_from(_send_from, bundle); } } + +/** + * Checks keys of _new_sources map against provided source id + * @return true, if source id is found in _new_sources, false otherwise + */ +bool ssr::OscSender::is_new_source(id_t id) +{ + if (_new_sources.empty()) + return false; + if(_new_sources.find(id) != _new_sources.end()) + { + return true; + } + else + { + return false; + } +} + +/** + * Checks, whether the settings stored in _new_sources under given source id + * are sufficient to send a '/source/new' message to all clients + * @return true, if sufficient fields are available, false otherwise + */ +bool ssr::OscSender::is_complete_source(id_t id) +{ + bool is_complete = false; + if(is_new_source(id)) + { + if((_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("properties_file") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted"))|| + (_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted"))) + is_complete = true; + } + return is_complete; +} + +/** + * Creates a lo::Message used to create a new source on clients. It will + * collect all parameters from a parameter_map in _new_sources according to an + * id. + * @param id id_t id of the local source a message will be created for. + */ +void ssr::OscSender::send_new_source_message_from_id(id_t id) +{ + lo::Message message; + if(_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("properties_file") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted") && + _new_sources.at(id).size() == 12 ) + { + message.add(_new_sources.at(id).get("name", "")); + message.add(_new_sources.at(id).get("model", "")); + message.add(_new_sources.at(id).get("file_name_or_port_number", "")); + message.add(_new_sources.at(id).get("x", 0.0)); + message.add(_new_sources.at(id).get("y", 0.0)); + message.add(_new_sources.at(id).get("orientation", 0.0)); + message.add(_new_sources.at(id).get("volume", 0.0)); + message.add(_new_sources.at(id).get("channel", 1)); + message.add(_new_sources.at(id).get("properties_file", "")); + message.add(_new_sources.at(id).get("position_fixed", false)); + message.add(_new_sources.at(id).get("orientation_fixed", false)); + message.add(_new_sources.at(id).get("muted", false)); + this->send_to_all_clients("source/new", message); + } + else if(_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted") && + _new_sources.at(id).size() == 10 ) + { + message.add(_new_sources.at(id).get("name", "")); + message.add(_new_sources.at(id).get("model", "")); + message.add(_new_sources.at(id).get("file_name_or_port_number", "")); + message.add(_new_sources.at(id).get("x", 0.0)); + message.add(_new_sources.at(id).get("y", 0.0)); + message.add(_new_sources.at(id).get("orientation", 0.0)); + message.add(_new_sources.at(id).get("volume", 0.0)); + message.add(_new_sources.at(id).get("position_fixed", false)); + message.add(_new_sources.at(id).get("orientation_fixed", false)); + message.add(_new_sources.at(id).get("muted", false)); + this->send_to_all_clients("source/new", message); + } +} + +// Subscriber interface (differentiating between client and server) + + +void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& + loudspeakers) +{ + (void) loudspeakers; + //not_implemented("OscSender::set_loudspeakers()"); +} + +/** + * Subscriber function called, when Publisher created a new source. + * On server: Creates new parameter_map in _new_sources if not present + * On client: Sends message about successful creation of source to server + * @param id id_t representing the source + */ +void ssr::OscSender::new_source(id_t id) +{ + if(is_server()) + { + if(!this->is_new_source(id)) + _new_sources.insert(make_pair(id, apf::parameter_map params)); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else if(is_client()) + { + lo::Message message; + message.add(id); + this->send_to_server("update/source/new", message); + } +} + +/** + * Subscriber function called, when Publisher deleted a source. + * On server: Sends out OSC message all clients to delete source with given id. + * On client: Sends out OSC message about successful deletion of source with id + * to server and erases complementing volume level from _source_levels. + * @param id id_t representing the source + */ +void ssr::OscSender::delete_source(id_t id) +{ + lo::Message message; + message.add(id); + if(is_server()) + { + this->send_to_all_clients("source/delete", id); + } + else if (is_client()) + { + this->send_to_server("update/source/delete", id); + _source_levels.erase(id); + } +} + +/** + * Subscriber function called, when Publisher deleted all sources. + * On server: Sends out OSC message to delete all sources on all clients. + * On client: Sends out OSC message about successful deletion to server. + * Clears local _source_levels. + */ +void ssr::OscSender::delete_all_sources() +{ + lo::Message message; + message.add(0); + if(is_server()) + this->send_to_all_clients("source/delete", message); + else if(is_client()) + this->send_to_server("update/source/delete", message); + + _source_levels.clear(); +} + +/** + * Subscriber function called, when Publisher set a source's position. + * On server: Sends out OSC message to set position of given source on all + * clients. If id is found in _new_sources, the Position will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message about successful positioning of source to + * server. + * @param id id_t representing the source + * @param position new Position of source + * @return true + */ +bool ssr::OscSender::set_source_position(id_t id, const Position& position) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("x", position.x); + _new_sources.at(id).set("y", position.y); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(position.x); + message.add(position.y); + this->send_to_all_clients("source/position", message); + } + } + else if (is_client()) + { + message.add(id); + message.add(position.x); + message.add(position.y); + this->send_to_server("update/source/position", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's position fixed + * state. + * On server: Sends out OSC message to set position fixed state of given source + * on all clients. If id is found in _new_sources, the position_fixed state + * will be stored in the parameter_map for id and an OSC message will be send + * to clients only, if the source is complete. + * On client: Sends out OSC message about the source's position_fixed state to + * server. + * @param id id_t representing the source + * @param fixed bool representing the source's position_fixed state + * @return true + */ +bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("position_fixed", fixed); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(fixed); + this->send_to_all_clients("source/position_fixed", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(fixed); + this->send_to_server("update/source/position_fixed", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's orientation. + * On server: Sends out OSC message to set Orientation of given source on all + * clients. If id is found in _new_sources, the Orientation will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message about new orientation of source to server. + * @param id id_t representing the source + * @param orientation new Orientation of source + * @return true + */ +bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& + orientation) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("orientation", orientation.azimuth); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(orientation.azimuth); + this->send_to_all_clients("source/orientation", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(orientation.azimuth); + this->send_to_server("update/source/orientation", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's volume. + * On server: Sends out OSC message to set volume of given source on all + * clients. If id is found in _new_sources, the volume will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's volume. + * @param id id_t representing the source + * @param gain new volume of source + * @return true + */ +bool ssr::OscSender::set_source_gain(id_t id, const float& gain) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("volume", gain); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(gain); + this->send_to_all_clients("source/volume", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(gain); + this->send_to_server("update/source/volume", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's mute state. + * On server: Sends out OSC message to set mute state of given source on all + * clients. If id is found in _new_sources, the mute state will be stored in + * the parameter_map for id and an OSC message will be send to clients only, if + * the source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's mute state. + * @param id id_t representing the source + * @param mute a bool representing the mute state of source + * @return true + */ +bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("mute", mute); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(mute); + this->send_to_all_clients("source/mute", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(mute); + this->send_to_server("update/source/mute", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's name. + * On server: Sends out OSC message to set the name of given source on all + * clients. If id is found in _new_sources, the name will be stored in + * the parameter_map for id and an OSC message will be send to clients only, if + * the source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's name. + * @param id id_t representing the source + * @param name a std::string representing the name of source + * @return true + */ +bool ssr::OscSender::set_source_name(id_t id, const std::string& name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("name", mute); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(name); + this->send_to_all_clients("source/name", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(name); + this->send_to_server("update/source/name", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's properties_file. + * On server: Sends out OSC message to set the properties_file of given source + * on all clients. If id is found in _new_sources, the properties_file will be + * stored in the parameter_map for id and an OSC message will be send to + * clients only, if the source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's properties_file. + * @param id id_t representing the source + * @param name a std::string representing the properties_file of source + * @return true + */ +bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& + name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("properties_file", name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(name); + this->send_to_all_clients("source/properties_file", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(name); + this->send_to_server("update/source/properties_file", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set the decay exponent. + * On server: Sends out OSC message to set the decay_exponent on all clients. + * On client: Sends out OSC message to server about the updating of decay_exponent + * @param exponentn float representing the decay exponent + * @param name a std::string representing the properties_file of source + * @todo implement receiving in OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_decay_exponent(float exponent) +{ + lo::Message message; + message.add(exponent); + if(is_server()) + { + this->send_to_all_clients("scene/decay_exponent", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/decay_exponent", message); + } +} + +/** + * Subscriber function called, when Publisher set the amplitude reference + * distance. + * On server: Sends out OSC message to set the amplitude reference distance on + * all clients. + * On client: Sends out OSC message to server about the updating of the + * amplitude reference distance. + * @param distance a float representing the amplitude reference distance + * @todo implement receiving in OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_amplitude_reference_distance(float distance) +{ + lo::Message message; + message.add(distance); + if(is_server()) + { + this->send_to_all_clients("scene/amplitude_reference_distance", + message); + } + else if(is_client()) + { + this->send_to_server("update/scene/amplitude_reference_distance", + message); + } +} + +/** + * Subscriber function called, when Publisher set a source's model. + * On server: Sends out OSC message to set the model of given source on all + * clients. If id is found in _new_sources, the model will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's model. + * @param id id_t representing the source + * @param model a model_t representing the model of source + * @return true + */ +bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) +{ + lo::Message message; + std::string tmp_model; + tmp_model = apf::string::A2S(model); + if (tmp_model == "") return false; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("model", tmp_model); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(tmp_model); + this->send_to_all_clients("source/model", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(tmp_model); + this->send_to_server("update/source/model", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's port_name. + * On server: Sends out OSC message to set the port_name of given source on all + * clients. If id is found in _new_sources, the port_name will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's port_name. + * @param id id_t representing the source + * @param port_name a std::string representing the port_name of source + * @return true + * @todo check if it has to be ignored during _controller.new_source() + * @see Controller::new_source() + */ +bool ssr::OscSender::set_source_port_name(id_t id, const std::string& + port_name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("port_name", port_name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(port_name); + this->send_to_all_clients("source/port_name", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(port_name); + this->send_to_server("update/source/port_name", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's + * file_name_or_port_number member. + * On server: Sends out OSC message to set the file_name_or_port_number of + * given source on all clients. If id is found in _new_sources, the + * file_name_or_port_number will be stored in the parameter_map for id and an + * OSC message will be send to clients only, if the source is complete. + * On client: Sends out OSC message to server about the updating of the + * source's file_name_or_port_number. + * @param id id_t representing the source + * @param file_name a std::string representing the file name or + * port number of source + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_name(id_t id, const std::string& + file_name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("file_name_or_port_number", + file_name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(file_name); + this->send_to_all_clients("source/file_name_or_port_number", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(file_name); + this->send_to_server("update/source/file_name_or_port_number", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's channel. + * On server: Sends out OSC message to set the channel of given source on all + * clients. If id is found in _new_sources, the channel will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the updating of the + * source's channel. + * @param id id_t representing the source + * @param file_channel an int representing the channel in use for source + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("channel", file_channel); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(file_channel); + this->send_to_all_clients("source/channel", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(file_channel); + this->send_to_server("update/source/channel", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's file length. + * On server: Does nothing, as the Publisher only emits this on creation of a + * new source. + * On client: Sends out OSC message to server about the updating of the + * source's file length. + * @param id id_t representing the source + * @param length an int representing the source file's length + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) +{ + lo::Message message; + if(is_client()) + { + message.add(id); + message.add(length); + this->send_to_server("update/source/length", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set the reference position. + * On server: Sends out OSC message to all clients to update to the given + * reference position. + * On client: Sends out OSC message to server about the updating of the + * reference position. + * @param position a Position representing the new reference position + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_position(const Position& position) +{ + lo::Message message; + message.add(position.x); + message.add(position.y); + if(is_server()) + { + this->send_to_all_clients("reference/position", message); + } + else if(is_client()) + { + this->send_to_server("update/reference/position", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference orientation. + * On server: Sends out OSC message to all clients to update to the given + * reference orientation. + * On client: Sends out OSC message to server about the updating of the + * reference orientation. + * @param orientation an Orientation representing the new reference orientation + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_orientation(const Orientation& orientation) +{ + lo::Message message; + message.add(orientation.azimuth); + if(is_server()) + { + this->send_to_all_clients("reference/orientation", message); + } + else if(is_client()) + { + this->send_to_server("update/reference/orientation", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference offset + * position. + * On server: Sends out OSC message to all clients to update to the given + * reference offset position. + * On client: Sends out OSC message to server about the updating of the + * reference offset position. + * @param position a Position representing the new reference offset position + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_offset_position(const Position& position) +{ + lo::Message message; + message.add(position.x); + message.add(position.y); + if(is_server()) + { + this->send_to_all_clients("reference_offset/position", message); + } + else if(is_client()) + { + this->send_to_server("update/reference_offset/position", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference offset + * orientation. + * On server: Sends out OSC message to all clients to update to the given + * reference offset orientation. + * On client: Sends out OSC message to server about the updating of the + * reference offset orientation. + * @param orientation an Orientation representing the new reference offset + * orientation + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_offset_orientation(const Orientation& + orientation) +{ + lo::Message message; + message.add(orientation.azimuth); + if(is_server()) + { + this->send_to_all_clients("reference_offset/orientation", message); + } + else if(is_client()) + { + this->send_to_server("update/reference_offset/orientation", message); + } +} + +/** + * Subscriber function called, when Publisher set the master volume. + * On server: Sends out OSC message to all clients to update to the given + * master volume (submits in dB!). + * On client: Sends out OSC message to server about the updating of the master + * volume (submits in dB!). + * @param volume float representing the new volume (linear scale) + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_master_volume(float volume) +{ + lo::Message message; + message.add(apf::math::linear2dB(volume)); + if(is_server()) + { + this->send_to_all_clients("scene/volume", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/volume", message); + } +} + +/** + * Subscriber function called, when Publisher set a source's output levels. + * On server: + * On client: + * @param id id_t representing the source + * @param first float* + * @param last float* + * @todo understand what should actually be done here + */ +void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* + last) +{ + void (id); + void (first); + void (last); +} + +/** + * Subscriber function called, when Publisher set the processing state. + * On server: Sends out OSC message to all clients to update their processing + * state. + * On client: Sends out OSC message to server about the update of its + * processing state. + * @param state bool representing the processing state + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_processing_state(bool state) +{ + lo::Message message; + message.add(state); + if(is_server()) + { + this->send_to_all_clients("state/processing", message); + } + else if(is_client()) + { + this->send_to_server("update/state/processing", message); + } +} + +/** + * Subscriber function called, when Publisher set the processing state. + * On server: Sends out OSC message to all clients to update their processing + * state. + * On client: Sends out OSC message to server about the update of its + * processing state. + * @param state a std::pair of a bool representing the processing state and + * jack_nframes_t, representing the current location in the transport + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_transport_state( const std::pair& state) +{ + lo::Message message_state; + lo::Message message_time; + message_state.add(state.first); + message_time.add(std::to_string(state.second)); + if(is_server()) + { + lo::Bundle bundle({ + {"state/transport", message_state}, + {"state/transport/seek", message_time} + }); + this->send_to_all_clients(bundle); + } + else if(is_client()) + { + lo::Bundle bundle({ + {"update/state/transport", message_state}, + {"update/state/transport/seek", message_time} + }); + this->send_to_server(bundle); + } +} + +/** + * Subscriber function called, when Publisher set whether to auto rotate + * sources. + * On server: Sends out OSC message to all clients to update their + * auto rotate settings. + * On client: Sends out OSC message to server about the update of its + * auto rotate settings. + * @param auto_rotate_sources a bool representing the current + * auto_rotate_sources setting. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) +{ + lo::Message message; + message.add(auto_rotate_sources); + if(is_server()) + { + this->send_to_all_clients("scene/auto_rotate_sources", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/auto_rotate_sources", message); + } +} + +/** + * Subscriber function called, when Publisher set cpu_load. + * On server: Does nothing. + * On client: Sends out OSC message to server indicating the cpu_load. + * @param load a float representing the current cpu load + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_cpu_load(float load) +{ + lo::Message message; + message.add(load); + if(is_client()) + { + this->send_to_server("update/cpu_load", message); + } +} + +/** + * Subscriber function called, when Publisher set sample rate. + * On server: Sends out OSC message to all clients to update their + * sample rate. + * On client: Sends out OSC message to server about the update of its + * sample rate. + * @param sr an integer representing the current sample rate. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_sample_rate(int sr) +{ + lo::Message message; + message.add(sr); + if(is_server()) + { + this->send_to_all_clients("scene/sample_rate", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/sample_rate", message); + } +} + +/** + * Subscriber function called, when Publisher set the master signal level. + * On server: Sends out OSC message to all clients to update their master + * signal level. + * On client: Sends out OSC message to server about the update of its signal + * level. + * @param level a float representing the current master signal level. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_master_signal_level(float level) +{ + lo::Message message; + message.add(apf::math::linear2dB(level)); + if(is_server()) + { + this->send_to_all_clients("scene/master_signal_level", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/master_signal_level", message); + } +} + +/** + * Subscriber function called, when Publisher set a source's signal level. + * On server: Sends out OSC message to all clients to update a source's signal + * level. + * On client: Sends out OSC message to server about the update of the source's + * signal level. + * @param id an id_t representing the source. + * @param level a float representing the signal level of the source. + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) +{ + lo::Message message; + message.add(apf::math::linear2dB(level)); + if(is_server()) + { + this->send_to_all_clients("scene/master_signal_level", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/master_signal_level", message); + } + return true; +} + From e2d6ac820856afa4b44f42b4c40e7857a7565fde Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:28:01 +0200 Subject: [PATCH 034/363] src/networking/oscreceiver.cpp: Adding callback functions for client to server OSC messages. Fixing typos in server to client callback functions. Renaming processing/state and transport/{state,seek} for clearer interface. --- src/networking/oscreceiver.cpp | 382 +++++++++++++++++++++++++++++++-- 1 file changed, 364 insertions(+), 18 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 14f8805b..d33390d6 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -53,11 +53,363 @@ void ssr::OscReceiver::start() /** * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every - * callback, that interface with the Publisher's functionality. + * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { -//TODO: implement! + // update on new source: "update/source/new, i, id" + _receiver.add_method("update/source/new", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << " created."); + } + ); + + // update on deleted source: "update/source/delete, i, id" + _receiver.add_method("update/source/delete", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + if(agrv[0]->i == 0) + { + VERBOSE("Update: Client '" << client.hostname() << "', all sources + deleted."); } + else + { + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << " deleted."); + } + } + ); + + // update on source position: "update/source/position, iff, id, x, y" + _receiver.add_method("update/source/position", "iff", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", position: "<< argv[1]->f << "/"argv[2]->f << "."); + } + ); + + // update on source position fixation: "update/source/position_fixed, i{T,F}, + // id, {true,false}" + _receiver.add_method("update/source/position_fixed", NULL, [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + std::string position_fixed; + if(message.types() == "iT") + { + position_fixed = "true"; + } + else if(message.types() == "iF") + { + position_fixed = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", position_fixed: "<< position_fixed << "."); + } + ); + + // update on source orientation: "update/source/orientation, if, id, azimuth" + _receiver.add_method("update/source/orientation", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", orientation: "<< argv[1]->f << "."); + } + ); + + // update on source volume: "update/source/volume, if, id, volume" + _receiver.add_method("update/source/volume", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", volume: "<< argv[1]->f << "."); + } + ); + + // update on source position mute: "update/source/mute, i{T,F}, + // id, {true,false}" + _receiver.add_method("update/source/mute", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "iT") + { + state = "true"; + } + else if(message.types() == "iF") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", mute: "<< state < "."); + } + ); + + // update on source name: "update/source/name, is, id, name" + _receiver.add_method("update/source/name", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", name: "<< argv[1]->s << "."); + } + ); + + // update on source properties_file: "update/source/properties_file, is, id, + // properties_file" + _receiver.add_method("update/source/properties_file", "is", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", properties_file: "<< argv[1]->s << "."); + } + ); + + // update on scene decay exponent: "update/scene/decay_exponent, f, + // decay_exponent" + _receiver.add_method("update/scene/decay_exponent", "f", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: + "<< argv[0]->f << "."); } + ); + + // update on scene amplitude reference distance: + // "update/scene/amplitude_reference_distance, f, + // amplitude_reference_distance" + _receiver.add_method("update/scene/amplitude_reference_distance", "f", + [](lo_arg **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', + amplitude_reference_distance: "<< argv[0]->f << "."); } + ); + + // update on source model: "update/source/model, is, id, model" + _receiver.add_method("update/source/model", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", model: "<< argv[1]->s << "."); + } + ); + + // update on source port_name: "update/source/port_name, is, id, port_name" + _receiver.add_method("update/source/port_name", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", port_name: "<< argv[1]->s << "."); + } + ); + + // update on source file_name_or_port_number: + // "update/source/file_name_or_port_number, is, id, file_name_or_port_number" + _receiver.add_method("update/source/file_name_or_port_number", "is", + [](lo_arg **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); + } + ); + + // update on source channel: "update/source/channel, ii, id, channel" + _receiver.add_method("update/source/channel", "ii", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", channel: "<< argv[1]->i << "."); + } + ); + + // update on source file length: "update/source/length, ii, id, length" + _receiver.add_method("update/source/length", "ii", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", length: "<< argv[1]->i << "."); + } + ); + + // update on reference position: "update/reference/position, ff, x, y" + _receiver.add_method("update/reference/position", "ff", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference + position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + } + ); + + // update on reference orientation: "update/reference/orientation, f, + // azimuth" + _receiver.add_method("update/reference/orientation", "f", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference + orientation: "<< argv[0]->f << " (azimuth)."); + } + ); + + // update on reference offset position: "update/reference_offset/position, + // ff, x, y" + _receiver.add_method("update/reference_offset/position", "ff", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference offset + position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + } + ); + + // update on reference offset orientation: + // "update/reference_offset/orientation, f, azimuth" + _receiver.add_method("update/reference_offset/orientation", "f", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference offset + orientation: "<< argv[0]->f << " (azimuth)."); + } + ); + + // update on scene volume: "update/scene/volume, f, volume" + _receiver.add_method("update/scene/volume", "f", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene volume: "<< + argv[0]->f << "dB."); + } + ); + + // update on state processing: "update/processing/state, {T,F}, {true,false}" + _receiver.add_method("update/processing/state", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', state processing: + "<< state < "."); + } + ); + + // update on transport state: "update/transport/state, {T,F}, {true,false}" + _receiver.add_method("update/transport/state", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', transport state: + "<< state < "."); + } + ); + + // update on transport seek: "update/transport/seek, s, time" + _receiver.add_method("update/transport/seek", "s", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', transport seek: + "<< argv[0]->s << "."); + } + ); + + // update on scene source auto rotation: "update/scene/auto_rotate_sources, + // {T,F}, {true,false}" + _receiver.add_method("update/scene/auto_rotate_sources", NULL, [](lo_arg + **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', scene + auto_rotate_sources: "<< state < "."); + } + ); + + // update on cpu_load: "update/cpu_load, f, load" + _receiver.add_method("update/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("Update: Client '" << client.hostname() << "', cpu_load: "<< + argv[0]->f << "%."); + } + ); + + // update on scene sample rate: "update/scene/sample_rate, i, sample_rate" + _receiver.add_method("update/scene/sample_rate", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene sample_rate: + "<< argv[0]->i << "Hz."); + } + ); + + // update on scene master signal level: "update/scene/master_signal_level, f, + // master_signal_level" + _receiver.add_method("update/scene/master_signal_level", "f", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene + master_signal_level: "<< argv[0]->f << "dB."); + } + ); + + // update on source signal level: "update/source/level, if, id, level" + _receiver.add_method("update/source/level", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", level: "<< argv[1]->f << "dB."); + } + ); + } /** @@ -191,7 +543,7 @@ void ssr::OscReceiver::add_server_to_client_methods() { std::string name(argv[0]->s); std::string model(argv[1]->s); - std::string file_name_or_portname(argv[2]->s); + std::string file_name_or_port_number(argv[2]->s); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); @@ -421,7 +773,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // clear scene: "scene/clear" - _receiver.add_method("scene/load", NULL + _receiver.add_method("scene/clear", NULL , [](lo_arg **argv, int) { _controller.delete_all_sources(); @@ -430,8 +782,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set processing state: "state/processing, T, true" - _receiver.add_method("state/processing", "T" - , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "T" , [](lo_arg **argv, int) { _controller.start_processing(); VERBOSE2("start processing."); @@ -439,26 +790,23 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set processing state: "state/processing, F, false" - _receiver.add_method("state/processing", "F" - , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "F" , [](lo_arg **argv, int) { _controller.stop_processing(); VERBOSE2("stop processing."); } ); - // set transport state: "state/transport, T, true" - _receiver.add_method("state/transport", "T" - , [](lo_arg **argv, int) + // set transport state: "transport/state, T, true" + _receiver.add_method("transport/state", "T" , [](lo_arg **argv, int) { _controller.transport_start(); VERBOSE2("start transport."); } ); - // set transport state: "state/transport, F, false" - _receiver.add_method("state/transport", "F" - , [](lo_arg **argv, int) + // set transport state: "transport/state, F, false" + _receiver.add_method("transport/state", "F" , [](lo_arg **argv, int) { _controller.transport_stop(); VERBOSE2("stop transport."); @@ -466,8 +814,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // rewind transport state: "state/transport/rewind" - _receiver.add_method("state/transport/rewind", NULL - , [](lo_arg **argv, int) + _receiver.add_method("transport/rewind", NULL , [](lo_arg **argv, int) { _controller.transport_locate(0); VERBOSE2("rewind transport."); @@ -475,8 +822,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // seek transport state: "state/transport/seek, s, time" - _receiver.add_method("state/transport/seek", "s" - , [](lo_arg **argv, int) + _receiver.add_method("transport/seek", "s" , [](lo_arg **argv, int) { float time; if(string2time(argv[0]->s, time)) From 0a81034a94d41d5d029089d252ee34ad564cc320 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:29:54 +0200 Subject: [PATCH 035/363] src/networking/oscsender.h: Cleanup and adding TODO. --- src/networking/oscsender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cdf32f50..73e2d746 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -31,6 +31,7 @@ namespace ssr * the Subscriber interface. * The Publisher is subscribed to, using its interface to send out OSC messages * on all events it emmits. + * @todo implement sending levels periodically */ class OscSender : public Subscriber { @@ -82,7 +83,6 @@ class OscSender : public Subscriber void send_to_all_client(std::string path, lo::Message message); void send_to_all_client(lo::Bundle bundle); - void update_all_clients(std::string str); void send_levels(); // Subscriber Interface From 12c159f128817744b7b46ceeea71af231953432d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:31:57 +0200 Subject: [PATCH 036/363] src/networking/oscsender.cpp: Adding documentation for set_loudspeakers function. Fixing copy stupidity in set_source_signal_level and changing to new OSC message format in set_transport_state and set_processing_state. --- src/networking/oscsender.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index d22bd18e..7a8a6725 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -364,11 +364,16 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) // Subscriber interface (differentiating between client and server) +/** + * Subscriber function called, when Publisher sets up the list of loudspeakers. + * Not implemented in OscSender. + * @param loudpspeakers Loudspeaker container representing the list of + * loudspeakers to set up. + */ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& loudspeakers) { (void) loudspeakers; - //not_implemented("OscSender::set_loudspeakers()"); } /** @@ -1113,11 +1118,11 @@ void ssr::OscSender::set_processing_state(bool state) message.add(state); if(is_server()) { - this->send_to_all_clients("state/processing", message); + this->send_to_all_clients("processing/state", message); } else if(is_client()) { - this->send_to_server("update/state/processing", message); + this->send_to_server("update/processing/state", message); } } @@ -1142,16 +1147,16 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients(bundle); } else if(is_client()) { lo::Bundle bundle({ - {"update/state/transport", message_state}, - {"update/state/transport/seek", message_time} + {"update/transport/state", message_state}, + {"update/transport/seek", message_time} }); this->send_to_server(bundle); } @@ -1267,11 +1272,11 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) message.add(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("scene/master_signal_level", message); + this->send_to_all_clients("source/level", message); } else if(is_client()) { - this->send_to_server("update/scene/master_signal_level", message); + this->send_to_server("update/source/level", message); } return true; } From 4f959b73de7eb03c086c27317c14aeac16d3d317 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:33:31 +0200 Subject: [PATCH 037/363] src/networking/oscreceiver.h: Adding TODO. --- src/networking/oscreceiver.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 56867ac3..3c19e907 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -31,6 +31,7 @@ class OscHandler; * This class holds a Publisher and an OscHandler reference. * It is responsible for all incoming OSC messages and using callback functions * to trigger functionality in the Publisher. + * @todo add functionality to only process a subset of incoming client messages */ class OscReceiver { From 194ce3f7cc942e51036ffc81f540291d30f991b2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 15:37:23 +0200 Subject: [PATCH 038/363] src/networking/oscsender.h: Adding more todos. --- src/networking/oscsender.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 73e2d746..59b427bf 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -31,7 +31,8 @@ namespace ssr * the Subscriber interface. * The Publisher is subscribed to, using its interface to send out OSC messages * on all events it emmits. - * @todo implement sending levels periodically + * @todo implement sending levels periodically using apf/cxx_thread_policy.h + * @todo implement polling clients periodically using apf/cxx_thread_policy.h */ class OscSender : public Subscriber { From 6b61f8158c884e7d9ee53c7da534e9cbed0f0967 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:21:10 +0200 Subject: [PATCH 039/363] src/networking/oschandler.cpp: Fixing accidental std::multimap initialization in Constructor. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index fb5c044e..30b8e312 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -18,7 +18,7 @@ * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) From ad015824cd1a28014629e35300751c57225944a9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:30:21 +0200 Subject: [PATCH 040/363] src/networking/oschandler.cpp: Fixing type definition of std::multimap in constructor. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 30b8e312..f0476db1 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -18,7 +18,7 @@ * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) From c86a4989f0550e3bd635de179316e9d717624f2d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:36:37 +0200 Subject: [PATCH 041/363] src/networking/oschandler.cpp: Fixing accidental additional comma in initializer list. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index f0476db1..2b982b28 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -19,7 +19,7 @@ */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) - : _controller(controller), + : _controller(controller) , _osc_receiver(controller, *this, port_in) , _mode(mode) { From a02d2d70bd05ba72a8ce1ba678f94a0b1a214cf0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:50:24 +0200 Subject: [PATCH 042/363] src/networking/oschandler.cpp: Add TODO to fix initializer list warning during make. --- src/networking/oschandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2b982b28..bcd9a11f 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -16,6 +16,8 @@ * @param mode a string defining the mode (client|server) * @param clients a multimap holding hostname, port pairs (only used for * server) + * @todo add _osc_sender to initializer list, to circumvent reorder warning, + * create client list after initialization, when in server mode */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) From 394f78833aef881a651856bdeee4de1a2e943980 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 17:01:10 +0200 Subject: [PATCH 043/363] src/networking/oschandler.cpp: Fix start/stop functionality. The class members were wrongly named and the function declaration insufficient. --- src/networking/oschandler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bcd9a11f..7c4e0c9e 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -50,19 +50,19 @@ ssr::OscHandler::~OscHandler() /** * Stop this OscHandler by stopping its OscReceiver and OscSender */ -ssr::OscHandler::stop() +void ssr::OscHandler::stop() { - _oscSender.stop(); - _oscReceiver.stop(); + _osc_receiver.stop(); + _osc_sender.stop(); } /** * Start this OscHandler by starting its OscReceiver and OscSender */ -ssr::OscHandler::start() +void ssr::OscHandler::start() { - _oscReceiver.start(); - _oscSender.start(); + _osc_receiver.start(); + _osc_sender.start(); } /** From 783c52207c26725210da4c0943a4c8c056f2f25f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:08:51 +0200 Subject: [PATCH 044/363] src/networking/oscsender.cpp: Adding public function to add a lo::Address to the vector of clients. --- src/networking/oscsender.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 7a8a6725..c7aec020 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -361,6 +361,15 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) } } +/** + * Adds a new client to the vector of clients + * @param clients lo::Address of a client + */ +void add_client(lo::Address client) +{ + _client_addresses.push_back(client); +} + // Subscriber interface (differentiating between client and server) From ed93f00647c055c25f8d877e62162db0c134a955 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:09:20 +0200 Subject: [PATCH 045/363] src/networking/oscsender.h: Adding add_client() to the public interface. --- src/networking/oscsender.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 59b427bf..1d8bdb17 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -75,6 +75,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(lo::Address server_address); lo::Address server_address(); + void add_client(lo::Address client); void poll_clients(); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From 829c9a68b1d135d6eef8f46638a27f7d4eb5f9c6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:11:15 +0200 Subject: [PATCH 046/363] src/networking/oschandler.cpp: Fixing ordering in constructor initializer list. Adding list of clients to _osc_sender (as lo::Address objects), if server mode is selected. Removing todo about reorder warning. --- src/networking/oschandler.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 7c4e0c9e..cfae55be 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -16,28 +16,21 @@ * @param mode a string defining the mode (client|server) * @param clients a multimap holding hostname, port pairs (only used for * server) - * @todo add _osc_sender to initializer list, to circumvent reorder warning, - * create client list after initialization, when in server mode */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) - : _controller(controller) + : _mode(mode) + , _controller(controller) , _osc_receiver(controller, *this, port_in) - , _mode(mode) + , _osc_sender(controller, *this, port_out) { if (mode == "server") { - std::vector new_clients; for (const auto& hostname: clients) { - new_clients.push_back(new lo::Address(hostname.first, + _osc_sender.add_client(new lo::Address(hostname.first, std::to_string(hostname.second))); } - _osc_sender(controller, *this, port_out, new_clients); - } - else if(mode == "client") - { - _osc_sender(controller, *this, port_out); } } From ce64b5f2510548b8441cdd3f63a862a1239c4cc5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 19:14:08 +0200 Subject: [PATCH 047/363] src/networking/oschandler.cpp: Fixing broken operands of accessing members of _osc_sender. Clearly defining function heads for set_server_for_client and server_address to use ssr:OscHandler. --- src/networking/oschandler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index cfae55be..cdab5505 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -63,10 +63,10 @@ void ssr::OscHandler::start() * @param self reference to OscHandler holding OscSender * @param server_address lo::Address object to be used for OscSender */ -void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address +void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address server_address) { - self->_osc_sender.set_server_address(server_address); + self._osc_sender.set_server_address(server_address); } /** @@ -74,7 +74,7 @@ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ -lo::Address OscReceiver::server_address(OscHandler& self) +lo::Address OscReceiver::server_address(ssr::OscHandler& self) { return self->_osc_sender.server_address; } @@ -89,7 +89,7 @@ lo::Address OscReceiver::server_address(OscHandler& self) void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message) { - self->_osc_sender.send_to_client(client_address, path, message); + self._osc_sender.send_to_client(client_address, path, message); } /** @@ -102,7 +102,7 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, lo::Bundle bundle) { - self->_osc_sender.send_to_client(client_address, bundle); + self._osc_sender.send_to_client(client_address, bundle); } /** @@ -114,7 +114,7 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, lo::Message message) { - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(path, message); } /** @@ -126,7 +126,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_all_clients(bundle); + self._osc_sender.send_to_all_clients(bundle); } /** From 54d12fdcc83a9dcbce4544dab529699d298ae3ea Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:52:57 +0200 Subject: [PATCH 048/363] src/networking/oschandler.cpp: Removing accidental copies of send_to_all_clients functions. Properly implementing mode(), OscReceiver::server_address. Fixing access to _osc_sender member. --- src/networking/oschandler.cpp | 50 +++++------------------------------ 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index cdab5505..079a85d8 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -74,9 +74,9 @@ void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ -lo::Address OscReceiver::server_address(ssr::OscHandler& self) +lo::Address ssr::OscReceiver::server_address(ssr::OscHandler& self) { - return self->_osc_sender.server_address; + return self._osc_sender.server_address(); } /** @@ -105,30 +105,6 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address self._osc_sender.send_to_client(client_address, bundle); } -/** - * OscHandler's friend function to send an OSC message to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, - lo::Message message) -{ - self._osc_sender.send_to_all_clients(path, message); -} - -/** - * OscHandler's friend function to send an OSC bundle to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param client_address lo::Address of client to send to (must be in _client_addresses) - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) -{ - self._osc_sender.send_to_all_clients(bundle); -} - /** * OscHandler's friend function to send an OSC message to all clients, using * OscSender. @@ -138,7 +114,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, lo::Message message) { - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(path, message); } /** @@ -149,19 +125,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_all_clients(bundle); -} - -/** - * OscHandler's friend function to send an OSC message to the server, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, - lo::Message message) -{ - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(bundle); } /** @@ -172,13 +136,13 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_server(bundle); + self._osc_sender.send_to_server(bundle); } /** * This function returns the OscHandler's mode */ -std::string mode() +std::string ssr::OscHandler::mode() { - return *this->_mode; + return _mode; } From b2046aed98e200bf95c7829677df52343b14264f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:53:52 +0200 Subject: [PATCH 049/363] src/networking/oscsender.h: Fixing naming typo of send_to_all_clients functions. --- src/networking/oscsender.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 1d8bdb17..20a28ae5 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -82,8 +82,8 @@ class OscSender : public Subscriber void send_to_client(lo::Address address, std::string path, lo::Message message); void send_to_client(lo::Address address, lo::Bundle bundle); - void send_to_all_client(std::string path, lo::Message message); - void send_to_all_client(lo::Bundle bundle); + void send_to_all_clients(std::string path, lo::Message message); + void send_to_all_clients(lo::Bundle bundle); void send_levels(); From 922a33c0120ee44c8ca98219cf09b4e0b6f1f657 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:54:29 +0200 Subject: [PATCH 050/363] src/networking/oscreceiver.cpp: Fixing typo for oscreceiver.h include. --- src/networking/oscreceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d33390d6..b4dd1bfb 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -3,7 +3,7 @@ * @file oscreceiver.cpp */ -#include "oscreiver.h" +#include "oscreceiver.h" #include "oschandler.h" #include "publisher.h" #include "apf/stringtools.h" From 60509f42cd3386ec2a8b698477eeeef81b345779 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 17:41:54 +0200 Subject: [PATCH 051/363] src/networking/oscreceiver.cpp: Fixing non-escaped linebreaks in VERBOSE messages. --- src/networking/oscreceiver.cpp | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b4dd1bfb..ca40e0c0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -74,7 +74,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Address client(message.source()); if(agrv[0]->i == 0) { - VERBOSE("Update: Client '" << client.hostname() << "', all sources + VERBOSE("Update: Client '" << client.hostname() << "', all sources \ deleted."); } else { @@ -181,7 +181,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: + VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: \ "<< argv[0]->f << "."); } ); @@ -192,7 +192,7 @@ void ssr::OscReceiver::add_client_to_server_methods() [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', + VERBOSE("Update: Client '" << client.hostname() << "', \ amplitude_reference_distance: "<< argv[0]->f << "."); } ); @@ -252,7 +252,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference + VERBOSE("Update: Client '" << client.hostname() << "', reference \ position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); } ); @@ -263,7 +263,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference + VERBOSE("Update: Client '" << client.hostname() << "', reference \ orientation: "<< argv[0]->f << " (azimuth)."); } ); @@ -274,7 +274,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset + VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); } ); @@ -285,7 +285,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset + VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ orientation: "<< argv[0]->f << " (azimuth)."); } ); @@ -314,8 +314,8 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', state processing: - "<< state < "."); + VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ + " << state < "."); } ); @@ -333,7 +333,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', transport state: + VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ "<< state < "."); } ); @@ -343,7 +343,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', transport seek: + VERBOSE("Update: Client '" << client.hostname() << "', transport seek: \ "<< argv[0]->s << "."); } ); @@ -364,7 +364,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', scene + VERBOSE("Update: Client '" << client.hostname() << "', scene \ auto_rotate_sources: "<< state < "."); } ); @@ -384,8 +384,8 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene sample_rate: - "<< argv[0]->i << "Hz."); + VERBOSE("Update: Client '" << client.hostname() << "', scene \ + sample_rate: "<< argv[0]->i << "Hz."); } ); @@ -395,7 +395,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene + VERBOSE("Update: Client '" << client.hostname() << "', scene \ master_signal_level: "<< argv[0]->f << "dB."); } ); @@ -448,7 +448,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ true"); } ); @@ -457,7 +457,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ false"); } ); @@ -509,7 +509,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, argv[1]->s); - VERBOSE2("set source properties file name: id = " << argv[0]->i << ", + VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ file = " << argv[1]->s); } ); @@ -518,8 +518,8 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/model", "is", [](lo_arg **argv, int) { _controller.set_source_model(argv[0]->i, argv[1]->s); - VERBOSE2("set source model: id = " << argv[0]->i << ", - model = " << argv[1]->s); + VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << + argv[1]->s); } ); @@ -527,8 +527,8 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, argv[1]->s); - VERBOSE2("set source port name: id = " << argv[0]->i << ", - port = " << argv[1]->s); + VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << + argv[1]->s); } ); From 4c13f3b088355271d5fc520664dc573e53ce43b0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:29:58 +0200 Subject: [PATCH 052/363] src/networking/oschandler.h: Fix header guard. --- src/networking/oschandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 756074e8..c60fa08a 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -6,7 +6,6 @@ #ifndef OSC_HANDLER_H #define OSC_HANDLER_H -#endif #ifdef HAVE_CONFIG_H #include // for ENABLE_* @@ -64,3 +63,4 @@ class OscHandler }; } // namespace ssr +#endif From 8b9cd1ea546390862c7661ca832e5f1cd1621c2e Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:30:35 +0200 Subject: [PATCH 053/363] src/networking/oscreceiver.h: Fix header guard. Remove redundant _mode std::string. --- src/networking/oscreceiver.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3c19e907..116d26b2 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -6,7 +6,6 @@ #ifndef OSC_RECEIVER_H #define OSC_RECEIVER_H -#endif #ifdef HAVE_CONFIG_H @@ -39,7 +38,6 @@ class OscReceiver lo::ServerThread _receiver; Publisher& _controller; ssr::OscHandler& _handler; - std::string _mode; void add_client_to_server_methods(); void add_server_to_client_methods(); public: @@ -61,3 +59,4 @@ class OscReceiver }; } // namespace ssr +#endif From 0cd1f5e0f894bf85041b9e1dce1832565a6aaceb Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:30:57 +0200 Subject: [PATCH 054/363] src/networking/oscsender.h: Fix header guard. --- src/networking/oscsender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 20a28ae5..b180de74 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -6,7 +6,6 @@ #ifndef OSC_SENDER_H #define OSC_SENDER_H -#endif #ifdef HAVE_CONFIG_H #include // for ENABLE_* @@ -127,3 +126,4 @@ class OscSender : public Subscriber }; } // namespace ssr +#endif From 8c157d4fd4e4242813cd723f5470efe9de6fd160 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:33:05 +0200 Subject: [PATCH 055/363] src/networking/oscreceiver.cpp: Fix Constructor definition (OscHandler added to arguments, initializer list reorganized). Set check for client/server mode to use _handler instance. Fixing typo in add_client_to_server_methods, calling agrv instead of argv. --- src/networking/oscreceiver.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index ca40e0c0..2c37df54 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -17,9 +17,10 @@ using namespace apf::str; * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, int port_in) - : _controller(controller) - , _receiver(port_in) +ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int port_in) + : _receiver(port_in) + , _controller(controller) + , _handler(handler) {} /** @@ -38,11 +39,11 @@ ssr::OscReceiver::~OscReceiver() void ssr::OscReceiver::start() { // add method handlers for received messages - if (_mode == "server") + if (_handler.mode() == "server") { add_client_to_server_methods(); } - else if (_mode == "client") + else if (_handler.mode() == "client") { add_server_to_client_methods(); } @@ -72,7 +73,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - if(agrv[0]->i == 0) + if(argv[0]->i == 0) { VERBOSE("Update: Client '" << client.hostname() << "', all sources \ deleted."); } From e3416561b2d7c1f112bdb0e2298b743d5bae28fc Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:56:54 +0200 Subject: [PATCH 056/363] src/networking/oscreceiver.cpp: Using apf::string::A2S() in VERBOSE output, where needed. Avoiding unused parameter warning with argv in some lambda functions. Using << in VERBOSE instead of <. --- src/networking/oscreceiver.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2c37df54..c0df7e6b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -91,7 +91,8 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position: "<< argv[1]->f << "/"argv[2]->f << "."); + argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << + "."); } ); @@ -151,7 +152,8 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", mute: "<< state < "."); + apf::str::A2S(argv[0]->i) << ", mute: "<< state << + "."); } ); @@ -307,6 +309,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -316,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ - " << state < "."); + " << state << "."); } ); @@ -326,6 +329,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -335,7 +339,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ - "<< state < "."); + "<< state << "."); } ); @@ -357,6 +361,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -366,7 +371,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', scene \ - auto_rotate_sources: "<< state < "."); + auto_rotate_sources: "<< state << "."); } ); From fe523e8db3d4effa36a1635a0ebb30301e61dde0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:08:37 +0200 Subject: [PATCH 057/363] src/networking/oscreceiver.cpp: Using apf::str::A2S to convert members of lo::Message objects to std::string. Using apf::str::S2A for Source::model_t editing. Adding *this pointer to lambda functions, that require access to _controller. --- src/networking/oscreceiver.cpp | 67 +++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c0df7e6b..e87330a2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -427,31 +427,32 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _receiver.add_method("poll", NULL, [](lo_arg **argv, int, lo::Message + _receiver.add_method("poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server = server_address(&_handler); + lo::Address server = server_address(_handler); lo::Address from(message.source()); + (void) argv; if(server.hostname() != from.hostname() && server.port() != from.port()) { - set_server_address(from); + set_server_for_client(_handler, from); // TODO: send reply to subscribed server } } - ): + ); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("source/position", "iff", [](lo_arg **argv, int) + _receiver.add_method("source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f); + argv[2]->f)); VERBOSE2("set source position: id = " << argv[0]->i << ", " << Position(argv[1]->f, argv[2]->f)); } ); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) + _receiver.add_method("source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ @@ -460,7 +461,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) + _receiver.add_method("source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ @@ -469,7 +470,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("source/orientation", "if", [](lo_arg **argv, int) + _receiver.add_method("source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " @@ -478,16 +479,17 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("source/volume", "if", [](lo_arg **argv, int) + _receiver.add_method("source/volume", "if", [this](lo_arg **argv, int) { - _controller.set_source_gain(argv[0]->i, dB2linear(argv[1]->f)); + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << - dB2linear(argv[1]->f)); + apf::math::dB2linear(argv[1]->f)); } ); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) + _receiver.add_method("source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -495,7 +497,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) + _receiver.add_method("source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -503,38 +505,45 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source name: "source/name, is, id, name" - _receiver.add_method("source/name", "is", [](lo_arg **argv, int) + _receiver.add_method("source/name", "is", [this](lo_arg **argv, int) { - _controller.set_source_name(argv[0]->i, argv[1]->s); + _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); // set source file: "source/properties_file, is, id, properties_file" - _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) + _receiver.add_method("source/properties_file", "is", [this](lo_arg **argv, + int) { - _controller.set_source_properties_file(argv[0]->i, argv[1]->s); + _controller.set_source_properties_file(argv[0]->i, + apf::str::A2S(argv[1]->s)); VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ - file = " << argv[1]->s); + file = " << apf::str::A2S(argv[1]->s)); } ); // set source model: "source/model, is, id, model" - _receiver.add_method("source/model", "is", [](lo_arg **argv, int) + _receiver.add_method("source/model", "is", [this](lo_arg **argv, int) { - _controller.set_source_model(argv[0]->i, argv[1]->s); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + _controller.set_source_model(argv[0]->i, model); VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); // set source port name: "source/port_name, is, id, port_name" - _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) + _receiver.add_method("source/port_name", "is", [this](lo_arg **argv, int) { - _controller.set_source_port_name(argv[0]->i, argv[1]->s); + _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); @@ -547,9 +556,9 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, lo::Message message) { - std::string name(argv[0]->s); - std::string model(argv[1]->s); - std::string file_name_or_port_number(argv[2]->s); + std::string name(apf::str::A2S(argv[0]->s)); + std::string model(apf::str::A2S(argv[1]->s)); + std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); From acf8b95c46a4e25a46fedc9e3fdff23720f58f8d Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:28:11 +0200 Subject: [PATCH 058/363] src/networking/oscreceiver.cpp: Using several if clauses, instead of a switch in the lambda responsible for setting up a new source. Initializing all dependant types earlier. --- src/networking/oscreceiver.cpp | 95 ++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e87330a2..45ea9700 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -553,15 +553,14 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, + _receiver.add_method("source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); - std::string model(apf::str::A2S(argv[1]->s)); std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); + std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); - float orientation(argv[5]->f); float volume(argv[6]->f); int channel = 0; std::string properties_file = ""; @@ -569,132 +568,152 @@ void ssr::OscReceiver::add_server_to_client_methods() bool orientation_fixed; bool muted; bool setup = false; - switch (message.types()) + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); + if (types.compare("sssffffTTT") == 0) { - case "sssffffTTT": position_fixed = true; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffTTF": + } + if (types.compare("sssffffTTF") == 0) + { position_fixed = true; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffTFF": + } + if (types.compare("sssffffTFF") == 0) + { position_fixed = true; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffFFF": + } + if (types.compare("sssffffFFF") == 0) + { position_fixed = false; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffTFT": + } + if (types.compare("sssffffTFT") == 0) + { position_fixed = true; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffFTF": + } + if (types.compare("sssffffFTF") == 0) + { position_fixed = false; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffFTT": + } + if (types.compare("sssffffFTT") == 0) + { position_fixed = false; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffFFT": + } + if (types.compare("sssffffFFT") == 0) + { position_fixed = false; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffisTTT": + } + if (types.compare("sssffffisTTT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffisTTF": + } + if (types.compare("sssffffisTTF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffisTFF": + } + if (types.compare("sssffffisTFF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffisFFF": + } + if (types.compare("sssffffisFFF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffisTFT": + } + if (types.compare("sssffffisTFT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffisFTF": + } + if (types.compare("sssffffisFTF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffisFTT": + } + if (types.compare("sssffffisFTT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffisFFT": + } + if (types.compare("sssffffisFFT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = false; muted = true; setup = true; - break; } if (setup) { _controller.new_source(name, model, file_name_or_port_number, channel, - Position(x, y), position_fixed, orientation, orientation_fixed, + position, position_fixed, orientation, orientation_fixed, volume, muted, properties_file); VERBOSE2("Creating source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << "\nchannel: " << channel << - "\nposition: " << Position(x, y) << + "\nposition: " << position << "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << "\norientation_fixed: " << orientation_fixed << From a21db62abae2a736d7e10a49d292423175944ab0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:48:39 +0200 Subject: [PATCH 059/363] src/networking/oscreceiver.cpp: Adding namespaces to apf functions in use. Adding this pointer capture to remaining functions needing it. Explicitely converting lo::Message members of type std::string using apf::str::A2S. --- src/networking/oscreceiver.cpp | 69 ++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 45ea9700..c945d1ea 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -727,7 +727,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("source/delete", "i", [](lo_arg **argv, int) + _receiver.add_method("source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -743,15 +743,15 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference position: "reference/position, ff, x, y" - _receiver.add_method("reference/position", "ff", [](lo_arg **argv, int) + _receiver.add_method("reference/position", "ff", [this](lo_arg **argv, int) { - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f); + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/orientation", "f", [](lo_arg **argv, int) + _receiver.add_method("reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -759,11 +759,11 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference offset position: "reference_offset/position, ff, x, y" - _receiver.add_method("reference_offset/position", "ff" - , [](lo_arg **argv, int) + _receiver.add_method("reference_offset/position", "ff" , [this](lo_arg + **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f); + argv[1]->f)); VERBOSE2("set reference offset position: " << Position(argv[0]->f, argv[1]->f)); } @@ -771,8 +771,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/orientation", "f" - , [](lo_arg **argv, int) + _receiver.add_method("reference_offset/orientation", "f" , [this](lo_arg **argv, + int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference offset orientation: " << @@ -781,85 +781,89 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // save scene to file: "scene/save, s, file" - _receiver.add_method("scene/save", "s" - , [](lo_arg **argv, int) + _receiver.add_method("scene/save", "s" , [this](lo_arg **argv, int) { - _controller.save_scene_as_XML(argv[0]->s); - VERBOSE2("saving theme as: " << argv[0]->s); + _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); + VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); } ); // load scene from file: "scene/load, s, file" - _receiver.add_method("scene/load", "s" - , [](lo_arg **argv, int) + _receiver.add_method("scene/load", "s" , [this](lo_arg **argv, int) { - _controller.load_scene(argv[0]->s); - VERBOSE2("loading scene: " << argv[0]->s); + _controller.load_scene(apf::str::A2S(argv[0]->s)); + VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); } ); // set master volume: "scene/volume, f, volume" - _receiver.add_method("scene/volume", "f" - , [](lo_arg **argv, int) + _receiver.add_method("scene/volume", "f" , [this](lo_arg **argv, int) { - _controller.set_master_volume(dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << dB2linear(argv[0]->f) << " dB"); } + _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << " \ + dB"); + } ); // clear scene: "scene/clear" - _receiver.add_method("scene/clear", NULL - , [](lo_arg **argv, int) + _receiver.add_method("scene/clear", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.delete_all_sources(); VERBOSE2("clearing scene."); } ); // set processing state: "state/processing, T, true" - _receiver.add_method("processing/state", "T" , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "T" , [this](lo_arg **argv, int) { + (void) argv; _controller.start_processing(); VERBOSE2("start processing."); } ); // set processing state: "state/processing, F, false" - _receiver.add_method("processing/state", "F" , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "F" , [this](lo_arg **argv, int) { + (void) argv; _controller.stop_processing(); VERBOSE2("stop processing."); } ); // set transport state: "transport/state, T, true" - _receiver.add_method("transport/state", "T" , [](lo_arg **argv, int) + _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_start(); VERBOSE2("start transport."); } ); // set transport state: "transport/state, F, false" - _receiver.add_method("transport/state", "F" , [](lo_arg **argv, int) + _receiver.add_method("transport/state", "F" , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_stop(); VERBOSE2("stop transport."); } ); // rewind transport state: "state/transport/rewind" - _receiver.add_method("transport/rewind", NULL , [](lo_arg **argv, int) + _receiver.add_method("transport/rewind", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_locate(0); VERBOSE2("rewind transport."); } ); // seek transport state: "state/transport/seek, s, time" - _receiver.add_method("transport/seek", "s" , [](lo_arg **argv, int) + _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; - if(string2time(argv[0]->s, time)) + if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) { _controller.transport_locate(time); VERBOSE2("Seek transport to: " << time); @@ -873,13 +877,12 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // reset tracker: "tracker/reset" - _receiver.add_method("tracker/reset", NULL - , [](lo_arg **argv, int) + _receiver.add_method("tracker/reset", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.calibrate_client(); VERBOSE2("calibrate tracker."); } ); - } From cbff4beb67e16c749ee281ac44285d6144bbdba0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 13:20:59 +0200 Subject: [PATCH 060/363] src/networking/oscsender.h: Removing unused member _mode. Moving members around to reflect Constructor implementation. --- src/networking/oscsender.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index b180de74..920b8b29 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -36,23 +36,22 @@ namespace ssr class OscSender : public Subscriber { private: - // address of server (client) - lo::Address _server_address; + // reference to controller + Publisher& _controller; + // reference to handler + OscHandler& _handler; // ServerThread to send from specific port (client|server) lo::ServerThread _send_from; + bool _is_subscribed; + // address of server (client) + lo::Address _server_address; // vector of client address objects (server) std::vector _client_addresses; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; - // reference to handler - OscHandler& _handler; // TODO: really needed? - // reference to controller - Publisher& _controller; // thread used for calling poll_all_clients continuously std::thread *_poll_thread; - bool _is_subscribed; bool _poll_all_clients; - std::string _mode; typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; From 8931460576de0d5062693fcfbf2ad58389c46fa7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 13:25:43 +0200 Subject: [PATCH 061/363] src/networking/oscsender.cpp: Adding publisher.h apf/{stringtools,math}.h to includes. Removing server specific constructor to reflect header. Fixing initializer list. Fixing Destructor. Fixing start() function VERBOSE printouts. Fixing calls to _handler.mode(). Introducing int32_t for id_t types, when sending OSC messages with id. Various small typo fixes. --- src/networking/oscsender.cpp | 137 +++++++++++++++++------------------ 1 file changed, 67 insertions(+), 70 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index c7aec020..ea3e5ef6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -6,6 +6,9 @@ #include #include "oschandler.h" #include "oscsender.h" +#include "publisher.h" +#include "apf/stringtools.h" +#include "apf/math.h" /** * Constructor used to create client objects @@ -18,36 +21,15 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out) : _controller(controller) , _handler(handler) - , _send_from(lo::ServerThread(port_out)) - , _is_subscribed(false) - , _mode(handler.mode()) -{} - -/** - * Constructor used to create server objects - * @param controller reference to a Publisher object - * @param handler reference to an OscHandler object - * @param port_out an integer describing the port number to be used - * for outgoing traffic - * @param client_addresses vector of lo::Address objects representing - * clients to this server - */ -ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int - port_out, std::vector client_addresses) - : _controller(controller) - , _handler(handler) - , _send_from(lo::ServerThread(port_out)) - , _client_addresses(client_addresses) - , _is_subscribed(false) - , _poll_all_clients(false) - , _mode(handler.mode()) - , _poll_thread(0) + , _send_from(port_out) + , _server_address("none") {} /** * Destructor */ -~OscSender(); +ssr::OscSender::~OscSender() +{} /** Function to start the OscSender object * This subscribes the OscSender to the Publisher and starts the @@ -55,16 +37,15 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int */ void ssr::OscSender::start() { - _controller.subscribe(*this); + _controller.subscribe(this); _is_subscribed = true; // check if lo::ServerThread is valid if (!_send_from.is_valid()) { ERROR("OSC ServerThread to send from could not be started!"); - return 1; } - _send_from.set_callbacks([&_send_from]() + _send_from.set_callbacks([this]() { - VERBOSE2("OSC ServerThread init: "<<&_send_from <<"."); + VERBOSE2("OSC ServerThread init: "<<&this->_send_from <<"."); }, []() { @@ -74,7 +55,7 @@ void ssr::OscSender::start() VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); _poll_all_clients = true; - _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients(), this); + _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients()), this); } /** @@ -84,7 +65,7 @@ void ssr::OscSender::start() */ void ssr::OscSender::stop() { - _controller.unsubscribe(*this); + _controller.unsubscribe(this); _is_subscribed = false; VERBOSE2("Stopping client polling thread ..."); _poll_all_clients = false; @@ -101,7 +82,7 @@ void ssr::OscSender::stop() */ bool ssr::OscSender::is_client() { - if(_oschandler.mode() == "client") + if(_handler.mode() == "client") { return true; } @@ -117,7 +98,7 @@ bool ssr::OscSender::is_client() */ bool ssr::OscSender::is_server() { - if(_oschandler.mode() == "server") + if(_handler.mode() == "server") { return true; } @@ -189,7 +170,7 @@ void ssr::OscSender::send_to_server(lo::Bundle bundle) void ssr::OscSender::send_to_client(lo::Address address, std::string path, lo::Message message) { - for (const auto& client _client_addresses) + for (const auto& client: _client_addresses) { if(client.hostname() == address.hostname() && client.port() == address.port()) @@ -207,7 +188,7 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, */ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - for (const auto& client _client_addresses) + for (const auto& client: _client_addresses) { if(client.hostname() == address.hostname() && client.port() == address.port()) @@ -365,7 +346,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) * Adds a new client to the vector of clients * @param clients lo::Address of a client */ -void add_client(lo::Address client) +void ssr::OscSender::add_client(lo::Address client) { _client_addresses.push_back(client); } @@ -396,14 +377,15 @@ void ssr::OscSender::new_source(id_t id) if(is_server()) { if(!this->is_new_source(id)) - _new_sources.insert(make_pair(id, apf::parameter_map params)); + _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else if(is_client()) { lo::Message message; - message.add(id); + int32_t message_id = id; + message.add(message_id); this->send_to_server("update/source/new", message); } } @@ -418,14 +400,15 @@ void ssr::OscSender::new_source(id_t id) void ssr::OscSender::delete_source(id_t id) { lo::Message message; - message.add(id); + int32_t message_id = id; + message.add(message_id); if(is_server()) { - this->send_to_all_clients("source/delete", id); + this->send_to_all_clients("source/delete", message); } else if (is_client()) { - this->send_to_server("update/source/delete", id); + this->send_to_server("update/source/delete", message); _source_levels.erase(id); } } @@ -463,6 +446,7 @@ void ssr::OscSender::delete_all_sources() bool ssr::OscSender::set_source_position(id_t id, const Position& position) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -474,7 +458,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add(id); + message.add(message_id); message.add(position.x); message.add(position.y); this->send_to_all_clients("source/position", message); @@ -482,7 +466,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else if (is_client()) { - message.add(id); + message.add(message_id); message.add(position.x); message.add(position.y); this->send_to_server("update/source/position", message); @@ -506,6 +490,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -516,14 +501,14 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add(id); + message.add(message_id); message.add(fixed); this->send_to_all_clients("source/position_fixed", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(fixed); this->send_to_server("update/source/position_fixed", message); } @@ -545,6 +530,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& orientation) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -555,14 +541,14 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add(id); + message.add(message_id); message.add(orientation.azimuth); this->send_to_all_clients("source/orientation", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(orientation.azimuth); this->send_to_server("update/source/orientation", message); } @@ -584,6 +570,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -594,14 +581,14 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add(id); + message.add(message_id); message.add(gain); this->send_to_all_clients("source/volume", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(gain); this->send_to_server("update/source/volume", message); } @@ -623,6 +610,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -633,14 +621,14 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add(id); + message.add(message_id); message.add(mute); this->send_to_all_clients("source/mute", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(mute); this->send_to_server("update/source/mute", message); } @@ -662,24 +650,25 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) { - _new_sources.at(id).set("name", mute); + _new_sources.at(id).set("name", name); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else { - message.add(id); + message.add(message_id); message.add(name); this->send_to_all_clients("source/name", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(name); this->send_to_server("update/source/name", message); } @@ -702,6 +691,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -712,14 +702,14 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(name); this->send_to_all_clients("source/properties_file", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(name); this->send_to_server("update/source/properties_file", message); } @@ -789,8 +779,9 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { lo::Message message; + int32_t message_id = id; std::string tmp_model; - tmp_model = apf::string::A2S(model); + tmp_model = apf::str::A2S(model); if (tmp_model == "") return false; if(is_server()) { @@ -802,14 +793,14 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - message.add(id); + message.add(message_id); message.add(tmp_model); this->send_to_all_clients("source/model", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(tmp_model); this->send_to_server("update/source/model", message); } @@ -834,6 +825,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -844,14 +836,14 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(port_name); this->send_to_all_clients("source/port_name", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(port_name); this->send_to_server("update/source/port_name", message); } @@ -878,6 +870,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -889,14 +882,14 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(file_name); this->send_to_all_clients("source/file_name_or_port_number", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(file_name); this->send_to_server("update/source/file_name_or_port_number", message); } @@ -920,6 +913,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -930,14 +924,14 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add(id); + message.add(message_id); message.add(file_channel); this->send_to_all_clients("source/channel", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(file_channel); this->send_to_server("update/source/channel", message); } @@ -959,9 +953,10 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { lo::Message message; + int32_t message_id = id; if(is_client()) { - message.add(id); + message.add(message_id); message.add(length); this->send_to_server("update/source/length", message); } @@ -1106,9 +1101,9 @@ void ssr::OscSender::set_master_volume(float volume) void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* last) { - void (id); - void (first); - void (last); + (void) id; + (void) first; + (void) last; } /** @@ -1278,10 +1273,12 @@ void ssr::OscSender::set_master_signal_level(float level) bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { lo::Message message; + int32_t message_id = id; + message.add(message_id); message.add(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("source/level", message); + this->send_to_all_clients("source/volume", message); } else if(is_client()) { From 1daddd46ea0406e35a1d58bd72a4fef08ce640b5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 15:47:03 +0200 Subject: [PATCH 062/363] src/networking/oscsender.h: Changing std::thread pointer to object type for _poll_thread. Removing public function poll_clients() (unused). --- src/networking/oscsender.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 920b8b29..bec1ea8e 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -50,7 +50,7 @@ class OscSender : public Subscriber // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously - std::thread *_poll_thread; + std::thread _poll_thread; bool _poll_all_clients; typedef std::map source_level_map_t; source_level_map_t _source_levels; @@ -58,9 +58,9 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); + void poll_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete - void poll_all_clients(); void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: @@ -74,7 +74,6 @@ class OscSender : public Subscriber void set_server_address(lo::Address server_address); lo::Address server_address(); void add_client(lo::Address client); - void poll_clients(); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From ce5bc564b3ef526ce6bd3a6acb639c3df0ca597d Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 15:48:23 +0200 Subject: [PATCH 063/363] src/networking/oscsender.cpp: Using a detached std::thread for polling all clients instead of joinable std::thread. Making this a server-exclusive feature. --- src/networking/oscsender.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index ea3e5ef6..f34829f5 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -54,8 +54,12 @@ void ssr::OscSender::start() ); VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); - _poll_all_clients = true; - _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients()), this); + if (is_server()) + { + _poll_all_clients = true; + std::thread _poll_thread(&OscSender::poll_all_clients, this); + _poll_thread.detach(); + } } /** @@ -67,13 +71,11 @@ void ssr::OscSender::stop() { _controller.unsubscribe(this); _is_subscribed = false; - VERBOSE2("Stopping client polling thread ..."); - _poll_all_clients = false; - if (_poll_thread) + if (is_server()) { - _poll_thread->join(); + _poll_all_clients = false; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - VERBOSE2("Client polling thread stopped."); } /** @@ -114,12 +116,14 @@ bool ssr::OscSender::is_server() */ void ssr::OscSender::poll_all_clients() { + VERBOSE("Polling all clients."); while(_poll_all_clients) { send_to_all_clients("poll", lo::Message()); //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } + VERBOSE("Stopped polling all clients."); } /** From 4e239974f0e246d57d75769721b326536e5af60c Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:07:03 +0200 Subject: [PATCH 064/363] configure.ac: Adding linker flag for liblo. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 78ba3df4..2bdef8d0 100644 --- a/configure.ac +++ b/configure.ac @@ -524,6 +524,7 @@ ENABLE_EXPLICIT([floating-control-panel], [separate control window], dnl check for liblo ENABLE_FORCED([osc-interface], [OSC interface], [ + CPPFLAGS="$CPPFLAGS -llo" AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) AC_MSG_RESULT([$have_osc_interface]) From 33c15efce9e424208752f675c48e8bddd4baa7d8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:40:47 +0200 Subject: [PATCH 065/363] configure.ac: Adding liblo libs to LIBS, by checking with pkg-config. Removing useless CPPFLAGS from header check for liblo. --- configure.ac | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 2bdef8d0..8229a615 100644 --- a/configure.ac +++ b/configure.ac @@ -212,6 +212,14 @@ PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.0], LIBS="$LIBS $LIBXML_LIBS" ]) +dnl Checking for liblo +PKG_CHECK_MODULES([LIBLO], [liblo >= 0.28], + [ + PKG_FLAGS="$PKG_FLAGS $LIBLO_CFLAGS" + LIBS="$LIBS $LIBLO_LIBS" + ] +) + dnl by the way, AC_HELP_STRING is deprecated, use AS_HELP_STRING instead! ENABLE_EXPLICIT([debugging],[debugging symbols, asserts, ...]) @@ -521,15 +529,6 @@ ENABLE_EXPLICIT([floating-control-panel], [separate control window], [ AS_IF([test x$have_gui = xno], [have_floating_control_panel=no]) ]) -dnl check for liblo -ENABLE_FORCED([osc-interface], [OSC interface], - [ - CPPFLAGS="$CPPFLAGS -llo" - AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) - AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) - AC_MSG_RESULT([$have_osc_interface]) - ] -) ENABLE_FORCED([ip-interface], [network (TCP/IP) interface], [ @@ -537,6 +536,13 @@ ENABLE_FORCED([ip-interface], [network (TCP/IP) interface], AC_CHECK_HEADER([asio.hpp], , [have_ip_interface=no]) ]) +ENABLE_FORCED([osc-interface], [network OSC interface], +[ + AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) + AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) + AC_MSG_RESULT([$have_osc_interface]) +]) + ENABLE_FORCED([ecasound], [Ecasound soundfile playback/recording], [ dnl Checking for libecasoundc. It does not provide pkg-config and installs From e12546e2774507b156d3ce892abedab1761e7635 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:46:10 +0200 Subject: [PATCH 066/363] src/networking/oscreceiver.cpp: Moving _receiver.stop() to the OscReceiver.stop() implementation, which wasn't there yet. --- src/networking/oscreceiver.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c945d1ea..9e4feac2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -25,12 +25,9 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po /** * Destructor - * Stops the lo::ServerThread, used for listening for OSC messages */ ssr::OscReceiver::~OscReceiver() -{ - _receiver.stop(); -} +{} /** * Starts the OscReceiver, by adding client|server callback functions and @@ -51,6 +48,15 @@ void ssr::OscReceiver::start() _receiver.start(); } +/** + * Stops the OscReceiver, by stopping the lo::ServerThread, used for listening + * for OSC messages + */ +void ssr::OscReceiver::stop() +{ + _receiver.stop(); +} + /** * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every From 8f8ec2793cd590321a30805b08dd28b4d0c43f70 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:46:42 +0200 Subject: [PATCH 067/363] src/networking/oscsender.h: Removing redundant lo/lo.h include. --- src/networking/oscsender.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index bec1ea8e..6a64ce08 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -14,9 +14,7 @@ #include #include #include -#include #include - #include "ssr_global.h" #include "subscriber.h" #include "apf/parameter_map.h" From ccf39bcc8e838d6110d88de514cf7865d9231077 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 12:48:57 +0200 Subject: [PATCH 068/363] src/networking/oschandler.cpp: Adding VERBOSE message to constructor. --- src/networking/oschandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 079a85d8..bb8f13f3 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -24,6 +24,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, , _osc_receiver(controller, *this, port_in) , _osc_sender(controller, *this, port_out) { + VERBOSE("Initialized OscHandler."); if (mode == "server") { for (const auto& hostname: clients) From 7041e5027e622d2fac4a399982d4bf837f725350 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 12:49:31 +0200 Subject: [PATCH 069/363] src/networking/oscreceiver.cpp: Adding VERBOSE message to constructor and start(). --- src/networking/oscreceiver.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 9e4feac2..23886e2c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -21,7 +21,9 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po : _receiver(port_in) , _controller(controller) , _handler(handler) -{} +{ + VERBOSE("Initialized OscReceiver."); +} /** * Destructor @@ -38,14 +40,17 @@ void ssr::OscReceiver::start() // add method handlers for received messages if (_handler.mode() == "server") { + VERBOSE("Adding client-to-server callback methods."); add_client_to_server_methods(); } else if (_handler.mode() == "client") { + VERBOSE("Adding server-to-client callback methods."); add_server_to_client_methods(); } // start server thread _receiver.start(); + VERBOSE("Started ServerThread for receiving messages."); } /** From 2ee0d2730324aee8daa75cf1abf449f800885904 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 13:00:30 +0200 Subject: [PATCH 070/363] src/networking/oscsender.cpp: Adding VERBOSE message to constructor. Fixing _server_address initialization by adding a port. --- src/networking/oscsender.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f34829f5..fe3b22cb 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -22,8 +22,10 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int : _controller(controller) , _handler(handler) , _send_from(port_out) - , _server_address("none") -{} + , _server_address("none", "50001") +{ + VERBOSE("Initialized OscSender."); +} /** * Destructor From ffcf192b6a29c856e9674ec6d5191ac2cf71ac65 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:23:03 +0200 Subject: [PATCH 071/363] src/networking/oschandler.cpp: Adding further VERBOSE messages to constructor and destructor, start() and stop(). Adding ssr::OscReceiver::send_to_server again, after accidentally deleting it. --- src/networking/oschandler.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bb8f13f3..bb355501 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -24,9 +24,10 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, , _osc_receiver(controller, *this, port_in) , _osc_sender(controller, *this, port_out) { - VERBOSE("Initialized OscHandler."); + VERBOSE("OscHandler: Initialized."); if (mode == "server") { + VERBOSE2("OscHandler: server mode."); for (const auto& hostname: clients) { _osc_sender.add_client(new lo::Address(hostname.first, @@ -39,13 +40,17 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, * Destructor */ ssr::OscHandler::~OscHandler() -{} +{ + stop(); + VERBOSE("OscHandler: Destructing."); +} /** * Stop this OscHandler by stopping its OscReceiver and OscSender */ void ssr::OscHandler::stop() { + VERBOSE("OscHandler: Stopping"); _osc_receiver.stop(); _osc_sender.stop(); } @@ -55,6 +60,7 @@ void ssr::OscHandler::stop() */ void ssr::OscHandler::start() { + VERBOSE("OscHandler: Starting"); _osc_receiver.start(); _osc_sender.start(); } @@ -129,6 +135,19 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) self._osc_sender.send_to_all_clients(bundle); } +/** + * OscHandler's friend function to send an OSC message to the server, using + * OscSender and a designated path. + * @param self reference to OscHandler holding OscSender + * @param path std::string defining the path to send on + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_server(OscHandler& self, std::string path, + lo::Message message) +{ + self._osc_sender.send_to_server(path, message); +} + /** * OscHandler's friend function to send an OSC bundle to the server, using * OscSender. From f98be9515b0858c1b678e8d30cb958c820c14615 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:28:27 +0200 Subject: [PATCH 072/363] src/networking/oscreceiver.cpp: Adding VERBOSE message to constructur, destructor, start() and stop(). Adding VERBOSE message for each callback method. Adding leading / to all callback listeners (every high-level language, such as SuperCollider and Pd use it that way). --- src/networking/oscreceiver.cpp | 428 ++++++++++++++++++++------------- 1 file changed, 259 insertions(+), 169 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 23886e2c..e3954eec 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -22,14 +22,16 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po , _controller(controller) , _handler(handler) { - VERBOSE("Initialized OscReceiver."); + VERBOSE("OscReceiver: Initialized."); } /** * Destructor */ ssr::OscReceiver::~OscReceiver() -{} +{ + VERBOSE("OscReceiver: Destructing."); +} /** * Starts the OscReceiver, by adding client|server callback functions and @@ -37,20 +39,33 @@ ssr::OscReceiver::~OscReceiver() */ void ssr::OscReceiver::start() { + VERBOSE("OscReceiver: Starting."); // add method handlers for received messages if (_handler.mode() == "server") { - VERBOSE("Adding client-to-server callback methods."); add_client_to_server_methods(); + VERBOSE("OscReceiver: Added client-to-server callbacks."); } else if (_handler.mode() == "client") { - VERBOSE("Adding server-to-client callback methods."); add_server_to_client_methods(); + VERBOSE("OscReceiver: Added server-to-client callbacks."); } - // start server thread + // check if lo::ServerThread is valid + if (!_receiver.is_valid()) { + ERROR("OscReceiver: ServerThread could not be started!"); + } + _receiver.set_callbacks([this]() + { + VERBOSE("OscReceiver: Started ServerThread for receiving messages."); + }, + []() + { + VERBOSE2("OscReceiver: ServerThread cleanup."); + } + ); + VERBOSE("OscReceiver: url = " << _receiver.url() << "."); _receiver.start(); - VERBOSE("Started ServerThread for receiving messages."); } /** @@ -59,6 +74,7 @@ void ssr::OscReceiver::start() */ void ssr::OscReceiver::stop() { + VERBOSE("OscReceiver: Stopping."); _receiver.stop(); } @@ -69,47 +85,51 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { - // update on new source: "update/source/new, i, id" - _receiver.add_method("update/source/new", "i", [](lo_arg **argv, int, + // update on new source: "/update/source/new, i, id" + _receiver.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << " created."); } ); + VERBOSE("OscReceiver: Added method for /update/source/new."); - // update on deleted source: "update/source/delete, i, id" - _receiver.add_method("update/source/delete", "i", [](lo_arg **argv, int, + // update on deleted source: "/update/source/delete, i, id" + _receiver.add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); if(argv[0]->i == 0) { - VERBOSE("Update: Client '" << client.hostname() << "', all sources \ - deleted."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', all sources deleted."); + } else { - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << " deleted."); + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " + << argv[0]->i << " deleted."); } } ); + VERBOSE("OscReceiver: Added method for /update/source/delete."); - // update on source position: "update/source/position, iff, id, x, y" - _receiver.add_method("update/source/position", "iff", [](lo_arg **argv, int, + // update on source position: "/update/source/position, iff, id, x, y" + _receiver.add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/position."); - // update on source position fixation: "update/source/position_fixed, i{T,F}, + // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _receiver.add_method("update/source/position_fixed", NULL, [](lo_arg **argv, + _receiver.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -122,34 +142,37 @@ void ssr::OscReceiver::add_client_to_server_methods() { position_fixed = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", position_fixed: "<< position_fixed << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); - // update on source orientation: "update/source/orientation, if, id, azimuth" - _receiver.add_method("update/source/orientation", "if", [](lo_arg **argv, int, + // update on source orientation: "/update/source/orientation, if, id, azimuth" + _receiver.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", orientation: "<< argv[1]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/orientation."); - // update on source volume: "update/source/volume, if, id, volume" - _receiver.add_method("update/source/volume", "if", [](lo_arg **argv, int, + // update on source volume: "/update/source/volume, if, id, volume" + _receiver.add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", volume: "<< argv[1]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/volume."); - // update on source position mute: "update/source/mute, i{T,F}, + // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _receiver.add_method("update/source/mute", NULL, [](lo_arg **argv, int, + _receiver.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -162,160 +185,181 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - apf::str::A2S(argv[0]->i) << ", mute: "<< state << - "."); + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << + apf::str::A2S(argv[0]->i) << ", mute: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/mute."); - // update on source name: "update/source/name, is, id, name" - _receiver.add_method("update/source/name", "is", [](lo_arg **argv, int, + // update on source name: "/update/source/name, is, id, name" + _receiver.add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", name: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/name."); - // update on source properties_file: "update/source/properties_file, is, id, + // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _receiver.add_method("update/source/properties_file", "is", [](lo_arg **argv, + _receiver.add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", properties_file: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/properties_file."); - // update on scene decay exponent: "update/scene/decay_exponent, f, + // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _receiver.add_method("update/scene/decay_exponent", "f", [](lo_arg **argv, + _receiver.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: \ - "<< argv[0]->f << "."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', decay_exponent: "<< argv[0]->f << "."); + } ); + VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _receiver.add_method("update/scene/amplitude_reference_distance", "f", + _receiver.add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', \ - amplitude_reference_distance: "<< argv[0]->f << "."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', amplitude_reference_distance: "<< argv[0]->f << "."); + } ); + VERBOSE("OscReceiver: Added method for \ +/update/scene/amplitude_reference_distance."); - // update on source model: "update/source/model, is, id, model" - _receiver.add_method("update/source/model", "is", [](lo_arg **argv, int, + // update on source model: "/update/source/model, is, id, model" + _receiver.add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", model: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/model."); - // update on source port_name: "update/source/port_name, is, id, port_name" - _receiver.add_method("update/source/port_name", "is", [](lo_arg **argv, int, + // update on source port_name: "/update/source/port_name, is, id, port_name" + _receiver.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", port_name: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/port_name."); // update on source file_name_or_port_number: - // "update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _receiver.add_method("update/source/file_name_or_port_number", "is", + // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" + _receiver.add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for \ +/update/source/file_name_or_port_number."); - // update on source channel: "update/source/channel, ii, id, channel" - _receiver.add_method("update/source/channel", "ii", [](lo_arg **argv, int, + // update on source channel: "/update/source/channel, ii, id, channel" + _receiver.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", channel: "<< argv[1]->i << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/channel."); - // update on source file length: "update/source/length, ii, id, length" - _receiver.add_method("update/source/length", "ii", [](lo_arg **argv, int, + // update on source file length: "/update/source/length, ii, id, length" + _receiver.add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", length: "<< argv[1]->i << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/length."); - // update on reference position: "update/reference/position, ff, x, y" - _receiver.add_method("update/reference/position", "ff", [](lo_arg **argv, + // update on reference position: "/update/reference/position, ff, x, y" + _receiver.add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference \ - position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference position: "<< argv[0]->f << "/" << argv[1]->f << + " (x/y)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference/position."); - // update on reference orientation: "update/reference/orientation, f, + // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _receiver.add_method("update/reference/orientation", "f", [](lo_arg **argv, + _receiver.add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference \ - orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference orientation: "<< argv[0]->f << " (azimuth)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference/orientation."); - // update on reference offset position: "update/reference_offset/position, + // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _receiver.add_method("update/reference_offset/position", "ff", [](lo_arg + _receiver.add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ - position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference offset position: "<< argv[0]->f << "/" << argv[1]->f + << " (x/y)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference_offset/position."); // update on reference offset orientation: - // "update/reference_offset/orientation, f, azimuth" - _receiver.add_method("update/reference_offset/orientation", "f", [](lo_arg + // "/update/reference_offset/orientation, f, azimuth" + _receiver.add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ - orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference offset orientation: "<< argv[0]->f << " (azimuth)."); } ); + VERBOSE("OscReceiver: Added method for \ +/update/reference_offset/orientation."); - // update on scene volume: "update/scene/volume, f, volume" - _receiver.add_method("update/scene/volume", "f", [](lo_arg **argv, int, + // update on scene volume: "/update/scene/volume, f, volume" + _receiver.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene volume: "<< + VERBOSE3("Update: Client '" << client.hostname() << "', scene volume: "<< argv[0]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/volume."); - // update on state processing: "update/processing/state, {T,F}, {true,false}" - _receiver.add_method("update/processing/state", NULL, [](lo_arg **argv, int, + // update on state processing: "/update/processing/state, {T,F}, {true,false}" + _receiver.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -329,13 +373,14 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ - " << state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', state processing: " << state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/processing/state."); - // update on transport state: "update/transport/state, {T,F}, {true,false}" - _receiver.add_method("update/transport/state", NULL, [](lo_arg **argv, int, + // update on transport state: "/update/transport/state, {T,F}, {true,false}" + _receiver.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -349,24 +394,26 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ - "<< state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', transport state: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/transport/state."); - // update on transport seek: "update/transport/seek, s, time" - _receiver.add_method("update/transport/seek", "s", [](lo_arg **argv, int, + // update on transport seek: "/update/transport/seek, s, time" + _receiver.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', transport seek: \ - "<< argv[0]->s << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', transport seek: "<< argv[0]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/transport/seek."); - // update on scene source auto rotation: "update/scene/auto_rotate_sources, + // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _receiver.add_method("update/scene/auto_rotate_sources", NULL, [](lo_arg + _receiver.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -381,51 +428,56 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - auto_rotate_sources: "<< state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene auto_rotate_sources: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); - // update on cpu_load: "update/cpu_load, f, load" - _receiver.add_method("update/cpu_load", "f", [](lo_arg **argv, int, + // update on cpu_load: "/update/cpu_load, f, load" + _receiver.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE2("Update: Client '" << client.hostname() << "', cpu_load: "<< + VERBOSE3("Update: Client '" << client.hostname() << "', cpu_load: "<< argv[0]->f << "%."); } ); + VERBOSE("OscReceiver: Added method for /update/cpu_load."); - // update on scene sample rate: "update/scene/sample_rate, i, sample_rate" - _receiver.add_method("update/scene/sample_rate", "i", [](lo_arg **argv, int, + // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" + _receiver.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - sample_rate: "<< argv[0]->i << "Hz."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene sample_rate: "<< argv[0]->i << "Hz."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/sample_rate."); - // update on scene master signal level: "update/scene/master_signal_level, f, + // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _receiver.add_method("update/scene/master_signal_level", "f", [](lo_arg + _receiver.add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - master_signal_level: "<< argv[0]->f << "dB."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene master_signal_level: "<< argv[0]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); - // update on source signal level: "update/source/level, if, id, level" - _receiver.add_method("update/source/level", "if", [](lo_arg **argv, int, + // update on source signal level: "/update/source/level, if, id, level" + _receiver.add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE2("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", level: "<< argv[1]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/source/level."); } @@ -438,22 +490,31 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _receiver.add_method("poll", NULL, [this](lo_arg **argv, int, lo::Message + this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server = server_address(_handler); lo::Address from(message.source()); (void) argv; - if(server.hostname() != from.hostname() && server.port() != from.port()) + VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << + from.port() << "."); + if((server.hostname() != from.hostname()) && + (server.port() != from.port()) && + (from.port() != "50001") && + (from.hostname() != "none") + ) { set_server_for_client(_handler, from); - // TODO: send reply to subscribed server + lo::Message reply; + reply.add_true(); + this->send_to_server(_handler, "/update/subscribe", reply); } } ); + VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("source/position", "iff", [this](lo_arg **argv, int) + _receiver.add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -461,36 +522,41 @@ void ssr::OscReceiver::add_server_to_client_methods() Position(argv[1]->f, argv[2]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("source/position_fixed", "iT", [this](lo_arg **argv, int) + _receiver.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + int) { _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ - true"); + VERBOSE2("set source position fixed: id = " << argv[0]->i << + ", fixed = true"); } ); + VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("source/position_fixed", "iF", [this](lo_arg **argv, int) + _receiver.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ - false"); + VERBOSE2("set source position fixed: id = " << argv[0]->i << + ", fixed = false"); } ); + VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("source/orientation", "if", [this](lo_arg **argv, int) + _receiver.add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - VERBOSE2("set source orientation: id = " << argv[0]->i << ", " - << Orientation(argv[1]->f)); + VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << + Orientation(argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("source/volume", "if", [this](lo_arg **argv, int) + _receiver.add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -498,45 +564,50 @@ void ssr::OscReceiver::add_server_to_client_methods() apf::math::dB2linear(argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("source/mute", "iT", [this](lo_arg **argv, int) + _receiver.add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); } ); + VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("source/mute", "iF", [this](lo_arg **argv, int) + _receiver.add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); } ); + VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _receiver.add_method("source/name", "is", [this](lo_arg **argv, int) + _receiver.add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/name."); - // set source file: "source/properties_file, is, id, properties_file" - _receiver.add_method("source/properties_file", "is", [this](lo_arg **argv, + // set source file: "/source/properties_file, is, id, properties_file" + _receiver.add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ - file = " << apf::str::A2S(argv[1]->s)); + VERBOSE2("set source properties file name: id = " << argv[0]->i << + ", file = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/properties_file."); - // set source model: "source/model, is, id, model" - _receiver.add_method("source/model", "is", [this](lo_arg **argv, int) + // set source model: "/source/model, is, id, model" + _receiver.add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -548,23 +619,25 @@ void ssr::OscReceiver::add_server_to_client_methods() apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/model."); - // set source port name: "source/port_name, is, id, port_name" - _receiver.add_method("source/port_name", "is", [this](lo_arg **argv, int) + // set source port name: "/source/port_name, is, id, port_name" + _receiver.add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/port_name."); - // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, position_fixed, // orientation_fixed, muted" - // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("source/new", NULL, [this](lo_arg **argv, int, + _receiver.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -735,10 +808,11 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /source/new."); - // delete source: "source/delete, i, id" + // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("source/delete", "i", [this](lo_arg **argv, int) + _receiver.add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -752,25 +826,28 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /source/delete."); - // set reference position: "reference/position, ff, x, y" - _receiver.add_method("reference/position", "ff", [this](lo_arg **argv, int) + // set reference position: "/reference/position, ff, x, y" + _receiver.add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/position."); - // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/orientation", "f", [this](lo_arg **argv, int) + // set reference orientation: "/reference/orientation, f, azimuth" + _receiver.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference/orientation."); - // set reference offset position: "reference_offset/position, ff, x, y" - _receiver.add_method("reference_offset/position", "ff" , [this](lo_arg + // set reference offset position: "/reference_offset/position, ff, x, y" + _receiver.add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -779,69 +856,77 @@ void ssr::OscReceiver::add_server_to_client_methods() argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference_offset/position."); - // set reference offset orientation: "reference_offset/orientation, f, + // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/orientation", "f" , [this](lo_arg **argv, - int) + _receiver.add_method("/reference_offset/orientation", "f" , [this](lo_arg + **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference offset orientation: " << Orientation(argv[0]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); - // save scene to file: "scene/save, s, file" - _receiver.add_method("scene/save", "s" , [this](lo_arg **argv, int) + // save scene to file: "/scene/save, s, file" + _receiver.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); } ); + VERBOSE("OscReceiver: Added method for /scene/save."); - // load scene from file: "scene/load, s, file" - _receiver.add_method("scene/load", "s" , [this](lo_arg **argv, int) + // load scene from file: "/scene/load, s, file" + _receiver.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); } ); + VERBOSE("OscReceiver: Added method for /scene/load."); - // set master volume: "scene/volume, f, volume" - _receiver.add_method("scene/volume", "f" , [this](lo_arg **argv, int) + // set master volume: "/scene/volume, f, volume" + _receiver.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << " \ - dB"); + VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << + " dB"); } ); + VERBOSE("OscReceiver: Added method for /scene/volume."); - // clear scene: "scene/clear" - _receiver.add_method("scene/clear", NULL , [this](lo_arg **argv, int) + // clear scene: "/scene/clear" + _receiver.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); VERBOSE2("clearing scene."); } ); + VERBOSE("OscReceiver: Added method for /scene/clear."); - // set processing state: "state/processing, T, true" - _receiver.add_method("processing/state", "T" , [this](lo_arg **argv, int) + // set processing state: "/processing/state, T, true" + _receiver.add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); VERBOSE2("start processing."); } ); + VERBOSE("OscReceiver: Added method for /processing/state true."); - // set processing state: "state/processing, F, false" - _receiver.add_method("processing/state", "F" , [this](lo_arg **argv, int) + // set processing state: "/processing/state, F, false" + _receiver.add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); VERBOSE2("stop processing."); } ); + VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) @@ -851,26 +936,29 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE2("start transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/state true."); - // set transport state: "transport/state, F, false" - _receiver.add_method("transport/state", "F" , [this](lo_arg **argv, int) + // set transport state: "/transport/state, F, false" + _receiver.add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); VERBOSE2("stop transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/state false."); - // rewind transport state: "state/transport/rewind" - _receiver.add_method("transport/rewind", NULL , [this](lo_arg **argv, int) + // rewind transport state: "/transport/rewind" + _receiver.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); VERBOSE2("rewind transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/rewind."); - // seek transport state: "state/transport/seek, s, time" + // seek transport state: "/transport/seek, s, time" _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; @@ -886,14 +974,16 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /transport/seek."); - // reset tracker: "tracker/reset" - _receiver.add_method("tracker/reset", NULL , [this](lo_arg **argv, int) + // reset tracker: "/tracker/reset" + _receiver.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); VERBOSE2("calibrate tracker."); } ); + VERBOSE("OscReceiver: Added method for /tracker/reset."); } From 5f2a9ee920b8dff9f9af9797cb879a80d0e64377 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:39:40 +0200 Subject: [PATCH 073/363] src/networking/oscsender.cpp: Clarifying VERBOSE messages. Adding leading / to the path of every send_to_all_clients and send_to_server function call. Making all lo::Message.add() calls type explicit to circumvent ambiguity. --- src/networking/oscsender.cpp | 369 +++++++++++++++++++---------------- 1 file changed, 203 insertions(+), 166 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index fe3b22cb..45628bb4 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -22,9 +22,9 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int : _controller(controller) , _handler(handler) , _send_from(port_out) - , _server_address("none", "50001") + , _server_address("none", "50002") { - VERBOSE("Initialized OscSender."); + VERBOSE("OscSender: Initialized."); } /** @@ -43,18 +43,18 @@ void ssr::OscSender::start() _is_subscribed = true; // check if lo::ServerThread is valid if (!_send_from.is_valid()) { - ERROR("OSC ServerThread to send from could not be started!"); + ERROR("OscSender: ServerThread could not be started!"); } _send_from.set_callbacks([this]() { - VERBOSE2("OSC ServerThread init: "<<&this->_send_from <<"."); + VERBOSE("OscSender: Started ServerThread for sending messages."); }, []() { - VERBOSE2("OSC ServerThread cleanup."); + VERBOSE2("OscSender: ServerThread cleanup."); } ); - VERBOSE("OSC URL: " << _send_from.url()<<"."); + VERBOSE("OscSender: url = " << _send_from.url() << "."); _send_from.start(); if (is_server()) { @@ -114,18 +114,18 @@ bool ssr::OscSender::is_server() /** * Sends a '/poll' message to all client instances listed in _client_addresses, - * then makes the thread calling this function sleep for 1000 milliseconds + * then makes the thread calling this function sleep for 100 milliseconds */ void ssr::OscSender::poll_all_clients() { - VERBOSE("Polling all clients."); + VERBOSE2("OscSender: Polling all clients."); while(_poll_all_clients) { - send_to_all_clients("poll", lo::Message()); + send_to_all_clients("/poll", lo::Message()); //TODO find better solution to compensate for execution time std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - VERBOSE("Stopped polling all clients."); + VERBOSE2("OscSender: Stopped polling all clients."); } /** @@ -143,7 +143,9 @@ lo::Address ssr::OscSender::server_address() */ void ssr::OscSender::set_server_address(lo::Address server_address) { - this->_server_address = server_address; + this->_server_address = new lo::Address(server_address); + VERBOSE2("OscSender: Setting up new server_address: "<< + server_address.hostname() << ":" << server_address.port() << "."); } /** @@ -154,7 +156,14 @@ void ssr::OscSender::set_server_address(lo::Address server_address) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - _server_address.send_from(_send_from, path, message); + if((_server_address.hostname() != "none") && (_server_address.port() != + "50002")) + { + _server_address.send_from(_send_from, path, message.types(), message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } /** @@ -164,6 +173,9 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) void ssr::OscSender::send_to_server(lo::Bundle bundle) { _server_address.send_from(_send_from, bundle); + VERBOSE3("OscSender: Sending bundle (" << bundle.length() << + " messages) to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } /** @@ -181,7 +193,10 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, if(client.hostname() == address.hostname() && client.port() == address.port()) { - client.send_from(_send_from, path, message); + client.send_from(_send_from, path, message.types(), message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to client " << address.hostname() << ":" << address.port() << + "."); } } } @@ -200,7 +215,8 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) address.port()) { client.send_from(_send_from, bundle); - } + VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << + ":" << address.port() << "."); } } } @@ -215,6 +231,9 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) for (const auto& client_address: _client_addresses) { client_address.send_from(_send_from, path, message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to client " << client_address.hostname() << ":" << + client_address.port() << "."); } } @@ -227,6 +246,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) for (const auto& client_address: _client_addresses) { client_address.send_from(_send_from, bundle); + VERBOSE3("OscSender: Sending bundle to all clients."); } } @@ -308,19 +328,23 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("muted") && _new_sources.at(id).size() == 12 ) { - message.add(_new_sources.at(id).get("name", "")); - message.add(_new_sources.at(id).get("model", "")); - message.add(_new_sources.at(id).get("file_name_or_port_number", "")); - message.add(_new_sources.at(id).get("x", 0.0)); - message.add(_new_sources.at(id).get("y", 0.0)); - message.add(_new_sources.at(id).get("orientation", 0.0)); - message.add(_new_sources.at(id).get("volume", 0.0)); - message.add(_new_sources.at(id).get("channel", 1)); - message.add(_new_sources.at(id).get("properties_file", "")); - message.add(_new_sources.at(id).get("position_fixed", false)); - message.add(_new_sources.at(id).get("orientation_fixed", false)); - message.add(_new_sources.at(id).get("muted", false)); - this->send_to_all_clients("source/new", message); + message.add_string(_new_sources.at(id).get("name", "")); + message.add_string(_new_sources.at(id).get("model", "")); + message.add_string(_new_sources.at(id).get("file_name_or_port_number", + "")); + message.add_float(_new_sources.at(id).get("x", 0.0)); + message.add_float(_new_sources.at(id).get("y", 0.0)); + message.add_float(_new_sources.at(id).get("orientation", 0.0)); + message.add_float(_new_sources.at(id).get("volume", 0.0)); + message.add_int32(_new_sources.at(id).get("channel", 1)); + message.add_string(_new_sources.at(id).get("properties_file", "")); + (_new_sources.at(id).get("position_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("orientation_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("muted", false)? + message.add_true(): message.add_false()); + this->send_to_all_clients("/source/new", message); } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -334,17 +358,21 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("muted") && _new_sources.at(id).size() == 10 ) { - message.add(_new_sources.at(id).get("name", "")); - message.add(_new_sources.at(id).get("model", "")); - message.add(_new_sources.at(id).get("file_name_or_port_number", "")); - message.add(_new_sources.at(id).get("x", 0.0)); - message.add(_new_sources.at(id).get("y", 0.0)); - message.add(_new_sources.at(id).get("orientation", 0.0)); - message.add(_new_sources.at(id).get("volume", 0.0)); - message.add(_new_sources.at(id).get("position_fixed", false)); - message.add(_new_sources.at(id).get("orientation_fixed", false)); - message.add(_new_sources.at(id).get("muted", false)); - this->send_to_all_clients("source/new", message); + message.add_string(_new_sources.at(id).get("name", "")); + message.add_string(_new_sources.at(id).get("model", "")); + message.add_string(_new_sources.at(id).get("file_name_or_port_number", + "")); + message.add_float(_new_sources.at(id).get("x", 0.0)); + message.add_float(_new_sources.at(id).get("y", 0.0)); + message.add_float(_new_sources.at(id).get("orientation", 0.0)); + message.add_float(_new_sources.at(id).get("volume", 0.0)); + (_new_sources.at(id).get("position_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("orientation_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("muted", false)? + message.add_true(): message.add_false()); + this->send_to_all_clients("/source/new", message); } } @@ -355,6 +383,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) void ssr::OscSender::add_client(lo::Address client) { _client_addresses.push_back(client); + VERBOSE2("OscSender: Added client " << client.hostname() << " to list."); } // Subscriber interface (differentiating between client and server) @@ -370,6 +399,7 @@ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& loudspeakers) { (void) loudspeakers; + VERBOSE3("OscSender: set_loudspeakers"); } /** @@ -391,8 +421,8 @@ void ssr::OscSender::new_source(id_t id) { lo::Message message; int32_t message_id = id; - message.add(message_id); - this->send_to_server("update/source/new", message); + message.add_int32(message_id); + this->send_to_server("/update/source/new", message); } } @@ -407,14 +437,14 @@ void ssr::OscSender::delete_source(id_t id) { lo::Message message; int32_t message_id = id; - message.add(message_id); + message.add_int32(message_id); if(is_server()) { - this->send_to_all_clients("source/delete", message); + this->send_to_all_clients("/source/delete", message); } else if (is_client()) { - this->send_to_server("update/source/delete", message); + this->send_to_server("/update/source/delete", message); _source_levels.erase(id); } } @@ -428,11 +458,11 @@ void ssr::OscSender::delete_source(id_t id) void ssr::OscSender::delete_all_sources() { lo::Message message; - message.add(0); + message.add_int32(0); if(is_server()) - this->send_to_all_clients("source/delete", message); + this->send_to_all_clients("/source/delete", message); else if(is_client()) - this->send_to_server("update/source/delete", message); + this->send_to_server("/update/source/delete", message); _source_levels.clear(); } @@ -464,18 +494,18 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add(message_id); - message.add(position.x); - message.add(position.y); - this->send_to_all_clients("source/position", message); + message.add_int32(message_id); + message.add_float(position.x); + message.add_float(position.y); + this->send_to_all_clients("/source/position", message); } } else if (is_client()) { - message.add(message_id); - message.add(position.x); - message.add(position.y); - this->send_to_server("update/source/position", message); + message.add_int32(message_id); + message.add_float(position.x); + message.add_float(position.y); + this->send_to_server("/update/source/position", message); } return true; } @@ -507,16 +537,16 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add(message_id); - message.add(fixed); - this->send_to_all_clients("source/position_fixed", message); + message.add_int32(message_id); + message.add_bool(fixed); + this->send_to_all_clients("/source/position_fixed", message); } } else if(is_client()) { - message.add(message_id); - message.add(fixed); - this->send_to_server("update/source/position_fixed", message); + message.add_int32(message_id); + message.add_bool(fixed); + this->send_to_server("/update/source/position_fixed", message); } return true; } @@ -547,16 +577,16 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add(message_id); - message.add(orientation.azimuth); - this->send_to_all_clients("source/orientation", message); + message.add_int32(message_id); + message.add_float(orientation.azimuth); + this->send_to_all_clients("/source/orientation", message); } } else if(is_client()) { - message.add(message_id); - message.add(orientation.azimuth); - this->send_to_server("update/source/orientation", message); + message.add_int32(message_id); + message.add_float(orientation.azimuth); + this->send_to_server("/update/source/orientation", message); } return true; } @@ -587,16 +617,16 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add(message_id); - message.add(gain); - this->send_to_all_clients("source/volume", message); + message.add_int32(message_id); + message.add_float(gain); + this->send_to_all_clients("/source/volume", message); } } else if(is_client()) { - message.add(message_id); - message.add(gain); - this->send_to_server("update/source/volume", message); + message.add_int32(message_id); + message.add_float(gain); + this->send_to_server("/update/source/volume", message); } return true; } @@ -627,16 +657,16 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add(message_id); - message.add(mute); - this->send_to_all_clients("source/mute", message); + message.add_int32(message_id); + message.add_bool(mute); + this->send_to_all_clients("/source/mute", message); } } else if(is_client()) { - message.add(message_id); - message.add(mute); - this->send_to_server("update/source/mute", message); + message.add_int32(message_id); + message.add_bool(mute); + this->send_to_server("/update/source/mute", message); } return true; } @@ -667,16 +697,16 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - message.add(message_id); - message.add(name); - this->send_to_all_clients("source/name", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_all_clients("/source/name", message); } } else if(is_client()) { - message.add(message_id); - message.add(name); - this->send_to_server("update/source/name", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_server("/update/source/name", message); } return true; } @@ -708,16 +738,16 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add(message_id); - message.add(name); - this->send_to_all_clients("source/properties_file", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_all_clients("/source/properties_file", message); } } else if(is_client()) { - message.add(message_id); - message.add(name); - this->send_to_server("update/source/properties_file", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_server("/update/source/properties_file", message); } return true; } @@ -733,14 +763,14 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& void ssr::OscSender::set_decay_exponent(float exponent) { lo::Message message; - message.add(exponent); + message.add_float(exponent); if(is_server()) { - this->send_to_all_clients("scene/decay_exponent", message); + this->send_to_all_clients("/scene/decay_exponent", message); } else if(is_client()) { - this->send_to_server("update/scene/decay_exponent", message); + this->send_to_server("/update/scene/decay_exponent", message); } } @@ -757,15 +787,15 @@ void ssr::OscSender::set_decay_exponent(float exponent) void ssr::OscSender::set_amplitude_reference_distance(float distance) { lo::Message message; - message.add(distance); + message.add_float(distance); if(is_server()) { - this->send_to_all_clients("scene/amplitude_reference_distance", + this->send_to_all_clients("/scene/amplitude_reference_distance", message); } else if(is_client()) { - this->send_to_server("update/scene/amplitude_reference_distance", + this->send_to_server("/update/scene/amplitude_reference_distance", message); } } @@ -799,16 +829,16 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - message.add(message_id); - message.add(tmp_model); - this->send_to_all_clients("source/model", message); + message.add_int32(message_id); + message.add_string(tmp_model); + this->send_to_all_clients("/source/model", message); } } else if(is_client()) { - message.add(message_id); - message.add(tmp_model); - this->send_to_server("update/source/model", message); + message.add_int32(message_id); + message.add_string(tmp_model); + this->send_to_server("/update/source/model", message); } return true; } @@ -842,16 +872,16 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add(message_id); - message.add(port_name); - this->send_to_all_clients("source/port_name", message); + message.add_int32(message_id); + message.add_string(port_name); + this->send_to_all_clients("/source/port_name", message); } } else if(is_client()) { - message.add(message_id); - message.add(port_name); - this->send_to_server("update/source/port_name", message); + message.add_int32(message_id); + message.add_string(port_name); + this->send_to_server("/update/source/port_name", message); } return true; } @@ -888,16 +918,16 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add(message_id); - message.add(file_name); - this->send_to_all_clients("source/file_name_or_port_number", message); + message.add_int32(message_id); + message.add_string(file_name); + this->send_to_all_clients("/source/file_name_or_port_number", message); } } else if(is_client()) { - message.add(message_id); - message.add(file_name); - this->send_to_server("update/source/file_name_or_port_number", message); + message.add_int32(message_id); + message.add_string(file_name); + this->send_to_server("/update/source/file_name_or_port_number", message); } return true; } @@ -920,6 +950,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { lo::Message message; int32_t message_id = id; + int32_t message_file_channel = file_channel; if(is_server()) { if(is_new_source(id)) @@ -930,16 +961,16 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add(message_id); - message.add(file_channel); - this->send_to_all_clients("source/channel", message); + message.add_int32(message_id); + message.add_int32(message_file_channel); + this->send_to_all_clients("/source/channel", message); } } else if(is_client()) { - message.add(message_id); - message.add(file_channel); - this->send_to_server("update/source/channel", message); + message.add_int32(message_id); + message.add_int32(message_file_channel); + this->send_to_server("/update/source/channel", message); } return true; } @@ -960,11 +991,12 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { lo::Message message; int32_t message_id = id; + int32_t message_length = length; if(is_client()) { - message.add(message_id); - message.add(length); - this->send_to_server("update/source/length", message); + message.add_int32(message_id); + message.add_int32(message_length); + this->send_to_server("/update/source/length", message); } return true; } @@ -982,15 +1014,15 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) void ssr::OscSender::set_reference_position(const Position& position) { lo::Message message; - message.add(position.x); - message.add(position.y); + message.add_float(position.x); + message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("reference/position", message); + this->send_to_all_clients("/reference/position", message); } else if(is_client()) { - this->send_to_server("update/reference/position", message); + this->send_to_server("/update/reference/position", message); } } @@ -1007,14 +1039,14 @@ void ssr::OscSender::set_reference_position(const Position& position) void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { lo::Message message; - message.add(orientation.azimuth); + message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("reference/orientation", message); + this->send_to_all_clients("/reference/orientation", message); } else if(is_client()) { - this->send_to_server("update/reference/orientation", message); + this->send_to_server("/update/reference/orientation", message); } } @@ -1032,15 +1064,15 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) void ssr::OscSender::set_reference_offset_position(const Position& position) { lo::Message message; - message.add(position.x); - message.add(position.y); + message.add_float(position.x); + message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("reference_offset/position", message); + this->send_to_all_clients("/reference_offset/position", message); } else if(is_client()) { - this->send_to_server("update/reference_offset/position", message); + this->send_to_server("/update/reference_offset/position", message); } } @@ -1060,14 +1092,14 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { lo::Message message; - message.add(orientation.azimuth); + message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("reference_offset/orientation", message); + this->send_to_all_clients("/reference_offset/orientation", message); } else if(is_client()) { - this->send_to_server("update/reference_offset/orientation", message); + this->send_to_server("/update/reference_offset/orientation", message); } } @@ -1084,14 +1116,14 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& void ssr::OscSender::set_master_volume(float volume) { lo::Message message; - message.add(apf::math::linear2dB(volume)); + message.add_float(apf::math::linear2dB(volume)); if(is_server()) { - this->send_to_all_clients("scene/volume", message); + this->send_to_all_clients("/scene/volume", message); } else if(is_client()) { - this->send_to_server("update/scene/volume", message); + this->send_to_server("/update/scene/volume", message); } } @@ -1125,14 +1157,14 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* void ssr::OscSender::set_processing_state(bool state) { lo::Message message; - message.add(state); + message.add_bool(state); if(is_server()) { - this->send_to_all_clients("processing/state", message); + this->send_to_all_clients("/processing/state", message); } else if(is_client()) { - this->send_to_server("update/processing/state", message); + this->send_to_server("/update/processing/state", message); } } @@ -1152,23 +1184,26 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients(bundle); + +// TODO: debug this! +// this->send_to_all_clients(bundle); } else if(is_client()) { lo::Bundle bundle({ - {"update/transport/state", message_state}, - {"update/transport/seek", message_time} + {"/update/transport/state", message_state}, + {"/update/transport/seek", message_time} }); - this->send_to_server(bundle); +// TODO: debug this! +// this->send_to_server(bundle); } } @@ -1187,14 +1222,14 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients("scene/auto_rotate_sources", message); + this->send_to_all_clients("/scene/auto_rotate_sources", message); } else if(is_client()) { - this->send_to_server("update/scene/auto_rotate_sources", message); + this->send_to_server("/update/scene/auto_rotate_sources", message); } } @@ -1209,10 +1244,10 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) void ssr::OscSender::set_cpu_load(float load) { lo::Message message; - message.add(load); + message.add_float(load); if(is_client()) { - this->send_to_server("update/cpu_load", message); + this->send_to_server("/update/cpu_load", message); } } @@ -1229,14 +1264,15 @@ void ssr::OscSender::set_cpu_load(float load) void ssr::OscSender::set_sample_rate(int sr) { lo::Message message; - message.add(sr); + int32_t message_sr = sr; + message.add_int32(message_sr); if(is_server()) { - this->send_to_all_clients("scene/sample_rate", message); + this->send_to_all_clients("/scene/sample_rate", message); } else if(is_client()) { - this->send_to_server("update/scene/sample_rate", message); + this->send_to_server("/update/scene/sample_rate", message); } } @@ -1253,14 +1289,15 @@ void ssr::OscSender::set_sample_rate(int sr) void ssr::OscSender::set_master_signal_level(float level) { lo::Message message; - message.add(apf::math::linear2dB(level)); + float message_level(apf::math::linear2dB(level)); + message.add_float(message_level); if(is_server()) { - this->send_to_all_clients("scene/master_signal_level", message); + this->send_to_all_clients("/scene/master_signal_level", message); } else if(is_client()) { - this->send_to_server("update/scene/master_signal_level", message); + this->send_to_server("/update/scene/master_signal_level", message); } } @@ -1280,15 +1317,15 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { lo::Message message; int32_t message_id = id; - message.add(message_id); - message.add(apf::math::linear2dB(level)); + message.add_int32(message_id); + message.add_float(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("source/volume", message); + this->send_to_all_clients("/source/volume", message); } else if(is_client()) { - this->send_to_server("update/source/level", message); + this->send_to_server("/update/source/level", message); } return true; } From 736f3d88a5ea6dc6fc663890b7f9003c4176c272 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 19:30:12 +0200 Subject: [PATCH 074/363] src/networking/*: Using std::string compare() for all string based if clauses, checking for default server. Using lo:Address hostname() and port() functions to create new addresses. Copying by value in server_address(), to prevent double free. --- src/networking/oschandler.cpp | 2 +- src/networking/oscreceiver.cpp | 10 +++++----- src/networking/oscsender.cpp | 21 +++++++++++---------- src/networking/oscsender.h | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bb355501..d60667a7 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -73,7 +73,7 @@ void ssr::OscHandler::start() void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address server_address) { - self._osc_sender.set_server_address(server_address); + self._osc_sender.set_server_address(server_address.hostname(), server_address.port()); } /** diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e3954eec..4216b609 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -493,15 +493,15 @@ void ssr::OscReceiver::add_server_to_client_methods() this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server = server_address(_handler); + lo::Address server(server_address(_handler)); lo::Address from(message.source()); (void) argv; VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << from.port() << "."); - if((server.hostname() != from.hostname()) && - (server.port() != from.port()) && - (from.port() != "50001") && - (from.hostname() != "none") + if((server.hostname().compare(from.hostname()) != 0) && + (server.port().compare(from.port()) != 0) && + (from.port().compare("50001") != 0) && + (from.hostname().compare("none") != 0) ) { set_server_for_client(_handler, from); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 45628bb4..861ebb73 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -134,18 +134,19 @@ void ssr::OscSender::poll_all_clients() */ lo::Address ssr::OscSender::server_address() { - return this->_server_address; + lo::Address server(_server_address.hostname(), _server_address.port()); + return server; } /** * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address */ -void ssr::OscSender::set_server_address(lo::Address server_address) +void ssr::OscSender::set_server_address(std::string hostname, std::string port) { - this->_server_address = new lo::Address(server_address); - VERBOSE2("OscSender: Setting up new server_address: "<< - server_address.hostname() << ":" << server_address.port() << "."); + _server_address = lo::Address(hostname, port); + VERBOSE2("OscSender: Setting up new server address: "<< + _server_address.hostname() << ":" << _server_address.port() << "."); } /** @@ -156,13 +157,13 @@ void ssr::OscSender::set_server_address(lo::Address server_address) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server_address.hostname() != "none") && (_server_address.port() != - "50002")) + if((_server_address.hostname().compare("none") != 0) && + (_server_address.port().compare("50002") != 0)) { _server_address.send_from(_send_from, path, message.types(), message); - VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 6a64ce08..9ccc8dfc 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -69,7 +69,7 @@ class OscSender : public Subscriber void start(); void stop(); - void set_server_address(lo::Address server_address); + void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(lo::Address client); void send_to_server(std::string path, lo::Message message); From 25dacd56405032aa0df30050b6334e13978a4cfd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:33:20 +0200 Subject: [PATCH 075/363] src/networking/oscsender.*: Making _client_addresses a vector of pointers to lo::Address objects. Remodelling add_client() to use std::string for hostname and port instead of a lo::Address. Properly dereferencing all calls to member functions of client objects in _client_addresses. Setting sleep time for poll thread to 1s. --- src/networking/oscsender.cpp | 31 ++++++++++++++++--------------- src/networking/oscsender.h | 6 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 861ebb73..d6b6c2df 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -76,7 +76,7 @@ void ssr::OscSender::stop() if (is_server()) { _poll_all_clients = false; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } @@ -118,12 +118,12 @@ bool ssr::OscSender::is_server() */ void ssr::OscSender::poll_all_clients() { - VERBOSE2("OscSender: Polling all clients."); + VERBOSE("OscSender: Starting to poll all clients."); while(_poll_all_clients) { send_to_all_clients("/poll", lo::Message()); //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } VERBOSE2("OscSender: Stopped polling all clients."); } @@ -191,10 +191,10 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, { for (const auto& client: _client_addresses) { - if(client.hostname() == address.hostname() && client.port() == + if(client->hostname() == address.hostname() && client->port() == address.port()) { - client.send_from(_send_from, path, message.types(), message); + client->send_from(_send_from, path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -212,10 +212,10 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { for (const auto& client: _client_addresses) { - if(client.hostname() == address.hostname() && client.port() == + if(client->hostname() == address.hostname() && client->port() == address.port()) { - client.send_from(_send_from, bundle); + client->send_from(_send_from, bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } @@ -231,10 +231,10 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) { for (const auto& client_address: _client_addresses) { - client_address.send_from(_send_from, path, message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << client_address.hostname() << ":" << - client_address.port() << "."); + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + client_address->send_from(_send_from, path, message.types(), message); } } @@ -246,7 +246,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { for (const auto& client_address: _client_addresses) { - client_address.send_from(_send_from, bundle); + client_address->send_from(_send_from, bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } @@ -379,12 +379,13 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) /** * Adds a new client to the vector of clients - * @param clients lo::Address of a client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client */ -void ssr::OscSender::add_client(lo::Address client) +void ssr::OscSender::add_client(std::string hostname, std::string port) { - _client_addresses.push_back(client); - VERBOSE2("OscSender: Added client " << client.hostname() << " to list."); + _client_addresses.push_back(new lo::Address(hostname, port)); + VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); } // Subscriber interface (differentiating between client and server) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 9ccc8dfc..cd6fa5c7 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -43,8 +43,8 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; - // vector of client address objects (server) - std::vector _client_addresses; + // vector of pointers to client address objects (server) + std::vector _client_addresses; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously @@ -71,7 +71,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string hostname, std::string port); lo::Address server_address(); - void add_client(lo::Address client); + void add_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From bcdfa59ddfc9725b1430dafc4665003843b06b9a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:36:12 +0200 Subject: [PATCH 076/363] src/networking/oschandler.cpp: Adding VERBOSE message before adding clients. Adding clients using the new add_client() function. --- src/networking/oschandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index d60667a7..824610c0 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -27,11 +27,10 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, VERBOSE("OscHandler: Initialized."); if (mode == "server") { - VERBOSE2("OscHandler: server mode."); - for (const auto& hostname: clients) + VERBOSE("OscHandler: " << clients.size() << " client(s)."); + for (const auto& client: clients) { - _osc_sender.add_client(new lo::Address(hostname.first, - std::to_string(hostname.second))); + _osc_sender.add_client(client.first, std::to_string(client.second)); } } } From 42c52b4673f38329cb8a6eb27cced6076bfc8bd8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:43:05 +0200 Subject: [PATCH 077/363] src/configuration.cpp: Using the multimap of client information by reference. Fixing a missing comma in the help output of ssr. --- src/configuration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index acfa725e..e84c5a87 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -128,7 +128,7 @@ std::string ssr::remove_whitespace(const std::string& str) * string and stores it in a multimap. */ static int parse_network_clients(const char *input, - std::multimap clients) + std::multimap& clients) { std::istringstream iss(input); std::string name; @@ -303,7 +303,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) "(default: client)\n" " -C --network_clients=VALUE\n" " List of network clients and their ports (e.g. " - "client1:50002 client2:50002)\n" + "client1:50002, client2:50002)\n" " -P --network_port_send=VALUE\n" " Port to send OSC messages from (default: 50001)\n" " -p --network_port_receive=VALUE\n" From e184c2f902fd022f32456300b30b0835b689d79e Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:43:48 +0200 Subject: [PATCH 078/363] data/ssr.conf.example: Fixing the example string used for clients. --- data/ssr.conf.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index 67478ec4..eb5bdb58 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -106,8 +106,8 @@ # networking port for receiving (default: 50002) #NETWORK_PORT_RECEIVE = 50002 -# networking clients by hostname:port -#NETWORK_CLIENTS = "test:50002 test:50002" +# networking clients, comma-separated by hostname:port +#NETWORK_CLIENTS = "client:50002, client:50002" ############################## Verbosity Level ################################# From bc904e4a10daaf9102c0117c692951cce9ec8425 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:11:05 +0200 Subject: [PATCH 079/363] src/configuration.cpp: Dropping network-port-{send,receive} in favor of osc-port. Using only hyphen instead of underscore for option strings. --- src/configuration.cpp | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index e84c5a87..4c09b4d0 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -154,7 +154,7 @@ static int parse_network_clients(const char *input, clients.insert(make_pair(name, port)); } } - VERBOSE2("Using the following network clients:"); + VERBOSE("Read the following clients:"); for (const auto& client: clients) { VERBOSE2(client.first << ":" << client.second); } @@ -209,8 +209,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) // default network settings, also stated in data/ssr.conf.example conf.network_mode = "client"; - conf.network_port_send = 50001; - conf.network_port_receive = 50002; + conf.osc_port = 50001; conf.renderer_params.set("decay_exponent", 1); // 1 / r^1 conf.renderer_params.set("amplitude_reference_distance", 3); // meters @@ -298,16 +297,14 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) " --no-auto-rotation\n" " Don't auto-rotate sound sources' orientation toward " "the reference\n" -" -N --network_mode=VALUE\n" +" -N --network-mode=VALUE\n" " Which network mode to use: client or server " "(default: client)\n" -" -C --network_clients=VALUE\n" +" -C --network-clients=VALUE\n" " List of network clients and their ports (e.g. " - "client1:50002, client2:50002)\n" -" -P --network_port_send=VALUE\n" -" Port to send OSC messages from (default: 50001)\n" -" -p --network_port_receive=VALUE\n" -" Port to receive OSC messages on (default: 50002)\n" + "client1:50001, client2:50001)\n" +" -p --osc-port=VALUE\n" +" Port to use for OSC communication (default: 50001)\n" #ifdef ENABLE_IP_INTERFACE " -i, --ip-server[=PORT]\n" @@ -393,8 +390,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) {"no-auto-rotation", no_argument, nullptr, 0 }, {"network-mode", required_argument, nullptr, 'N'}, {"network-clients", required_argument, nullptr, 'C'}, - {"network-port-send", required_argument, nullptr, 'P'}, - {"network-port-receive", required_argument, nullptr, 'p'}, + {"osc-port", required_argument, nullptr, 'p'}, {"ip-server", optional_argument, nullptr, 'i'}, {"no-ip-server", no_argument, nullptr, 'I'}, {"end-of-message-character", required_argument, nullptr, 0}, @@ -413,7 +409,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) }; // one colon: required argument; two colons: optional argument // if first character is '-', non-option arguments return 1 (see case 1 below) - const char *optstring = "-c:C:fgGhi::IN:n:o:P:p:r:s:t:TvV?"; + const char *optstring = "-c:C:fgGhi::IN:n:o:p:r:s:t:TvV?"; int opt; int longindex = 0; @@ -570,16 +566,9 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) case 'o': conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; - case 'P': - //TODO: check if in port range - if (!S2A(optarg, conf.network_port_send)) - { - ERROR("Invalid port for network send specified!"); - } - break; case 'p': //TODO: check if in port range - if (!S2A(optarg, conf.network_port_receive)) + if (!S2A(optarg, conf.osc_port)) { ERROR("Invalid port for network receive specified!"); } @@ -904,13 +893,9 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ { parse_network_clients(value, conf.network_clients); } - else if (!strcmp(key, "NETWORK_PORT_SEND")) - { - conf.network_port_send = atoi(value); - } - else if (!strcmp(key, "NETWORK_PORT_RECEIVE")) + else if (!strcmp(key, "OSC_PORT")) { - conf.network_port_receive = atoi(value); + conf.osc_port = atoi(value); } else if (!strcmp(key, "NETWORK_INTERFACE")) { From 326ff7954cad2bac9242022bec80f2d24d5ae895 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:11:37 +0200 Subject: [PATCH 080/363] src/configuration.h: Dropping network_port_{send,receive} in favor of osc_port. --- src/configuration.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 7a488ffe..d921d982 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -61,8 +61,7 @@ struct conf_struct std::string network_mode; ///< network mode (client or server) ///< list of network clients and ports std::multimap network_clients; - int network_port_send; ///< network sending port - int network_port_receive; ///< network receiving port + int osc_port; ///< osc communication port int end_of_message_character; ///< ASCII bool auto_rotate_sources; ///< Automatic orientation of sources From 0bd3fc9ee287de4cd9e0f8ef41d0dd8f95e82ff2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:13:17 +0200 Subject: [PATCH 081/363] data/ssr.conf.example: Dropping NETWORK_PORT_{SEND,RECEIVE} in favor of OSC_PORT (which defaults to 50001). Updating NETWORK_CLIENTS example accordingly. Clarifying NETWORK_MODE comment. --- data/ssr.conf.example | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index eb5bdb58..06c74fd1 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -97,17 +97,14 @@ ############################ Networking configuration ########################## -# networking mode (client|server|off) +# networking mode: client, server (default: client) #NETWORK_MODE = server # networking port for sending (default: 50001) -#NETWORK_PORT_SEND = 50001 - -# networking port for receiving (default: 50002) -#NETWORK_PORT_RECEIVE = 50002 +#OSC_PORT = 50001 # networking clients, comma-separated by hostname:port -#NETWORK_CLIENTS = "client:50002, client:50002" +#NETWORK_CLIENTS = "client:50001, client:50001" ############################## Verbosity Level ################################# From 216aaed1ec9970c69543ccf05a8142528d3af278 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:23:47 +0200 Subject: [PATCH 082/363] src/controller.h: Updating _osc_interface initialization to use _conf.osc_port. --- src/controller.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/controller.h b/src/controller.h index 367e8036..fd52006c 100644 --- a/src/controller.h +++ b/src/controller.h @@ -428,12 +428,10 @@ Controller::Controller(int argc, char* argv[]) if (_conf.network_mode == "client" || _conf.network_mode == "server") { VERBOSE2("Starting OSC interface as "<< _conf.network_mode << - ".\nReceiving messages on port " << - std::to_string(_conf.network_port_receive) << - ".\nSending messages from port " << - std::to_string(_conf.network_port_send) << "."); - _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, - _conf.network_port_send, _conf.network_mode, _conf.network_clients)); + " on port " << + std::to_string(_conf.osc_port) << "."); + _osc_interface.reset(new OscHandler(*this, _conf.osc_port, + _conf.network_mode, _conf.network_clients)); _osc_interface->start(); } #endif From 2e31a213a0c6e0b29b03042a3a313470d78febb4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:30:13 +0200 Subject: [PATCH 083/363] src/networking/oschandler.h: Adding lo::ServerThread to OscHandler, to reflect change in configuration branch (only one OSC port needed). Replacing port_in/port_out parameters from Constructor with port. Adding public function declaration for getting a reference to _server. --- src/networking/oschandler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index c60fa08a..eaabad99 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -35,16 +35,18 @@ class OscHandler private: std::string _mode; //< mode: client|server Publisher& _controller; //< reference to Publisher object + lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port_in, int port_out, std::string - mode, std::multimap clients); + OscHandler(Publisher& controller, int port, std::string mode, + std::multimap clients); ~OscHandler(); void start(); void stop(); std::string mode(); + const lo::ServerThread& server() const; friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 981091efb425f6c7295dd8621875ad2883cf8fdd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:33:11 +0200 Subject: [PATCH 084/363] src/networking/oschandler.cpp: Changing constructor to initialize ServerThread in OscHandler. Removing port_{in,out} usage in constructor. Starting lo::ServerThread in start() implementation. Starting _server after starting _osc_{receiver,sender}. Implementing server() function to return a reference to OscHandler's _server. --- src/networking/oschandler.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 824610c0..1b4c0b9c 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -17,12 +17,13 @@ * @param clients a multimap holding hostname, port pairs (only used for * server) */ -ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) +ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, + std::multimap clients) : _mode(mode) , _controller(controller) - , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) + , _server(port) + , _osc_receiver(controller, *this) + , _osc_sender(controller, *this) { VERBOSE("OscHandler: Initialized."); if (mode == "server") @@ -41,6 +42,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, ssr::OscHandler::~OscHandler() { stop(); + //TODO: delete members of _client_addresses VERBOSE("OscHandler: Destructing."); } @@ -60,8 +62,23 @@ void ssr::OscHandler::stop() void ssr::OscHandler::start() { VERBOSE("OscHandler: Starting"); + // check if lo::ServerThread is valid + if (!_server.is_valid()) { + ERROR("OscHandler: ServerThread could not be started!"); + } + _server.set_callbacks([this]() + { + VERBOSE("OscHandler: Started ServerThread."); + }, + []() + { + VERBOSE2("OscHandler: ServerThread cleanup."); + } + ); + VERBOSE("OscHandler: url = " << _server.url() << "."); _osc_receiver.start(); _osc_sender.start(); + _server.start(); } /** @@ -160,8 +177,18 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) /** * This function returns the OscHandler's mode + * @return std::string (either server or client) */ std::string ssr::OscHandler::mode() { return _mode; } + +/** + * Return reference to OscHandler's lo::ServerThread + * @return lo::ServerThread& reference to _server + */ +const lo::ServerThread& ssr::OscHandler::server() const +{ + return _server; +} From 2244c2e5077440897ad8bfad66cc524273ab4a2d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:34:12 +0200 Subject: [PATCH 085/363] src/networking/oscreceiver.h: Removing lo::ServerThread member from OscReceiver. Removing port_in argument to constructor. --- src/networking/oscreceiver.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 116d26b2..6327b3d6 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -35,13 +35,12 @@ class OscHandler; class OscReceiver { private: - lo::ServerThread _receiver; Publisher& _controller; ssr::OscHandler& _handler; void add_client_to_server_methods(); void add_server_to_client_methods(); public: - OscReceiver(Publisher& controller, OscHandler& handler, int port_in); + OscReceiver(Publisher& controller, OscHandler& handler); ~OscReceiver(); void start(); void stop(); From 0cf62154bb8a521b8ff5af7b27f7f91033736091 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:35:41 +0200 Subject: [PATCH 086/363] src/networking/oscreceiver.cpp: Removing usage of port_in in constructor. Removing initialization of a lo::ServerThread in OscReceiver. Replacing all calls to _receiver with _handler.server(). --- src/networking/oscreceiver.cpp | 135 ++++++++++++++------------------- 1 file changed, 59 insertions(+), 76 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 4216b609..0772d19b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -17,8 +17,7 @@ using namespace apf::str; * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int port_in) - : _receiver(port_in) +ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) , _controller(controller) , _handler(handler) { @@ -51,21 +50,6 @@ void ssr::OscReceiver::start() add_server_to_client_methods(); VERBOSE("OscReceiver: Added server-to-client callbacks."); } - // check if lo::ServerThread is valid - if (!_receiver.is_valid()) { - ERROR("OscReceiver: ServerThread could not be started!"); - } - _receiver.set_callbacks([this]() - { - VERBOSE("OscReceiver: Started ServerThread for receiving messages."); - }, - []() - { - VERBOSE2("OscReceiver: ServerThread cleanup."); - } - ); - VERBOSE("OscReceiver: url = " << _receiver.url() << "."); - _receiver.start(); } /** @@ -75,7 +59,6 @@ void ssr::OscReceiver::start() void ssr::OscReceiver::stop() { VERBOSE("OscReceiver: Stopping."); - _receiver.stop(); } /** @@ -86,7 +69,7 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // update on new source: "/update/source/new, i, id" - _receiver.add_method("/update/source/new", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -97,7 +80,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - _receiver.add_method("/update/source/delete", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -116,7 +99,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - _receiver.add_method("/update/source/position", "iff", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -129,7 +112,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _receiver.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -149,7 +132,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _receiver.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -160,7 +143,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - _receiver.add_method("/update/source/volume", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -172,7 +155,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _receiver.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -192,7 +175,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - _receiver.add_method("/update/source/name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -204,7 +187,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _receiver.add_method("/update/source/properties_file", "is", [](lo_arg **argv, + _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -216,7 +199,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _receiver.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -229,7 +212,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _receiver.add_method("/update/scene/amplitude_reference_distance", "f", + _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -241,7 +224,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - _receiver.add_method("/update/source/model", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -252,7 +235,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _receiver.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -264,7 +247,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _receiver.add_method("/update/source/file_name_or_port_number", "is", + _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -276,7 +259,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - _receiver.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -287,7 +270,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - _receiver.add_method("/update/source/length", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -298,7 +281,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - _receiver.add_method("/update/reference/position", "ff", [](lo_arg **argv, + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -311,7 +294,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _receiver.add_method("/update/reference/orientation", "f", [](lo_arg **argv, + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -323,7 +306,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _receiver.add_method("/update/reference_offset/position", "ff", [](lo_arg + _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -336,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _receiver.add_method("/update/reference_offset/orientation", "f", [](lo_arg + _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -348,7 +331,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - _receiver.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -359,7 +342,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _receiver.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -380,7 +363,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _receiver.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -401,7 +384,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - _receiver.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -413,7 +396,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _receiver.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -435,7 +418,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - _receiver.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -446,7 +429,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _receiver.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -458,7 +441,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _receiver.add_method("/update/scene/master_signal_level", "f", [](lo_arg + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -469,7 +452,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - _receiver.add_method("/update/source/level", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -490,7 +473,7 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -514,7 +497,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -525,7 +508,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -536,7 +519,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -546,7 +529,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -556,7 +539,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("/source/volume", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -567,7 +550,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("/source/mute", "iT", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -576,7 +559,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("/source/mute", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -585,7 +568,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _receiver.add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -595,7 +578,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - _receiver.add_method("/source/properties_file", "is", [this](lo_arg **argv, + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -607,7 +590,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - _receiver.add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -622,7 +605,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - _receiver.add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -637,7 +620,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("/source/new", NULL, [this](lo_arg **argv, int, + _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -812,7 +795,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -829,7 +812,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/delete."); // set reference position: "/reference/position, ff, x, y" - _receiver.add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -838,7 +821,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - _receiver.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -847,7 +830,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - _receiver.add_method("/reference_offset/position", "ff" , [this](lo_arg + _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -860,7 +843,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _receiver.add_method("/reference_offset/orientation", "f" , [this](lo_arg + _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -871,7 +854,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); // save scene to file: "/scene/save, s, file" - _receiver.add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); @@ -880,7 +863,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - _receiver.add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); @@ -889,7 +872,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - _receiver.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -899,7 +882,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - _receiver.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -909,7 +892,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/clear."); // set processing state: "/processing/state, T, true" - _receiver.add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -919,7 +902,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - _receiver.add_method("/processing/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -929,7 +912,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" - _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -939,7 +922,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - _receiver.add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -949,7 +932,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - _receiver.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -959,7 +942,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -977,7 +960,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/seek."); // reset tracker: "/tracker/reset" - _receiver.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); From 33eeec75d1012243f48f3ed1914a6fe5261ebc69 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:36:46 +0200 Subject: [PATCH 087/363] src/networking/oscsender.h: Removing lo::ServerThread as member of OscSender. Removing obsolete OscSender Constructor. Removing port_out argument of remaining constructor. --- src/networking/oscsender.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cd6fa5c7..0673140a 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -38,8 +38,6 @@ class OscSender : public Subscriber Publisher& _controller; // reference to handler OscHandler& _handler; - // ServerThread to send from specific port (client|server) - lo::ServerThread _send_from; bool _is_subscribed; // address of server (client) lo::Address _server_address; @@ -62,9 +60,7 @@ class OscSender : public Subscriber void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: - OscSender(Publisher& controller, OscHandler& handler, int port_out); - OscSender(Publisher& controller, OscHandler& handler, int port_out, - std::vector client_addresses); + OscSender(Publisher& controller, OscHandler& handler); ~OscSender(); void start(); From d136e3ee38b628e2d138903603544ff00449cc62 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:38:24 +0200 Subject: [PATCH 088/363] src/networking/oscsender.cpp: Removing port_out argument from constructor. Updating default server_address to use port 50001. Removing initialization of lo::ServerThread in OscSender. Replacing all calls to _send_from with _handler.server(). --- src/networking/oscsender.cpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index d6b6c2df..f20abd3e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -17,12 +17,10 @@ * @param port_out an integer describing the port number to be used * for outgoing traffic */ -ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int - port_out) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) - , _send_from(port_out) - , _server_address("none", "50002") + , _server_address("none", "50001") { VERBOSE("OscSender: Initialized."); } @@ -41,21 +39,6 @@ void ssr::OscSender::start() { _controller.subscribe(this); _is_subscribed = true; - // check if lo::ServerThread is valid - if (!_send_from.is_valid()) { - ERROR("OscSender: ServerThread could not be started!"); - } - _send_from.set_callbacks([this]() - { - VERBOSE("OscSender: Started ServerThread for sending messages."); - }, - []() - { - VERBOSE2("OscSender: ServerThread cleanup."); - } - ); - VERBOSE("OscSender: url = " << _send_from.url() << "."); - _send_from.start(); if (is_server()) { _poll_all_clients = true; @@ -158,9 +141,9 @@ void ssr::OscSender::set_server_address(std::string hostname, std::string port) void ssr::OscSender::send_to_server(std::string path, lo::Message message) { if((_server_address.hostname().compare("none") != 0) && - (_server_address.port().compare("50002") != 0)) + (_server_address.port().compare("50001") != 0)) { - _server_address.send_from(_send_from, path, message.types(), message); + _server_address.send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -173,7 +156,7 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server_address.send_from(_send_from, bundle); + _server_address.send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle (" << bundle.length() << " messages) to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -194,7 +177,7 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_send_from, path, message.types(), message); + client->send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -215,7 +198,7 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_send_from, bundle); + client->send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } @@ -234,7 +217,7 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << client_address->hostname() << ":" << client_address->port() << "."); - client_address->send_from(_send_from, path, message.types(), message); + client_address->send_from(_handler.server(), path, message.types(), message); } } @@ -246,7 +229,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { for (const auto& client_address: _client_addresses) { - client_address->send_from(_send_from, bundle); + client_address->send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } From 65ddbcc03e16a5808d15bce6d378a96724375b63 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:25:07 +0200 Subject: [PATCH 089/363] src/networking/oschandler.h: Making access to lo::ServerThread non-static. --- src/networking/oschandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index eaabad99..2d7e1f57 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -46,7 +46,7 @@ class OscHandler void start(); void stop(); std::string mode(); - const lo::ServerThread& server() const; + lo::ServerThread& server(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From df36d60dfbc013a7633f6caac56f72c0af9e6c3a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:26:46 +0200 Subject: [PATCH 090/363] src/networking/oschandler.cpp: Making ssr::OscHandler::server() non-static. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 1b4c0b9c..54f2f27f 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -188,7 +188,7 @@ std::string ssr::OscHandler::mode() * Return reference to OscHandler's lo::ServerThread * @return lo::ServerThread& reference to _server */ -const lo::ServerThread& ssr::OscHandler::server() const +lo::ServerThread& ssr::OscHandler::server() { return _server; } From dfbdd3f5781d8a15e8bcba209cf8f5021d50805d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:28:46 +0200 Subject: [PATCH 091/363] src/networking/oscreceiver.cpp: Fixing initializer list in constructor. Adding initialization of lo::ServerThread reference to add_client_to_server_methods() and add_server_to_client_methods() to properly access the OscHandler's _server member. --- src/networking/oscreceiver.cpp | 120 +++++++++++++++++---------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0772d19b..2618fd8d 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -18,7 +18,7 @@ using namespace apf::str; * @todo add error handler for ServerThread */ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) - , _controller(controller) + : _controller(controller) , _handler(handler) { VERBOSE("OscReceiver: Initialized."); @@ -68,8 +68,9 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + lo::ServerThread& server = _handler.server(); // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, + server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -80,7 +81,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, + server.add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -99,7 +100,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, + server.add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -112,7 +113,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + server.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -132,7 +133,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + server.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -143,7 +144,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, + server.add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -155,7 +156,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + server.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -175,7 +176,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, + server.add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -187,7 +188,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, + server.add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -199,7 +200,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + server.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -212,7 +213,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", + server.add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -224,7 +225,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, + server.add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -235,7 +236,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + server.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -247,7 +248,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _handler.server().add_method("/update/source/file_name_or_port_number", "is", + server.add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -259,7 +260,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + server.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -270,7 +271,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, + server.add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -281,7 +282,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, + server.add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -294,7 +295,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, + server.add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -306,7 +307,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg + server.add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -319,7 +320,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg + server.add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -331,7 +332,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + server.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -342,7 +343,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + server.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -363,7 +364,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + server.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -384,7 +385,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + server.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -396,7 +397,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + server.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -418,7 +419,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + server.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -429,7 +430,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + server.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -441,7 +442,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg + server.add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -452,7 +453,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, + server.add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -471,9 +472,10 @@ void ssr::OscReceiver::add_client_to_server_methods() */ void ssr::OscReceiver::add_server_to_client_methods() { + lo::ServerThread& server = _handler.server(); // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + server.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -497,7 +499,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) + server.add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -508,7 +510,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + server.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -519,7 +521,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + server.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -529,7 +531,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) + server.add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -539,7 +541,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) + server.add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -550,7 +552,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) + server.add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -559,7 +561,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) + server.add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -568,7 +570,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) + server.add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -578,7 +580,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, + server.add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -590,7 +592,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) + server.add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -605,7 +607,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) + server.add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -620,7 +622,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, + server.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -795,7 +797,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) + server.add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -812,7 +814,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/delete."); // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) + server.add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -821,7 +823,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + server.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -830,7 +832,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg + server.add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -843,7 +845,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg + server.add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -854,7 +856,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) + server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); @@ -863,7 +865,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) + server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); @@ -872,7 +874,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + server.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -882,7 +884,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + server.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -892,7 +894,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/clear."); // set processing state: "/processing/state, T, true" - _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) + server.add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -902,7 +904,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) + server.add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -912,7 +914,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" - _handler.server().add_method("transport/state", "T" , [this](lo_arg **argv, int) + server.add_method("transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -922,7 +924,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) + server.add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -932,7 +934,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + server.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -942,7 +944,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _handler.server().add_method("transport/seek", "s" , [this](lo_arg **argv, int) + server.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -960,7 +962,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/seek."); // reset tracker: "/tracker/reset" - _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + server.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); From 3d0c4fdb427699fc814ea8bf8f2214408ddf9063 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 18:51:53 +0200 Subject: [PATCH 092/363] src/networking/oschandler.h: Adding global int _message_level, defining the type of OSC messages sent (very verbose). This should ultimately be a client address based setting, so clients can subscribe to several layers of messages. Adding message_leve() function for returning _message_level. Adding friend functions add_client(), remove_client() for OscReceiver to add and remove clients from the list of clients in OscSender. --- src/networking/oschandler.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 2d7e1f57..9ae8e70c 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -38,6 +38,7 @@ class OscHandler lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; + const unsigned int _message_level = 2; public: OscHandler(Publisher& controller, int port, std::string mode, @@ -47,6 +48,7 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); + const unsigned int& message_level(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); @@ -62,6 +64,8 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); + friend void OscReceiver::add_client(OscHandler& self, lo::Address client); + friend void OscReceiver::remove_client(OscHandler& self, lo::Address client); }; } // namespace ssr From 3bd57329d9b6fec25e7407884b888f63b425431a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 18:53:44 +0200 Subject: [PATCH 093/363] src/networking/oschandler.cpp: Adding implementations of OscReceiver's friend functions add_client() and remove_client(). Adding implementation of message_level() function. --- src/networking/oschandler.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 54f2f27f..9b6703fd 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -175,6 +175,29 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) self._osc_sender.send_to_server(bundle); } +/** + * OscHandler's friend function to add a client to the list of OscSender's + * _client_addresses. + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be added + */ +void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) +{ + self._osc_sender.add_client(client.hostname(), client.port()); +} + +/** + * OscHandler's friend function to remove a client from the list of OscSender's + * _client_addresses. + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be removed + */ +void ssr::OscReceiver::remove_client(OscHandler& self, lo::Address client) +{ + self._osc_sender.remove_client(client.hostname(), client.port()); +} + + /** * This function returns the OscHandler's mode * @return std::string (either server or client) @@ -192,3 +215,12 @@ lo::ServerThread& ssr::OscHandler::server() { return _server; } + +/** + * Return reference to current _message_level + * @return const unsigned int& + */ +const unsigned int& ssr::OscHandler::message_level() +{ + return _message_level; +} From c693ac2517a5861a5898480c8e91863e0f60b24f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:03:31 +0200 Subject: [PATCH 094/363] src/networking/oscreceiver.h: Adding functions add_client() and remove_client() to add and remove clients on OscSender. --- src/networking/oscreceiver.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 6327b3d6..4cd2b9df 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -55,6 +55,8 @@ class OscReceiver void send_to_all_clients(OscHandler& self, lo::Bundle bundle); void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); + void add_client(OscHandler& self, lo::Address client); + void remove_client(OscHandler& self, lo::Address client); }; } // namespace ssr From f27d4e27b11051d5c17f921465e2e7407fb18c2e Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:14:08 +0200 Subject: [PATCH 095/363] src/networking/oscreceiver.cpp: Adding callback function for /subscribe message (adds client to the list of clients). Updating comments for start() and stop(). Changing the /poll callback to use /subscribe by directly calling send_from() on the calling address, instead of using the friend function. Using references for all calls to strings from a lo::Message argument list. Fixing typo in /transport/seek callback function. --- src/networking/oscreceiver.cpp | 73 ++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2618fd8d..0374a70b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -33,8 +33,7 @@ ssr::OscReceiver::~OscReceiver() } /** - * Starts the OscReceiver, by adding client|server callback functions and - * starting the lo::ServerThread used for listening to OSC messages. + * Starts the OscReceiver, by adding client/ server callback functions. */ void ssr::OscReceiver::start() { @@ -53,8 +52,7 @@ void ssr::OscReceiver::start() } /** - * Stops the OscReceiver, by stopping the lo::ServerThread, used for listening - * for OSC messages + * Stops the OscReceiver */ void ssr::OscReceiver::stop() { @@ -68,7 +66,32 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + // add local reference to OscHandler's lo::ServerThread for add_method() lo::ServerThread& server = _handler.server(); + + // adding new subscribing client: "/subscribe, T" + server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message + message) + { + lo::Address client(message.source()); + (void) argv; + VERBOSE2("Subscribe called with " << message.types() << "."); + if(message.types().compare("T") == 0) + { + add_client(_handler, client); + VERBOSE("Client '" << client.hostname() << ":" << client.port() << + "' subscribed."); + } + else if(message.types().compare("F") == 0) + { + remove_client(_handler, client); + VERBOSE("Client '" << client.hostname() << ":" << client.port() << + "' unsubscribed."); + } + } + ); + VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + // update on new source: "/update/source/new, i, id" server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) @@ -481,8 +504,6 @@ void ssr::OscReceiver::add_server_to_client_methods() lo::Address server(server_address(_handler)); lo::Address from(message.source()); (void) argv; - VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << - from.port() << "."); if((server.hostname().compare(from.hostname()) != 0) && (server.port().compare(from.port()) != 0) && (from.port().compare("50001") != 0) && @@ -490,9 +511,9 @@ void ssr::OscReceiver::add_server_to_client_methods() ) { set_server_for_client(_handler, from); - lo::Message reply; - reply.add_true(); - this->send_to_server(_handler, "/update/subscribe", reply); + from.send_from(_handler.server(), "/subscribe", "T"); + VERBOSE2("OscReceiver: Got /poll from server " << from.hostname() << + ":" << from.port() << ". Subscribing..."); } } ); @@ -625,8 +646,9 @@ void ssr::OscReceiver::add_server_to_client_methods() server.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string name(apf::str::A2S(argv[0]->s)); - std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); + VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); @@ -703,7 +725,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTTT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = true; muted = true; @@ -712,7 +734,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTTF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = true; muted = false; @@ -721,7 +743,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTFF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = false; muted = false; @@ -730,7 +752,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFFF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = false; muted = false; @@ -739,7 +761,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTFT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = false; muted = true; @@ -748,7 +770,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFTF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = true; muted = false; @@ -757,7 +779,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFTT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = true; muted = true; @@ -766,7 +788,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFFT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = false; muted = true; @@ -788,8 +810,7 @@ void ssr::OscReceiver::add_server_to_client_methods() "\norientation_fixed: " << orientation_fixed << "\nvolume (linear): " << volume << "\nmuted: " << muted << - "\nproperties_file: " << properties_file << - "\n"); + "\nproperties_file: " << properties_file); } } ); @@ -858,8 +879,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // save scene to file: "/scene/save, s, file" server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { - _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); - VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); + _controller.save_scene_as_XML(std::string(&(argv[0]->s))); + VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); } ); VERBOSE("OscReceiver: Added method for /scene/save."); @@ -867,8 +888,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // load scene from file: "/scene/load, s, file" server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { - _controller.load_scene(apf::str::A2S(argv[0]->s)); - VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); + _controller.load_scene(std::string(&(argv[0]->s))); + VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); } ); VERBOSE("OscReceiver: Added method for /scene/load."); @@ -944,7 +965,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - server.add_method("transport/seek", "s" , [this](lo_arg **argv, int) + server.add_method("/transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) From 2bf8a815df817fba07a2501351115492c94a4d29 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:17:35 +0200 Subject: [PATCH 096/363] src/networking/oscsender.h: Creating anonymous namespace for _message_type_false and _message_type_true const std::strings. Adding function server_is_default(), bool_to_message_type(), remove_all_clients() and remove_client(). --- src/networking/oscsender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 0673140a..b8d62b58 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -19,6 +19,12 @@ #include "subscriber.h" #include "apf/parameter_map.h" +namespace +{ + const std::string _message_type_false{"F"}; + const std::string _message_type_true{"T"}; +} + namespace ssr { @@ -54,7 +60,10 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); + bool server_is_default(); + const std::string bool_to_message_type(const bool& message); void poll_all_clients(); + void remove_all_client_addresses(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message @@ -68,6 +77,7 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(std::string hostname, std::string port); + void remove_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From 0ac4356ae241018408872f67fd438a68925da85d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:27:25 +0200 Subject: [PATCH 097/363] src/networking/oscsender.cpp: Adding implementations for server_is_default(), bool_to_message_type(), remove_client() and remove_all_clients(). Changing all subscriber interface functions to directly send OSC messages to server/clients (this is very redundant, but needed, as lo::Message loses scope of some data types, if used as before - bug?). Adding VERBOSE messaging to all subscriber interface functions. Adding several layers of OSC message sending verbosity (ultimately planend to be settable by each client individually). --- src/networking/oscsender.cpp | 748 +++++++++++++++++++++++++---------- 1 file changed, 530 insertions(+), 218 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f20abd3e..b3214ce3 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -58,6 +58,7 @@ void ssr::OscSender::stop() _is_subscribed = false; if (is_server()) { + remove_all_client_addresses(); _poll_all_clients = false; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -95,6 +96,39 @@ bool ssr::OscSender::is_server() } } +/** + * Returns true, if the _server_address is the default (setup at initialization) + * @return true, if _server_address is the default, false otherwise. + */ +bool ssr::OscSender::server_is_default() +{ + if((_server_address.hostname().compare("none") == 0) && + (_server_address.port().compare("50001") == 0)) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the _server_address is the default (setup at initialization) + * @return true, if _server_address is the default, false otherwise. + */ +const std::string ssr::OscSender::bool_to_message_type(const bool& message) +{ + if(message) + { + return _message_type_true; + } + else + { + return _message_type_false; + } +} + /** * Sends a '/poll' message to all client instances listed in _client_addresses, * then makes the thread calling this function sleep for 100 milliseconds @@ -371,6 +405,41 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); } +/** + * Removes a client from the vector of clients + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + */ +void ssr::OscSender::remove_client(std::string hostname, std::string port) +{ + for (auto client = _client_addresses.begin(); client != + _client_addresses.end(); ) + { + if(!((*client)->hostname().compare(hostname)) && + !((*client)->port().compare(port))) + { + delete *client; + client = _client_addresses.erase(client); + VERBOSE2("OscSender: Removed client " << hostname << ":" << port << "."); + } + else + { + ++client; + } + } +} + +/** + * Removes all clients from the vector of clients. + */ +void ssr::OscSender::remove_all_client_addresses() +{ + for (auto client: _client_addresses ) delete client; + _client_addresses.clear(); + VERBOSE2("OscSender: Removed all clients."); +} + + // Subscriber interface (differentiating between client and server) @@ -404,10 +473,12 @@ void ssr::OscSender::new_source(id_t id) } else if(is_client()) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); - this->send_to_server("/update/source/new", message); + int32_t message_id = static_cast(id); + _server_address.send_from(_handler.server(), "/update/source/new", "i", + message_id); + VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -420,17 +491,26 @@ void ssr::OscSender::new_source(id_t id) */ void ssr::OscSender::delete_source(id_t id) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); + int32_t message_id = static_cast(id); if(is_server()) { - this->send_to_all_clients("/source/delete", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/delete", "i", + message_id); + VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if (is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/source/delete", message); _source_levels.erase(id); + _server_address.send_from(_handler.server(), "/update/source/delete", + "i", message_id); + VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -442,13 +522,23 @@ void ssr::OscSender::delete_source(id_t id) */ void ssr::OscSender::delete_all_sources() { - lo::Message message; - message.add_int32(0); if(is_server()) - this->send_to_all_clients("/source/delete", message); - else if(is_client()) - this->send_to_server("/update/source/delete", message); - + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/delete", "i", 0); + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } + } + else if(is_client() && !server_is_default()) + { + _server_address.send_from(_handler.server(), "/update/source/delete", + "i", 0); + VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + } _source_levels.clear(); } @@ -466,8 +556,7 @@ void ssr::OscSender::delete_all_sources() */ bool ssr::OscSender::set_source_position(id_t id, const Position& position) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -479,18 +568,24 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add_int32(message_id); - message.add_float(position.x); - message.add_float(position.y); - this->send_to_all_clients("/source/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/position", "iff", + message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << + position.x << ", " << position.y << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if (is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(position.x); - message.add_float(position.y); - this->send_to_server("/update/source/position", message); + _server_address.send_from(_handler.server(), "/update/source/position", + "iff", message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << + ", " << position.x << ", " << position.y << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -510,8 +605,8 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) */ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { - lo::Message message; - int32_t message_id = id; +// lo::Message message; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -522,16 +617,24 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add_int32(message_id); - message.add_bool(fixed); - this->send_to_all_clients("/source/position_fixed", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/position_fixed", + "i"+bool_to_message_type(fixed), message_id); + VERBOSE3("OscSender: Sent [/source/position_fixed, i" << + bool_to_message_type(fixed) << ", " << message_id << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_bool(fixed); - this->send_to_server("/update/source/position_fixed", message); + _server_address.send_from(_handler.server(), "/update/source/position_fixed", + "i"+bool_to_message_type(fixed), message_id); + VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" + +bool_to_message_type(fixed) << ", " << message_id << "] to server " + << _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -550,8 +653,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& orientation) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + float message_orientation = orientation.azimuth; if(is_server()) { if(is_new_source(id)) @@ -562,16 +665,25 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add_int32(message_id); - message.add_float(orientation.azimuth); - this->send_to_all_clients("/source/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/orientation", + "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/source/orientation, if, " << + message_id << ", " << message_orientation << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(orientation.azimuth); - this->send_to_server("/update/source/orientation", message); + _server_address.send_from(_handler.server(), "/update/source/orientation", + "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + apf::str::A2S(message_id) << ", " << + apf::str::A2S(message_orientation) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -590,8 +702,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& */ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -602,16 +713,25 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add_int32(message_id); - message.add_float(gain); - this->send_to_all_clients("/source/volume", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/volume", "if", + message_id, gain); + VERBOSE3("OscSender: Sent [/source/volume, if, " << + message_id << ", " << gain << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(gain); - this->send_to_server("/update/source/volume", message); + _server_address.send_from(_handler.server(), "/update/source/volume", + "if", message_id, gain); + VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } @@ -630,8 +750,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) */ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -642,16 +761,24 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add_int32(message_id); - message.add_bool(mute); - this->send_to_all_clients("/source/mute", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/source/mute, i" << + bool_to_message_type(mute) << ", " << message_id << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_bool(mute); - this->send_to_server("/update/source/mute", message); + _server_address.send_from(_handler.server(), "/update/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/update/source/mute, i" << bool_to_message_type(mute) << + ", " << apf::str::A2S(message_id) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -670,8 +797,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) */ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + const char * message_name = name.c_str(); if(is_server()) { if(is_new_source(id)) @@ -682,16 +809,23 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - message.add_int32(message_id); - message.add_string(name); - this->send_to_all_clients("/source/name", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/name", "is", + message_id, message_name); + VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << + message_name << "] to client " << client_address->hostname() << ":" + << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(name); - this->send_to_server("/update/source/name", message); + _server_address.send_from(_handler.server(), "/update/source/name", "is", + message_id, message_name); + VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " + << message_name << "] to server " << _server_address.hostname() << ":" + << _server_address.port() << "."); } return true; } @@ -712,7 +846,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + const char * file_name = name.c_str(); if(is_server()) { if(is_new_source(id)) @@ -723,16 +858,24 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(name); - this->send_to_all_clients("/source/properties_file", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/properties_file", + "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id + << ", " << file_name << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(name); - this->send_to_server("/update/source/properties_file", message); + _server_address.send_from(_handler.server(), + "/update/source/properties_file", "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << + message_id << ", " << file_name << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -747,15 +890,24 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& */ void ssr::OscSender::set_decay_exponent(float exponent) { - lo::Message message; - message.add_float(exponent); if(is_server()) { - this->send_to_all_clients("/scene/decay_exponent", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/decay_exponent", + "f", exponent); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/decay_exponent", message); + _server_address.send_from(_handler.server(), + "/update/scene/decay_exponent", "f", exponent); + VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -771,17 +923,24 @@ void ssr::OscSender::set_decay_exponent(float exponent) */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { - lo::Message message; - message.add_float(distance); if(is_server()) { - this->send_to_all_clients("/scene/amplitude_reference_distance", - message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/amplitude_reference_distance", - message); + _server_address.send_from(_handler.server(), + "/update/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " + << distance << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -799,31 +958,36 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) */ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { - lo::Message message; - int32_t message_id = id; - std::string tmp_model; - tmp_model = apf::str::A2S(model); - if (tmp_model == "") return false; + int32_t message_id = static_cast(id); + std::string message_model = apf::str::A2S(model); + if (message_model == "") return false; if(is_server()) { if(is_new_source(id)) { - _new_sources.at(id).set("model", tmp_model); + _new_sources.at(id).set("model", message_model); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else { - message.add_int32(message_id); - message.add_string(tmp_model); - this->send_to_all_clients("/source/model", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/model", "is", + message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " + << message_model << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(tmp_model); - this->send_to_server("/update/source/model", message); + _server_address.send_from(_handler.server(), "/update/source/model", "is", + message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << + ", " << message_model << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } return true; } @@ -845,8 +1009,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -857,16 +1020,23 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(port_name); - this->send_to_all_clients("/source/port_name", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/port_name", "is", + message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << + ", " << port_name << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(port_name); - this->send_to_server("/update/source/port_name", message); + _server_address.send_from(_handler.server(), "/update/source/port_name", + "is", message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << + ", " << port_name << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } return true; } @@ -890,8 +1060,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -903,16 +1072,26 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(file_name); - this->send_to_all_clients("/source/file_name_or_port_number", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << + message_id << ", " << file_name << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(file_name); - this->send_to_server("/update/source/file_name_or_port_number", message); + _server_address.send_from(_handler.server(), + "/update/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " + << message_id << ", " << file_name << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -933,9 +1112,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& */ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { - lo::Message message; - int32_t message_id = id; - int32_t message_file_channel = file_channel; + int32_t message_id = static_cast(id); + int32_t message_file_channel = static_cast(file_channel); if(is_server()) { if(is_new_source(id)) @@ -946,16 +1124,24 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add_int32(message_id); - message.add_int32(message_file_channel); - this->send_to_all_clients("/source/channel", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/file_channel", + "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << + ", " << message_file_channel << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_int32(message_file_channel); - this->send_to_server("/update/source/channel", message); + _server_address.send_from(_handler.server(), + "/update/source/file_channel", "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id + << ", " << message_file_channel << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -974,14 +1160,15 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) */ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { - lo::Message message; - int32_t message_id = id; - int32_t message_length = length; - if(is_client()) + int32_t message_id = static_cast(id); + int32_t message_length = static_cast(length); + if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_int32(message_length); - this->send_to_server("/update/source/length", message); + _server_address.send_from(_handler.server(), "/update/source/length", "ii", + message_id, message_length); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id + << ", " << message_length << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -998,16 +1185,24 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) */ void ssr::OscSender::set_reference_position(const Position& position) { - lo::Message message; - message.add_float(position.x); - message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("/reference/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/reference/position", "ff", + position.x, position.y); + VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << + ", " << position.y << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference/position", message); + _server_address.send_from(_handler.server(), "/update/reference/position", + "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x + << ", " << position.y << "] to server " << _server_address.hostname() + << ":" << _server_address.port() << "."); } } @@ -1023,15 +1218,24 @@ void ssr::OscSender::set_reference_position(const Position& position) */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { - lo::Message message; - message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("/reference/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/reference/orientation", + "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference/orientation, f, " << + orientation.azimuth << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference/orientation", message); + _server_address.send_from(_handler.server(), + "/update/reference/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << + orientation.azimuth << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } } @@ -1048,16 +1252,24 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) */ void ssr::OscSender::set_reference_offset_position(const Position& position) { - lo::Message message; - message.add_float(position.x); - message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("/reference_offset/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference_offset/position", message); + _server_address.send_from(_handler.server(), + "/update/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1076,15 +1288,24 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { - lo::Message message; - message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("/reference_offset/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << + orientation.azimuth << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference_offset/orientation", message); + _server_address.send_from(_handler.server(), + "/update/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << + orientation.azimuth << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } } @@ -1100,15 +1321,25 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& */ void ssr::OscSender::set_master_volume(float volume) { - lo::Message message; - message.add_float(apf::math::linear2dB(volume)); + float message_volume = apf::math::linear2dB(volume); if(is_server()) { - this->send_to_all_clients("/scene/volume", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/volume", message); + _server_address.send_from(_handler.server(), "/update/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1141,20 +1372,29 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* */ void ssr::OscSender::set_processing_state(bool state) { - lo::Message message; - message.add_bool(state); if(is_server()) { - this->send_to_all_clients("/processing/state", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/processing/state, " << + bool_to_message_type(state) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/processing/state", message); + _server_address.send_from(_handler.server(), "/update/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/update/processing/state, " << + bool_to_message_type(state) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } /** - * Subscriber function called, when Publisher set the processing state. + * Subscriber function called, when Publisher sets the transport state. * On server: Sends out OSC message to all clients to update their processing * state. * On client: Sends out OSC message to server about the update of its @@ -1167,28 +1407,42 @@ void ssr::OscSender::set_processing_state(bool state) void ssr::OscSender::set_transport_state( const std::pair& state) { - lo::Message message_state; - lo::Message message_time; - message_state.add_bool(state.first); - message_time.add_string(std::to_string(state.second)); + int32_t message_nframes = static_cast(state.second); if(is_server()) { - lo::Bundle bundle({ - {"/transport/state", message_state}, - {"/transport/seek", message_time} - }); - -// TODO: debug this! -// this->send_to_all_clients(bundle); + if(_handler.message_level() >= 2) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + client_address->send_from(_handler.server(), "/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - lo::Bundle bundle({ - {"/update/transport/state", message_state}, - {"/update/transport/seek", message_time} - }); -// TODO: debug this! -// this->send_to_server(bundle); + if(_handler.message_level() >= 2) + { + _server_address.send_from(_handler.server(), "/update/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/update/transport/state, " << + bool_to_message_type(state.first) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + _server_address.send_from(_handler.server(), "/update/transport/seek", + "i", message_nframes); + VERBOSE3("OscSender: Sent [/update/transport/state, i, " << + message_nframes << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); + } } } @@ -1206,15 +1460,26 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients("/scene/auto_rotate_sources", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/auto_rotate_sources", message); + _server_address.send_from(_handler.server(), + "/update/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1228,11 +1493,17 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) */ void ssr::OscSender::set_cpu_load(float load) { - lo::Message message; - message.add_float(load); - if(is_client()) + //TODO: implement pooling of cpu_load updates + if(is_client() && !server_is_default()) { - this->send_to_server("/update/cpu_load", message); + if(_handler.message_level() >= 2) + { + _server_address.send_from(_handler.server(), "/update/cpu_load", "f", + load); + VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } } @@ -1248,16 +1519,25 @@ void ssr::OscSender::set_cpu_load(float load) */ void ssr::OscSender::set_sample_rate(int sr) { - lo::Message message; - int32_t message_sr = sr; - message.add_int32(message_sr); + int32_t message_sr = static_cast(sr); if(is_server()) { - this->send_to_all_clients("/scene/sample_rate", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/sample_rate", "i", + message_sr); + VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/sample_rate", message); + _server_address.send_from(_handler.server(), "/update/scene/sample_rate", + "i", message_sr); + VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1273,16 +1553,32 @@ void ssr::OscSender::set_sample_rate(int sr) */ void ssr::OscSender::set_master_signal_level(float level) { - lo::Message message; float message_level(apf::math::linear2dB(level)); - message.add_float(message_level); if(is_server()) { - this->send_to_all_clients("/scene/master_signal_level", message); + if(_handler.message_level() >= 1) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/master_signal_level", message); + if(_handler.message_level() >= 1) + { + _server_address.send_from(_handler.server(), + "/update/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + } } } @@ -1300,17 +1596,33 @@ void ssr::OscSender::set_master_signal_level(float level) */ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); - message.add_float(apf::math::linear2dB(level)); + int32_t message_id = static_cast(id); + float message_level(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("/source/volume", message); + if(_handler.message_level() >= 1) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/level", "if", + message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/source/level", message); + if(_handler.message_level() >= 1) + { + _server_address.send_from(_handler.server(), "/update/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/update/source/level, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } return true; } From b3ca84413c733828dd877fdd870465386879ad85 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 00:38:11 +0200 Subject: [PATCH 098/363] src/networking/oscclient.*: Adding class definition and implementation for OSC client, which is defined by a lo::Address and an enum class defining the message level. --- src/networking/oscclient.cpp | 60 ++++++++++++++++++++++++++++++++++++ src/networking/oscclient.h | 39 +++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/networking/oscclient.cpp create mode 100644 src/networking/oscclient.h diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp new file mode 100644 index 00000000..91004d81 --- /dev/null +++ b/src/networking/oscclient.cpp @@ -0,0 +1,60 @@ +/** + * Implementation of oscclient.h + * @file oscclient.cpp + */ + +#include "oscclient.h" + +/** + * Constructor used to create OSC client objects + * @param hostname a std::string used in the object's address + * @param port a std::string used in the object's address + * @param message_level the MessageLevel defining the clients level of messages + */ +ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel + message_level) + : _address(hostname, port) + , _message_level(message_level) +{} + +/** + * Destructor + **/ +ssr::OscClient::~OscClient() +{} + +/** + * Function to get the OscClient's _message_level. + * @return message_level a MessageLevel used for the OscClient + **/ +ssr::MessageLevel ssr::OscClient::message_level() +{ + return _message_level; +} + +/** + * Function to set the OscClient's _message_level. + * @param message_level a MessageLevel to be used for the OscClient + **/ +void ssr::OscClient::set_message_level(MessageLevel message_level) +{ + _message_level = message_level; +} + +/** + * Function to get the OscClient's hostname. + * @return std::string representing the OscClient's hostname + **/ +const std::string ssr::OscClient::hostname() +{ + return _address.hostname(); +} + +/** + * Function to get the OscClient's port. + * @return std::string representing the OscClient's port + **/ +const std::string ssr::OscClient::port() +{ + return _address.port(); +} diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h new file mode 100644 index 00000000..956f4f04 --- /dev/null +++ b/src/networking/oscclient.h @@ -0,0 +1,39 @@ +/** + * Header for OscClient, defining a class, holding client information + * @file oscclient.h + */ + +#ifndef OSC_CLIENT_H +#define OSC_CLIENT_H + +#include +#include + +namespace ssr +{ + +enum class MessageLevel : unsigned int +{ + MESSAGE_LEVEL_SERVER = 0, + MESSAGE_LEVEL_THIN_CLIENT = 1, + MESSAGE_LEVEL_CLIENT = 2 +}; + +class OscClient +{ + private: + const lo::Address _address; + MessageLevel _message_level; + public: + OscClient(std::string hostname, std::string port, MessageLevel + message_level); + ~OscClient(); + + ssr::MessageLevel message_level(); + void set_message_level(MessageLevel message_level); + const std::string hostname(); + const std::string port(); +}; + +} +#endif From 126f6f90d58a2fbf3a8f10f3dcb7b6ea88a4e3ae Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 00:38:51 +0200 Subject: [PATCH 099/363] src/Makefile.am: Adding src/networking/oscclient.{h,cpp}. --- src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 4d37deb1..03669651 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -182,6 +182,8 @@ if ENABLE_OSC_INTERFACE AM_CPPFLAGS += -I$(srcdir)/networking SSRSOURCES += \ + networking/oscclient.cpp \ + networking/oscclient.h \ networking/oschandler.cpp \ networking/oschandler.h \ networking/oscreceiver.cpp \ From 700976bb59fa9b5a74e13378ee9139073767db54 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 14:40:59 +0200 Subject: [PATCH 100/363] src/networking/oscclient.h: Adding function to retrieve lo::Address from OscClient. --- src/networking/oscclient.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 956f4f04..27c7b953 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -30,6 +30,7 @@ class OscClient ~OscClient(); ssr::MessageLevel message_level(); + lo::Address address(); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); From 7ab7eec23e7c33fb3723da79cc46a22dd4cbbe0f Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 14:41:39 +0200 Subject: [PATCH 101/363] src/networking/oscclient.cpp: Adding implementation for address(). --- src/networking/oscclient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 91004d81..897981c6 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -32,6 +32,15 @@ ssr::MessageLevel ssr::OscClient::message_level() return _message_level; } +/** + * Function to get the OscClient's _address + * @return a lo::Address used for the OscClient + **/ +lo::Address ssr::OscClient::address() +{ + return _address; +} + /** * Function to set the OscClient's _message_level. * @param message_level a MessageLevel to be used for the OscClient From 4037537e78defb84eb16808d7129b44056a0ac15 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 15:18:59 +0200 Subject: [PATCH 102/363] src/networking/oscsender.cpp: Fixing documentation for constructor and start(). --- src/networking/oscsender.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b3214ce3..80bc36fa 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -11,11 +11,9 @@ #include "apf/math.h" /** - * Constructor used to create client objects + * Constructor used to create OscSender objects * @param controller reference to a Publisher object * @param handler reference to an OscHandler object - * @param port_out an integer describing the port number to be used - * for outgoing traffic */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) @@ -31,7 +29,8 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) ssr::OscSender::~OscSender() {} -/** Function to start the OscSender object +/** + * Function to start the OscSender object * This subscribes the OscSender to the Publisher and starts the * lo::ServerThread to send from */ From cc567becddd3b6d3d8da65669ae943374244e591 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 30 May 2017 14:19:30 +0200 Subject: [PATCH 103/363] src/networking/oscclient.h: Adding bool for active state. Adding public functions to retrieve the _active state of OscClient objects and deactivating them. --- src/networking/oscclient.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 27c7b953..88616f19 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -24,6 +24,8 @@ class OscClient private: const lo::Address _address; MessageLevel _message_level; + bool _active = false; + public: OscClient(std::string hostname, std::string port, MessageLevel message_level); @@ -31,6 +33,8 @@ class OscClient ssr::MessageLevel message_level(); lo::Address address(); + bool active(); + void deactivate(); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); From 52232fe5017008bc8afa9955136ec58638f364ca Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 30 May 2017 14:20:58 +0200 Subject: [PATCH 104/363] src/networking/oscclient.cpp: Extending constructor to set _active state of OscClient objects to true on initialization. Adding implementation to retrieve the object's _active state. Adding function to deactivate instances of the objects. --- src/networking/oscclient.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 897981c6..a7b18009 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -15,7 +15,9 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel message_level) : _address(hostname, port) , _message_level(message_level) -{} +{ + _active = true; +} /** * Destructor @@ -32,6 +34,25 @@ ssr::MessageLevel ssr::OscClient::message_level() return _message_level; } +/** + * Function to get the OscClient's _active state + * @return a bool, representing the OscClient's state + **/ +bool ssr::OscClient::active() +{ + return _active; +} + +/** + * Function to set the OscClient's _active state + * @param bool, representing the OscClient's new state + **/ +void ssr::OscClient::deactivate() +{ + _active = false; +} + + /** * Function to get the OscClient's _address * @return a lo::Address used for the OscClient From e7487c5a5acac7001565b8f3c3f08150893a59ce Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 14:30:06 +0200 Subject: [PATCH 105/363] src/networking/oscclient.h: Shortening member names of enum class MessageLevel. Changing _address to be non-const. Returning _address by reference in address(). --- src/networking/oscclient.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 88616f19..45a57702 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -14,15 +14,15 @@ namespace ssr enum class MessageLevel : unsigned int { - MESSAGE_LEVEL_SERVER = 0, - MESSAGE_LEVEL_THIN_CLIENT = 1, - MESSAGE_LEVEL_CLIENT = 2 + SERVER = 0, + THIN_CLIENT = 1, + CLIENT = 2 }; class OscClient { private: - const lo::Address _address; + lo::Address _address; MessageLevel _message_level; bool _active = false; @@ -32,7 +32,7 @@ class OscClient ~OscClient(); ssr::MessageLevel message_level(); - lo::Address address(); + lo::Address& address(); bool active(); void deactivate(); void set_message_level(MessageLevel message_level); From 2ec2366b0a5c32f85f3e34253871200fba8b57be Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 14:32:17 +0200 Subject: [PATCH 106/363] src/networking/oscclient.cpp: Adding VERBOSE message to constructor. Changing return type of address() to be a lo::Address reference. --- src/networking/oscclient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index a7b18009..91655c71 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -4,6 +4,7 @@ */ #include "oscclient.h" +#include "ssr_global.h" /** * Constructor used to create OSC client objects @@ -17,6 +18,8 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel , _message_level(message_level) { _active = true; + VERBOSE("OscClient: Initialized as " << _address.hostname() << ":" << + _address.port() << "."); } /** @@ -57,7 +60,7 @@ void ssr::OscClient::deactivate() * Function to get the OscClient's _address * @return a lo::Address used for the OscClient **/ -lo::Address ssr::OscClient::address() +lo::Address& ssr::OscClient::address() { return _address; } From 4963d45b09a5cbab1e185ae9b67cf409e0f73d44 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:51:37 +0200 Subject: [PATCH 107/363] src/networking/oscclient.h: Adding definition of activate(). --- src/networking/oscclient.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 45a57702..c43d02b0 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -34,6 +34,7 @@ class OscClient ssr::MessageLevel message_level(); lo::Address& address(); bool active(); + void activate(); void deactivate(); void set_message_level(MessageLevel message_level); const std::string hostname(); From ebe1be74c7f4dc22a59bd0fad59068e6facfa619 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:53:39 +0200 Subject: [PATCH 108/363] src/networking/oscclient.cpp: Adding implementation of activate(). Deleting false @param documentation for deactivate(). --- src/networking/oscclient.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 91655c71..7e9e88fc 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -47,14 +47,21 @@ bool ssr::OscClient::active() } /** - * Function to set the OscClient's _active state - * @param bool, representing the OscClient's new state + * Function to set the OscClient's _active state to false **/ void ssr::OscClient::deactivate() { _active = false; } +/** + * Function to set the OscClient's _active state to true + **/ +void ssr::OscClient::activate() +{ + _active = true; +} + /** * Function to get the OscClient's _address From 340c9cf0934d96b37f4578f215688f8665e85236 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:56:07 +0200 Subject: [PATCH 109/363] src/networking/oschandler.h: Renaming remove_client() friend function to deactivate_client(). --- src/networking/oschandler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 9ae8e70c..c696df8f 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -65,7 +65,8 @@ class OscHandler friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); friend void OscReceiver::add_client(OscHandler& self, lo::Address client); - friend void OscReceiver::remove_client(OscHandler& self, lo::Address client); + friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address + client); }; } // namespace ssr From 7bed977dbb5df30596c4461426987da3c7cf986c Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:57:35 +0200 Subject: [PATCH 110/363] src/networking/oschandler.cpp: Changing implementation of remove_client() to deactivate_client(). --- src/networking/oschandler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 9b6703fd..2b42e576 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -187,14 +187,14 @@ void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) } /** - * OscHandler's friend function to remove a client from the list of OscSender's - * _client_addresses. + * OscHandler's friend function to deactivate a client from the list of + * OscSender's _clients * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be removed + * @param client lo::Address representing client to be deactivated */ -void ssr::OscReceiver::remove_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) { - self._osc_sender.remove_client(client.hostname(), client.port()); + self._osc_sender.deactivate_client(client.hostname(), client.port()); } From fbace1df345707ecb20ba7182b171b45879e3e24 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:00:59 +0200 Subject: [PATCH 111/363] src/networking/oscreceiver.h: Changing definition of remove_client() to deactivate_client. src/networking/oscreceiver.cpp: Changing call to remove_client() to deactivate_client(). --- src/networking/oscreceiver.cpp | 2 +- src/networking/oscreceiver.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0374a70b..007b8c2a 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -84,7 +84,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } else if(message.types().compare("F") == 0) { - remove_client(_handler, client); + deactivate_client(_handler, client); VERBOSE("Client '" << client.hostname() << ":" << client.port() << "' unsubscribed."); } diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 4cd2b9df..01453b4a 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -56,7 +56,7 @@ class OscReceiver void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); void add_client(OscHandler& self, lo::Address client); - void remove_client(OscHandler& self, lo::Address client); + void deactivate_client(OscHandler& self, lo::Address client); }; } // namespace ssr From d135ac7e95d544c70780b6d4a196ac697bce0750 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:34:13 +0200 Subject: [PATCH 112/363] src/networking/oscsender.h: Adding OscClient by including oscclient.h and adding std::vector _clients, (making the std::vector _client_addresses obsolete. Replacing remove_all_client_addresses() by remove_all_clients(). Replacing remove_client() by deactivate_client(). Fixing line wrap. --- src/networking/oscsender.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index b8d62b58..cd145d60 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -15,6 +15,7 @@ #include #include #include +#include "oscclient.h" #include "ssr_global.h" #include "subscriber.h" #include "apf/parameter_map.h" @@ -47,8 +48,10 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; - // vector of pointers to client address objects (server) + // (obsolete) vector of pointers to client address objects (server) std::vector _client_addresses; + // vector of pointers to OscClient objects (server) + std::vector _clients; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously @@ -63,7 +66,7 @@ class OscSender : public Subscriber bool server_is_default(); const std::string bool_to_message_type(const bool& message); void poll_all_clients(); - void remove_all_client_addresses(); + void remove_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message @@ -77,7 +80,7 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(std::string hostname, std::string port); - void remove_client(std::string hostname, std::string port); + void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message @@ -115,8 +118,8 @@ class OscSender : public Subscriber virtual void set_master_volume(float volume); virtual void set_source_output_levels(id_t id, float* first, float* last); virtual void set_processing_state(bool state); - virtual void set_transport_state( - const std::pair& state); + virtual void set_transport_state( const std::pair& + state); virtual void set_auto_rotation(bool auto_rotate_sources); virtual void set_decay_exponent(float exponent); virtual void set_amplitude_reference_distance(float distance); From 1656cf1e3e4452b60f6dca78c41ff01ff3499de7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:49:05 +0200 Subject: [PATCH 113/363] src/networking/oscsender.cpp: Replacing calls to remove_all_client_addresses() with remove_all_clients(). Sending /poll only to activated clients. Rewriting add_client() to use _clients, reusing clients that were once subscribed and otherwise adding a new OscClient with MessageLevel::CLIENT. Replacing remove_client() by deactivate_client(), which only deactivates the client object, but never deletes it (this is somewhat a memory leak, if too many clients subscribe, that never reconnect again, as clients are only added to the list/reused from the list, but never deleted). Rewriting all functions in Subscriber interface (that require it) to use _clients instead _client_addresses. This makes proper checks to the client objects activate state (and checks for MessageLevel in the future) possible. --- src/networking/oscsender.cpp | 494 +++++++++++++++++++++-------------- 1 file changed, 300 insertions(+), 194 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 80bc36fa..a0a54e3a 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -57,7 +57,7 @@ void ssr::OscSender::stop() _is_subscribed = false; if (is_server()) { - remove_all_client_addresses(); + remove_all_clients(); _poll_all_clients = false; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -129,15 +129,21 @@ const std::string ssr::OscSender::bool_to_message_type(const bool& message) } /** - * Sends a '/poll' message to all client instances listed in _client_addresses, - * then makes the thread calling this function sleep for 100 milliseconds + * Sends a '/poll' message to all client instances listed in _clients, then + * makes the thread calling this function sleep for 1000 milliseconds */ void ssr::OscSender::poll_all_clients() { VERBOSE("OscSender: Starting to poll all clients."); while(_poll_all_clients) { - send_to_all_clients("/poll", lo::Message()); + for(const auto& client: _clients) + { + if(client && (*client).active()) + { + (*client).address().send_from(_handler.server(), "/poll", ""); + } + } //TODO find better solution to compensate for execution time std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -400,30 +406,41 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) */ void ssr::OscSender::add_client(std::string hostname, std::string port) { - _client_addresses.push_back(new lo::Address(hostname, port)); - VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); + bool setup = false; + for (auto& client: _clients) + { + if(client && !((*client).active()) && + (*client).address().hostname().compare(hostname) == 0 && + (*client).address().port().compare(port) == 0 ) + { + (*client).activate(); + setup = true; + VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << + "."); + break; + } + } + if (!setup) + { + _clients.push_back(new OscClient(hostname, port, MessageLevel::CLIENT)); + VERBOSE2("OscSender: Added new client " << hostname << ":" << port << "."); + } } /** - * Removes a client from the vector of clients + * Deactivate a client * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client */ -void ssr::OscSender::remove_client(std::string hostname, std::string port) +void ssr::OscSender::deactivate_client(std::string hostname, std::string port) { - for (auto client = _client_addresses.begin(); client != - _client_addresses.end(); ) + for (auto& client: _clients) { - if(!((*client)->hostname().compare(hostname)) && - !((*client)->port().compare(port))) + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->active()) { - delete *client; - client = _client_addresses.erase(client); - VERBOSE2("OscSender: Removed client " << hostname << ":" << port << "."); - } - else - { - ++client; + (*client).deactivate(); + VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); } } } @@ -431,10 +448,10 @@ void ssr::OscSender::remove_client(std::string hostname, std::string port) /** * Removes all clients from the vector of clients. */ -void ssr::OscSender::remove_all_client_addresses() +void ssr::OscSender::remove_all_clients() { - for (auto client: _client_addresses ) delete client; - _client_addresses.clear(); + for (auto client: _clients) delete client; + _clients.clear(); VERBOSE2("OscSender: Removed all clients."); } @@ -493,13 +510,16 @@ void ssr::OscSender::delete_source(id_t id) int32_t message_id = static_cast(id); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/delete", "i", - message_id); - VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/delete", "i", + message_id); + VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -523,12 +543,15 @@ void ssr::OscSender::delete_all_sources() { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/delete", "i", 0); + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -567,14 +590,17 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/position", "iff", - message_id, position.x, position.y); - VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << - position.x << ", " << position.y << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/position", + "iff", message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << + position.x << ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -616,14 +642,18 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/position_fixed", - "i"+bool_to_message_type(fixed), message_id); - VERBOSE3("OscSender: Sent [/source/position_fixed, i" << - bool_to_message_type(fixed) << ", " << message_id << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/position_fixed", "i"+bool_to_message_type(fixed), + message_id); + VERBOSE3("OscSender: Sent [/source/position_fixed, i" << + bool_to_message_type(fixed) << ", " << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -664,14 +694,17 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/orientation", - "if", message_id, message_orientation); - VERBOSE3("OscSender: Sent [/source/orientation, if, " << - message_id << ", " << message_orientation << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/orientation", "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id + << ", " << message_orientation << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -712,14 +745,16 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/volume", "if", - message_id, gain); - VERBOSE3("OscSender: Sent [/source/volume, if, " << - message_id << ", " << gain << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/volume", + "if", message_id, gain); + VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << + ", " << gain << "] to client " << (*client).address().hostname() + << ":" << (*client).address().port() << "."); + } } } } @@ -760,14 +795,17 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/mute", - "i"+bool_to_message_type(mute), message_id); - VERBOSE3("OscSender: Sent [/source/mute, i" << - bool_to_message_type(mute) << ", " << message_id << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/source/mute, i" << + bool_to_message_type(mute) << ", " << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -808,13 +846,17 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/name", "is", - message_id, message_name); - VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << - message_name << "] to client " << client_address->hostname() << ":" - << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/name", + "is", message_id, message_name); + VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " + << message_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -857,14 +899,17 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/properties_file", - "is", message_id, file_name); - VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id - << ", " << file_name << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/properties_file", "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/source/properties_file, is, " << + message_id << ", " << file_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -891,13 +936,16 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/decay_exponent", - "f", exponent); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/decay_exponent", "f", exponent); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -924,13 +972,16 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/amplitude_reference_distance", "f", distance); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -970,13 +1021,17 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/model", "is", - message_id, message_model.c_str()); - VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " - << message_model << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/model", + "is", message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " + << message_model << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1019,13 +1074,17 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/port_name", "is", - message_id, port_name.c_str()); - VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << - ", " << port_name << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/port_name", + "is", message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << + ", " << port_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1071,15 +1130,18 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/source/file_name_or_port_number", "is", message_id, - file_name.c_str()); - VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << - message_id << ", " << file_name << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << + message_id << ", " << file_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1123,14 +1185,17 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/file_channel", - "ii", message_id, message_file_channel); - VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << - ", " << message_file_channel << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/file_channel", "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id + << ", " << message_file_channel << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1186,13 +1251,17 @@ void ssr::OscSender::set_reference_position(const Position& position) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/reference/position", "ff", - position.x, position.y); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/reference/position", + "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1219,13 +1288,17 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/reference/orientation", - "f", orientation.azimuth); - VERBOSE3("OscSender: Sent [/reference/orientation, f, " << - orientation.azimuth << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference/orientation, f, " << + orientation.azimuth << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1253,13 +1326,17 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/reference_offset/position", "ff", position.x, position.y); - VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1289,13 +1366,17 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/reference_offset/orientation", "f", orientation.azimuth); - VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << - orientation.azimuth << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << + orientation.azimuth << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1323,13 +1404,16 @@ void ssr::OscSender::set_master_volume(float volume) float message_volume = apf::math::linear2dB(volume); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/volume", "f", - message_volume); - VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -1373,13 +1457,17 @@ void ssr::OscSender::set_processing_state(bool state) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/processing/state", - bool_to_message_type(state)); - VERBOSE3("OscSender: Sent [/processing/state, " << - bool_to_message_type(state) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/processing/state, " << + bool_to_message_type(state) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1411,19 +1499,22 @@ void ssr::OscSender::set_transport_state( const std::pair= 2) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); - client_address->send_from(_handler.server(), "/transport/seek", "i", - message_nframes); - VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + (*client).address().send_from(_handler.server(), "/transport/seek", + "i", message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes + << "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1461,14 +1552,18 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); - VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1489,10 +1584,10 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) * @param load a float representing the current cpu load * @todo implement receiver callback in * OscReceiver::add_server_to_client_methods() + * @todo implement pooling of cpu_load updates */ void ssr::OscSender::set_cpu_load(float load) { - //TODO: implement pooling of cpu_load updates if(is_client() && !server_is_default()) { if(_handler.message_level() >= 2) @@ -1521,13 +1616,17 @@ void ssr::OscSender::set_sample_rate(int sr) int32_t message_sr = static_cast(sr); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/sample_rate", "i", - message_sr); - VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/scene/sample_rate", + "i", message_sr); + VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1557,14 +1656,17 @@ void ssr::OscSender::set_master_signal_level(float level) { if(_handler.message_level() >= 1) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1601,13 +1703,17 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { if(_handler.message_level() >= 1) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/level", "if", - message_id, message_level); - VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } From 4b48e44357595708c1a4d7ec1f902191c0cccad9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 22:33:47 +0200 Subject: [PATCH 114/363] src/networking/oscclient.h: Adding GUI_CLIENT to MessageLevel enum. --- src/networking/oscclient.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index c43d02b0..2a830de4 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -16,7 +16,8 @@ enum class MessageLevel : unsigned int { SERVER = 0, THIN_CLIENT = 1, - CLIENT = 2 + CLIENT = 2, + GUI_CLIENT = 3 }; class OscClient From 13054bc7b20f446030daa5821819af6132578aba Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 22:37:01 +0200 Subject: [PATCH 115/363] src/networking/oscsender.cpp: Removing unneeded calls through this pointer. Changing all calls to clients to use -> --- src/networking/oscsender.cpp | 184 +++++++++++++++++------------------ 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index a0a54e3a..cefdec20 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -139,9 +139,9 @@ void ssr::OscSender::poll_all_clients() { for(const auto& client: _clients) { - if(client && (*client).active()) + if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/poll", ""); + client->address().send_from(_handler.server(), "/poll", ""); } } //TODO find better solution to compensate for execution time @@ -409,11 +409,11 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) bool setup = false; for (auto& client: _clients) { - if(client && !((*client).active()) && - (*client).address().hostname().compare(hostname) == 0 && - (*client).address().port().compare(port) == 0 ) + if(client && !(client->active()) && + !(client->address().hostname().compare(hostname)) && + !(client->address().port().compare(port)) ) { - (*client).activate(); + client->activate(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << "."); @@ -439,7 +439,7 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) if(!(client->hostname().compare(hostname)) && !(client->port().compare(port)) && client->active()) { - (*client).deactivate(); + client->deactivate(); VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); } } @@ -482,10 +482,10 @@ void ssr::OscSender::new_source(id_t id) { if(is_server()) { - if(!this->is_new_source(id)) + if(!is_new_source(id)) _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else if(is_client()) { @@ -514,11 +514,11 @@ void ssr::OscSender::delete_source(id_t id) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/delete", "i", + client->address().send_from(_handler.server(), "/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -547,9 +547,9 @@ void ssr::OscSender::delete_all_sources() { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/delete", "i", 0); + client->address().send_from(_handler.server(), "/source/delete", "i", 0); VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -586,7 +586,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) _new_sources.at(id).set("x", position.x); _new_sources.at(id).set("y", position.y); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -594,12 +594,12 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/position", + client->address().send_from(_handler.server(), "/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -638,7 +638,7 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { _new_sources.at(id).set("position_fixed", fixed); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -646,13 +646,13 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/position_fixed", "i"+bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << bool_to_message_type(fixed) << ", " << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -690,7 +690,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { _new_sources.at(id).set("orientation", orientation.azimuth); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -698,12 +698,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id << ", " << message_orientation << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -741,7 +741,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { _new_sources.at(id).set("volume", gain); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -749,11 +749,11 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/volume", + client->address().send_from(_handler.server(), "/source/volume", "if", message_id, gain); VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << - ", " << gain << "] to client " << (*client).address().hostname() - << ":" << (*client).address().port() << "."); + ", " << gain << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } @@ -799,12 +799,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/mute", + client->address().send_from(_handler.server(), "/source/mute", "i"+bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << bool_to_message_type(mute) << ", " << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -842,7 +842,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { _new_sources.at(id).set("name", name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -850,12 +850,12 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/name", + client->address().send_from(_handler.server(), "/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << message_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -895,7 +895,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { _new_sources.at(id).set("properties_file", name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -903,12 +903,12 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id << ", " << file_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -940,11 +940,11 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -976,11 +976,11 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1017,7 +1017,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { _new_sources.at(id).set("model", message_model); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1025,12 +1025,12 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/model", + client->address().send_from(_handler.server(), "/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " << message_model << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1070,7 +1070,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& { _new_sources.at(id).set("port_name", port_name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1078,12 +1078,12 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/port_name", + client->address().send_from(_handler.server(), "/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << ", " << port_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1126,7 +1126,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& _new_sources.at(id).set("file_name_or_port_number", file_name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1134,13 +1134,13 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1181,7 +1181,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { _new_sources.at(id).set("channel", file_channel); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1189,12 +1189,12 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1255,11 +1255,11 @@ void ssr::OscSender::set_reference_position(const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/reference/position", + client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1292,11 +1292,11 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << orientation.azimuth << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1330,11 +1330,11 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1370,11 +1370,11 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << orientation.azimuth << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1408,11 +1408,11 @@ void ssr::OscSender::set_master_volume(float volume) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/scene/volume", "f", + client->address().send_from(_handler.server(), "/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1461,11 +1461,11 @@ void ssr::OscSender::set_processing_state(bool state) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/processing/state", + client->address().send_from(_handler.server(), "/processing/state", bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << bool_to_message_type(state) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1503,17 +1503,17 @@ void ssr::OscSender::set_transport_state( const std::pairactive()) { - (*client).address().send_from(_handler.server(), "/transport/state", + client->address().send_from(_handler.server(), "/transport/state", bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << bool_to_message_type(state.first) << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); - (*client).address().send_from(_handler.server(), "/transport/seek", + client->address().hostname() << ":" << + client->address().port() << "."); + client->address().send_from(_handler.server(), "/transport/seek", "i", message_nframes); VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes - << "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + << "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1556,12 +1556,12 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/auto_rotate_sources", bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << bool_to_message_type(auto_rotate_sources) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1620,11 +1620,11 @@ void ssr::OscSender::set_sample_rate(int sr) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/scene/sample_rate", + client->address().send_from(_handler.server(), "/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << apf::str::A2S(message_sr) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1660,12 +1660,12 @@ void ssr::OscSender::set_master_signal_level(float level) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << apf::str::A2S(message_level) << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1707,12 +1707,12 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/level", + client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " << message_level << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } From dfba7e49a8405403d985358e1e3d9081c292972c Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 02:26:07 +0200 Subject: [PATCH 116/363] src/networking/oscsender.cpp: Adding check for size to is_complete_source(). Implementing send_new_source_message_from_id(). Fixing various calls to _new_sources, as it would otherwise trigger multiple calls to send_new_source_message_from_id(). Removing server-side execution in set_port_name(), as port_name is a local setting and depends on port_name prefix (which must always be kept local). --- src/networking/oscsender.cpp | 189 ++++++++++++++++++++--------------- 1 file changed, 111 insertions(+), 78 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index cefdec20..57e99f42 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -312,7 +312,8 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted"))|| + _new_sources.at(id).has_key("mute") && + _new_sources.at(id).size() == 12)|| (_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && _new_sources.at(id).has_key("file_name_or_port_number") && @@ -322,21 +323,21 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("volume") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted"))) + _new_sources.at(id).has_key("mute") && + _new_sources.at(id).size() == 10)) is_complete = true; } return is_complete; } /** - * Creates a lo::Message used to create a new source on clients. It will + * Creates a message used to create a new source on clients. It will * collect all parameters from a parameter_map in _new_sources according to an * id. * @param id id_t id of the local source a message will be created for. */ void ssr::OscSender::send_new_source_message_from_id(id_t id) { - lo::Message message; if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && _new_sources.at(id).has_key("file_name_or_port_number") && @@ -348,26 +349,53 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted") && - _new_sources.at(id).size() == 12 ) - { - message.add_string(_new_sources.at(id).get("name", "")); - message.add_string(_new_sources.at(id).get("model", "")); - message.add_string(_new_sources.at(id).get("file_name_or_port_number", - "")); - message.add_float(_new_sources.at(id).get("x", 0.0)); - message.add_float(_new_sources.at(id).get("y", 0.0)); - message.add_float(_new_sources.at(id).get("orientation", 0.0)); - message.add_float(_new_sources.at(id).get("volume", 0.0)); - message.add_int32(_new_sources.at(id).get("channel", 1)); - message.add_string(_new_sources.at(id).get("properties_file", "")); - (_new_sources.at(id).get("position_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("orientation_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("muted", false)? - message.add_true(): message.add_false()); - this->send_to_all_clients("/source/new", message); + _new_sources.at(id).has_key("mute")) + { + for (const auto& client: _clients) + { + if(client && client->active()) + { + client->address().send_from(_handler.server(), "/source/new", + "sssffffis"+ + bool_to_message_type(_new_sources.at(id).get( + "position_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get( + "orientation_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get( + "mute", false)), + _new_sources.at(id).get("name", "").c_str(), + _new_sources.at(id).get("model", "").c_str(), + _new_sources.at(id).get( + "file_name_or_port_number","").c_str(), + _new_sources.at(id).get("x", 0.0), + _new_sources.at(id).get("y", 0.0), + _new_sources.at(id).get("orientation", 0.0), + _new_sources.at(id).get("volume", 0.0), + _new_sources.at(id).get("channel", 1), + _new_sources.at(id).get("properties_file", "")); + VERBOSE2("OscSender: Sent [/source/new, sssffffis" << + bool_to_message_type(_new_sources.at(id).get( + "position_fixed", false)) << + bool_to_message_type(_new_sources.at(id).get( + "orientation_fixed", false)) << + bool_to_message_type(_new_sources.at(id).get("mute", + false)) << + ", " << + _new_sources.at(id).get("name", "") << ", " << + _new_sources.at(id).get("model", "") << ", " << + _new_sources.at(id).get("file_name_or_port_number","") + << ", " << + _new_sources.at(id).get("x", 0.0) << ", " << + _new_sources.at(id).get("y", 0.0) << ", " << + _new_sources.at(id).get("orientation", 0.0) << ", " << + _new_sources.at(id).get("volume", 0.0) << ", " << + _new_sources.at(id).get("channel", 1) << ", " << + _new_sources.at(id).get("properties_file", "") + << "] to client " << + client->address().hostname() << ":" << + client->address().port() << "."); + } + } } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -378,24 +406,48 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("volume") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted") && - _new_sources.at(id).size() == 10 ) - { - message.add_string(_new_sources.at(id).get("name", "")); - message.add_string(_new_sources.at(id).get("model", "")); - message.add_string(_new_sources.at(id).get("file_name_or_port_number", - "")); - message.add_float(_new_sources.at(id).get("x", 0.0)); - message.add_float(_new_sources.at(id).get("y", 0.0)); - message.add_float(_new_sources.at(id).get("orientation", 0.0)); - message.add_float(_new_sources.at(id).get("volume", 0.0)); - (_new_sources.at(id).get("position_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("orientation_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("muted", false)? - message.add_true(): message.add_false()); - this->send_to_all_clients("/source/new", message); + _new_sources.at(id).has_key("mute")) + { + for (const auto& client: _clients) + { + if(client && client->active()) + { + client->address().send_from(_handler.server(), "/source/new", + "sssffff"+ + bool_to_message_type( + _new_sources.at(id).get("position_fixed", false)) + +bool_to_message_type( + _new_sources.at(id).get("orientation_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get("mute", + false)), + _new_sources.at(id).get("name", "").c_str(), + _new_sources.at(id).get("model", "").c_str(), + _new_sources.at(id).get( + "file_name_or_port_number","").c_str(), + _new_sources.at(id).get("x", 0.0), + _new_sources.at(id).get("y", 0.0), + _new_sources.at(id).get("orientation", 0.0), + _new_sources.at(id).get("volume", 0.0)); + VERBOSE2("OscSender: Sent [/source/new, sssffff" << + bool_to_message_type( + _new_sources.at(id).get( "position_fixed", false)) << + bool_to_message_type( + _new_sources.at(id).get("orientation_fixed", false)) << + bool_to_message_type( + _new_sources.at(id).get("mute", false)) << ", " << + _new_sources.at(id).get("name", "") << ", " << + _new_sources.at(id).get("model", "") << ", " << + _new_sources.at(id).get("file_name_or_port_number","") + << ", " << + _new_sources.at(id).get("x", 0.0) << ", " << + _new_sources.at(id).get("y", 0.0) << ", " << + _new_sources.at(id).get("orientation", 0.0) << ", " << + _new_sources.at(id).get("volume", 0.0) + << "] to client " << + client->address().hostname() << ":" << + client->address().port() << "."); + } + } } } @@ -419,6 +471,14 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) "."); break; } + else if(client && client->active() && + !(client->address().hostname().compare(hostname)) && + !(client->address().port().compare(port)) ) + { + setup = true; + VERBOSE2("OscSender: Client " << hostname << ":" << port << + " already active."); + } } if (!setup) { @@ -630,7 +690,6 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) */ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { -// lo::Message message; int32_t message_id = static_cast(id); if(is_server()) { @@ -689,6 +748,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& if(is_new_source(id)) { _new_sources.at(id).set("orientation", orientation.azimuth); + _new_sources.at(id).set("orientation_fixed", false); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -787,11 +847,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) int32_t message_id = static_cast(id); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && + _new_sources.at(id).has_key("file_name_or_port_number")) { _new_sources.at(id).set("mute", mute); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -886,14 +947,13 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { - lo::Message message; int32_t message_id = static_cast(id); const char * file_name = name.c_str(); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && !name.empty()) { - _new_sources.at(id).set("properties_file", name); + _new_sources.at(id).set("properties_file", file_name); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1048,10 +1108,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) /** * Subscriber function called, when Publisher set a source's port_name. - * On server: Sends out OSC message to set the port_name of given source on all - * clients. If id is found in _new_sources, the port_name will be stored in the - * parameter_map for id and an OSC message will be send to clients only, if the - * source is complete. + * On server: Does nothing, as port_name is local and depends on prefix * On client: Sends out OSC message to server about the successful updating of * the source's port_name. * @param id id_t representing the source @@ -1064,31 +1121,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { int32_t message_id = static_cast(id); - if(is_server()) - { - if(is_new_source(id)) - { - _new_sources.at(id).set("port_name", port_name); - if(is_complete_source(id)) - send_new_source_message_from_id(id); - } - else - { - for (const auto& client: _clients) - { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/source/port_name", - "is", message_id, port_name.c_str()); - VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << - ", " << port_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } - } - } - } - else if(is_client() && !server_is_default()) + if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); @@ -1177,7 +1210,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) int32_t message_file_channel = static_cast(file_channel); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && file_channel > 0) { _new_sources.at(id).set("channel", file_channel); if(is_complete_source(id)) From 53b5999b8c0c0a9065f68042d6cf5c2c380f45a8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:34:27 +0200 Subject: [PATCH 117/363] src/networking/oschandler.h: Removing definition of _message_level and message_level(). src/networking/oschandler.cpp: Removing implementation of message_level(). --- src/networking/oschandler.cpp | 8 -------- src/networking/oschandler.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2b42e576..4a9fe469 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -216,11 +216,3 @@ lo::ServerThread& ssr::OscHandler::server() return _server; } -/** - * Return reference to current _message_level - * @return const unsigned int& - */ -const unsigned int& ssr::OscHandler::message_level() -{ - return _message_level; -} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index c696df8f..67258345 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -38,7 +38,6 @@ class OscHandler lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; - const unsigned int _message_level = 2; public: OscHandler(Publisher& controller, int port, std::string mode, @@ -48,7 +47,6 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); - const unsigned int& message_level(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 264066670e9a5f6f591af1bfb52169c7f6d63274 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:35:45 +0200 Subject: [PATCH 118/363] src/networking/oscsender.h: Adding MessageLevel type _message_level to store a clients level of messages sent towards their server. This can be set with the set_message_level() function, defined here. --- src/networking/oscsender.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cd145d60..88c799dd 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -48,6 +48,8 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; + // level of messages to send to server (client) + MessageLevel _message_level; // (obsolete) vector of pointers to client address objects (server) std::vector _client_addresses; // vector of pointers to OscClient objects (server) @@ -79,6 +81,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string hostname, std::string port); lo::Address server_address(); + void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); From 31d9190a03ba3e0ba55fc1dacfe0affa0f366968 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:39:02 +0200 Subject: [PATCH 119/363] src/networking/oscsender.cpp: Unifying use of compare for is_client()/is_server(). Switching to using _message_level of OscSender instead of (now deleted) OscHandler in all very fast client to server messages. --- src/networking/oscsender.cpp | 160 +++++++++++++++++------------------ 1 file changed, 78 insertions(+), 82 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 57e99f42..5b90f71d 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -19,6 +19,7 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) , _server_address("none", "50001") + , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); } @@ -69,7 +70,7 @@ void ssr::OscSender::stop() */ bool ssr::OscSender::is_client() { - if(_handler.mode() == "client") + if(!_handler.mode().compare("client")) { return true; } @@ -85,7 +86,7 @@ bool ssr::OscSender::is_client() */ bool ssr::OscSender::is_server() { - if(_handler.mode() == "server") + if(!_handler.mode().compare("server")) { return true; } @@ -160,6 +161,16 @@ lo::Address ssr::OscSender::server_address() return server; } +/** + * Function to set OscSender's _message_level. + * If the message level is out of + * @param MessageLevel enum representing the new message level + */ +void ssr::OscSender::set_message_level(const unsigned int& message_level) +{ + _message_level = static_cast(message_level); +} + /** * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address @@ -1530,42 +1541,38 @@ void ssr::OscSender::set_transport_state( const std::pair(state.second); if(is_server()) { - if(_handler.message_level() >= 2) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - client->address().send_from(_handler.server(), "/transport/seek", - "i", message_nframes); - VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes - << "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + client->address().hostname() << ":" << client->address().port() << + "."); + client->address().send_from(_handler.server(), "/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 2) - { - _server_address.send_from(_handler.server(), "/update/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/update/transport/state, " << - bool_to_message_type(state.first) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); - _server_address.send_from(_handler.server(), "/update/transport/seek", - "i", message_nframes); - VERBOSE3("OscSender: Sent [/update/transport/state, i, " << - message_nframes << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/update/transport/state, " << + bool_to_message_type(state.first) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + _server_address.send_from(_handler.server(), "/update/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/update/transport/state, i, " << message_nframes + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1621,16 +1628,14 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) */ void ssr::OscSender::set_cpu_load(float load) { - if(is_client() && !server_is_default()) + if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 2) - { - _server_address.send_from(_handler.server(), "/update/cpu_load", "f", - load); - VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) - << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/cpu_load", "f", + load); + VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1687,32 +1692,28 @@ void ssr::OscSender::set_master_signal_level(float level) float message_level(apf::math::linear2dB(level)); if(is_server()) { - if(_handler.message_level() >= 1) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), - "/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + client->address().hostname() << ":" << client->address().port() << + "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 1) - { - _server_address.send_from(_handler.server(), - "/update/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), + "/update/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1734,33 +1735,28 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) float message_level(apf::math::linear2dB(level)); if(is_server()) { - if(_handler.message_level() >= 1) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/source/level", - "if", message_id, message_level); - VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), "/source/level", "if", + message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 1) - { - _server_address.send_from(_handler.server(), "/update/source/level", - "if", message_id, message_level); - VERBOSE3("OscSender: Sent [/update/source/level, if, " << - apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/update/source/level, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } From 3271564361bd0bad72204985cf1e69d880305f2e Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 19:56:07 +0200 Subject: [PATCH 120/363] src/ssr_global.h: Adding enum class MessageLevel for easier include. --- src/ssr_global.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ssr_global.h b/src/ssr_global.h index 9e269eb2..efb117c4 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -51,6 +51,13 @@ extern float c; ///< speed of sound (meters per second) extern float c_inverse; ///< reciprocal value of c /// time to sleep after connecting a new soundfile with ecasound extern unsigned int usleeptime; +enum class MessageLevel : id_t +{ + SERVER = 0, + THIN_CLIENT = 1, + CLIENT = 2, + GUI_CLIENT = 3 +}; } // namespace ssr From 30fd57753f56e406dce6941ad25f0349911717fe Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:04:13 +0200 Subject: [PATCH 121/363] src/networking/oscclient.h: Adding include for ssr_global.h for VERBOSE and MessageLevel. Removing enum class MessageLevel (now in ssr_global). src/networking/oscclient.cpp: Removing include for ssr_global.h (now in header). --- src/networking/oscclient.cpp | 1 - src/networking/oscclient.h | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 7e9e88fc..f1030028 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -4,7 +4,6 @@ */ #include "oscclient.h" -#include "ssr_global.h" /** * Constructor used to create OSC client objects diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 2a830de4..e975c94c 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -8,18 +8,11 @@ #include #include +#include "ssr_global.h" // for VERBOSE, MessageLevel namespace ssr { -enum class MessageLevel : unsigned int -{ - SERVER = 0, - THIN_CLIENT = 1, - CLIENT = 2, - GUI_CLIENT = 3 -}; - class OscClient { private: From 964756bed6d15769b0f32ce570722139fabea4bb Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:10:03 +0200 Subject: [PATCH 122/363] src/networking/oscreceiver.h: Adding comment for include. Adding set_message_level() (friend function for OscHandler). Changing add_client to use a MessageLevel parameter. Line wraps. src/networking/oscreceiver.cpp: Style changes for string compare in start(). Updating callback handler for /subscribe message to also be able to set an inital message_level for the client subscribing. Prettifying VERBOSE output in /subscribe callback handler. Adding callback handler for /message_level, enabling clients to set their own message_level (the amount of messages received from the server, defaults to MessageLevel::CLIENT - which is a lot of messages (some unneeded probably) already). --- src/networking/oscreceiver.cpp | 42 ++++++++++++++++++++++++---------- src/networking/oscreceiver.h | 13 +++++++---- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 007b8c2a..6f0c5859 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -39,12 +39,12 @@ void ssr::OscReceiver::start() { VERBOSE("OscReceiver: Starting."); // add method handlers for received messages - if (_handler.mode() == "server") + if (!_handler.mode().compare("server")) { add_client_to_server_methods(); VERBOSE("OscReceiver: Added client-to-server callbacks."); } - else if (_handler.mode() == "client") + else if (!_handler.mode().compare("client")) { add_server_to_client_methods(); VERBOSE("OscReceiver: Added server-to-client callbacks."); @@ -69,29 +69,47 @@ void ssr::OscReceiver::add_client_to_server_methods() // add local reference to OscHandler's lo::ServerThread for add_method() lo::ServerThread& server = _handler.server(); - // adding new subscribing client: "/subscribe, T" + // adding new subscribing client: "/subscribe, {T,Ti,F}" server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - (void) argv; - VERBOSE2("Subscribe called with " << message.types() << "."); - if(message.types().compare("T") == 0) + if(!message.types().compare("T")) { - add_client(_handler, client); - VERBOSE("Client '" << client.hostname() << ":" << client.port() << - "' subscribed."); + VERBOSE2("OscReceiver: Got subscribe request from '" << + client.hostname() << ":" << client.port() << "'."); + add_client(_handler, client, ssr::MessageLevel::CLIENT); } - else if(message.types().compare("F") == 0) + else if(!message.types().compare("F")) { + VERBOSE2("OscReceiver: Got unsubscribe request from '" << + client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); - VERBOSE("Client '" << client.hostname() << ":" << client.port() << - "' unsubscribed."); + } + else if(!message.types().compare("Ti")) + { + VERBOSE2("OscReceiver: Got subscribe request from '" << + client.hostname() << ":" << client.port() << + "' for message level: " << argv[1]->i); + add_client(_handler, client, static_cast(argv[1]->i)); } } ); VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + // adding new subscribing client: "/message_level, i" + server.add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message + message) + { + lo::Address client(message.source()); + VERBOSE2("OscReceiver: Got request to set message level for client '" << + client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + set_message_level(_handler, client, + static_cast(argv[0]->i)); + } + ); + VERBOSE("OscReceiver: Added method for /message_level."); + // update on new source: "/update/source/new, i, id" server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 01453b4a..696da2b3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -15,7 +15,7 @@ #include #include -#include "ssr_global.h" +#include "ssr_global.h" // for VERBOSE, MessageLevel namespace ssr { @@ -51,12 +51,17 @@ class OscReceiver std::string path, lo::Message message); void send_to_client(OscHandler& self, lo::Address client_address, lo::Bundle bundle); - void send_to_all_clients(OscHandler& self, std::string path, lo::Message message); + void send_to_all_clients(OscHandler& self, std::string path, lo::Message + message); void send_to_all_clients(OscHandler& self, lo::Bundle bundle); - void send_to_server(OscHandler& self, std::string path, lo::Message message); + void send_to_server(OscHandler& self, std::string path, lo::Message + message); void send_to_server(OscHandler& self, lo::Bundle bundle); - void add_client(OscHandler& self, lo::Address client); + void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel + message_level); void deactivate_client(OscHandler& self, lo::Address client); + void set_message_level(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level); }; } // namespace ssr From 64c5e72580b7f9dbadca66bbfccbcbf6e50c381f Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:13:51 +0200 Subject: [PATCH 123/363] src/networking/oscsender.h: Adding comment for include. Updating add_client() to use an additional parameter for MessageLevel. Adding set_client_message_level(). src/networking/oscsender.cpp: Adding implementation of set_client_message_level(). Changing add_client() to use the MessageLevel provided as parameter. Updating VERBOSE output for add_client(). --- src/networking/oscsender.cpp | 33 ++++++++++++++++++++++++++++++--- src/networking/oscsender.h | 7 +++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 5b90f71d..0d5df6fa 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -467,7 +467,8 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client */ -void ssr::OscSender::add_client(std::string hostname, std::string port) +void ssr::OscSender::add_client(std::string hostname, std::string port, + ssr::MessageLevel message_level) { bool setup = false; for (auto& client: _clients) @@ -476,6 +477,8 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) !(client->address().hostname().compare(hostname)) && !(client->address().port().compare(port)) ) { + if(client->message_level() != message_level) + client->set_message_level(message_level); client->activate(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << @@ -493,8 +496,10 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) } if (!setup) { - _clients.push_back(new OscClient(hostname, port, MessageLevel::CLIENT)); - VERBOSE2("OscSender: Added new client " << hostname << ":" << port << "."); + _clients.push_back(new OscClient(hostname, port, message_level)); + VERBOSE2("OscSender: Added new client " << hostname << ":" << port << + " using message level " << static_cast(message_level) << + "."); } } @@ -516,6 +521,28 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) } } +/** + * Set message level of a client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + * @param message_level ssr::MessageLevel enum representing the message level + * to use + */ +void ssr::OscSender::set_client_message_level(std::string hostname, std::string + port, ssr::MessageLevel message_level) +{ + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port))) + { + client->set_message_level(message_level); + VERBOSE2("OscSender: Set message level of client '" << hostname << ":" << + port << "' to: " << static_cast(message_level) << "."); + } + } +} + /** * Removes all clients from the vector of clients. */ diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 88c799dd..4453337f 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -16,7 +16,7 @@ #include #include #include "oscclient.h" -#include "ssr_global.h" +#include "ssr_global.h" // for VERBOSE, MessageLevel #include "subscriber.h" #include "apf/parameter_map.h" @@ -82,7 +82,10 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void set_message_level(const unsigned int& message_level); - void add_client(std::string hostname, std::string port); + void add_client(std::string hostname, std::string port, ssr::MessageLevel + message_level); + void set_client_message_level(std::string hostname, std::string port, + ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From c988b9a2ede816f130fe763066da33c0452d57e9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:16:57 +0200 Subject: [PATCH 124/363] src/networking/oschandler.h: Adding include ssr_global.h for MessageLevel. Updating friend function add_client() to include MessageLevel parameter. adding friend function set_message_level(). src/networking/oschandler.cpp: Updating call to add_client() in constructor and implementation of add_client() to incorporate MessageLevel parameter. Adding implementation of friend function set_message_level(). --- src/networking/oschandler.cpp | 20 +++++++++++++++++--- src/networking/oschandler.h | 7 +++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 4a9fe469..27810c98 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -31,7 +31,8 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, VERBOSE("OscHandler: " << clients.size() << " client(s)."); for (const auto& client: clients) { - _osc_sender.add_client(client.first, std::to_string(client.second)); + _osc_sender.add_client(client.first, std::to_string(client.second), + ssr::MessageLevel::CLIENT); } } } @@ -181,9 +182,10 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) * @param self reference to OscHandler holding OscSender * @param client lo::Address representing client to be added */ -void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level = ssr::MessageLevel::CLIENT) { - self._osc_sender.add_client(client.hostname(), client.port()); + self._osc_sender.add_client(client.hostname(), client.port(), message_level); } /** @@ -197,6 +199,18 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) self._osc_sender.deactivate_client(client.hostname(), client.port()); } +/** + * OscHandler's friend function to set a client's message_level + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be deactivated + */ +void ssr::OscReceiver::set_message_level(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level) +{ + self._osc_sender.set_client_message_level(client.hostname(), client.port(), + message_level); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 67258345..371d71fa 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -14,7 +14,7 @@ #include #include #include - +#include "ssr_global.h" // for VERBOSE, MessageLevel #include "oscreceiver.h" #include "oscsender.h" @@ -62,9 +62,12 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); - friend void OscReceiver::add_client(OscHandler& self, lo::Address client); + friend void OscReceiver::add_client(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address client); + friend void OscReceiver::set_message_level(OscHandler& self, lo::Address + client, ssr::MessageLevel message_level); }; } // namespace ssr From 58be8eaf5cc8662a0e29e9ed7a2ddc045290ba30 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 2 Jun 2017 15:25:46 +0200 Subject: [PATCH 125/363] src/networking/oscreceiver.h: Splitting add_server_to_client_methods() into several functions, so they can be applied to server objects as well. src/networking/oscreceiver.cpp: Splitting the implementation of callback handler adding into several functions, so they can be more easily applied fine-grained to server objects as well. --- src/networking/oscreceiver.cpp | 240 +++++++++++++++++++++++---------- src/networking/oscreceiver.h | 10 +- 2 files changed, 175 insertions(+), 75 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6f0c5859..3a595b61 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -42,12 +42,23 @@ void ssr::OscReceiver::start() if (!_handler.mode().compare("server")) { add_client_to_server_methods(); - VERBOSE("OscReceiver: Added client-to-server callbacks."); + add_update_notification_methods(); + add_source_methods(); + add_reference_methods(); + add_scene_methods(); + add_processing_methods(); + add_transport_methods(); + add_tracker_methods(); } else if (!_handler.mode().compare("client")) { - add_server_to_client_methods(); - VERBOSE("OscReceiver: Added server-to-client callbacks."); + add_poll_methods(); + add_source_methods(); + add_reference_methods(); + add_scene_methods(); + add_processing_methods(); + add_transport_methods(); + add_tracker_methods(); } } @@ -60,17 +71,15 @@ void ssr::OscReceiver::stop() } /** - * Adds callback handlers for OSC messages received from clients. + * Adds callback handlers (for server) for subscribe and message level messages + * received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { - // add local reference to OscHandler's lo::ServerThread for add_method() - lo::ServerThread& server = _handler.server(); - // adding new subscribing client: "/subscribe, {T,Ti,F}" - server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -95,10 +104,10 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" - server.add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -108,10 +117,19 @@ void ssr::OscReceiver::add_client_to_server_methods() static_cast(argv[0]->i)); } ); - VERBOSE("OscReceiver: Added method for /message_level."); + VERBOSE("OscReceiver: Added method for /message_level i."); +} +/** + * Adds callback handlers (for server) for update messages received from + * clients. + * This function uses C++11 lambda functions to define the behavior for every + * callback. + */ +void ssr::OscReceiver::add_update_notification_methods() +{ // update on new source: "/update/source/new, i, id" - server.add_method("/update/source/new", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -122,7 +140,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - server.add_method("/update/source/delete", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -141,7 +159,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - server.add_method("/update/source/position", "iff", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -154,7 +172,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - server.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -174,7 +192,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - server.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -185,7 +203,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - server.add_method("/update/source/volume", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -197,7 +215,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - server.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -217,7 +235,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - server.add_method("/update/source/name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -229,7 +247,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - server.add_method("/update/source/properties_file", "is", [](lo_arg **argv, + _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -241,7 +259,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - server.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -254,7 +272,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - server.add_method("/update/scene/amplitude_reference_distance", "f", + _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -266,7 +284,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - server.add_method("/update/source/model", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -277,7 +295,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - server.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -289,7 +307,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - server.add_method("/update/source/file_name_or_port_number", "is", + _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -301,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - server.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -312,7 +330,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - server.add_method("/update/source/length", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -323,7 +341,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - server.add_method("/update/reference/position", "ff", [](lo_arg **argv, + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -336,7 +354,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - server.add_method("/update/reference/orientation", "f", [](lo_arg **argv, + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -348,7 +366,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - server.add_method("/update/reference_offset/position", "ff", [](lo_arg + _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -361,7 +379,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - server.add_method("/update/reference_offset/orientation", "f", [](lo_arg + _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -373,7 +391,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - server.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -384,7 +402,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - server.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -405,7 +423,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - server.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -426,7 +444,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - server.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -438,7 +456,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - server.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -460,7 +478,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - server.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -471,7 +489,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - server.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -483,7 +501,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - server.add_method("/update/scene/master_signal_level", "f", [](lo_arg + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -494,7 +512,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - server.add_method("/update/source/level", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -503,20 +521,19 @@ void ssr::OscReceiver::add_client_to_server_methods() } ); VERBOSE("OscReceiver: Added method for /update/source/level."); - } /** - * Adds callback handlers for OSC messages received from a server. + * Adds callback handlers (for clients) for poll messages received from a + * server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void ssr::OscReceiver::add_server_to_client_methods() +void ssr::OscReceiver::add_poll_methods() { - lo::ServerThread& server = _handler.server(); // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - server.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -536,9 +553,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /poll."); +} +/** + * Adds callback handlers (for clients and server) for source related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * set source related settings). + */ +void ssr::OscReceiver::add_source_methods() +{ // set source position: "source/position, iff, id, x, y" - server.add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -549,7 +578,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - server.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -560,7 +589,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - server.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -570,7 +599,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - server.add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -580,7 +609,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - server.add_method("/source/volume", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -591,7 +620,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - server.add_method("/source/mute", "iT", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -600,7 +629,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - server.add_method("/source/mute", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -609,7 +638,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - server.add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -619,7 +648,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - server.add_method("/source/properties_file", "is", [this](lo_arg **argv, + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -631,7 +660,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - server.add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -646,7 +675,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - server.add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -661,7 +690,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - server.add_method("/source/new", NULL, [this](lo_arg **argv, int, + _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); @@ -836,7 +865,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - server.add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -851,9 +880,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /source/delete."); +} +/** + * Adds callback handlers (for clients and server) for reference related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_reference_methods() +{ // set reference position: "/reference/position, ff, x, y" - server.add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -862,7 +904,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - server.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -871,7 +913,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - server.add_method("/reference_offset/position", "ff" , [this](lo_arg + _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -884,7 +926,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - server.add_method("/reference_offset/orientation", "f" , [this](lo_arg + _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -893,9 +935,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); +} +/** + * Adds callback handlers (for clients and server) for scene related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_scene_methods() +{ // save scene to file: "/scene/save, s, file" - server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(std::string(&(argv[0]->s))); VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); @@ -904,7 +958,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(std::string(&(argv[0]->s))); VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); @@ -913,7 +967,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - server.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -923,7 +977,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - server.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -931,9 +985,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /scene/clear."); +} +/** + * Adds callback handlers (for clients and server) for processing related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_processing_methods() +{ // set processing state: "/processing/state, T, true" - server.add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -943,7 +1010,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - server.add_method("/processing/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -951,9 +1018,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /processing/state false."); +} +/** + * Adds callback handlers (for clients and server) for transport related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_transport_methods() +{ // set transport state: "transport/state, T, true" - server.add_method("transport/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -963,7 +1043,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - server.add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -973,7 +1053,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - server.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -983,7 +1063,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - server.add_method("/transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -999,9 +1079,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /transport/seek."); +} +/** + * Adds callback handlers (for clients and server) for tracker related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_tracker_methods() +{ // reset tracker: "/tracker/reset" - server.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); @@ -1009,5 +1101,5 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /tracker/reset."); - } + diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 696da2b3..4011a46b 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -38,7 +38,15 @@ class OscReceiver Publisher& _controller; ssr::OscHandler& _handler; void add_client_to_server_methods(); - void add_server_to_client_methods(); + void add_update_notification_methods(); + void add_poll_methods(); + void add_source_methods(); + void add_reference_methods(); + void add_scene_methods(); + void add_processing_methods(); + void add_transport_methods(); + void add_tracker_methods(); + public: OscReceiver(Publisher& controller, OscHandler& handler); ~OscReceiver(); From 92470da46fef41bf89d529acd7e97487807c2318 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:21:56 +0200 Subject: [PATCH 126/363] src/networking/oschandler.h: Adding anonymous namespace for some bool2string representations. Adding bool_to_message_type() and bool_to_string() to public interface for VERBOSE messages used throughout OscSender and OscReceiver. src/networking/oschandler.cpp: Adding implementation of bool_to_message_type() and bool_to_string(). --- src/networking/oschandler.cpp | 33 +++++++++++++++++++++++++++++++++ src/networking/oschandler.h | 11 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 27810c98..99fb56be 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -230,3 +230,36 @@ lo::ServerThread& ssr::OscHandler::server() return _server; } +/** + * Returns a std::string representing the message type of a boolean type + * @param message bool + * @return _message_type_true if message true, _message_type_false otherwise + */ +const std::string ssr::OscHandler::bool_to_message_type(const bool& message) +{ + if(message) + { + return _message_type_true; + } + else + { + return _message_type_false; + } +} + +/** + * Returns a std::string representing the string of a boolean type + * @param message bool + * @return 'true' if message true, 'false' otherwise + */ +const std::string ssr::OscHandler::bool_to_string(const bool& message) +{ + if(message) + { + return _string_true; + } + else + { + return _string_false; + } +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 371d71fa..f42d01f3 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -18,6 +18,14 @@ #include "oscreceiver.h" #include "oscsender.h" +namespace +{ + const std::string _message_type_false{"F"}; + const std::string _message_type_true{"T"}; + const std::string _string_false{"false"}; + const std::string _string_true{"true"}; +} + namespace ssr { @@ -47,6 +55,9 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); + const std::string bool_to_message_type(const bool& message); + const std::string bool_to_string(const bool& message); + // OscReceiver friend functions friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 4c1646f7ed3784ad39cee6273699ee911cd43186 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:23:55 +0200 Subject: [PATCH 127/363] src/networking/oscsender.h: Removing anonymous namespace and function bool_to_message_type. src/networking/oscsender.cpp: Removing implementation of bool_to_message_type() and replacing all calls to it by the version now held by OscHandler. --- src/networking/oscsender.cpp | 109 ++++++++++++++++++----------------- src/networking/oscsender.h | 7 --- 2 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0d5df6fa..f66b3c80 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -113,21 +113,21 @@ bool ssr::OscSender::server_is_default() } } -/** - * Returns true, if the _server_address is the default (setup at initialization) - * @return true, if _server_address is the default, false otherwise. - */ -const std::string ssr::OscSender::bool_to_message_type(const bool& message) -{ - if(message) - { - return _message_type_true; - } - else - { - return _message_type_false; - } -} +///** +// * Returns true, if the _server_address is the default (setup at initialization) +// * @return true, if _server_address is the default, false otherwise. +// */ +//const std::string ssr::OscSender::bool_to_message_type(const bool& message) +//{ +// if(message) +// { +// return _message_type_true; +// } +// else +// { +// return _message_type_false; +// } +//} /** * Sends a '/poll' message to all client instances listed in _clients, then @@ -368,11 +368,11 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) { client->address().send_from(_handler.server(), "/source/new", "sssffffis"+ - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "position_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get( + +_handler.bool_to_message_type(_new_sources.at(id).get( "orientation_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get( + +_handler.bool_to_message_type(_new_sources.at(id).get( "mute", false)), _new_sources.at(id).get("name", "").c_str(), _new_sources.at(id).get("model", "").c_str(), @@ -385,13 +385,12 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "position_fixed", false)) << - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "orientation_fixed", false)) << - bool_to_message_type(_new_sources.at(id).get("mute", - false)) << - ", " << + _handler.bool_to_message_type(_new_sources.at(id).get( + "mute", false)) << ", " << _new_sources.at(id).get("name", "") << ", " << _new_sources.at(id).get("model", "") << ", " << _new_sources.at(id).get("file_name_or_port_number","") @@ -425,12 +424,12 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) { client->address().send_from(_handler.server(), "/source/new", "sssffff"+ - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("position_fixed", false)) - +bool_to_message_type( + +_handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get("mute", - false)), + +_handler.bool_to_message_type(_new_sources.at(id).get( + "mute", false)), _new_sources.at(id).get("name", "").c_str(), _new_sources.at(id).get("model", "").c_str(), _new_sources.at(id).get( @@ -440,11 +439,11 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("orientation", 0.0), _new_sources.at(id).get("volume", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get( "position_fixed", false)) << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("mute", false)) << ", " << _new_sources.at(id).get("name", "") << ", " << _new_sources.at(id).get("model", "") << ", " << @@ -744,10 +743,10 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/position_fixed", "i"+bool_to_message_type(fixed), + "/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << - bool_to_message_type(fixed) << ", " << message_id << + _handler.bool_to_message_type(fixed) << ", " << message_id << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -757,10 +756,11 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position_fixed", - "i"+bool_to_message_type(fixed), message_id); + "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" - +bool_to_message_type(fixed) << ", " << message_id << "] to server " - << _server_address.hostname() << ":" << _server_address.port() << "."); + +_handler.bool_to_message_type(fixed) << ", " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } @@ -899,9 +899,9 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) if(client && client->active()) { client->address().send_from(_handler.server(), "/source/mute", - "i"+bool_to_message_type(mute), message_id); + "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << - bool_to_message_type(mute) << ", " << message_id << + _handler.bool_to_message_type(mute) << ", " << message_id << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -911,9 +911,10 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/mute", - "i"+bool_to_message_type(mute), message_id); - VERBOSE3("OscSender: Sent [/update/source/mute, i" << bool_to_message_type(mute) << - ", " << apf::str::A2S(message_id) << "] to server " << + "i"+_handler.bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/update/source/mute, i" << + _handler.bool_to_message_type(mute) << ", " << + apf::str::A2S(message_id) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } return true; @@ -1533,9 +1534,9 @@ void ssr::OscSender::set_processing_state(bool state) if(client && client->active()) { client->address().send_from(_handler.server(), "/processing/state", - bool_to_message_type(state)); + _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << - bool_to_message_type(state) << "] to client " << + _handler.bool_to_message_type(state) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -1544,9 +1545,9 @@ void ssr::OscSender::set_processing_state(bool state) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/processing/state", - bool_to_message_type(state)); + _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << - bool_to_message_type(state) << "] to server " << + _handler.bool_to_message_type(state) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1574,9 +1575,9 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); + _handler.bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << + _handler.bool_to_message_type(state.first) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); client->address().send_from(_handler.server(), "/transport/seek", "i", @@ -1591,9 +1592,9 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); + _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + _handler.bool_to_message_type(auto_rotate_sources) << + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1637,9 +1638,9 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { _server_address.send_from(_handler.server(), "/update/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); + _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to server " << + _handler.bool_to_message_type(auto_rotate_sources) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 4453337f..d8849439 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -20,12 +20,6 @@ #include "subscriber.h" #include "apf/parameter_map.h" -namespace -{ - const std::string _message_type_false{"F"}; - const std::string _message_type_true{"T"}; -} - namespace ssr { @@ -66,7 +60,6 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); bool server_is_default(); - const std::string bool_to_message_type(const bool& message); void poll_all_clients(); void remove_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources From 89d4f7958d5c08ae3c058edbae34e32f9f08d6f9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:25:42 +0200 Subject: [PATCH 128/363] src/networking/oscreceiver.cpp: Fixing linewraps. Improving readability of all source related VERBOSE messages by adding more relevant output derived from incoming message. --- src/networking/oscreceiver.cpp | 204 ++++++++++++++++++++------------- 1 file changed, 122 insertions(+), 82 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 3a595b61..e72c5920 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -172,8 +172,8 @@ void ssr::OscReceiver::add_update_notification_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg + **argv, int, lo::Message message) { lo::Address client(message.source()); std::string position_fixed; @@ -192,8 +192,8 @@ void ssr::OscReceiver::add_update_notification_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << @@ -213,10 +213,9 @@ void ssr::OscReceiver::add_update_notification_methods() ); VERBOSE("OscReceiver: Added method for /update/source/volume."); - // update on source position mute: "/update/source/mute, i{T,F}, - // id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, - lo::Message message) + // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, + int, lo::Message message) { lo::Address client(message.source()); std::string state; @@ -567,122 +566,144 @@ void ssr::OscReceiver::add_poll_methods() void ssr::OscReceiver::add_source_methods() { // set source position: "source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << + argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); - VERBOSE2("set source position: id = " << argv[0]->i << ", " << - Position(argv[1]->f, argv[2]->f)); - } - ); - VERBOSE("OscReceiver: Added method for /source/position."); - - // set source fixed: "source/position_fixed, iT, id, true" - _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, - int) - { - _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << - ", fixed = true"); } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed true."); + VERBOSE("OscReceiver: Added method for /source/position iff."); - // set source fixed: "source/position_fixed, iF, id, false" - _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + // set source fixed: "source/position_fixed, i{T,F}, id, true|false" + _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg + **argv, int, lo::Message message) { - _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << - ", fixed = false"); + if (!message.types().compare("iT")) + { + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", true] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, true); + } + else if (!message.types().compare("iF")) + { + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", false] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, false); + } } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed false."); + VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); // set source orientation: "source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << - Orientation(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/orientation."); + VERBOSE("OscReceiver: Added method for /source/orientation if."); - // set source volume: "source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) + // set source volume: "/source/volume, if, id, volume" + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/volume, " << argv[0]->i << ", " << + argv[1]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); - VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << - apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/volume."); + VERBOSE("OscReceiver: Added method for /source/volume if."); - // set source mute: "source/mute, iT, id, true" - _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) - { - _controller.set_source_mute(argv[0]->i, true); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); - } - ); - VERBOSE("OscReceiver: Added method for /source/mute true."); - - // set source mute: "source/mute, iF, id, false" - _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) + // set source mute: "source/mute, i{T,F}, id, true|false" + _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, + lo::Message message) { - _controller.set_source_mute(argv[0]->i, false); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); + if(!message.types().compare("iT")) + { + VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << + ", true] from client '"<< message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_mute(argv[0]->i, true); + } + else if(!message.types().compare("iF")) + { + VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << + ", false] from client '"<< message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_mute(argv[0]->i, false); + } } ); - VERBOSE("OscReceiver: Added method for /source/mute false."); + VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); // set source name: "source/name, is, id, name" - _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, + lo::Message message) { - _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << - apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); + _controller.set_source_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/name."); + VERBOSE("OscReceiver: Added method for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, - int) + int, lo::Message message) { - _controller.set_source_properties_file(argv[0]->i, - apf::str::A2S(argv[1]->s)); - VERBOSE2("set source properties file name: id = " << argv[0]->i << - ", file = " << apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << + ", " << name << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_properties_file(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/properties_file."); + VERBOSE("OscReceiver: Added method for /source/properties_file is."); // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, + int, lo::Message message) { + std::string name(&argv[1]->s); Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + if (!apf::str::S2A(name, model)) { model = Source::point; } + VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_source_model(argv[0]->i, model); - VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << - apf::str::A2S(argv[1]->s)); } ); - VERBOSE("OscReceiver: Added method for /source/model."); + VERBOSE("OscReceiver: Added method for /source/model is."); // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, + int, lo::Message message) { - _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << - apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_port_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/port_name."); + VERBOSE("OscReceiver: Added method for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, position_fixed, @@ -693,7 +714,6 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); std::string name(&(argv[0]->s)); std::string file_name_or_port_number(&(argv[2]->s)); std::string types(message.types()); @@ -702,6 +722,7 @@ void ssr::OscReceiver::add_source_methods() float volume(argv[6]->f); int channel = 0; std::string properties_file = ""; + std::string channel_and_properties = ""; bool position_fixed; bool orientation_fixed; bool muted; @@ -773,6 +794,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = true; @@ -782,6 +804,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = false; @@ -791,6 +814,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = false; @@ -800,6 +824,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = false; @@ -809,6 +834,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = true; @@ -818,6 +844,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = false; @@ -827,6 +854,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = true; @@ -836,6 +864,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = true; @@ -843,10 +872,19 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { + VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << + ", " << file_name_or_port_number << ", " << x << ", " << y << ", " + << orientation.azimuth << ", " << volume << ", " << + channel_and_properties << ", " << + _handler.bool_to_string(position_fixed) << ", " << + _handler.bool_to_string(orientation_fixed) << ", " << + _handler.bool_to_string(muted) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, - volume, muted, properties_file); - VERBOSE2("Creating source with following properties:" + position, position_fixed, orientation, orientation_fixed, volume, + muted, properties_file); + VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << @@ -861,25 +899,27 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new."); + VERBOSE("OscReceiver: Added method for /source/new {sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); if (argv[0]->i == 0) { _controller.delete_all_sources(); - VERBOSE2("delete all sources"); } else { _controller.delete_source(argv[0]->i); - VERBOSE2("delete source with id = " << argv[0]->i); } } ); - VERBOSE("OscReceiver: Added method for /source/delete."); + VERBOSE("OscReceiver: Added method for /source/delete i."); } /** From 30b547bb6ec9e8c7492968776ca2bbc1b295f8bd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 23:46:47 +0200 Subject: [PATCH 129/363] src/networking/oschandler.*: Adding public definition and implementation of is_server() and is_client(). --- src/networking/oschandler.cpp | 32 ++++++++++++++++++++++++++++++++ src/networking/oschandler.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 99fb56be..e0d4b375 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -221,6 +221,38 @@ std::string ssr::OscHandler::mode() return _mode; } +/** + * Returns true, if the instance of OscHandler is a 'client', false otherwise. + * @return true, if _oschandler.mode() returns 'client', false otherwise. + */ +bool ssr::OscHandler::is_client() +{ + if(!_mode.compare("client")) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the instance of OscHandler is a 'server', false otherwise. + * @return true, if _oschandler.mode() returns 'server', false otherwise. + */ +bool ssr::OscHandler::is_server() +{ + if(!_mode.compare("server")) + { + return true; + } + else + { + return false; + } +} + /** * Return reference to OscHandler's lo::ServerThread * @return lo::ServerThread& reference to _server diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index f42d01f3..0faaa5ee 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -54,6 +54,8 @@ class OscHandler void start(); void stop(); std::string mode(); + bool is_client(); + bool is_server(); lo::ServerThread& server(); const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); From c9486563275cf973b03c69cb211e224b3932eefa Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 23:52:45 +0200 Subject: [PATCH 130/363] src/networking/oscsender.*: Replacing all calls to is_server() and is_client() by the versions from OscHandler. Removing is_client() and is_server() declarations and implementations. --- src/networking/oscsender.cpp | 146 ++++++++++++++--------------------- src/networking/oscsender.h | 2 - 2 files changed, 57 insertions(+), 91 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f66b3c80..62b1efbd 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -39,7 +39,7 @@ void ssr::OscSender::start() { _controller.subscribe(this); _is_subscribed = true; - if (is_server()) + if (_handler.is_server()) { _poll_all_clients = true; std::thread _poll_thread(&OscSender::poll_all_clients, this); @@ -56,7 +56,7 @@ void ssr::OscSender::stop() { _controller.unsubscribe(this); _is_subscribed = false; - if (is_server()) + if (_handler.is_server()) { remove_all_clients(); _poll_all_clients = false; @@ -64,38 +64,6 @@ void ssr::OscSender::stop() } } -/** - * Returns true, if the instance of OscHandler is a 'client', false otherwise. - * @return true, if _oschandler.mode() returns 'client', false otherwise. - */ -bool ssr::OscSender::is_client() -{ - if(!_handler.mode().compare("client")) - { - return true; - } - else - { - return false; - } -} - -/** - * Returns true, if the instance of OscHandler is a 'server', false otherwise. - * @return true, if _oschandler.mode() returns 'server', false otherwise. - */ -bool ssr::OscSender::is_server() -{ - if(!_handler.mode().compare("server")) - { - return true; - } - else - { - return false; - } -} - /** * Returns true, if the _server_address is the default (setup at initialization) * @return true, if _server_address is the default, false otherwise. @@ -577,14 +545,14 @@ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& */ void ssr::OscSender::new_source(id_t id) { - if(is_server()) + if(_handler.is_server()) { if(!is_new_source(id)) _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) send_new_source_message_from_id(id); } - else if(is_client()) + else if(_handler.is_client()) { int32_t message_id = static_cast(id); _server_address.send_from(_handler.server(), "/update/source/new", "i", @@ -605,7 +573,7 @@ void ssr::OscSender::new_source(id_t id) void ssr::OscSender::delete_source(id_t id) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -619,7 +587,7 @@ void ssr::OscSender::delete_source(id_t id) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _source_levels.erase(id); _server_address.send_from(_handler.server(), "/update/source/delete", @@ -638,7 +606,7 @@ void ssr::OscSender::delete_source(id_t id) */ void ssr::OscSender::delete_all_sources() { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -651,7 +619,7 @@ void ssr::OscSender::delete_all_sources() } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/delete", "i", 0); @@ -676,7 +644,7 @@ void ssr::OscSender::delete_all_sources() bool ssr::OscSender::set_source_position(id_t id, const Position& position) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -701,7 +669,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); @@ -728,7 +696,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -753,7 +721,7 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); @@ -781,7 +749,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { int32_t message_id = static_cast(id); float message_orientation = orientation.azimuth; - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -806,7 +774,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); @@ -833,7 +801,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -856,7 +824,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/volume", "if", message_id, gain); @@ -883,7 +851,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && _new_sources.at(id).has_key("file_name_or_port_number")) @@ -908,7 +876,7 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/mute", "i"+_handler.bool_to_message_type(mute), message_id); @@ -936,7 +904,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { int32_t message_id = static_cast(id); const char * message_name = name.c_str(); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -960,7 +928,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); @@ -988,7 +956,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { int32_t message_id = static_cast(id); const char * file_name = name.c_str(); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && !name.empty()) { @@ -1012,7 +980,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); @@ -1033,7 +1001,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& */ void ssr::OscSender::set_decay_exponent(float exponent) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1047,7 +1015,7 @@ void ssr::OscSender::set_decay_exponent(float exponent) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); @@ -1069,7 +1037,7 @@ void ssr::OscSender::set_decay_exponent(float exponent) */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1083,7 +1051,7 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); @@ -1110,7 +1078,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) int32_t message_id = static_cast(id); std::string message_model = apf::str::A2S(model); if (message_model == "") return false; - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -1134,7 +1102,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); @@ -1160,7 +1128,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { int32_t message_id = static_cast(id); - if(is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); @@ -1191,7 +1159,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -1217,7 +1185,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/file_name_or_port_number", "is", message_id, @@ -1247,7 +1215,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { int32_t message_id = static_cast(id); int32_t message_file_channel = static_cast(file_channel); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && file_channel > 0) { @@ -1271,7 +1239,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); @@ -1298,7 +1266,7 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { int32_t message_id = static_cast(id); int32_t message_length = static_cast(length); - if(is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); @@ -1321,7 +1289,7 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) */ void ssr::OscSender::set_reference_position(const Position& position) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1336,7 +1304,7 @@ void ssr::OscSender::set_reference_position(const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); @@ -1358,7 +1326,7 @@ void ssr::OscSender::set_reference_position(const Position& position) */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1373,7 +1341,7 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); @@ -1396,7 +1364,7 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) */ void ssr::OscSender::set_reference_offset_position(const Position& position) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1411,7 +1379,7 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); @@ -1436,7 +1404,7 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1451,7 +1419,7 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); @@ -1474,7 +1442,7 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& void ssr::OscSender::set_master_volume(float volume) { float message_volume = apf::math::linear2dB(volume); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1488,7 +1456,7 @@ void ssr::OscSender::set_master_volume(float volume) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/volume", "f", message_volume); @@ -1527,7 +1495,7 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* */ void ssr::OscSender::set_processing_state(bool state) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1542,7 +1510,7 @@ void ssr::OscSender::set_processing_state(bool state) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); @@ -1567,7 +1535,7 @@ void ssr::OscSender::set_transport_state( const std::pair& state) { int32_t message_nframes = static_cast(state.second); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1588,7 +1556,7 @@ void ssr::OscSender::set_transport_state( const std::pair(sr); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1695,7 +1663,7 @@ void ssr::OscSender::set_sample_rate(int sr) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); @@ -1718,7 +1686,7 @@ void ssr::OscSender::set_sample_rate(int sr) void ssr::OscSender::set_master_signal_level(float level) { float message_level(apf::math::linear2dB(level)); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1734,7 +1702,7 @@ void ssr::OscSender::set_master_signal_level(float level) } } } - else if(is_client() && !server_is_default() && _message_level == + else if(_handler.is_client() && !server_is_default() && _message_level == MessageLevel::GUI_CLIENT) { _server_address.send_from(_handler.server(), @@ -1761,7 +1729,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { int32_t message_id = static_cast(id); float message_level(apf::math::linear2dB(level)); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1776,7 +1744,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) } } } - else if(is_client() && !server_is_default() && _message_level == + else if(_handler.is_client() && !server_is_default() && _message_level == MessageLevel::GUI_CLIENT) { _server_address.send_from(_handler.server(), "/update/source/level", diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index d8849439..3b280f00 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -57,8 +57,6 @@ class OscSender : public Subscriber source_level_map_t _source_levels; float _master_level; - bool is_client(); - bool is_server(); bool server_is_default(); void poll_all_clients(); void remove_all_clients(); From 7bdfc6d8e26fdeb248016c1ce75191b0441d115c Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 00:01:43 +0200 Subject: [PATCH 131/363] src/networking/oscreceiver.cpp: Using is_server() and is_client() in start(). Improving VERBOSE output of reference, reference_offset, scene, processing and transport message handlers by adding information on caller and displaying whole message sent properly. --- src/networking/oscreceiver.cpp | 179 ++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 68 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e72c5920..e0588cdd 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -39,7 +39,7 @@ void ssr::OscReceiver::start() { VERBOSE("OscReceiver: Starting."); // add method handlers for received messages - if (!_handler.mode().compare("server")) + if (_handler.is_server()) { add_client_to_server_methods(); add_update_notification_methods(); @@ -50,7 +50,7 @@ void ssr::OscReceiver::start() add_transport_methods(); add_tracker_methods(); } - else if (!_handler.mode().compare("client")) + else if (_handler.is_client()) { add_poll_methods(); add_source_methods(); @@ -544,10 +544,10 @@ void ssr::OscReceiver::add_poll_methods() (from.hostname().compare("none") != 0) ) { + VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << + ":" << from.port() << ". Subscribing..."); set_server_for_client(_handler, from); from.send_from(_handler.server(), "/subscribe", "T"); - VERBOSE2("OscReceiver: Got /poll from server " << from.hostname() << - ":" << from.port() << ". Subscribing..."); } } ); @@ -935,46 +935,55 @@ void ssr::OscReceiver::add_source_methods() void ssr::OscReceiver::add_reference_methods() { // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); - VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/position."); + VERBOSE("OscReceiver: Added method for /reference/position ff."); // set reference orientation: "/reference/orientation, f, azimuth" - _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/orientation, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_reference_orientation(Orientation(argv[0]->f)); - VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/orientation."); + VERBOSE("OscReceiver: Added method for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg - **argv, int) + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_offset_position(Position(argv[0]->f, argv[1]->f)); - VERBOSE2("set reference offset position: " << Position(argv[0]->f, - argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/position."); + VERBOSE("OscReceiver: Added method for /reference_offset/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg - **argv, int) + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); - VERBOSE2("set reference offset orientation: " << - Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); + VERBOSE("OscReceiver: Added method for /reference_offset/orientation f."); } /** @@ -989,39 +998,52 @@ void ssr::OscReceiver::add_reference_methods() void ssr::OscReceiver::add_scene_methods() { // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, + lo::Message message) { - _controller.save_scene_as_XML(std::string(&(argv[0]->s))); - VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.save_scene_as_XML(name); } ); - VERBOSE("OscReceiver: Added method for /scene/save."); + VERBOSE("OscReceiver: Added method for /scene/save s."); // load scene from file: "/scene/load, s, file" - _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, + lo::Message message) { - _controller.load_scene(std::string(&(argv[0]->s))); - VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.load_scene(name); } ); - VERBOSE("OscReceiver: Added method for /scene/load."); + VERBOSE("OscReceiver: Added method for /scene/load s."); // set master volume: "/scene/volume, f, volume" - _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << - " dB"); } ); - VERBOSE("OscReceiver: Added method for /scene/volume."); + VERBOSE("OscReceiver: Added method for /scene/volume f."); // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: [/scene/clear] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.delete_all_sources(); - VERBOSE2("clearing scene."); } ); VERBOSE("OscReceiver: Added method for /scene/clear."); @@ -1040,24 +1062,30 @@ void ssr::OscReceiver::add_scene_methods() void ssr::OscReceiver::add_processing_methods() { // set processing state: "/processing/state, T, true" - _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", NULL, [this](lo_arg **argv, + int, lo::Message message) { (void) argv; - _controller.start_processing(); - VERBOSE2("start processing."); + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/processing/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.start_processing(); + } + else if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/processing/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.stop_processing(); + } } ); - VERBOSE("OscReceiver: Added method for /processing/state true."); + VERBOSE("OscReceiver: Added method for /processing/state {T,F}."); - // set processing state: "/processing/state, F, false" - _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) - { - (void) argv; - _controller.stop_processing(); - VERBOSE2("stop processing."); - } - ); - VERBOSE("OscReceiver: Added method for /processing/state false."); } /** @@ -1073,52 +1101,64 @@ void ssr::OscReceiver::add_processing_methods() void ssr::OscReceiver::add_transport_methods() { // set transport state: "transport/state, T, true" - _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, int) - { - (void) argv; - _controller.transport_start(); - VERBOSE2("start transport."); - } - ); - VERBOSE("OscReceiver: Added method for /transport/state true."); - - // set transport state: "/transport/state, F, false" - _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; - _controller.transport_stop(); - VERBOSE2("stop transport."); + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_start(); + } + if(!message.types().compare("F")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_stop(); + } } ); - VERBOSE("OscReceiver: Added method for /transport/state false."); + VERBOSE("OscReceiver: Added method for /transport/state {T,F}."); // rewind transport state: "/transport/rewind" - _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg + **argv, int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: Got [/transport/rewind] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.transport_locate(0); - VERBOSE2("rewind transport."); } ); VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, + int, lo::Message message) { float time; - if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) + std::string message_time(&argv[0]->s); + if(apf::str::string2time(message_time, time)) { + VERBOSE2("OscReceiver: Got [/transport/seek, " << message_time << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_locate(time); - VERBOSE2("Seek transport to: " << time); } else { ERROR("Couldn't get the time out of the \"seek\" attribute (\"" - << argv[0]->s << "\")."); + << message_time << "\")."); } } ); - VERBOSE("OscReceiver: Added method for /transport/seek."); + VERBOSE("OscReceiver: Added method for /transport/seek s."); } /** @@ -1133,11 +1173,14 @@ void ssr::OscReceiver::add_transport_methods() void ssr::OscReceiver::add_tracker_methods() { // reset tracker: "/tracker/reset" - _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: Got [/tracker/reset] from client " << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.calibrate_client(); - VERBOSE2("calibrate tracker."); } ); VERBOSE("OscReceiver: Added method for /tracker/reset."); From 181d6257a98e114f26c05dd6612ce235b726b5a5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 13:48:41 +0200 Subject: [PATCH 132/363] src/networking/oscsender.cpp, src/networking/oscsender.cpp: Renaming all source related mentions of volume to gain to be consistent with the Publisher/Subscriber interface. --- src/networking/oscreceiver.cpp | 28 ++++++++++++------------ src/networking/oscsender.cpp | 40 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e0588cdd..1da0f0f2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -202,16 +202,16 @@ void ssr::OscReceiver::add_update_notification_methods() ); VERBOSE("OscReceiver: Added method for /update/source/orientation."); - // update on source volume: "/update/source/volume, if, id, volume" - _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, + // update on source gain: "/update/source/gain, if, id, gain" + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", volume: "<< argv[1]->f << "."); + argv[0]->i << ", gain: "<< argv[1]->f << "."); } ); - VERBOSE("OscReceiver: Added method for /update/source/volume."); + VERBOSE("OscReceiver: Added method for /update/source/gain."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, @@ -612,18 +612,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/orientation if."); - // set source volume: "/source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, + // set source gain: "/source/gain, if, id, gain" + _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/volume, " << argv[0]->i << ", " << + VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/volume if."); + VERBOSE("OscReceiver: Added method for /source/gain if."); // set source mute: "source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, @@ -706,10 +706,10 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, volume, position_fixed, + // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, volume, channel, + // file_name_or_port_number, x, y, orientation, gain, channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -719,7 +719,7 @@ void ssr::OscReceiver::add_source_methods() std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); - float volume(argv[6]->f); + float gain(argv[6]->f); int channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; @@ -874,7 +874,7 @@ void ssr::OscReceiver::add_source_methods() { VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << ", " - << orientation.azimuth << ", " << volume << ", " << + << orientation.azimuth << ", " << gain<< ", " << channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << @@ -882,7 +882,7 @@ void ssr::OscReceiver::add_source_methods() message.source().hostname() << ":" << message.source().port() << "'."); _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, volume, + position, position_fixed, orientation, orientation_fixed, gain, muted, properties_file); VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << @@ -893,7 +893,7 @@ void ssr::OscReceiver::add_source_methods() "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << "\norientation_fixed: " << orientation_fixed << - "\nvolume (linear): " << volume << + "\ngain (linear): " << gain << "\nmuted: " << muted << "\nproperties_file: " << properties_file); } diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 62b1efbd..29225784 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -286,7 +286,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && @@ -299,7 +299,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && _new_sources.at(id).has_key("mute") && @@ -323,7 +323,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && @@ -349,7 +349,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0), _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), - _new_sources.at(id).get("volume", 0.0), + _new_sources.at(id).get("gain", 0.0), _new_sources.at(id).get("channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << @@ -366,7 +366,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0) << ", " << _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << - _new_sources.at(id).get("volume", 0.0) << ", " << + _new_sources.at(id).get("gain", 0.0) << ", " << _new_sources.at(id).get("channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") << "] to client " << @@ -381,7 +381,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && _new_sources.at(id).has_key("mute")) @@ -405,7 +405,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0), _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), - _new_sources.at(id).get("volume", 0.0)); + _new_sources.at(id).get("gain", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << _handler.bool_to_message_type( _new_sources.at(id).get( "position_fixed", false)) << @@ -420,7 +420,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0) << ", " << _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << - _new_sources.at(id).get("volume", 0.0) + _new_sources.at(id).get("gain", 0.0) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); @@ -567,7 +567,7 @@ void ssr::OscSender::new_source(id_t id) * Subscriber function called, when Publisher deleted a source. * On server: Sends out OSC message all clients to delete source with given id. * On client: Sends out OSC message about successful deletion of source with id - * to server and erases complementing volume level from _source_levels. + * to server and erases complementing gain level from _source_levels. * @param id id_t representing the source */ void ssr::OscSender::delete_source(id_t id) @@ -778,7 +778,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { _server_address.send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); - VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -787,15 +787,15 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } /** - * Subscriber function called, when Publisher set a source's volume. - * On server: Sends out OSC message to set volume of given source on all - * clients. If id is found in _new_sources, the volume will be stored in the + * Subscriber function called, when Publisher set a source's gain. + * On server: Sends out OSC message to set gain of given source on all + * clients. If id is found in _new_sources, the gain will be stored in the * parameter_map for id and an OSC message will be send to clients only, if the * source is complete. * On client: Sends out OSC to server message about the successful updating of - * the source's volume. + * the source's gain. * @param id id_t representing the source - * @param gain new volume of source + * @param gain new gain of source * @return true */ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) @@ -805,7 +805,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(is_new_source(id)) { - _new_sources.at(id).set("volume", gain); + _new_sources.at(id).set("gain", gain); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -815,9 +815,9 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/volume", + client->address().send_from(_handler.server(), "/source/gain", "if", message_id, gain); - VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << + VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " << gain << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -826,9 +826,9 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/volume", + _server_address.send_from(_handler.server(), "/update/source/gain", "if", message_id, gain); - VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); From da910cc508c70aa51afd8c4aeb80345529cb7d03 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 14:57:28 +0200 Subject: [PATCH 133/363] src/networking/oscreceiver.cpp: Minor fixes in comments. TODO for exception handling in is_new_source(). Erasing source information from _new_sources after the /source/new message has been sent to clients. --- src/networking/oscreceiver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 1da0f0f2..b5a678ff 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -565,7 +565,7 @@ void ssr::OscReceiver::add_poll_methods() */ void ssr::OscReceiver::add_source_methods() { - // set source position: "source/position, iff, id, x, y" + // set source position: "/source/position, iff, id, x, y" _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int, lo::Message message) { @@ -578,7 +578,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position iff."); - // set source fixed: "source/position_fixed, i{T,F}, id, true|false" + // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -600,7 +600,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); - // set source orientation: "source/orientation, if, id, azimuth" + // set source orientation: "/source/orientation, if, id, azimuth" _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int, lo::Message message) { @@ -625,7 +625,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/gain if."); - // set source mute: "source/mute, i{T,F}, id, true|false" + // set source mute: "/source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -647,7 +647,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); - // set source name: "source/name, is, id, name" + // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, lo::Message message) { From d50da8382a9e99d9ace31f6afcbeafbd058d27a8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 14:57:28 +0200 Subject: [PATCH 134/363] src/networking/oscreceiver.cpp: Minor fixes in comments. --- src/networking/oscreceiver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 1da0f0f2..b5a678ff 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -565,7 +565,7 @@ void ssr::OscReceiver::add_poll_methods() */ void ssr::OscReceiver::add_source_methods() { - // set source position: "source/position, iff, id, x, y" + // set source position: "/source/position, iff, id, x, y" _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int, lo::Message message) { @@ -578,7 +578,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position iff."); - // set source fixed: "source/position_fixed, i{T,F}, id, true|false" + // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -600,7 +600,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); - // set source orientation: "source/orientation, if, id, azimuth" + // set source orientation: "/source/orientation, if, id, azimuth" _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int, lo::Message message) { @@ -625,7 +625,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/gain if."); - // set source mute: "source/mute, i{T,F}, id, true|false" + // set source mute: "/source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -647,7 +647,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); - // set source name: "source/name, is, id, name" + // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, lo::Message message) { From 941d65486c09a81d6edeaf9ee3d34324ab8bbdcc Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 15:32:47 +0200 Subject: [PATCH 135/363] src/networking/oscsender.cpp: Erasing source from _new_sources once the assembled /source/new message has been sent out to clients. TODO about exception handling in is_new_source(). --- src/networking/oscsender.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 29225784..09d28f98 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -260,6 +260,7 @@ bool ssr::OscSender::is_new_source(id_t id) { if (_new_sources.empty()) return false; + //TODO: introduce exception handling for this call if(_new_sources.find(id) != _new_sources.end()) { return true; @@ -374,6 +375,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) client->address().port() << "."); } } + _new_sources.erase(id); } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -426,6 +428,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) client->address().port() << "."); } } + _new_sources.erase(id); } } From d12b118fde4cb1f39dc1f73370983c5f64c7b90b Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 15:57:58 +0200 Subject: [PATCH 136/363] src/networking/oscsender.*: Adding private member for setting the /poll message frequency in milliseconds. Removing commented, now obsolete function bool_to_message_type(). --- src/networking/oscsender.cpp | 22 +++------------------- src/networking/oscsender.h | 1 + 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 09d28f98..0bfed9c2 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -58,9 +58,9 @@ void ssr::OscSender::stop() _is_subscribed = false; if (_handler.is_server()) { - remove_all_clients(); _poll_all_clients = false; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(_poll_milliseconds)); + remove_all_clients(); } } @@ -81,22 +81,6 @@ bool ssr::OscSender::server_is_default() } } -///** -// * Returns true, if the _server_address is the default (setup at initialization) -// * @return true, if _server_address is the default, false otherwise. -// */ -//const std::string ssr::OscSender::bool_to_message_type(const bool& message) -//{ -// if(message) -// { -// return _message_type_true; -// } -// else -// { -// return _message_type_false; -// } -//} - /** * Sends a '/poll' message to all client instances listed in _clients, then * makes the thread calling this function sleep for 1000 milliseconds @@ -114,7 +98,7 @@ void ssr::OscSender::poll_all_clients() } } //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(_poll_milliseconds)); } VERBOSE2("OscSender: Stopped polling all clients."); } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 3b280f00..6bc4eb1c 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -52,6 +52,7 @@ class OscSender : public Subscriber std::map _new_sources; // thread used for calling poll_all_clients continuously std::thread _poll_thread; + const unsigned int _poll_milliseconds{1000}; bool _poll_all_clients; typedef std::map source_level_map_t; source_level_map_t _source_levels; From f91e37075f0157e311ba1b61fda39114a5f7986c Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 20:24:43 +0200 Subject: [PATCH 137/363] src/publisher.h: Adding set_source_file_channel() to public Publisher interface. --- src/publisher.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/publisher.h b/src/publisher.h index f8f7ea87..3f4c1739 100644 --- a/src/publisher.h +++ b/src/publisher.h @@ -113,6 +113,7 @@ struct Publisher set_source_port_name(id_t id, const std::string& port_name) = 0; virtual void set_source_position_fixed(id_t id, const bool fix) = 0; + virtual void set_source_file_channel(id_t id, const int& channel) = 0; /// set position of the reference /// @param position well, the position From 60f4c9c2c88b3b74c07c96de7b20f9bd4d495a12 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 20:27:13 +0200 Subject: [PATCH 138/363] src/networking/oscreceiver.cpp: Adding callback function for /source/file_channel. Renaming all channel variables to file_channel for consistency. src/networking/oscsender.cpp: Renaming all channel variables to file_channel for consistency. --- src/networking/oscreceiver.cpp | 64 ++++++++++++++++++++-------------- src/networking/oscsender.cpp | 10 +++--- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b5a678ff..14f2fc3b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -317,16 +317,16 @@ void ssr::OscReceiver::add_update_notification_methods() VERBOSE("OscReceiver: Added method for \ /update/source/file_name_or_port_number."); - // update on source channel: "/update/source/channel, ii, id, channel" - _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + // update on source file_channel: "/update/source/file_channel, ii, id, file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", channel: "<< argv[1]->i << "."); + argv[0]->i << ", file_channel: "<< argv[1]->i << "."); } ); - VERBOSE("OscReceiver: Added method for /update/source/channel."); + VERBOSE("OscReceiver: Added method for /update/source/file_channel."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, @@ -612,6 +612,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/orientation if."); + // set source file_channel: "/source/file_channel, ii, id, file_channel" + _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " + << argv[1]->i << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + } + ); + VERBOSE("OscReceiver: Added method for /source/file_channel ii."); + // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) @@ -709,7 +721,7 @@ void ssr::OscReceiver::add_source_methods() // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, gain, channel, + // file_name_or_port_number, x, y, orientation, gain, file_channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -720,7 +732,7 @@ void ssr::OscReceiver::add_source_methods() float x(argv[3]->f); float y(argv[4]->f); float gain(argv[6]->f); - int channel = 0; + int file_channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; bool position_fixed; @@ -792,9 +804,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTTT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = true; @@ -802,9 +814,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTTF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = false; @@ -812,9 +824,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTFF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = false; @@ -822,9 +834,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFFF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = false; @@ -832,9 +844,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTFT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = true; @@ -842,9 +854,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFTF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = false; @@ -852,9 +864,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFTT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = true; @@ -862,9 +874,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFFT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = true; @@ -881,14 +893,14 @@ void ssr::OscReceiver::add_source_methods() _handler.bool_to_string(muted) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, gain, - muted, properties_file); + _controller.new_source(name, model, file_name_or_port_number, + file_channel, position, position_fixed, orientation, + orientation_fixed, gain, muted, properties_file); VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << - "\nchannel: " << channel << + "\nfile_channel: " << file_channel << "\nposition: " << position << "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0bfed9c2..5d607887 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -272,7 +272,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && _new_sources.at(id).has_key("gain") && - _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("file_channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && @@ -309,7 +309,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && _new_sources.at(id).has_key("gain") && - _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("file_channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && @@ -335,7 +335,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), _new_sources.at(id).get("gain", 0.0), - _new_sources.at(id).get("channel", 1), + _new_sources.at(id).get("file_channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << _handler.bool_to_message_type(_new_sources.at(id).get( @@ -352,7 +352,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << _new_sources.at(id).get("gain", 0.0) << ", " << - _new_sources.at(id).get("channel", 1) << ", " << + _new_sources.at(id).get("file_channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") << "] to client " << client->address().hostname() << ":" << @@ -1206,7 +1206,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { if(is_new_source(id) && file_channel > 0) { - _new_sources.at(id).set("channel", file_channel); + _new_sources.at(id).set("file_channel", file_channel); if(is_complete_source(id)) send_new_source_message_from_id(id); } From 89fd1f5deca9fb78398fab67bd04de80802b80c1 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:24:44 +0200 Subject: [PATCH 139/363] src/networking/oscreceiver.cpp: Making VERBOSE output of /update callback handlers more readable, adhering to the output of the other handlers. Fixing line wraps. --- src/networking/oscreceiver.cpp | 468 +++++++++++++++++---------------- 1 file changed, 244 insertions(+), 224 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 14f2fc3b..d3bf01f0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -79,8 +79,8 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // adding new subscribing client: "/subscribe, {T,Ti,F}" - _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, + lo::Message message) { lo::Address client(message.source()); if(!message.types().compare("T")) @@ -100,15 +100,16 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got subscribe request from '" << client.hostname() << ":" << client.port() << "' for message level: " << argv[1]->i); - add_client(_handler, client, static_cast(argv[1]->i)); + add_client(_handler, client, + static_cast(argv[1]->i)); } } ); VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) { lo::Address client(message.source()); VERBOSE2("OscReceiver: Got request to set message level for client '" << @@ -129,141 +130,142 @@ void ssr::OscReceiver::add_client_to_server_methods() void ssr::OscReceiver::add_update_notification_methods() { // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << " created."); + VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/new."); + VERBOSE("OscReceiver: Added method for /update/source/new i."); // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - if(argv[0]->i == 0) - { - VERBOSE3("Update: Client '" << client.hostname() << - "', all sources deleted."); - } - else - { - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " - << argv[0]->i << " deleted."); - } + VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/delete."); + VERBOSE("OscReceiver: Added method for /update/source/delete i."); // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/position", "iff", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << - "."); + VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position."); + VERBOSE("OscReceiver: Added method for /update/source/position iff."); - // update on source position fixation: "/update/source/position_fixed, i{T,F}, - // id, {true,false}" + // update on source position fixation: "/update/source/position_fixed, + // i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string position_fixed; - if(message.types() == "iT") + bool state; + if(!message.types().compare("iT")) { - position_fixed = "true"; + state = true; } - else if(message.types() == "iF") + else if(!message.types().compare("iF")) { - position_fixed = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position_fixed: "<< position_fixed << "."); + VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(state) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); + VERBOSE("OscReceiver: Added method for /update/source/position_fixed\ +i{F,T}."); - // update on source orientation: "/update/source/orientation, if, id, azimuth" + // update on source orientation: "/update/source/orientation, if, id, + // azimuth" _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", orientation: "<< argv[1]->f << "."); + VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/orientation."); + VERBOSE("OscReceiver: Added method for /update/source/orientation if."); // update on source gain: "/update/source/gain, if, id, gain" - _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", gain: "<< argv[1]->f << "."); + VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/gain."); + VERBOSE("OscReceiver: Added method for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; - if(message.types() == "iT") + bool state; + if(!message.types().compare("iT")) { - state = "true"; + state = true; } - else if(message.types() == "iF") + else if(!message.types().compare("iF")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - apf::str::A2S(argv[0]->i) << ", mute: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << + ", " << _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/mute."); + VERBOSE("OscReceiver: Added method for /update/source/mute i{F,T}."); // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", name: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/name."); + VERBOSE("OscReceiver: Added method for /update/source/name is."); // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/properties_file", "is", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", properties_file: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/properties_file."); + VERBOSE("OscReceiver: Added method for /update/source/properties_file is."); // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', decay_exponent: "<< argv[0]->f << "."); + VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); @@ -271,255 +273,272 @@ void ssr::OscReceiver::add_update_notification_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", - [](lo_arg **argv, int, lo::Message message) + _handler.server().add_method("/update/scene/amplitude_reference_distance", + "f", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', amplitude_reference_distance: "<< argv[0]->f << "."); + VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + << argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/scene/amplitude_reference_distance."); +/update/scene/amplitude_reference_distance f."); // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", model: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/model."); + VERBOSE("OscReceiver: Added method for /update/source/model is."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", port_name: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/port_name."); + VERBOSE("OscReceiver: Added method for /update/source/port_name is."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/file_name_or_port_number, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/source/file_name_or_port_number."); +/update/source/file_name_or_port_number is."); - // update on source file_channel: "/update/source/file_channel, ii, id, file_channel" - _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, - lo::Message message) + // update on source file_channel: "/update/source/file_channel, ii, id, + // file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", file_channel: "<< argv[1]->i << "."); + VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/file_channel."); + VERBOSE("OscReceiver: Added method for /update/source/file_channel ii."); // update on source file length: "/update/source/length, ii, id, length" - _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", length: "<< argv[1]->i << "."); + VERBOSE3("OscReceiver: Got [/update/source/length, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/length."); + VERBOSE("OscReceiver: Added method for /update/source/length ii."); // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference position: "<< argv[0]->f << "/" << argv[1]->f << - " (x/y)."); + VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/position."); + VERBOSE("OscReceiver: Added method for /update/reference/position ff."); // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/orientation."); + VERBOSE("OscReceiver: Added method for /update/reference/orientation f."); // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/reference_offset/position", "ff", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference offset position: "<< argv[0]->f << "/" << argv[1]->f - << " (x/y)."); + VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + argv[0]->f << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference_offset/position."); + VERBOSE("OscReceiver: Added method for /update/reference_offset/position \ +ff."); // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/reference_offset/orientation", "f", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference offset orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << + message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/reference_offset/orientation."); +/update/reference_offset/orientation f."); // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', scene volume: "<< - argv[0]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/volume."); + VERBOSE("OscReceiver: Added method for /update/scene/volume f."); - // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, - lo::Message message) + // update on state processing: "/update/processing/state, {T,F}, + // {true,false}" + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', state processing: " << state << "."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/processing/state."); + VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', transport state: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/transport/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/state."); + VERBOSE("OscReceiver: Added method for /update/transport/state {F,T}."); // update on transport seek: "/update/transport/seek, s, time" - _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', transport seek: "<< argv[0]->s << "."); + std::string seek = &argv[0]->s; + VERBOSE3("OscReceiver: Got [/update/transport/seek, " << seek << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/seek."); + VERBOSE("OscReceiver: Added method for /update/transport/seek s."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg - **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', scene auto_rotate_sources: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); + VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources \ +{F,T}."); // update on cpu_load: "/update/cpu_load, f, load" _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', cpu_load: "<< - argv[0]->f << "%."); + VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/cpu_load."); + VERBOSE("OscReceiver: Added method for /update/cpu_load f."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', scene sample_rate: "<< argv[0]->i << "Hz."); + VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/sample_rate."); + VERBOSE("OscReceiver: Added method for /update/scene/sample_rate i."); - // update on scene master signal level: "/update/scene/master_signal_level, f, - // master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg - **argv, int, lo::Message message) + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/update/scene/master_signal_level", "f", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', scene master_signal_level: "<< argv[0]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); + VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level \ +f."); // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", level: "<< argv[1]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << + ", "<< argv[1]->f << "] from client '" << message.source().hostname() + << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/level."); + VERBOSE("OscReceiver: Added method for /update/source/level if."); } /** @@ -532,8 +551,8 @@ void ssr::OscReceiver::add_poll_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, + lo::Message message) { lo::Address server(server_address(_handler)); lo::Address from(message.source()); @@ -613,8 +632,8 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/orientation if."); // set source file_channel: "/source/file_channel, ii, id, file_channel" - _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg + **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << @@ -661,7 +680,7 @@ void ssr::OscReceiver::add_source_methods() // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, - lo::Message message) + lo::Message message) { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << @@ -674,8 +693,8 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg + **argv, int, lo::Message message) { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << @@ -911,7 +930,8 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new {sssffff,sssffffis}{F,T}{F,T}{F,T}."); + VERBOSE("OscReceiver: Added method for /source/new \ +{sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! @@ -971,8 +991,8 @@ void ssr::OscReceiver::add_reference_methods() VERBOSE("OscReceiver: Added method for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/reference_offset/position", "ff" , + [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << @@ -986,8 +1006,8 @@ void ssr::OscReceiver::add_reference_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/reference_offset/orientation", "f" , + [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" From f00c51634247976f6aa9e3f3632f025b30c29520 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:31:24 +0200 Subject: [PATCH 140/363] src/networking/oscreceiver.cpp: Capturing *this for callbacks, that need to access its functions. --- src/networking/oscreceiver.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d3bf01f0..0ed6577c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -165,8 +165,8 @@ void ssr::OscReceiver::add_update_notification_methods() // update on source position fixation: "/update/source/position_fixed, // i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/source/position_fixed", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; if(!message.types().compare("iT")) @@ -212,8 +212,8 @@ i{F,T}."); VERBOSE("OscReceiver: Added method for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg + **argv, int, lo::Message message) { bool state; if(!message.types().compare("iT")) @@ -415,7 +415,7 @@ ff."); // update on state processing: "/update/processing/state, {T,F}, // {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg + _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg **argv, int, lo::Message message) { bool state; @@ -437,7 +437,7 @@ ff."); VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg + _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg **argv, int, lo::Message message) { bool state; @@ -473,7 +473,7 @@ ff."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, - [](lo_arg **argv, int, lo::Message message) + [this](lo_arg **argv, int, lo::Message message) { bool state; (void) argv; From 16e8fcd1172527ccad24c0bfb872766b5fd76530 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:34:28 +0200 Subject: [PATCH 141/363] src/networking/oscreceiver.cpp: Changing VERBOSE output to 'Added callback...' instead of 'Added method...' for each callback add. --- src/networking/oscreceiver.cpp | 114 ++++++++++++++++----------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0ed6577c..8253612b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -105,7 +105,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); + VERBOSE("OscReceiver: Added callback for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, @@ -118,7 +118,7 @@ void ssr::OscReceiver::add_client_to_server_methods() static_cast(argv[0]->i)); } ); - VERBOSE("OscReceiver: Added method for /message_level i."); + VERBOSE("OscReceiver: Added callback for /message_level i."); } /** @@ -138,7 +138,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/new i."); + VERBOSE("OscReceiver: Added callback for /update/source/new i."); // update on deleted source: "/update/source/delete, i, id" _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, @@ -149,7 +149,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/delete i."); + VERBOSE("OscReceiver: Added callback for /update/source/delete i."); // update on source position: "/update/source/position, iff, id, x, y" _handler.server().add_method("/update/source/position", "iff", [](lo_arg @@ -161,7 +161,7 @@ void ssr::OscReceiver::add_update_notification_methods() "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position iff."); + VERBOSE("OscReceiver: Added callback for /update/source/position iff."); // update on source position fixation: "/update/source/position_fixed, // i{T,F}, id, {true,false}" @@ -183,7 +183,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position_fixed\ + VERBOSE("OscReceiver: Added callback for /update/source/position_fixed\ i{F,T}."); // update on source orientation: "/update/source/orientation, if, id, @@ -197,7 +197,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/orientation if."); + VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); // update on source gain: "/update/source/gain, if, id, gain" _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, @@ -209,7 +209,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/gain if."); + VERBOSE("OscReceiver: Added callback for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg @@ -230,7 +230,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/mute i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); // update on source name: "/update/source/name, is, id, name" _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, @@ -242,7 +242,7 @@ i{F,T}."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/name is."); + VERBOSE("OscReceiver: Added callback for /update/source/name is."); // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" @@ -256,7 +256,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" @@ -268,7 +268,7 @@ i{F,T}."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, @@ -281,7 +281,7 @@ i{F,T}."); ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/scene/amplitude_reference_distance f."); // update on source model: "/update/source/model, is, id, model" @@ -295,7 +295,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/model is."); + VERBOSE("OscReceiver: Added callback for /update/source/model is."); // update on source port_name: "/update/source/port_name, is, id, port_name" _handler.server().add_method("/update/source/port_name", "is", [](lo_arg @@ -308,7 +308,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/port_name is."); + VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" @@ -322,7 +322,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/source/file_name_or_port_number is."); // update on source file_channel: "/update/source/file_channel, ii, id, @@ -336,7 +336,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, @@ -348,7 +348,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/length ii."); + VERBOSE("OscReceiver: Added callback for /update/source/length ii."); // update on reference position: "/update/reference/position, ff, x, y" _handler.server().add_method("/update/reference/position", "ff", [](lo_arg @@ -360,7 +360,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/position ff."); + VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); // update on reference orientation: "/update/reference/orientation, f, // azimuth" @@ -372,7 +372,7 @@ i{F,T}."); << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); // update on reference offset position: "/update/reference_offset/position, // ff, x, y" @@ -385,7 +385,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference_offset/position \ + VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ ff."); // update on reference offset orientation: @@ -399,7 +399,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/reference_offset/orientation f."); // update on scene volume: "/update/scene/volume, f, volume" @@ -411,7 +411,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/volume f."); + VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); // update on state processing: "/update/processing/state, {T,F}, // {true,false}" @@ -434,7 +434,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg @@ -456,7 +456,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); // update on transport seek: "/update/transport/seek, s, time" _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, @@ -468,7 +468,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/seek s."); + VERBOSE("OscReceiver: Added callback for /update/transport/seek s."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" @@ -491,7 +491,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources \ + VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ {F,T}."); // update on cpu_load: "/update/cpu_load, f, load" @@ -503,7 +503,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/cpu_load f."); + VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg @@ -514,7 +514,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/sample_rate i."); + VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); // update on scene master signal level: "/update/scene/master_signal_level, // f, master_signal_level" @@ -526,7 +526,7 @@ ff."); << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level \ + VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ f."); // update on source signal level: "/update/source/level, if, id, level" @@ -538,7 +538,7 @@ f."); << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/level if."); + VERBOSE("OscReceiver: Added callback for /update/source/level if."); } /** @@ -570,7 +570,7 @@ void ssr::OscReceiver::add_poll_methods() } } ); - VERBOSE("OscReceiver: Added method for /poll."); + VERBOSE("OscReceiver: Added callback for /poll."); } /** @@ -595,7 +595,7 @@ void ssr::OscReceiver::add_source_methods() argv[2]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/position iff."); + VERBOSE("OscReceiver: Added callback for /source/position iff."); // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg @@ -617,7 +617,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/position_fixed i{T,F}."); // set source orientation: "/source/orientation, if, id, azimuth" _handler.server().add_method("/source/orientation", "if", [this](lo_arg @@ -629,7 +629,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/orientation if."); + VERBOSE("OscReceiver: Added callback for /source/orientation if."); // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg @@ -641,7 +641,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } ); - VERBOSE("OscReceiver: Added method for /source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, @@ -654,7 +654,7 @@ void ssr::OscReceiver::add_source_methods() apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/gain if."); + VERBOSE("OscReceiver: Added callback for /source/gain if."); // set source mute: "/source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, @@ -676,7 +676,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/mute i{T,F}."); // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, @@ -690,7 +690,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/name is."); + VERBOSE("OscReceiver: Added callback for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" _handler.server().add_method("/source/properties_file", "is", [this](lo_arg @@ -703,7 +703,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_properties_file(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /source/properties_file is."); // set source model: "/source/model, is, id, model" _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, @@ -721,7 +721,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_model(argv[0]->i, model); } ); - VERBOSE("OscReceiver: Added method for /source/model is."); + VERBOSE("OscReceiver: Added callback for /source/model is."); // set source port name: "/source/port_name, is, id, port_name" _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, @@ -734,7 +734,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_port_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/port_name is."); + VERBOSE("OscReceiver: Added callback for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, gain, position_fixed, @@ -930,7 +930,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new \ + VERBOSE("OscReceiver: Added callback for /source/new \ {sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" @@ -951,7 +951,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/delete i."); + VERBOSE("OscReceiver: Added callback for /source/delete i."); } /** @@ -976,7 +976,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/position ff."); + VERBOSE("OscReceiver: Added callback for /reference/position ff."); // set reference orientation: "/reference/orientation, f, azimuth" _handler.server().add_method("/reference/orientation", "f", [this](lo_arg @@ -988,7 +988,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_orientation(Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" _handler.server().add_method("/reference_offset/position", "ff" , @@ -1002,7 +1002,7 @@ void ssr::OscReceiver::add_reference_methods() argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/position ff."); + VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" @@ -1015,7 +1015,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/orientation f."); + VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); } /** @@ -1040,7 +1040,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.save_scene_as_XML(name); } ); - VERBOSE("OscReceiver: Added method for /scene/save s."); + VERBOSE("OscReceiver: Added callback for /scene/save s."); // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, @@ -1053,7 +1053,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.load_scene(name); } ); - VERBOSE("OscReceiver: Added method for /scene/load s."); + VERBOSE("OscReceiver: Added callback for /scene/load s."); // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, @@ -1065,7 +1065,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /scene/volume f."); + VERBOSE("OscReceiver: Added callback for /scene/volume f."); // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, @@ -1078,7 +1078,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added method for /scene/clear."); + VERBOSE("OscReceiver: Added callback for /scene/clear."); } /** @@ -1116,7 +1116,7 @@ void ssr::OscReceiver::add_processing_methods() } } ); - VERBOSE("OscReceiver: Added method for /processing/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /processing/state {T,F}."); } @@ -1155,7 +1155,7 @@ void ssr::OscReceiver::add_transport_methods() } } ); - VERBOSE("OscReceiver: Added method for /transport/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /transport/state {T,F}."); // rewind transport state: "/transport/rewind" _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg @@ -1168,7 +1168,7 @@ void ssr::OscReceiver::add_transport_methods() _controller.transport_locate(0); } ); - VERBOSE("OscReceiver: Added method for /transport/rewind."); + VERBOSE("OscReceiver: Added callback for /transport/rewind."); // seek transport state: "/transport/seek, s, time" _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, @@ -1190,7 +1190,7 @@ void ssr::OscReceiver::add_transport_methods() } } ); - VERBOSE("OscReceiver: Added method for /transport/seek s."); + VERBOSE("OscReceiver: Added callback for /transport/seek s."); } /** @@ -1215,6 +1215,6 @@ void ssr::OscReceiver::add_tracker_methods() _controller.calibrate_client(); } ); - VERBOSE("OscReceiver: Added method for /tracker/reset."); + VERBOSE("OscReceiver: Added callback for /tracker/reset."); } From 2c771262432a133faaf90de6e65efee77c723076 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 22:33:37 +0200 Subject: [PATCH 142/363] src/networking/oscreceiver.cpp: Ordering all callback handlers alphabetically for readability. Unifying output style of message types. --- src/networking/oscreceiver.cpp | 827 +++++++++++++++++---------------- 1 file changed, 414 insertions(+), 413 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 8253612b..e96a0027 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -42,23 +42,23 @@ void ssr::OscReceiver::start() if (_handler.is_server()) { add_client_to_server_methods(); - add_update_notification_methods(); - add_source_methods(); + add_processing_methods(); add_reference_methods(); add_scene_methods(); - add_processing_methods(); - add_transport_methods(); + add_source_methods(); add_tracker_methods(); + add_transport_methods(); + add_update_notification_methods(); } else if (_handler.is_client()) { add_poll_methods(); - add_source_methods(); add_reference_methods(); add_scene_methods(); + add_source_methods(); add_processing_methods(); - add_transport_methods(); add_tracker_methods(); + add_transport_methods(); } } @@ -78,6 +78,19 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + // adding new subscribing client: "/message_level, i" + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("OscReceiver: Got request to set message level for client '" << + client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + set_message_level(_handler, client, + static_cast(argv[0]->i)); + } + ); + VERBOSE("OscReceiver: Added callback for /message_level i."); + // adding new subscribing client: "/subscribe, {T,Ti,F}" _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -105,20 +118,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added callback for /subscribe {T,F,Ti}."); - - // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, - int, lo::Message message) - { - lo::Address client(message.source()); - VERBOSE2("OscReceiver: Got request to set message level for client '" << - client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); - set_message_level(_handler, client, - static_cast(argv[0]->i)); - } - ); - VERBOSE("OscReceiver: Added callback for /message_level i."); + VERBOSE("OscReceiver: Added callback for /subscribe {F,T,Ti}."); } /** @@ -129,186 +129,200 @@ void ssr::OscReceiver::add_client_to_server_methods() */ void ssr::OscReceiver::add_update_notification_methods() { - // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, - int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i - << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/new i."); - - // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, - int, lo::Message message) + // update on cpu_load: "/update/cpu_load, f, load" + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i - << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/delete i."); + VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); - // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg + // update on state processing: "/update/processing/state, {F,T}, + // false|true" + _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << - ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/position iff."); - - // update on source position fixation: "/update/source/position_fixed, - // i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, - [this](lo_arg **argv, int, lo::Message message) { bool state; - if(!message.types().compare("iT")) + (void) argv; + if(!message.types().compare("T")) { state = true; } - else if(!message.types().compare("iF")) + else if(!message.types().compare("F")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << - argv[0]->i << ", " << _handler.bool_to_string(state) << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/position_fixed\ -i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); - // update on source orientation: "/update/source/orientation, if, id, + // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); + + // update on reference position: "/update/reference/position, ff, x, y" + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); + VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); - // update on source gain: "/update/source/gain, if, id, gain" - _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, - int, lo::Message message) + // update on reference offset orientation: + // "/update/reference_offset/orientation, f, azimuth" + _handler.server().add_method("/update/reference_offset/orientation", "f", + [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i - << ", " << argv[1]->f << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for \ +/update/reference_offset/orientation f."); + + // update on reference offset position: "/update/reference_offset/position, + // ff, x, y" + _handler.server().add_method("/update/reference_offset/position", "ff", + [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/gain if."); + VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ +ff."); - // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg - **argv, int, lo::Message message) + // update on scene amplitude reference distance: + // "update/scene/amplitude_reference_distance, f, + // amplitude_reference_distance" + _handler.server().add_method("/update/scene/amplitude_reference_distance", + "f", [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + << argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for \ +/update/scene/amplitude_reference_distance f."); + + // update on scene source auto rotation: "/update/scene/auto_rotate_sources, + // {F,T}, false|true" + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; - if(!message.types().compare("iT")) + (void) argv; + if(!message.types().compare("T")) { state = true; } - else if(!message.types().compare("iF")) + else if(!message.types().compare("F")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << - ", " << _handler.bool_to_string(state) << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ +{F,T}."); - // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, - int, lo::Message message) + // update on scene decay exponent: "/update/scene/decay_exponent, f, + // decay_exponent" + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " - << name << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/name is."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); - // update on source properties_file: "/update/source/properties_file, is, id, - // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << - argv[0]->i << ", " << name << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ +f."); - // update on scene decay exponent: "/update/scene/decay_exponent, f, - // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f - << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); - // update on scene amplitude reference distance: - // "update/scene/amplitude_reference_distance, f, - // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", - "f", [](lo_arg **argv, int, lo::Message message) + // update on scene volume: "/update/scene/volume, f, volume" + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " - << argv[0]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for \ -/update/scene/amplitude_reference_distance f."); + VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); - // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + // update on deleted source: "/update/source/delete, i, id" + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " - << name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/model is."); + VERBOSE("OscReceiver: Added callback for /update/source/delete i."); - // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg + // update on source file_channel: "/update/source/file_channel, ii, id, + // file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/port_name, " << - argv[0]->i << ", " << name << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); + VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" @@ -325,18 +339,17 @@ i{F,T}."); VERBOSE("OscReceiver: Added callback for \ /update/source/file_name_or_port_number is."); - // update on source file_channel: "/update/source/file_channel, ii, id, - // file_channel" - _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg - **argv, int, lo::Message message) + // update on source gain: "/update/source/gain, if, id, gain" + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i - << ", " << argv[1]->i << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /update/source/gain if."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, @@ -350,113 +363,148 @@ i{F,T}."); ); VERBOSE("OscReceiver: Added callback for /update/source/length ii."); - // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg - **argv, int, lo::Message message) + // update on source signal level: "/update/source/level, if, id, level" + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << + ", "<< argv[1]->f << "] from client '" << message.source().hostname() + << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); + VERBOSE("OscReceiver: Added callback for /update/source/level if."); - // update on reference orientation: "/update/reference/orientation, f, - // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg - **argv, int, lo::Message message) + // update on source model: "/update/source/model, is, id, model" + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/source/model is."); - // update on reference offset position: "/update/reference_offset/position, - // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", - [](lo_arg **argv, int, lo::Message message) + // update on source mute: "/update/source/mute, i{F,T}, id, false|true" + _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg + **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << - argv[0]->f << ", " << argv[1]->f << "] from client '" << + bool state; + if(!message.types().compare("iT")) + { + state = true; + } + else if(!message.types().compare("iF")) + { + state = false; + } + VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << + ", " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ -ff."); + VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); - // update on reference offset orientation: - // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", - [](lo_arg **argv, int, lo::Message message) + // update on source name: "/update/source/name, is, id, name" + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for \ -/update/reference_offset/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/source/name is."); - // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + // update on source orientation: "/update/source/orientation, if, id, + // azimuth" + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); + + // update on new source: "/update/source/new, i, id" + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); + VERBOSE("OscReceiver: Added callback for /update/source/new i."); - // update on state processing: "/update/processing/state, {T,F}, - // {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg + // update on source port_name: "/update/source/port_name, is, id, port_name" + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { - bool state; - (void) argv; - if(!message.types().compare("T")) - { - state = true; - } - else if(!message.types().compare("F")) - { - state = false; - } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << - _handler.bool_to_string(state) << "] from client '" << + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); - // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg + // update on source position: "/update/source/position, iff, id, x, y" + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/position iff."); + + // update on source position fixation: "/update/source/position_fixed, + // i{F,T}, id, false|true" + _handler.server().add_method("/update/source/position_fixed", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; - (void) argv; - if(!message.types().compare("T")) + if(!message.types().compare("iT")) { state = true; } - else if(!message.types().compare("F")) + else if(!message.types().compare("iF")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/transport/state, " << - _handler.bool_to_string(state) << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(state) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/position_fixed \ +i{F,T}."); + + // update on source properties_file: "/update/source/properties_file, is, id, + // properties_file" + _handler.server().add_method("/update/source/properties_file", "is", + [](lo_arg **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); // update on transport seek: "/update/transport/seek, s, time" _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, @@ -470,10 +518,9 @@ ff."); ); VERBOSE("OscReceiver: Added callback for /update/transport/seek s."); - // update on scene source auto rotation: "/update/scene/auto_rotate_sources, - // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, - [this](lo_arg **argv, int, lo::Message message) + // update on transport state: "/update/transport/state, {F,T}, false|true" + _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg + **argv, int, lo::Message message) { bool state; (void) argv; @@ -485,60 +532,13 @@ ff."); { state = false; } - VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + VERBOSE3("OscReceiver: Got [/update/transport/state, " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ -{F,T}."); - - // update on cpu_load: "/update/cpu_load, f, load" - _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, - lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); - - // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg - **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); - - // update on scene master signal level: "/update/scene/master_signal_level, - // f, master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", - [](lo_arg **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ -f."); - - // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, - int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << - ", "<< argv[1]->f << "] from client '" << message.source().hostname() - << ":" << message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/level if."); + VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); } /** @@ -584,53 +584,26 @@ void ssr::OscReceiver::add_poll_methods() */ void ssr::OscReceiver::add_source_methods() { - // set source position: "/source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + // delete source: "/source/delete, i, id" + // special case: i == 0 deletes all sources! + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << - argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /source/position iff."); - - // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" - _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg - **argv, int, lo::Message message) - { - if (!message.types().compare("iT")) + VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + if (argv[0]->i == 0) { - VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, true); + _controller.delete_all_sources(); } - else if (!message.types().compare("iF")) + else { - VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, false); + _controller.delete_source(argv[0]->i); } } ); - VERBOSE("OscReceiver: Added callback for /source/position_fixed i{T,F}."); - - // set source orientation: "/source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg - **argv, int, lo::Message message) - { - VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /source/orientation if."); + VERBOSE("OscReceiver: Added callback for /source/delete i."); // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, int, lo::Message message) @@ -654,9 +627,27 @@ void ssr::OscReceiver::add_source_methods() apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added callback for /source/gain if."); + VERBOSE("OscReceiver: Added callback for /source/gain if."); + + // set source model: "/source/model, is, id, model" + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, + int, lo::Message message) + { + std::string name(&argv[1]->s); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(name, model)) + { + model = Source::point; + } + VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_model(argv[0]->i, model); + } + ); + VERBOSE("OscReceiver: Added callback for /source/model is."); - // set source mute: "/source/mute, i{T,F}, id, true|false" + // set source mute: "/source/mute, i{F,T}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -676,7 +667,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/mute i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/mute i{F,T}."); // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, @@ -692,54 +683,10 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/name is."); - // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg - **argv, int, lo::Message message) - { - std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_properties_file(argv[0]->i, name); - } - ); - VERBOSE("OscReceiver: Added callback for /source/properties_file is."); - - // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, - int, lo::Message message) - { - std::string name(&argv[1]->s); - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(name, model)) - { - model = Source::point; - } - VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_model(argv[0]->i, model); - } - ); - VERBOSE("OscReceiver: Added callback for /source/model is."); - - // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, - int, lo::Message message) - { - std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_port_name(argv[0]->i, name); - } - ); - VERBOSE("OscReceiver: Added callback for /source/port_name is."); - - // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffff{F,T}{F,T}{F,T}, name, model, // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" - // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffffis{F,T}{F,T}{F,T}, name, model, // file_name_or_port_number, x, y, orientation, gain, file_channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, @@ -933,25 +880,79 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added callback for /source/new \ {sssffff,sssffffis}{F,T}{F,T}{F,T}."); - // delete source: "/source/delete, i, id" - // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, + // set source orientation: "/source/orientation, if, id, azimuth" + _handler.server().add_method("/source/orientation", "if", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /source/orientation if."); + + // set source port name: "/source/port_name, is, id, port_name" + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - if (argv[0]->i == 0) + _controller.set_source_port_name(argv[0]->i, name); + } + ); + VERBOSE("OscReceiver: Added callback for /source/port_name is."); + + // set source position: "/source/position, iff, id, x, y" + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << + argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /source/position iff."); + + // set source fixed: "/source/position_fixed, i{F,T}, id, true|false" + _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg + **argv, int, lo::Message message) + { + if (!message.types().compare("iT")) { - _controller.delete_all_sources(); + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", true] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, true); } - else + else if (!message.types().compare("iF")) { - _controller.delete_source(argv[0]->i); + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", false] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, false); } } ); - VERBOSE("OscReceiver: Added callback for /source/delete i."); + VERBOSE("OscReceiver: Added callback for /source/position_fixed i{F,T}."); + + // set source file: "/source/properties_file, is, id, properties_file" + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg + **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << + ", " << name << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_properties_file(argv[0]->i, name); + } + ); + VERBOSE("OscReceiver: Added callback for /source/properties_file is."); + } /** @@ -966,18 +967,6 @@ void ssr::OscReceiver::add_source_methods() */ void ssr::OscReceiver::add_reference_methods() { - // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg - **argv, int, lo::Message message) - { - VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /reference/position ff."); - // set reference orientation: "/reference/orientation, f, azimuth" _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int, lo::Message message) @@ -990,19 +979,17 @@ void ssr::OscReceiver::add_reference_methods() ); VERBOSE("OscReceiver: Added callback for /reference/orientation f."); - // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , - [this](lo_arg **argv, int, lo::Message message) + // set reference position: "/reference/position, ff, x, y" + _handler.server().add_method("/reference/position", "ff", [this](lo_arg + **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f)); + VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); + VERBOSE("OscReceiver: Added callback for /reference/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" @@ -1016,6 +1003,20 @@ void ssr::OscReceiver::add_reference_methods() } ); VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); + + // set reference offset position: "/reference_offset/position, ff, x, y" + _handler.server().add_method("/reference_offset/position", "ff" , + [this](lo_arg **argv, int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/reference_offset/position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); } /** @@ -1029,19 +1030,19 @@ void ssr::OscReceiver::add_reference_methods() */ void ssr::OscReceiver::add_scene_methods() { - // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, - lo::Message message) + // clear scene: "/scene/clear" + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, + int, lo::Message message) { - std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << + (void) argv; + VERBOSE2("OscReceiver: [/scene/clear] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); - _controller.save_scene_as_XML(name); + _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added callback for /scene/save s."); + VERBOSE("OscReceiver: Added callback for /scene/clear."); // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) @@ -1055,6 +1056,19 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/load s."); + // save scene to file: "/scene/save, s, file" + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, + lo::Message message) + { + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.save_scene_as_XML(name); + } + ); + VERBOSE("OscReceiver: Added callback for /scene/save s."); + // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) @@ -1066,19 +1080,6 @@ void ssr::OscReceiver::add_scene_methods() } ); VERBOSE("OscReceiver: Added callback for /scene/volume f."); - - // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, - int, lo::Message message) - { - (void) argv; - VERBOSE2("OscReceiver: [/scene/clear] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.delete_all_sources(); - } - ); - VERBOSE("OscReceiver: Added callback for /scene/clear."); } /** @@ -1106,7 +1107,7 @@ void ssr::OscReceiver::add_processing_methods() "'."); _controller.start_processing(); } - else if(!message.types().compare("T")) + else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/processing/state, " << _handler.bool_to_string(false) << "] from client '" << @@ -1116,7 +1117,7 @@ void ssr::OscReceiver::add_processing_methods() } } ); - VERBOSE("OscReceiver: Added callback for /processing/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /processing/state {F,T}."); } @@ -1132,31 +1133,6 @@ void ssr::OscReceiver::add_processing_methods() */ void ssr::OscReceiver::add_transport_methods() { - // set transport state: "transport/state, T, true" - _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, - int, lo::Message message) - { - (void) argv; - if(!message.types().compare("T")) - { - VERBOSE2("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_start(); - } - if(!message.types().compare("F")) - { - VERBOSE2("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_stop(); - } - } - ); - VERBOSE("OscReceiver: Added callback for /transport/state {T,F}."); - // rewind transport state: "/transport/rewind" _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1191,6 +1167,31 @@ void ssr::OscReceiver::add_transport_methods() } ); VERBOSE("OscReceiver: Added callback for /transport/seek s."); + + // set transport state: "transport/state, T, true" + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, + int, lo::Message message) + { + (void) argv; + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_start(); + } + if(!message.types().compare("F")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_stop(); + } + } + ); + VERBOSE("OscReceiver: Added callback for /transport/state {F,T}."); } /** From 10147c2e7624c565b7ec5fc0d4674fc369b28431 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 23:39:06 +0200 Subject: [PATCH 143/363] src/networking/oscreceiver.cpp: Moving call to add_processing_methods() to alphabetical location. Changing VERBOSE messages in /subscribe and /message_level callbacks to adhere to style standard. Raising VERBOSE messages for /transport/seek and /transport/state messages to VERBOSE3. --- src/networking/oscreceiver.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e96a0027..4f2df46b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -53,10 +53,10 @@ void ssr::OscReceiver::start() else if (_handler.is_client()) { add_poll_methods(); + add_processing_methods(); add_reference_methods(); add_scene_methods(); add_source_methods(); - add_processing_methods(); add_tracker_methods(); add_transport_methods(); } @@ -82,9 +82,9 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE2("OscReceiver: Got request to set message level for client '" << - client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); set_message_level(_handler, client, static_cast(argv[0]->i)); } @@ -98,21 +98,24 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Address client(message.source()); if(!message.types().compare("T")) { - VERBOSE2("OscReceiver: Got subscribe request from '" << + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << "] from client '" << client.hostname() << ":" << client.port() << "'."); add_client(_handler, client, ssr::MessageLevel::CLIENT); } else if(!message.types().compare("F")) { - VERBOSE2("OscReceiver: Got unsubscribe request from '" << + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(false) << "] from client '" << client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); } else if(!message.types().compare("Ti")) { - VERBOSE2("OscReceiver: Got subscribe request from '" << - client.hostname() << ":" << client.port() << - "' for message level: " << argv[1]->i); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << ", " << argv[1]->i << + "] from client '" << client.hostname() << ":" << client.port() << + "'."); add_client(_handler, client, static_cast(argv[1]->i)); } @@ -1154,7 +1157,7 @@ void ssr::OscReceiver::add_transport_methods() std::string message_time(&argv[0]->s); if(apf::str::string2time(message_time, time)) { - VERBOSE2("OscReceiver: Got [/transport/seek, " << message_time << + VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.transport_locate(time); @@ -1175,7 +1178,7 @@ void ssr::OscReceiver::add_transport_methods() (void) argv; if(!message.types().compare("T")) { - VERBOSE2("OscReceiver: Got [/transport/state, " << + VERBOSE3("OscReceiver: Got [/transport/state, " << _handler.bool_to_string(true) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1183,7 +1186,7 @@ void ssr::OscReceiver::add_transport_methods() } if(!message.types().compare("F")) { - VERBOSE2("OscReceiver: Got [/transport/state, " << + VERBOSE3("OscReceiver: Got [/transport/state, " << _handler.bool_to_string(false) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); From fef26e9fa339bdc354c703bde70f1ab860e69f94 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 6 Jun 2017 10:41:46 +0200 Subject: [PATCH 144/363] src/networking/oscreceiver.cpp: Adding various TODOs. Fixing errernous call to unitialized variable in /message_level callback handler. Adding First prototype of variable string for client/server VERBOSE message. --- src/networking/oscreceiver.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 4f2df46b..2e5d1436 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -85,7 +85,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, client, + set_message_level(_handler, message.source(), static_cast(argv[0]->i)); } ); @@ -110,6 +110,8 @@ void ssr::OscReceiver::add_client_to_server_methods() client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); } + //TODO: add /subscribe, Fss, host, port + //TODO: add /subscribe, Tiss, host, port else if(!message.types().compare("Ti")) { VERBOSE2("OscReceiver: Got [/subscribe, " << @@ -592,8 +594,9 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { + std::string from = (_handler.is_server())? "client": "server"; VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << + "] from " << from << " '" << message.source().hostname() << ":" << message.source().port() << "'."); if (argv[0]->i == 0) { @@ -605,8 +608,8 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/delete i."); + // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, int, lo::Message message) @@ -1033,6 +1036,13 @@ void ssr::OscReceiver::add_reference_methods() */ void ssr::OscReceiver::add_scene_methods() { + //TODO: add /scene/transfer ss, host, port (_controller.get_scene_as_XML()) + //_add_master_volume(node); + //_add_transport_state(node); + //_add_reference(node); + //_add_loudspeakers(node); + //_add_sources(node); + // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1044,8 +1054,8 @@ void ssr::OscReceiver::add_scene_methods() _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added callback for /scene/clear."); + // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) From 1a22195cbfd2d621e9ac3fe0aa7a5250696e8036 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 6 Jun 2017 16:37:35 +0200 Subject: [PATCH 145/363] src/networking/oscreceiver.h: Using std::strings for hostname and port in set_message_level(). src/networking/oscreceiver.cpp: Adding /message_level ssi callback handler. src/networking/oschandler.h: Changing definition of set_message_level friend function to use std::string types for hostname and port instead of a lo::Address. src/networking/oschandler.cpp: Changing OscReceiver::set_message_level() parameters to use std::strings for hostname and port instead of a lo::Address and updating documentation for the function. --- src/networking/oschandler.cpp | 11 ++++++----- src/networking/oschandler.h | 4 ++-- src/networking/oscreceiver.cpp | 29 ++++++++++++++++++++++------- src/networking/oscreceiver.h | 4 ++-- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index e0d4b375..6dae5aa0 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -202,13 +202,14 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) /** * OscHandler's friend function to set a client's message_level * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be deactivated + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel to be used for client */ -void ssr::OscReceiver::set_message_level(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level) +void ssr::OscReceiver::set_message_level(OscHandler& self, std::string + hostname, std::string port, ssr::MessageLevel message_level) { - self._osc_sender.set_client_message_level(client.hostname(), client.port(), - message_level); + self._osc_sender.set_client_message_level(hostname, port, message_level); } diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 0faaa5ee..0e5bec51 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -79,8 +79,8 @@ class OscHandler ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address client); - friend void OscReceiver::set_message_level(OscHandler& self, lo::Address - client, ssr::MessageLevel message_level); + friend void OscReceiver::set_message_level(OscHandler& self, std::string + hostname, std::string port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2e5d1436..d6928450 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -79,17 +79,32 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - set_message_level(_handler, message.source(), - static_cast(argv[0]->i)); + if(!message.types().compare("i")) + { + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + set_message_level(_handler, message.source().hostname(), + message.source().port(), + static_cast(argv[0]->i)); + } + else if(!message.types().compare("ssi")) + { + std::string hostname(&argv[0]->s); + std::string port(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/message_level, " << hostname << ", " << + port << ", " << argv[2]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + set_message_level(_handler, hostname, port, + static_cast(argv[2]->i)); + } } ); - VERBOSE("OscReceiver: Added callback for /message_level i."); + VERBOSE("OscReceiver: Added callback for /message_level {i,ssi}."); // adding new subscribing client: "/subscribe, {T,Ti,F}" _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 4011a46b..5f8d9b27 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -68,8 +68,8 @@ class OscReceiver void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, lo::Address client); - void set_message_level(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level); + void set_message_level(OscHandler& self, std::string hostname, std::string + port, ssr::MessageLevel message_level); }; } // namespace ssr From 4079bf19e82875f5a10bad862a6a74cbac2b9306 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 7 Jun 2017 00:18:42 +0200 Subject: [PATCH 146/363] src/networking/*: Adding callback handlers for /subscribe {Fss,Tssi}. Rewriting add_client() and deactivate_client() to use std::string for hostname and port instead of a lo::Address object. --- src/networking/oschandler.cpp | 20 ++++++++----- src/networking/oschandler.h | 8 ++--- src/networking/oscreceiver.cpp | 53 ++++++++++++++++++++++++++-------- src/networking/oscreceiver.h | 7 +++-- 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 6dae5aa0..795278e1 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -180,23 +180,29 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) * OscHandler's friend function to add a client to the list of OscSender's * _client_addresses. * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be added + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel representing the client's message + * level */ -void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level = ssr::MessageLevel::CLIENT) +void ssr::OscReceiver::add_client(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level = + ssr::MessageLevel::CLIENT) { - self._osc_sender.add_client(client.hostname(), client.port(), message_level); + self._osc_sender.add_client(hostname, port, message_level); } /** * OscHandler's friend function to deactivate a client from the list of * OscSender's _clients * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be deactivated + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port */ -void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::deactivate_client(OscHandler& self, std::string + hostname, std::string port) { - self._osc_sender.deactivate_client(client.hostname(), client.port()); + self._osc_sender.deactivate_client(hostname, port); } /** diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 0e5bec51..d5ea260a 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -75,10 +75,10 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); - friend void OscReceiver::add_client(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level); - friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address - client); + friend void OscReceiver::add_client(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level); + friend void OscReceiver::deactivate_client(OscHandler& self, std::string + hostname, std::string port); friend void OscReceiver::set_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d6928450..c41cb8b0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -106,39 +106,68 @@ void ssr::OscReceiver::add_client_to_server_methods() ); VERBOSE("OscReceiver: Added callback for /message_level {i,ssi}."); - // adding new subscribing client: "/subscribe, {T,Ti,F}" + // subscribing and unsubscribing clients _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); if(!message.types().compare("T")) { + // subscribing client: "/subscribe, T" VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(true) << "] from client '" << - client.hostname() << ":" << client.port() << "'."); - add_client(_handler, client, ssr::MessageLevel::CLIENT); + message.source().hostname() << ":" << message.source().port() << + "'."); + add_client(_handler, message.source().hostname(), + message.source().port(), ssr::MessageLevel::CLIENT); } + // unsubscribing client: "/subscribe, F" else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(false) << "] from client '" << - client.hostname() << ":" << client.port() << "'."); - deactivate_client(_handler, client); + message.source().hostname() << ":" << message.source().port() << + "'."); + deactivate_client(_handler, message.source().hostname(), + message.source().port()); } - //TODO: add /subscribe, Fss, host, port - //TODO: add /subscribe, Tiss, host, port + // unsubscribing client: "/subscribe, Fss, hostname, port" + else if(!message.types().compare("Fss")) + { + std::string hostname(&argv[1]->s); + std::string port(&argv[2]->s); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(false) << ", " << hostname << ", " << port + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + deactivate_client(_handler, hostname, port); + } + // subscribing client: "/subscribe, Tssi, hostname, port, message_level" + else if(!message.types().compare("Tssi")) + { + std::string hostname(&argv[1]->s); + std::string port(&argv[2]->s); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << ", " << hostname << ", " << port + << ", " << argv[3]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + add_client(_handler, hostname, port, + static_cast(argv[3]->i)); + } + // subscribing client: "/subscribe, Ti, message_level" else if(!message.types().compare("Ti")) { VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(true) << ", " << argv[1]->i << - "] from client '" << client.hostname() << ":" << client.port() << - "'."); - add_client(_handler, client, + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + add_client(_handler, message.source().hostname(), + message.source().port(), static_cast(argv[1]->i)); } } ); - VERBOSE("OscReceiver: Added callback for /subscribe {F,T,Ti}."); + VERBOSE("OscReceiver: Added callback for /subscribe {F,Fss,T,Ti,Tssi}."); } /** diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 5f8d9b27..3a27d123 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -65,9 +65,10 @@ class OscReceiver void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); - void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel - message_level); - void deactivate_client(OscHandler& self, lo::Address client); + void add_client(OscHandler& self, std::string hostname, std::string port, + ssr::MessageLevel message_level); + void deactivate_client(OscHandler& self, std::string hostname, std::string + port); void set_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; From 8e58d47726b83c3bcc5a0599fc25c3a6d122b475 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 00:01:54 +0200 Subject: [PATCH 147/363] src/networking/*: Changing OscSender's _server_address to _server of type OscClient, to have easier control over MessageLevel of the server for clients, using the same functionality. Refactoring all involved functions. Making all setters for the lo::Address fields use reference type parameters. --- src/networking/oscclient.cpp | 13 ++ src/networking/oscclient.h | 1 + src/networking/oschandler.cpp | 39 +++++- src/networking/oschandler.h | 7 +- src/networking/oscreceiver.cpp | 19 +-- src/networking/oscreceiver.h | 8 +- src/networking/oscsender.cpp | 217 ++++++++++++++++++--------------- src/networking/oscsender.h | 9 +- 8 files changed, 194 insertions(+), 119 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index f1030028..2206aede 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -71,6 +71,19 @@ lo::Address& ssr::OscClient::address() return _address; } +/** + * Function to set the OscClient's _address. + * @param hostname reference to a std::string representing the hostname to be + * used + * @param port reference to a std::string& representing the port to be used + **/ +void ssr::OscClient::set_address(std::string& hostname, std::string& port) +{ + _address = lo::Address(hostname, port); + VERBOSE3("OscClient: Address changed to: " << _address.hostname() << ":" << + _address.port() << "."); +} + /** * Function to set the OscClient's _message_level. * @param message_level a MessageLevel to be used for the OscClient diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index e975c94c..085a38a1 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -30,6 +30,7 @@ class OscClient bool active(); void activate(); void deactivate(); + void set_address(std::string& hostname, std::string& port); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 795278e1..895e9681 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -85,16 +85,17 @@ void ssr::OscHandler::start() /** * OscHandler's friend function to set the OscSender's server_address * @param self reference to OscHandler holding OscSender - * @param server_address lo::Address object to be used for OscSender + * @param hostname reference to std::string representing hostname + * @param port reference to std::string representing port */ -void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address - server_address) +void ssr::OscReceiver::set_server_address(ssr::OscHandler& self, + std::string& hostname, std::string& port) { - self._osc_sender.set_server_address(server_address.hostname(), server_address.port()); + self._osc_sender.set_server_address(hostname, port); } /** - * OscHandler's friend function return OscSender's server_address + * OscHandler's friend function to return OscSender's server_address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ @@ -103,6 +104,34 @@ lo::Address ssr::OscReceiver::server_address(ssr::OscHandler& self) return self._osc_sender.server_address(); } +/** + * OscHandler's friend function to check, if the current lo::Address of the + * server is the default + * @see ssr::OscSender::server_is_default() + * @param self reference to OscHandler holding the OscSender + * @return bool true, if OscSender's server address is the default, false + * otherwise + */ +bool ssr::OscReceiver::server_is_default(ssr::OscHandler& self) +{ + return self._osc_sender.server_is_default(); +} + +/** + * OscHandler's friend function to check, if the provided hostname and port + * match the OscSender's _server lo::Address + * @param self reference to OscHandler holding the OscSender + * @param hostname reference to std::string representing the hostname + * @param port reference to std::string representing the port + * @return bool true, if OscSender's server address matches the provided + * hostname and port + */ +bool ssr::OscReceiver::server_is(ssr::OscHandler& self, std::string& hostname, + std::string& port) +{ + return self._osc_sender.server_is(hostname, port); +} + /** * OscHandler's friend function to send an OSC message to a client, using * OscSender. diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index d5ea260a..212eb925 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -60,9 +60,12 @@ class OscHandler const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); // OscReceiver friend functions - friend void OscReceiver::set_server_for_client(OscHandler& self, - lo::Address server_address); + friend void OscReceiver::set_server_address(OscHandler& self, + std::string& hostname, std::string& port); friend lo::Address OscReceiver::server_address(OscHandler& self); + friend bool OscReceiver::server_is_default(OscHandler& self); + friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, + std::string& port); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c41cb8b0..21624d97 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -595,6 +595,8 @@ i{F,T}."); * server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. + * @todo rename to add_client_to_server_methods() and add /message_level, i + * callback, to set server's MessageLevel. */ void ssr::OscReceiver::add_poll_methods() { @@ -603,20 +605,23 @@ void ssr::OscReceiver::add_poll_methods() _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server(server_address(_handler)); lo::Address from(message.source()); + std::string hostname(from.hostname()); + std::string port(from.port()); (void) argv; - if((server.hostname().compare(from.hostname()) != 0) && - (server.port().compare(from.port()) != 0) && - (from.port().compare("50001") != 0) && - (from.hostname().compare("none") != 0) - ) + if(!server_is(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Subscribing..."); - set_server_for_client(_handler, from); + set_server_address(_handler, hostname, port); from.send_from(_handler.server(), "/subscribe", "T"); } + else + { + VERBOSE3("OscReceiver: Got [/poll] from server " << from.hostname() << + ":" << from.port() << ". Sending alive signal."); + from.send_from(_handler.server(), "/alive", ""); + } } ); VERBOSE("OscReceiver: Added callback for /poll."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3a27d123..85612d59 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -52,9 +52,11 @@ class OscReceiver ~OscReceiver(); void start(); void stop(); - void set_server_for_client(OscHandler& handler, lo::Address - server_address); - lo::Address server_address(OscHandler& handler); + void set_server_address(OscHandler& handler, std::string& hostname, + std::string& port); lo::Address server_address(OscHandler& handler); + bool server_is_default(OscHandler& handler); + bool server_is(OscHandler& handler, std::string& hostname, std::string& + port); void send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); void send_to_client(OscHandler& self, lo::Address client_address, diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 5d607887..9a6ac8c6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -18,7 +18,7 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) - , _server_address("none", "50001") + , _server("none", "50001", MessageLevel::SERVER) , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); @@ -65,13 +65,34 @@ void ssr::OscSender::stop() } /** - * Returns true, if the _server_address is the default (setup at initialization) - * @return true, if _server_address is the default, false otherwise. + * Returns true, if the _server.address() is the default (setup at initialization) + * @return true, if _server.address() is the default, false otherwise. */ bool ssr::OscSender::server_is_default() { - if((_server_address.hostname().compare("none") == 0) && - (_server_address.port().compare("50001") == 0)) + if((_server.hostname().compare("none") == 0) && + (_server.port().compare("50001") == 0)) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the _server.address()'s hostname and port are the same as + * the provided. + * @param hostname a reference to a std::string representing the hostname + * @param port a reference to a std::string representing the port + * @return true, if _server.address() has the same hostname and port, false + * otherwise. + */ +bool ssr::OscSender::server_is(std::string& hostname, std::string& port) +{ + if((_server.hostname().compare(hostname) == 0) && + (_server.port().compare(port) == 0)) { return true; } @@ -104,13 +125,12 @@ void ssr::OscSender::poll_all_clients() } /** - * Function to return OscSender's _server_address + * Function to return OscSender's _server.address() * @return a lo::Address object representing the current server for this client */ -lo::Address ssr::OscSender::server_address() +lo::Address& ssr::OscSender::server_address() { - lo::Address server(_server_address.hostname(), _server_address.port()); - return server; + return _server.address(); } /** @@ -124,14 +144,15 @@ void ssr::OscSender::set_message_level(const unsigned int& message_level) } /** - * Function to set OscSender's _server_address - * @param server_address a lo::Address to be used as _server_address + * Function to set OscSender's _server address + * @param hostname a std::string& to be used as hostname + * @param port a std::string& to be used as port */ -void ssr::OscSender::set_server_address(std::string hostname, std::string port) +void ssr::OscSender::set_server_address(std::string& hostname, std::string& port) { - _server_address = lo::Address(hostname, port); + _server.set_address(hostname, port); VERBOSE2("OscSender: Setting up new server address: "<< - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } /** @@ -142,13 +163,13 @@ void ssr::OscSender::set_server_address(std::string hostname, std::string port) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server_address.hostname().compare("none") != 0) && - (_server_address.port().compare("50001") != 0)) + if((_server.hostname().compare("none") != 0) && + (_server.port().compare("50001") != 0)) { - _server_address.send_from(_handler.server(), path, message.types(), message); + _server.address().send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -158,10 +179,10 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server_address.send_from(_handler.server(), bundle); + _server.address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle (" << bundle.length() << - " messages) to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + " messages) to server " << _server.hostname() << ":" << + _server.port() << "."); } /** @@ -542,11 +563,11 @@ void ssr::OscSender::new_source(id_t id) else if(_handler.is_client()) { int32_t message_id = static_cast(id); - _server_address.send_from(_handler.server(), "/update/source/new", "i", + _server.address().send_from(_handler.server(), "/update/source/new", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -577,11 +598,11 @@ void ssr::OscSender::delete_source(id_t id) else if(_handler.is_client() && !server_is_default()) { _source_levels.erase(id); - _server_address.send_from(_handler.server(), "/update/source/delete", + _server.address().send_from(_handler.server(), "/update/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -608,10 +629,10 @@ void ssr::OscSender::delete_all_sources() } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/delete", + _server.address().send_from(_handler.server(), "/update/source/delete", "i", 0); VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } _source_levels.clear(); } @@ -658,11 +679,11 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/position", + _server.address().send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << ", " << position.x << ", " << position.y << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -710,12 +731,12 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/position_fixed", + _server.address().send_from(_handler.server(), "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -763,12 +784,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/orientation", + _server.address().send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -813,12 +834,12 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/gain", + _server.address().send_from(_handler.server(), "/update/source/gain", "if", message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -865,12 +886,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/mute", + _server.address().send_from(_handler.server(), "/update/source/mute", "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << apf::str::A2S(message_id) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -917,11 +938,11 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/name", "is", + _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server_address.hostname() << ":" - << _server_address.port() << "."); + << message_name << "] to server " << _server.hostname() << ":" + << _server.port() << "."); } return true; } @@ -969,11 +990,11 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << message_id << ", " << file_name << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1004,11 +1025,11 @@ void ssr::OscSender::set_decay_exponent(float exponent) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1040,11 +1061,11 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " - << distance << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + << distance << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1091,11 +1112,11 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/model", "is", + _server.address().send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + ", " << message_model << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1117,11 +1138,11 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& int32_t message_id = static_cast(id); if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/port_name", + _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + ", " << port_name << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1174,12 +1195,12 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1228,11 +1249,11 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1255,11 +1276,11 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) int32_t message_length = static_cast(length); if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/length", "ii", + _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", " << message_length << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1293,11 +1314,11 @@ void ssr::OscSender::set_reference_position(const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/reference/position", + _server.address().send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server_address.hostname() - << ":" << _server_address.port() << "."); + << ", " << position.y << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } } @@ -1330,11 +1351,11 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1368,11 +1389,11 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << position.x << ", " << position.y << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } } @@ -1408,11 +1429,11 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1445,11 +1466,11 @@ void ssr::OscSender::set_master_volume(float volume) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/scene/volume", "f", + _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1499,11 +1520,11 @@ void ssr::OscSender::set_processing_state(bool state) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/processing/state", + _server.address().send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << _handler.bool_to_message_type(state) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } } @@ -1546,16 +1567,16 @@ void ssr::OscSender::set_transport_state( const std::pair Date: Sat, 17 Jun 2017 01:20:40 +0200 Subject: [PATCH 148/363] src/networking/*: Removing _client_addresses from OscSender and replacing all calls to it by calls to _clients. Adding set_server_message_level(), to set the MessageLevel of a clients representation of a server. Minor fixes. --- src/networking/oschandler.cpp | 13 ++++++++ src/networking/oschandler.h | 2 ++ src/networking/oscreceiver.cpp | 21 ++++++++++++- src/networking/oscreceiver.h | 5 +++- src/networking/oscsender.cpp | 54 +++++++++++++++++++++------------- src/networking/oscsender.h | 5 ++-- 6 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 895e9681..b4ebf0bb 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -94,6 +94,19 @@ void ssr::OscReceiver::set_server_address(ssr::OscHandler& self, self._osc_sender.set_server_address(hostname, port); } +/** + * OscHandler's friend function to set a the OscSender _server's message_level + * @param self reference to OscHandler holding OscSender + * @param hostname reference to std::string representing the client's hostname + * @param port reference to std::string representing the client's port + * @param message_level ssr::MessageLevel to be used for server + */ +void ssr::OscReceiver::set_server_message_level(OscHandler& self, + ssr::MessageLevel message_level) +{ + self._osc_sender.set_server_message_level(message_level); +} + /** * OscHandler's friend function to return OscSender's server_address * @param self reference to OscHandler holding the OscSender diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 212eb925..f7610ecf 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -62,6 +62,8 @@ class OscHandler // OscReceiver friend functions friend void OscReceiver::set_server_address(OscHandler& self, std::string& hostname, std::string& port); + friend void OscReceiver::set_server_message_level(OscHandler& self, + MessageLevel message_level); friend lo::Address OscReceiver::server_address(OscHandler& self); friend bool OscReceiver::server_is_default(OscHandler& self); friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 21624d97..87fc7a01 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -78,7 +78,7 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { - // adding new subscribing client: "/message_level, i" + // setting MessageLevel of subscribed client: "/message_level, {i,ssi}" _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -600,6 +600,25 @@ i{F,T}."); */ void ssr::OscReceiver::add_poll_methods() { + + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) + { +// lo::Address from(message.source()); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if(server_is(_handler, hostname, port)) + { + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + set_server_message_level(_handler, + static_cast(argv[0]->i)); + } + } + ); + VERBOSE("OscReceiver: Added callback for /message_level i."); + // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 85612d59..5f237f2d 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -53,7 +53,10 @@ class OscReceiver void start(); void stop(); void set_server_address(OscHandler& handler, std::string& hostname, - std::string& port); lo::Address server_address(OscHandler& handler); + std::string& port); + lo::Address server_address(OscHandler& handler); + void set_server_message_level(OscHandler& handler, MessageLevel + message_level); bool server_is_default(OscHandler& handler); bool server_is(OscHandler& handler, std::string& hostname, std::string& port); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 9a6ac8c6..38ea2d6c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -135,7 +135,6 @@ lo::Address& ssr::OscSender::server_address() /** * Function to set OscSender's _message_level. - * If the message level is out of * @param MessageLevel enum representing the new message level */ void ssr::OscSender::set_message_level(const unsigned int& message_level) @@ -143,6 +142,15 @@ void ssr::OscSender::set_message_level(const unsigned int& message_level) _message_level = static_cast(message_level); } +/** + * Function to set OscSender server's _message_level (client). + * @param MessageLevel enum representing the new message level + */ +void ssr::OscSender::set_server_message_level(MessageLevel message_level) +{ + _server.set_message_level(message_level); +} + /** * Function to set OscSender's _server address * @param hostname a std::string& to be used as hostname @@ -163,8 +171,7 @@ void ssr::OscSender::set_server_address(std::string& hostname, std::string& port */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server.hostname().compare("none") != 0) && - (_server.port().compare("50001") != 0)) + if(!server_is_default()) { _server.address().send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << @@ -179,28 +186,32 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server.address().send_from(_handler.server(), bundle); - VERBOSE3("OscSender: Sending bundle (" << bundle.length() << - " messages) to server " << _server.hostname() << ":" << - _server.port() << "."); + if(!server_is_default()) + { + _server.address().send_from(_handler.server(), bundle); + VERBOSE3("OscSender: Sending bundle (" << bundle.length() << + " messages) to server " << _server.hostname() << ":" << + _server.port() << "."); + } } /** * Function to send a lo::Message to a client. * @param address a lo:Address that will be sent to, when found in - * _client_addresses. + * _clients. * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ void ssr::OscSender::send_to_client(lo::Address address, std::string path, lo::Message message) { - for (const auto& client: _client_addresses) + for (const auto& client: _clients) { if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_handler.server(), path, message.types(), message); + client->address().send_from(_handler.server(), path, message.types(), + message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -211,48 +222,49 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, /** * Function to send a lo::Bundle to a client. * @param address a lo:Address that will be sent to, when found in - * _client_addresses. + * _clients. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - for (const auto& client: _client_addresses) + for (const auto& client: _clients) { if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_handler.server(), bundle); + client->address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } } /** - * Function to send a lo::Message to all clients setup in _client_addresses + * Function to send a lo::Message to all clients setup in _clients * vector. * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { + client->address().send_from(_handler.server(), path, message.types(), + message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); - client_address->send_from(_handler.server(), path, message.types(), message); + "] to client " << client->hostname() << ":" << + client->port() << "."); } } /** - * Sends a lo::Bundle to all clients setup in _client_addresses vector. + * Sends a lo::Bundle to all clients setup in _clients vector. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), bundle); + client->address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 29ae2022..2d50552f 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -40,12 +40,10 @@ class OscSender : public Subscriber // reference to handler OscHandler& _handler; bool _is_subscribed; - // address of server (client) + // server object (client) OscClient _server; // level of messages to send to server (client) MessageLevel _message_level; - // (obsolete) vector of pointers to client address objects (server) - std::vector _client_addresses; // vector of pointers to OscClient objects (server) std::vector _clients; // map of id/parameter_map pairs for new sources (server) @@ -72,6 +70,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string& hostname, std::string& port); lo::Address& server_address(); + void set_server_message_level(MessageLevel message_level); bool server_is_default(); bool server_is(std::string& hostname, std::string& port); void set_message_level(const unsigned int& message_level); From 49612ffd68fa5d01b5e53ef5f1ae046c49d42ddf Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 12:18:11 +0200 Subject: [PATCH 149/363] src/networking/*: Renaming set_message_level() to set_client_message_level() in OscHandler/OscReceiver in alignment with set_client_message_level() in OscSender for better readability. --- src/networking/oschandler.cpp | 2 +- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 6 +++--- src/networking/oscreceiver.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index b4ebf0bb..0effd7a4 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -254,7 +254,7 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, std::string * @param port std::string representing the client's port * @param message_level ssr::MessageLevel to be used for client */ -void ssr::OscReceiver::set_message_level(OscHandler& self, std::string +void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level) { self._osc_sender.set_client_message_level(hostname, port, message_level); diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index f7610ecf..5374c8fe 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -84,7 +84,7 @@ class OscHandler std::string port, ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, std::string hostname, std::string port); - friend void OscReceiver::set_message_level(OscHandler& self, std::string + friend void OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 87fc7a01..cf397542 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -87,7 +87,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, message.source().hostname(), + set_client_message_level(_handler, message.source().hostname(), message.source().port(), static_cast(argv[0]->i)); } @@ -99,7 +99,7 @@ void ssr::OscReceiver::add_client_to_server_methods() port << ", " << argv[2]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, hostname, port, + set_client_message_level(_handler, hostname, port, static_cast(argv[2]->i)); } } @@ -1116,7 +1116,7 @@ void ssr::OscReceiver::add_scene_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: [/scene/clear] from client '" << + VERBOSE2("OscReceiver: Got [/scene/clear] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.delete_all_sources(); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 5f237f2d..323404da 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -74,7 +74,7 @@ class OscReceiver ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, std::string hostname, std::string port); - void set_message_level(OscHandler& self, std::string hostname, std::string + void set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; From cb6f8f783a7ba10dd9b77c8cbdfd23f94615929f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 12:57:03 +0200 Subject: [PATCH 150/363] src/networking/oscsender.*: Using _server.message_level() instead of _message_level. --- src/networking/oscsender.cpp | 24 +++++++----------------- src/networking/oscsender.h | 5 ++--- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 38ea2d6c..b9ffb447 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -19,7 +19,6 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) , _server("none", "50001", MessageLevel::SERVER) - , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); } @@ -133,15 +132,6 @@ lo::Address& ssr::OscSender::server_address() return _server.address(); } -/** - * Function to set OscSender's _message_level. - * @param MessageLevel enum representing the new message level - */ -void ssr::OscSender::set_message_level(const unsigned int& message_level) -{ - _message_level = static_cast(message_level); -} - /** * Function to set OscSender server's _message_level (client). * @param MessageLevel enum representing the new message level @@ -1576,8 +1566,8 @@ void ssr::OscSender::set_transport_state( const std::pair _clients; // map of id/parameter_map pairs for new sources (server) From 535f8e102f94221721842fca73ff34fad7b662fe Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 13:21:38 +0200 Subject: [PATCH 151/363] src/ssr_global.h: Adding GUI_SERVER to MessageLevel enum class for messages only meant for GUI updates. Making int representation implicit. --- src/ssr_global.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ssr_global.h b/src/ssr_global.h index efb117c4..726569c2 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -54,9 +54,10 @@ extern unsigned int usleeptime; enum class MessageLevel : id_t { SERVER = 0, - THIN_CLIENT = 1, - CLIENT = 2, - GUI_CLIENT = 3 + GUI_SERVER, + THIN_CLIENT, + CLIENT, + GUI_CLIENT }; } // namespace ssr From 9ee4df3845ef36984a37bc1785ee114a0dde2f46 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 13:22:32 +0200 Subject: [PATCH 152/363] src/networking/oscsender.cpp: Changing all MessageLevel checks for clients, when trying to send to server from GUI_CLIENT to GUI_SERVER. --- src/networking/oscsender.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b9ffb447..c517cf38 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1567,7 +1567,7 @@ void ssr::OscSender::set_transport_state( const std::pair Date: Sat, 17 Jun 2017 15:20:18 +0200 Subject: [PATCH 153/363] src/networking/*: Renaming OscSender::server_is(std::string& hostname, std::string& port) to OscSender::is_server(std::string& hostname, std::string& port) for better readability. Changing in all of its use-cases. --- src/networking/oschandler.cpp | 4 ++-- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 4 ++-- src/networking/oscreceiver.h | 2 +- src/networking/oscsender.cpp | 2 +- src/networking/oscsender.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0effd7a4..9ad2bf87 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -139,10 +139,10 @@ bool ssr::OscReceiver::server_is_default(ssr::OscHandler& self) * @return bool true, if OscSender's server address matches the provided * hostname and port */ -bool ssr::OscReceiver::server_is(ssr::OscHandler& self, std::string& hostname, +bool ssr::OscReceiver::is_server(ssr::OscHandler& self, std::string& hostname, std::string& port) { - return self._osc_sender.server_is(hostname, port); + return self._osc_sender.is_server(hostname, port); } /** diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 5374c8fe..88b0117f 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -66,7 +66,7 @@ class OscHandler MessageLevel message_level); friend lo::Address OscReceiver::server_address(OscHandler& self); friend bool OscReceiver::server_is_default(OscHandler& self); - friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, + friend bool OscReceiver::is_server(OscHandler& self, std::string& hostname, std::string& port); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index cf397542..70c22e5f 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -607,7 +607,7 @@ void ssr::OscReceiver::add_poll_methods() // lo::Address from(message.source()); std::string hostname(message.source().hostname()); std::string port(message.source().port()); - if(server_is(_handler, hostname, port)) + if(is_server(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << @@ -628,7 +628,7 @@ void ssr::OscReceiver::add_poll_methods() std::string hostname(from.hostname()); std::string port(from.port()); (void) argv; - if(!server_is(_handler, hostname, port)) + if(!is_server(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Subscribing..."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 323404da..a23d41b3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -58,7 +58,7 @@ class OscReceiver void set_server_message_level(OscHandler& handler, MessageLevel message_level); bool server_is_default(OscHandler& handler); - bool server_is(OscHandler& handler, std::string& hostname, std::string& + bool is_server(OscHandler& handler, std::string& hostname, std::string& port); void send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index c517cf38..68d71d7f 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -88,7 +88,7 @@ bool ssr::OscSender::server_is_default() * @return true, if _server.address() has the same hostname and port, false * otherwise. */ -bool ssr::OscSender::server_is(std::string& hostname, std::string& port) +bool ssr::OscSender::is_server(std::string& hostname, std::string& port) { if((_server.hostname().compare(hostname) == 0) && (_server.port().compare(port) == 0)) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index f1c9e579..056650be 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -71,7 +71,7 @@ class OscSender : public Subscriber lo::Address& server_address(); void set_server_message_level(MessageLevel message_level); bool server_is_default(); - bool server_is(std::string& hostname, std::string& port); + bool is_server(std::string& hostname, std::string& port); void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port, ssr::MessageLevel message_level); From 19084d7af89869b5e0dc4aff7cc3caf4fffec462 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 21:39:00 +0200 Subject: [PATCH 154/363] src/networking/oscreceiver.*: Renaming add_poll_methods() to add_server_to_client_methods(). Making /source/new callback more robust, by only initializing with OSC message types, once the understood type tags have been found. Minor line break fix. --- src/networking/oscreceiver.cpp | 68 ++++++++++++++++------------------ src/networking/oscreceiver.h | 6 +-- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 70c22e5f..20a14ba4 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -52,7 +52,7 @@ void ssr::OscReceiver::start() } else if (_handler.is_client()) { - add_poll_methods(); + add_server_to_client_methods(); add_processing_methods(); add_reference_methods(); add_scene_methods(); @@ -591,20 +591,17 @@ i{F,T}."); } /** - * Adds callback handlers (for clients) for poll messages received from a - * server. + * Adds callback handlers (for clients) for /poll and /message_level messages + * received from a server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo rename to add_client_to_server_methods() and add /message_level, i - * callback, to set server's MessageLevel. */ -void ssr::OscReceiver::add_poll_methods() +void ssr::OscReceiver::add_server_to_client_methods() { _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { -// lo::Address from(message.source()); std::string hostname(message.source().hostname()); std::string port(message.source().port()); if(is_server(_handler, hostname, port)) @@ -766,12 +763,6 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string name(&(argv[0]->s)); - std::string file_name_or_port_number(&(argv[2]->s)); - std::string types(message.types()); - float x(argv[3]->f); - float y(argv[4]->f); - float gain(argv[6]->f); int file_channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; @@ -779,70 +770,63 @@ void ssr::OscReceiver::add_source_methods() bool orientation_fixed; bool muted; bool setup = false; - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) - { - model = Source::point; - } - Position position(x, y); - Orientation orientation(argv[5]->f); - if (types.compare("sssffffTTT") == 0) + if (!message.types().compare("sssffffTTT")) { position_fixed = true; orientation_fixed = true; muted = true; setup = true; } - if (types.compare("sssffffTTF") == 0) + if (!message.types().compare("sssffffTTF")) { position_fixed = true; orientation_fixed = true; muted = false; setup = true; } - if (types.compare("sssffffTFF") == 0) + if (!message.types().compare("sssffffTFF")) { position_fixed = true; orientation_fixed = false; muted = false; setup = true; } - if (types.compare("sssffffFFF") == 0) + if (!message.types().compare("sssffffFFF")) { position_fixed = false; orientation_fixed = false; muted = false; setup = true; } - if (types.compare("sssffffTFT") == 0) + if (!message.types().compare("sssffffTFT")) { position_fixed = true; orientation_fixed = false; muted = true; setup = true; } - if (types.compare("sssffffFTF") == 0) + if (!message.types().compare("sssffffFTF")) { position_fixed = false; orientation_fixed = true; muted = false; setup = true; } - if (types.compare("sssffffFTT") == 0) + if (!message.types().compare("sssffffFTT")) { position_fixed = false; orientation_fixed = true; muted = true; setup = true; } - if (types.compare("sssffffFFT") == 0) + if (!message.types().compare("sssffffFFT")) { position_fixed = false; orientation_fixed = false; muted = true; setup = true; } - if (types.compare("sssffffisTTT") == 0) + if (!message.types().compare("sssffffisTTT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -852,7 +836,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisTTF") == 0) + if (!message.types().compare("sssffffisTTF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -862,7 +846,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisTFF") == 0) + if (!message.types().compare("sssffffisTFF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -872,7 +856,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisFFF") == 0) + if (!message.types().compare("sssffffisFFF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -882,7 +866,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisTFT") == 0) + if (!message.types().compare("sssffffisTFT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -892,7 +876,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisFTF") == 0) + if (!message.types().compare("sssffffisFTF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -902,7 +886,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisFTT") == 0) + if (!message.types().compare("sssffffisFTT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -912,7 +896,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisFFT") == 0) + if (!message.types().compare("sssffffisFFT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -924,6 +908,18 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); + float x(argv[3]->f); + float y(argv[4]->f); + float gain(argv[6]->f); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << ", " << orientation.azimuth << ", " << gain<< ", " << diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index a23d41b3..646b9dde 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -39,7 +39,7 @@ class OscReceiver ssr::OscHandler& _handler; void add_client_to_server_methods(); void add_update_notification_methods(); - void add_poll_methods(); + void add_server_to_client_methods(); void add_source_methods(); void add_reference_methods(); void add_scene_methods(); @@ -74,8 +74,8 @@ class OscReceiver ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, std::string hostname, std::string port); - void set_client_message_level(OscHandler& self, std::string hostname, std::string - port, ssr::MessageLevel message_level); + void set_client_message_level(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level); }; } // namespace ssr From 37c323b70d6af13f521588011ca442cbb81c78e7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 22:49:57 +0200 Subject: [PATCH 155/363] src/networking/oscsender.cpp: Fixing line breaks and indents. --- src/networking/oscsender.cpp | 186 +++++++++++++++++------------------ 1 file changed, 91 insertions(+), 95 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 68d71d7f..da8b0f8c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -493,7 +493,8 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) !(client->port().compare(port)) && client->active()) { client->deactivate(); - VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); + VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << + "."); } } } @@ -622,10 +623,11 @@ void ssr::OscSender::delete_all_sources() { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/delete", "i", 0); + client->address().send_from(_handler.server(), "/source/delete", "i", + 0); VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -721,8 +723,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), - message_id); + "/source/position_fixed", + "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << _handler.bool_to_message_type(fixed) << ", " << message_id << "] to client " << client->address().hostname() << ":" << @@ -733,12 +735,12 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/position_fixed", + _server.address().send_from(_handler.server(), + "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -774,8 +776,8 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { if(client && client->active()) { - client->address().send_from(_handler.server(), - "/source/orientation", "if", message_id, message_orientation); + client->address().send_from(_handler.server(), "/source/orientation", + "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id << ", " << message_orientation << "] to client " << client->address().hostname() << ":" << @@ -786,12 +788,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/orientation", - "if", message_id, message_orientation); + _server.address().send_from(_handler.server(), + "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << - apf::str::A2S(message_id) << ", " << - apf::str::A2S(message_orientation) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) + << "] to server " << _server.hostname() << ":" << _server.port() << + "."); } return true; } @@ -825,23 +827,22 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/gain", - "if", message_id, gain); - VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << - ", " << gain << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + client->address().send_from(_handler.server(), "/source/gain", "if", + message_id, gain); + VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " + << gain << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/gain", - "if", message_id, gain); + _server.address().send_from(_handler.server(), "/update/source/gain", "if", + message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -892,8 +893,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << - apf::str::A2S(message_id) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_id) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -928,12 +929,11 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/name", - "is", message_id, message_name); + client->address().send_from(_handler.server(), "/source/name", "is", + message_id, message_name); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << message_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + << message_name << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } @@ -943,8 +943,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server.hostname() << ":" - << _server.port() << "."); + << message_name << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -995,8 +995,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << file_name << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + message_id << ", " << file_name << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } return true; } @@ -1017,8 +1017,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(client && client->active()) { - client->address().send_from(_handler.server(), - "/scene/decay_exponent", "f", exponent); + client->address().send_from(_handler.server(), "/scene/decay_exponent", + "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); @@ -1030,8 +1030,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << "] to server " << _server.hostname() << ":" << _server.port() << + "."); } } @@ -1102,23 +1102,23 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/model", - "is", message_id, message_model.c_str()); + client->address().send_from(_handler.server(), "/source/model", "is", + message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " << message_model << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/model", "is", - message_id, message_model.c_str()); + _server.address().send_from(_handler.server(), "/update/source/model", + "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + ", " << message_model << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1143,8 +1143,8 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + ", " << port_name << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1189,8 +1189,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1243,8 +1243,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1254,8 +1254,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + << ", " << message_file_channel << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } return true; } @@ -1278,11 +1278,11 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) int32_t message_length = static_cast(length); if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/length", "ii", - message_id, message_length); - VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id - << ", " << message_length << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _server.address().send_from(_handler.server(), "/update/source/length", + "ii", message_id, message_length); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", + " << message_length << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1308,19 +1308,18 @@ void ssr::OscSender::set_reference_position(const Position& position) client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + ", " << position.y << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/reference/position", - "ff", position.x, position.y); + _server.address().send_from(_handler.server(), + "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + << ", " << position.y << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1346,8 +1345,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << orientation.azimuth << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1356,8 +1355,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1424,8 +1423,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << orientation.azimuth << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1434,8 +1433,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1471,8 +1470,7 @@ void ssr::OscSender::set_master_volume(float volume) _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } } @@ -1515,8 +1513,8 @@ void ssr::OscSender::set_processing_state(bool state) _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << _handler.bool_to_message_type(state) << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1574,11 +1572,11 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1678,8 +1675,8 @@ void ssr::OscSender::set_sample_rate(int sr) _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_sr) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1718,8 +1715,8 @@ void ssr::OscSender::set_master_signal_level(float level) _server.address().send_from(_handler.server(), "/update/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_level) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1761,8 +1758,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) "if", message_id, message_level); VERBOSE3("OscSender: Sent [/update/source/level, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } From f6435bd934fb9c5f388644e822496cc23d194c39 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 22:50:59 +0200 Subject: [PATCH 156/363] src/networking/oschandler.cpp: Removing obsolete TODO. --- src/networking/oschandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 9ad2bf87..14a7d96c 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -43,7 +43,6 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, ssr::OscHandler::~OscHandler() { stop(); - //TODO: delete members of _client_addresses VERBOSE("OscHandler: Destructing."); } From d80e0520fc9a2a6fda0afe7ad50314dccdb96202 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 23:01:53 +0200 Subject: [PATCH 157/363] src/networking/oscsender.cpp: Fixing broken string line wrap in VERBOSE. --- src/networking/oscsender.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index da8b0f8c..b5ea406c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1280,9 +1280,9 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); - VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", - " << message_length << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << + ", " << message_length << "] to server " << _server.hostname() << ":" + << _server.port() << "."); } return true; } From 15fe3dd327e8ad08ee77a7cef42d7532251cd845 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 23:47:34 +0200 Subject: [PATCH 158/363] src/networking/*: Implementing from_is() functionality in OscHandler, returning a const std::string, depending on whether the handler is server or client. Implementing from_is() in all VERBOSE messages in client/server callbacks. --- src/networking/oschandler.cpp | 17 ++++ src/networking/oschandler.h | 3 + src/networking/oscreceiver.cpp | 150 ++++++++++++++++++--------------- 3 files changed, 101 insertions(+), 69 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 14a7d96c..1f8f9c24 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -343,3 +343,20 @@ const std::string ssr::OscHandler::bool_to_string(const bool& message) return _string_false; } } + +/** + * Returns a std::string representing from where messages where received from + * on this instance. Depends on whether this instance is a server or a client. + * @return 'client' if _mode is "server", 'server' otherwise + */ +const std::string ssr::OscHandler::from_is() +{ + if(is_server()) + { + return _string_client; + } + else + { + return _string_server; + } +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 88b0117f..3d231651 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -24,6 +24,8 @@ namespace const std::string _message_type_true{"T"}; const std::string _string_false{"false"}; const std::string _string_true{"true"}; + const std::string _string_server{"server"}; + const std::string _string_client{"client"}; } namespace ssr @@ -59,6 +61,7 @@ class OscHandler lo::ServerThread& server(); const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); + const std::string from_is(); // OscReceiver friend functions friend void OscReceiver::set_server_address(OscHandler& self, std::string& hostname, std::string& port); diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 20a14ba4..2c1734fa 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -599,16 +599,17 @@ i{F,T}."); void ssr::OscReceiver::add_server_to_client_methods() { + // set OscSender's _server _message_level through OscHandler: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { std::string hostname(message.source().hostname()); std::string port(message.source().port()); + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from server '" << message.source().hostname() << ":" << + message.source().port() << "'."); if(is_server(_handler, hostname, port)) { - VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); set_server_message_level(_handler, static_cast(argv[0]->i)); } @@ -659,10 +660,10 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { - std::string from = (_handler.is_server())? "client": "server"; VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from " << from << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); if (argv[0]->i == 0) { _controller.delete_all_sources(); @@ -680,8 +681,9 @@ void ssr::OscReceiver::add_source_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " - << argv[1]->i << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->i << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } ); @@ -692,8 +694,9 @@ void ssr::OscReceiver::add_source_methods() int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << - argv[1]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); } @@ -711,8 +714,9 @@ void ssr::OscReceiver::add_source_methods() model = Source::point; } VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_model(argv[0]->i, model); } ); @@ -725,15 +729,16 @@ void ssr::OscReceiver::add_source_methods() if(!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", true] from client '"<< message.source().hostname() << ":" << + ", true] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_mute(argv[0]->i, true); } else if(!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", false] from client '"<< message.source().hostname() << ":" << - message.source().port() << "'."); + ", false] from " << _handler.from_is() << " '"<< + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_mute(argv[0]->i, false); } } @@ -745,9 +750,9 @@ void ssr::OscReceiver::add_source_methods() lo::Message message) { std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << + VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << name + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_name(argv[0]->i, name); } @@ -926,9 +931,9 @@ void ssr::OscReceiver::add_source_methods() channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << - _handler.bool_to_string(muted) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(muted) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.new_source(name, model, file_name_or_port_number, file_channel, position, position_fixed, orientation, orientation_fixed, gain, muted, properties_file); @@ -955,8 +960,9 @@ void ssr::OscReceiver::add_source_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); } ); @@ -968,8 +974,9 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_port_name(argv[0]->i, name); } ); @@ -980,8 +987,9 @@ void ssr::OscReceiver::add_source_methods() int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << - argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << "'."); + argv[1]->f << ", " << argv[2]->f << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); } @@ -995,14 +1003,14 @@ void ssr::OscReceiver::add_source_methods() if (!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from client '" << message.source().hostname() << ":" << + ", true] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position_fixed(argv[0]->i, true); } else if (!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from client '" << message.source().hostname() << ":" << + ", false] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position_fixed(argv[0]->i, false); } @@ -1016,7 +1024,7 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from client '" << message.source().hostname() << + ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_properties_file(argv[0]->i, name); } @@ -1042,8 +1050,9 @@ void ssr::OscReceiver::add_reference_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/orientation, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_orientation(Orientation(argv[0]->f)); } ); @@ -1054,8 +1063,9 @@ void ssr::OscReceiver::add_reference_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); @@ -1067,8 +1077,9 @@ void ssr::OscReceiver::add_reference_methods() [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + argv[0]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); } ); @@ -1079,7 +1090,7 @@ void ssr::OscReceiver::add_reference_methods() [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << + << ", " << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_reference_offset_position(Position(argv[0]->f, @@ -1112,9 +1123,9 @@ void ssr::OscReceiver::add_scene_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/scene/clear] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/clear] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); _controller.delete_all_sources(); } ); @@ -1125,9 +1136,9 @@ void ssr::OscReceiver::add_scene_methods() lo::Message message) { std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.load_scene(name); } ); @@ -1138,9 +1149,9 @@ void ssr::OscReceiver::add_scene_methods() lo::Message message) { std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.save_scene_as_XML(name); } ); @@ -1150,9 +1161,9 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << "] from " + << _handler.from_is() << " '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); } ); @@ -1179,17 +1190,17 @@ void ssr::OscReceiver::add_processing_methods() if(!message.types().compare("T")) { VERBOSE2("OscReceiver: Got [/processing/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(true) << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.start_processing(); } else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/processing/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(false) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.stop_processing(); } } @@ -1215,9 +1226,9 @@ void ssr::OscReceiver::add_transport_methods() **argv, int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/transport/rewind] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/transport/rewind] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_locate(0); } ); @@ -1232,8 +1243,9 @@ void ssr::OscReceiver::add_transport_methods() if(apf::str::string2time(message_time, time)) { VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.transport_locate(time); } else @@ -1253,17 +1265,17 @@ void ssr::OscReceiver::add_transport_methods() if(!message.types().compare("T")) { VERBOSE3("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(true) << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_start(); } if(!message.types().compare("F")) { VERBOSE3("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(false) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_stop(); } } @@ -1287,9 +1299,9 @@ void ssr::OscReceiver::add_tracker_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/tracker/reset] from client " << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/tracker/reset] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.calibrate_client(); } ); From 0f1f811eded1e7f4b6b4876fd367c2d8d8f378ad Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 01:49:42 +0200 Subject: [PATCH 159/363] src/networking/*: Adding client_has_message_level() to OscSender (and to OscReceiver by OscHandler friend function) to check for MessageLevel of a client defined by hostname and port. Applying checks to whether caller of a message is the server currently setup (client mode) or if a client exists with a MessageLevel::SERVER (server mode) to be able to shut out unsolicited OSC messages to clients and servers. This way clients only listen to servers subscribed to and servers only to clients with a MessageLevel of SERVER. --- src/networking/oschandler.cpp | 16 ++ src/networking/oschandler.h | 2 + src/networking/oscreceiver.cpp | 414 ++++++++++++++++++++++++++------- src/networking/oscreceiver.h | 2 + src/networking/oscsender.cpp | 30 ++- src/networking/oscsender.h | 2 + 6 files changed, 376 insertions(+), 90 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 1f8f9c24..3e7433a2 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -259,6 +259,22 @@ void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string self._osc_sender.set_client_message_level(hostname, port, message_level); } +/** + * OscHandler's friend function to check if a client's message_level is greater + * or equal to one provided. + * @param self reference to OscHandler holding OscSender + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel to check for + * @return true, if the MessageLevel is equal or greater than the one + * requested, false otherwise + */ +bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& + hostname, std::string& port, ssr::MessageLevel message_level) +{ + self._osc_sender.client_has_message_level(hostname, port, message_level); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 3d231651..a49a8cfa 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -89,6 +89,8 @@ class OscHandler hostname, std::string port); friend void OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); + friend bool OscReceiver::client_has_message_level(OscHandler& self, std::string& + hostname, std::string& port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2c1734fa..b48892e7 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -660,17 +660,25 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - if (argv[0]->i == 0) - { - _controller.delete_all_sources(); - } - else + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) { - _controller.delete_source(argv[0]->i); + if (argv[0]->i == 0) + { + _controller.delete_all_sources(); + } + else + { + _controller.delete_source(argv[0]->i); + } } } ); @@ -684,7 +692,15 @@ void ssr::OscReceiver::add_source_methods() << argv[1]->i << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + } } ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); @@ -697,8 +713,16 @@ void ssr::OscReceiver::add_source_methods() argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/gain if."); @@ -717,7 +741,15 @@ void ssr::OscReceiver::add_source_methods() name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_model(argv[0]->i, model); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_model(argv[0]->i, model); + } } ); VERBOSE("OscReceiver: Added callback for /source/model is."); @@ -729,9 +761,18 @@ void ssr::OscReceiver::add_source_methods() if(!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", true] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_mute(argv[0]->i, true); + ", true] from " << _handler.from_is() << " '"<< + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_mute(argv[0]->i, true); + } } else if(!message.types().compare("iF")) { @@ -739,7 +780,15 @@ void ssr::OscReceiver::add_source_methods() ", false] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_mute(argv[0]->i, false); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_mute(argv[0]->i, false); + } } } ); @@ -754,7 +803,15 @@ void ssr::OscReceiver::add_source_methods() << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_name(argv[0]->i, name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_name(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/name is."); @@ -913,42 +970,50 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { - std::string name(&(argv[0]->s)); - std::string file_name_or_port_number(&(argv[2]->s)); - float x(argv[3]->f); - float y(argv[4]->f); - float gain(argv[6]->f); - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) { - model = Source::point; + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); + float x(argv[3]->f); + float y(argv[4]->f); + float gain(argv[6]->f); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); + VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model + << ", " << file_name_or_port_number << ", " << x << ", " << y << + ", " << orientation.azimuth << ", " << gain<< ", " << + channel_and_properties << ", " << + _handler.bool_to_string(position_fixed) << ", " << + _handler.bool_to_string(orientation_fixed) << ", " << + _handler.bool_to_string(muted) << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" + << message.source().port() << "'."); + _controller.new_source(name, model, file_name_or_port_number, + file_channel, position, position_fixed, orientation, + orientation_fixed, gain, muted, properties_file); + VERBOSE2("OscReceiver: Created source with following properties:" + "\nname: " << name << + "\nmodel: " << model << + "\nfile_name_or_port_number: " << file_name_or_port_number << + "\nfile_channel: " << file_channel << + "\nposition: " << position << + "\nposition_fixed: " << position_fixed << + "\norientation: " << orientation << + "\norientation_fixed: " << orientation_fixed << + "\ngain (linear): " << gain << + "\nmuted: " << muted << + "\nproperties_file: " << properties_file); } - Position position(x, y); - Orientation orientation(argv[5]->f); - VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << - ", " << file_name_or_port_number << ", " << x << ", " << y << ", " - << orientation.azimuth << ", " << gain<< ", " << - channel_and_properties << ", " << - _handler.bool_to_string(position_fixed) << ", " << - _handler.bool_to_string(orientation_fixed) << ", " << - _handler.bool_to_string(muted) << "] from " << _handler.from_is() - << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.new_source(name, model, file_name_or_port_number, - file_channel, position, position_fixed, orientation, - orientation_fixed, gain, muted, properties_file); - VERBOSE2("OscReceiver: Created source with following properties:" - "\nname: " << name << - "\nmodel: " << model << - "\nfile_name_or_port_number: " << file_name_or_port_number << - "\nfile_channel: " << file_channel << - "\nposition: " << position << - "\nposition_fixed: " << position_fixed << - "\norientation: " << orientation << - "\norientation_fixed: " << orientation_fixed << - "\ngain (linear): " << gain << - "\nmuted: " << muted << - "\nproperties_file: " << properties_file); } } ); @@ -963,7 +1028,15 @@ void ssr::OscReceiver::add_source_methods() << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/orientation if."); @@ -977,7 +1050,15 @@ void ssr::OscReceiver::add_source_methods() name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_port_name(argv[0]->i, name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_port_name(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/port_name is."); @@ -990,8 +1071,16 @@ void ssr::OscReceiver::add_source_methods() argv[1]->f << ", " << argv[2]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/position iff."); @@ -1003,16 +1092,34 @@ void ssr::OscReceiver::add_source_methods() if (!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, true); + ", true] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_position_fixed(argv[0]->i, true); + } } else if (!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, false); + ", false] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_position_fixed(argv[0]->i, false); + } } } ); @@ -1024,9 +1131,18 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_properties_file(argv[0]->i, name); + ", " << name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_properties_file(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/properties_file is."); @@ -1053,7 +1169,15 @@ void ssr::OscReceiver::add_reference_methods() "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_orientation(Orientation(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_orientation(Orientation(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference/orientation f."); @@ -1066,7 +1190,15 @@ void ssr::OscReceiver::add_reference_methods() << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference/position ff."); @@ -1080,7 +1212,15 @@ void ssr::OscReceiver::add_reference_methods() argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); @@ -1093,8 +1233,16 @@ void ssr::OscReceiver::add_reference_methods() << ", " << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); @@ -1126,7 +1274,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/clear] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.delete_all_sources(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.delete_all_sources(); + } } ); VERBOSE("OscReceiver: Added callback for /scene/clear."); @@ -1139,7 +1295,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.load_scene(name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.load_scene(name); + } } ); VERBOSE("OscReceiver: Added callback for /scene/load s."); @@ -1152,7 +1316,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.save_scene_as_XML(name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.save_scene_as_XML(name); + } } ); VERBOSE("OscReceiver: Added callback for /scene/save s."); @@ -1164,7 +1336,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /scene/volume f."); @@ -1193,7 +1373,15 @@ void ssr::OscReceiver::add_processing_methods() _handler.bool_to_string(true) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.start_processing(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.start_processing(); + } } else if(!message.types().compare("F")) { @@ -1201,7 +1389,15 @@ void ssr::OscReceiver::add_processing_methods() _handler.bool_to_string(false) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.stop_processing(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.stop_processing(); + } } } ); @@ -1229,7 +1425,15 @@ void ssr::OscReceiver::add_transport_methods() VERBOSE2("OscReceiver: Got [/transport/rewind] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_locate(0); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.transport_locate(0); + } } ); VERBOSE("OscReceiver: Added callback for /transport/rewind."); @@ -1238,20 +1442,28 @@ void ssr::OscReceiver::add_transport_methods() _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int, lo::Message message) { - float time; std::string message_time(&argv[0]->s); - if(apf::str::string2time(message_time, time)) - { - VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << - "] from " << _handler.from_is() << " '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_locate(time); - } - else + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) { - ERROR("Couldn't get the time out of the \"seek\" attribute (\"" - << message_time << "\")."); + float time; + if(apf::str::string2time(message_time, time)) + { + _controller.transport_locate(time); + } + else + { + ERROR("Couldn't get the time out of the \"seek\" attribute (\"" + << message_time << "\")."); + } } } ); @@ -1268,7 +1480,15 @@ void ssr::OscReceiver::add_transport_methods() _handler.bool_to_string(true) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_start(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.transport_start(); + } } if(!message.types().compare("F")) { @@ -1276,7 +1496,15 @@ void ssr::OscReceiver::add_transport_methods() _handler.bool_to_string(false) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_stop(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.transport_stop(); + } } } ); @@ -1302,7 +1530,15 @@ void ssr::OscReceiver::add_tracker_methods() VERBOSE2("OscReceiver: Got [/tracker/reset] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.calibrate_client(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.calibrate_client(); + } } ); VERBOSE("OscReceiver: Added callback for /tracker/reset."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 646b9dde..9a1fba6f 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -76,6 +76,8 @@ class OscReceiver port); void set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); + bool client_has_message_level(OscHandler& self, std::string& hostname, + std::string& port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b5ea406c..85545338 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -500,7 +500,7 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) } /** - * Set message level of a client + * Set MessageLevel of a client * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client * @param message_level ssr::MessageLevel enum representing the message level @@ -521,6 +521,34 @@ void ssr::OscSender::set_client_message_level(std::string hostname, std::string } } +/** + * Compare MessageLevel of a client with one provided + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + * @param message_level ssr::MessageLevel enum representing the message level + * to use + * @return true, if @s message_level is equal or less of what the client, + * defined by @s hostname and @s port has set, false otherwise (also if client + * is not found). + */ +bool ssr::OscSender::client_has_message_level(std::string& hostname, + std::string& port, ssr::MessageLevel message_level) +{ + bool has_level = false; + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->message_level() >= + message_level) + { + has_level = true; + break; + } + } + return has_level; +} + + /** * Removes all clients from the vector of clients. */ diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 056650be..148ec100 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -77,6 +77,8 @@ class OscSender : public Subscriber message_level); void set_client_message_level(std::string hostname, std::string port, ssr::MessageLevel message_level); + bool client_has_message_level(std::string& hostname, std::string& port, + ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From ad0b5620782e3804b2d7865163fd038a88c867ca Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 11:34:41 +0200 Subject: [PATCH 160/363] src/networking/oscreceiver.cpp: Removing obsolete TODOs. --- src/networking/oscreceiver.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b48892e7..440c7e8c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -15,7 +15,6 @@ using namespace apf::str; * Constructor * @param controller reference to a Publisher object * @param port_in integer representing a port to used for incoming OSC messages - * @todo add error handler for ServerThread */ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) : _controller(controller) @@ -649,9 +648,6 @@ void ssr::OscReceiver::add_server_to_client_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * set source related settings). */ void ssr::OscReceiver::add_source_methods() { @@ -1155,9 +1151,6 @@ void ssr::OscReceiver::add_source_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_reference_methods() { @@ -1253,9 +1246,6 @@ void ssr::OscReceiver::add_reference_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_scene_methods() { @@ -1356,9 +1346,6 @@ void ssr::OscReceiver::add_scene_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_processing_methods() { @@ -1411,9 +1398,6 @@ void ssr::OscReceiver::add_processing_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_transport_methods() { @@ -1516,9 +1500,6 @@ void ssr::OscReceiver::add_transport_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_tracker_methods() { From c1d4b383d8fe4be312f1e179f74a8f4f3430548c Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:15:16 +0200 Subject: [PATCH 161/363] src/publisher.h: Adding set_source_file_name() to public Publisher interface. --- src/publisher.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/publisher.h b/src/publisher.h index 3f4c1739..be4c67b0 100644 --- a/src/publisher.h +++ b/src/publisher.h @@ -114,6 +114,7 @@ struct Publisher virtual void set_source_position_fixed(id_t id, const bool fix) = 0; virtual void set_source_file_channel(id_t id, const int& channel) = 0; + virtual void set_source_file_name(id_t id, const std::string& file_name) = 0; /// set position of the reference /// @param position well, the position From 651da3bbe89952029a86a19117df70003264aa30 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:16:07 +0200 Subject: [PATCH 162/363] src/networking/oschandler.cpp: Fix missing return statement in ssr::OscReceiver::client_has_message_level() friend function implementation. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 3e7433a2..688f3811 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -272,7 +272,7 @@ void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level) { - self._osc_sender.client_has_message_level(hostname, port, message_level); + return self._osc_sender.client_has_message_level(hostname, port, message_level); } From f102eafced8beba234cc675078a7aafe0d0b3046 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:33:39 +0200 Subject: [PATCH 163/363] src/networking/oscreceiver.cpp: Adding client callbacks for /cpu_load with MessageLevel GUI_CLIENT. Adding callback for /source/file_name_or_port_number. Adding callback for /source/level. Adding callback for /scene/amplitude_reference_distance, /scene/auto_rotate_sources, /scene/decay_exponent. Adding callback for /update/scene/master_signal_level. src/networking/oscsender.cpp: Updating check for MessageLevel in ssr:OscSender::client_has_message_level() to check if client is active. Adding server-side implementation to ssr::OscSender::set_cpu_load(). Removing server-side implementation from ssr::OscSender::set_sample_rate(). Sending messages only to GUI_CLIENT clients in set_source_signal_level(), set_master_signal_level(). Removing obsolete TODOs. Minor fixes. --- src/networking/oscreceiver.cpp | 148 ++++++++++++++++++++++++++++++++- src/networking/oscsender.cpp | 96 +++++++-------------- 2 files changed, 177 insertions(+), 67 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 440c7e8c..a79dbbd4 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -311,7 +311,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent f."); // update on scene master signal level: "/update/scene/master_signal_level, // f, master_signal_level" @@ -597,6 +597,16 @@ i{F,T}."); */ void ssr::OscReceiver::add_server_to_client_methods() { + // set cpu_load: "/cpu_load, f, load" + _handler.server().add_method("/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) + { + VERBOSE3("OscReceiver: Got [/cpu_load, " << argv[0]->f << + "] from server '" << message.source().hostname() << ":" << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /cpu_load f."); // set OscSender's _server _message_level through OscHandler: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, @@ -701,12 +711,36 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); + // set source file_name_or_port_number: + // "/source/file_name_or_port_number, is, id, file_name_or_port_number" + _handler.server().add_method("/source/file_name_or_port_number", "is", + [this](lo_arg **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/source/file_name_or_port_number, " << + argv[0]->i << ", " << name << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_file_name(argv[0]->i, name); + } + } + ); + VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number" + "is."); + // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << - argv[1]->f << "] from " << _handler.from_is() << " '" << + argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); std::string hostname(message.source().hostname()); @@ -723,6 +757,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/gain if."); + // set source signal level (GUI_CLIENT only): "/source/level, if, id, level" + _handler.server().add_method("/source/level", "if", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/source/level, " << argv[0]->i << ", "<< + argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /source/level if."); + // set source model: "/source/model, is, id, model" _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int, lo::Message message) @@ -1256,6 +1302,70 @@ void ssr::OscReceiver::add_scene_methods() //_add_loudspeakers(node); //_add_sources(node); + // set scene's amplitude reference distance: + // "/scene/amplitude_reference_distance, f, amplitude_reference_distance" + _handler.server().add_method("/scene/amplitude_reference_distance", "f", + [this](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/amplitude_reference_distance, " << + argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_amplitude_reference_distance(argv[0]->f); + } + } + ); + VERBOSE("OscReceiver: Added callback for \ +/scene/amplitude_reference_distance f."); + + // set scene source auto rotation: "/scene/auto_rotate_sources, {F,T}, + // false|true" + _handler.server().add_method("/scene/auto_rotate_sources", NULL, + [this](lo_arg **argv, int, lo::Message message) + { + (void) argv; + if(!message.types().compare("T")) + { + VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_auto_rotation(true); + } + } + else if(!message.types().compare("F")) + { + VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_auto_rotation(false); + } + } + } + ); + VERBOSE("OscReceiver: Added callback for /scene/auto_rotate_sources {F,T}."); + // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1277,6 +1387,27 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/clear."); + // set scene decay exponent: "/scene/decay_exponent, f, decay_exponent" + _handler.server().add_method("/scene/decay_exponent", "f", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_decay_exponent(argv[0]->f); + } + } + ); + VERBOSE("OscReceiver: Added callback for /scene/decay_exponent f."); + // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) @@ -1319,6 +1450,19 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/save s."); + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/scene/master_signal_level", "f", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/master_signal_level, " << argv[0]->f + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /scene/master_signal_level f."); + // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 85545338..60abb83d 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -538,8 +538,8 @@ bool ssr::OscSender::client_has_message_level(std::string& hostname, for (auto& client: _clients) { if(!(client->hostname().compare(hostname)) && - !(client->port().compare(port)) && client->message_level() >= - message_level) + !(client->port().compare(port)) && client->active() && + client->message_level() >= message_level) { has_level = true; break; @@ -1035,7 +1035,6 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& * On client: Sends out OSC message to server about the updating of decay_exponent * @param exponentn float representing the decay exponent * @param name a std::string representing the properties_file of source - * @todo implement receiving in OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_decay_exponent(float exponent) { @@ -1071,7 +1070,6 @@ void ssr::OscSender::set_decay_exponent(float exponent) * On client: Sends out OSC message to server about the updating of the * amplitude reference distance. * @param distance a float representing the amplitude reference distance - * @todo implement receiving in OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { @@ -1083,9 +1081,9 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + VERBOSE3("OscSender: Sent [/scene/amplitude_reference_distance, f, " << + distance << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } @@ -1190,8 +1188,6 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& * @param file_name a std::string representing the file name or * port number of source * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) @@ -1246,8 +1242,6 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& * @param id id_t representing the source * @param file_channel an int representing the channel in use for source * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { @@ -1297,8 +1291,6 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) * @param id id_t representing the source * @param length an int representing the source file's length * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { @@ -1322,8 +1314,6 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) * On client: Sends out OSC message to server about the updating of the * reference position. * @param position a Position representing the new reference position - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_position(const Position& position) { @@ -1358,8 +1348,6 @@ void ssr::OscSender::set_reference_position(const Position& position) * On client: Sends out OSC message to server about the updating of the * reference orientation. * @param orientation an Orientation representing the new reference orientation - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { @@ -1396,8 +1384,6 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) * On client: Sends out OSC message to server about the updating of the * reference offset position. * @param position a Position representing the new reference offset position - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_offset_position(const Position& position) { @@ -1435,8 +1421,6 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) * reference offset orientation. * @param orientation an Orientation representing the new reference offset * orientation - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) @@ -1473,8 +1457,6 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& * On client: Sends out OSC message to server about the updating of the master * volume (submits in dB!). * @param volume float representing the new volume (linear scale) - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_master_volume(float volume) { @@ -1526,8 +1508,6 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* * On client: Sends out OSC message to server about the update of its * processing state. * @param state bool representing the processing state - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_processing_state(bool state) { @@ -1564,8 +1544,6 @@ void ssr::OscSender::set_processing_state(bool state) * processing state. * @param state a std::pair of a bool representing the processing state and * jack_nframes_t, representing the current location in the transport - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_transport_state( const std::pair& state) @@ -1617,8 +1595,6 @@ void ssr::OscSender::set_transport_state( const std::pairactive() && client->message_level() == + MessageLevel::GUI_CLIENT) + { + client->address().send_from(_handler.server(), "/cpu_load", "f", load); + VERBOSE3("OscSender: Sent [/cpu_load, f, " << apf::str::A2S(load) << + "] to client " << client->hostname() << ":" << client->port() << + "."); + } + } + } + else if(_handler.is_client() && !server_is_default() && _server.message_level() == MessageLevel::GUI_SERVER) { _server.address().send_from(_handler.server(), "/update/cpu_load", "f", @@ -1672,33 +1660,16 @@ void ssr::OscSender::set_cpu_load(float load) /** * Subscriber function called, when Publisher set sample rate. - * On server: Sends out OSC message to all clients to update their - * sample rate. - * On client: Sends out OSC message to server about the update of its - * sample rate. + * On server: Does nothing, as the sample rate is set during SSR startup and + * can not be changed during runtime. + * On client: Sends out OSC message to server about the update of its sample + * rate. * @param sr an integer representing the current sample rate. - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_sample_rate(int sr) { int32_t message_sr = static_cast(sr); - if(_handler.is_server()) - { - for (const auto& client: _clients) - { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/scene/sample_rate", - "i", message_sr); - VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to client " << - client->address().hostname() << ":" << client->address().port() << - "."); - } - } - } - else if(_handler.is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); @@ -1710,13 +1681,10 @@ void ssr::OscSender::set_sample_rate(int sr) /** * Subscriber function called, when Publisher set the master signal level. - * On server: Sends out OSC message to all clients to update their master - * signal level. - * On client: Sends out OSC message to server about the update of its signal - * level. + * On server: Sends out OSC message to clients with MessageLevel GUI_CLIENT + * On client: Sends out OSC message to server with MessageLevel GUI_SERVER + * about the update of its signal level. * @param level a float representing the current master signal level. - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_master_signal_level(float level) { @@ -1725,8 +1693,8 @@ void ssr::OscSender::set_master_signal_level(float level) { for (const auto& client: _clients) { - if(client && client->active() && client->message_level() >= - MessageLevel::CLIENT) + if(client && client->active() && client->message_level() == + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); @@ -1757,8 +1725,6 @@ void ssr::OscSender::set_master_signal_level(float level) * @param id an id_t representing the source. * @param level a float representing the signal level of the source. * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { @@ -1769,7 +1735,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) for (const auto& client: _clients) { if(client && client->active() && client->message_level() >= - MessageLevel::CLIENT) + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); From 38c49db6e453d714e9deb757a868ede2fd25df9b Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 18:42:41 +0200 Subject: [PATCH 164/363] src/networking/oscreceiver.h: Remove obsolete todo. --- src/networking/oscreceiver.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 9a1fba6f..9250cf8a 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -30,7 +30,6 @@ class OscHandler; * This class holds a Publisher and an OscHandler reference. * It is responsible for all incoming OSC messages and using callback functions * to trigger functionality in the Publisher. - * @todo add functionality to only process a subset of incoming client messages */ class OscReceiver { From 5d23744f3e6e12d5a1fb1a1259a4afef609e0ae9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 01:01:40 +0200 Subject: [PATCH 165/363] src/ssr_global.h: Removing unused field THIN_CLIENT from enum class MessageLevel. Moving SERVER and GUI_SERVER to the top values. --- src/ssr_global.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ssr_global.h b/src/ssr_global.h index 726569c2..eefb266d 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -53,11 +53,10 @@ extern float c_inverse; ///< reciprocal value of c extern unsigned int usleeptime; enum class MessageLevel : id_t { - SERVER = 0, - GUI_SERVER, - THIN_CLIENT, - CLIENT, - GUI_CLIENT + CLIENT = 0, + GUI_CLIENT, + SERVER, + GUI_SERVER }; } // namespace ssr From 159107dfb3907925e52c34a2042dec5a60db6aef Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 10:02:26 +0200 Subject: [PATCH 166/363] src/networking/oscreceiver.cpp: Making callback for /update/source/mute and /update/source/position_fixed more robust. Switching to VERBOSE2 (from VERBOSE3) in callback handlers for all non-rapid messages. --- src/networking/oscreceiver.cpp | 98 +++++++++++++++++----------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index a79dbbd4..e6927fca 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -216,7 +216,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + VERBOSE2("OscReceiver: Got [/update/reference/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -227,7 +227,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/update/reference/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -240,7 +240,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + VERBOSE2("OscReceiver: Got [/update/reference_offset/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -254,7 +254,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + VERBOSE2("OscReceiver: Got [/update/reference_offset/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -269,7 +269,7 @@ ff."); _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + VERBOSE2("OscReceiver: Got [/update/scene/amplitude_reference_distance, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -292,7 +292,7 @@ ff."); { state = false; } - VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/update/scene/auto_rotate_sources, " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -306,7 +306,7 @@ ff."); _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -330,7 +330,7 @@ f."); _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + VERBOSE2("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -341,7 +341,7 @@ f."); _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + VERBOSE2("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -352,7 +352,7 @@ f."); _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/delete, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -364,7 +364,7 @@ f."); _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -378,7 +378,7 @@ f."); [](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/file_name_or_port_number, " << + VERBOSE2("OscReceiver: Got [/update/source/file_name_or_port_number, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -391,7 +391,7 @@ f."); _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/gain, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -403,7 +403,7 @@ f."); _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/length, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/length, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -427,7 +427,7 @@ f."); int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + VERBOSE2("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -439,19 +439,20 @@ f."); _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { - bool state; if(!message.types().compare("iT")) { - state = true; + VERBOSE2("OscReceiver: Got [/update/source/mute, " << argv[0]->i << + ", " << _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } else if(!message.types().compare("iF")) { - state = false; + VERBOSE2("OscReceiver: Got [/update/source/mute, " << argv[0]->i << + ", " << _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << - ", " << _handler.bool_to_string(state) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); } ); VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); @@ -461,7 +462,7 @@ f."); int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + VERBOSE2("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -473,7 +474,7 @@ f."); _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/orientation, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -485,7 +486,7 @@ f."); _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/new, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -497,7 +498,7 @@ f."); **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + VERBOSE2("OscReceiver: Got [/update/source/port_name, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -509,7 +510,7 @@ f."); _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + VERBOSE2("OscReceiver: Got [/update/source/position, " << argv[0]->i << ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -522,19 +523,20 @@ f."); _handler.server().add_method("/update/source/position_fixed", NULL, [this](lo_arg **argv, int, lo::Message message) { - bool state; if(!message.types().compare("iT")) { - state = true; + VERBOSE2("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(true) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } else if(!message.types().compare("iF")) { - state = false; + VERBOSE2("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(false) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } - VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << - argv[0]->i << ", " << _handler.bool_to_string(state) << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added callback for /update/source/position_fixed \ @@ -546,7 +548,7 @@ i{F,T}."); [](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + VERBOSE2("OscReceiver: Got [/update/source/properties_file, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -644,7 +646,7 @@ void ssr::OscReceiver::add_server_to_client_methods() } else { - VERBOSE3("OscReceiver: Got [/poll] from server " << from.hostname() << + VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Sending alive signal."); from.send_from(_handler.server(), "/alive", ""); } @@ -711,13 +713,13 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); - // set source file_name_or_port_number: - // "/source/file_name_or_port_number, is, id, file_name_or_port_number" + // set source file_name_or_port_number: "/source/file_name_or_port_number, + // is, id, file_name_or_port_number" _handler.server().add_method("/source/file_name_or_port_number", "is", [this](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/source/file_name_or_port_number, " << + VERBOSE2("OscReceiver: Got [/source/file_name_or_port_number, " << argv[0]->i << ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -732,7 +734,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number" + VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number " "is."); // set source gain: "/source/gain, if, id, gain" @@ -1031,9 +1033,9 @@ void ssr::OscReceiver::add_source_methods() } Position position(x, y); Orientation orientation(argv[5]->f); - VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model + VERBOSE2("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << - ", " << orientation.azimuth << ", " << gain<< ", " << + ", " << orientation.azimuth << ", " << gain << channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << @@ -1307,7 +1309,7 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/amplitude_reference_distance", "f", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/scene/amplitude_reference_distance, " << + VERBOSE2("OscReceiver: Got [/scene/amplitude_reference_distance, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); std::string hostname(message.source().hostname()); @@ -1332,7 +1334,7 @@ void ssr::OscReceiver::add_scene_methods() (void) argv; if(!message.types().compare("T")) { - VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/scene/auto_rotate_sources, " << _handler.bool_to_string(true) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1348,7 +1350,7 @@ void ssr::OscReceiver::add_scene_methods() } else if(!message.types().compare("F")) { - VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/scene/auto_rotate_sources, " << _handler.bool_to_string(false) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1391,7 +1393,7 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/decay_exponent", "f", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1450,8 +1452,8 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/save s."); - // update on scene master signal level: "/update/scene/master_signal_level, - // f, master_signal_level" + // set scene master signal level: "/scene/master_signal_level, f, + // master_signal_level" _handler.server().add_method("/scene/master_signal_level", "f", [this](lo_arg **argv, int, lo::Message message) { From b785d0e8bb0ad8e8d54e6d59a163b026c7074241 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 10:13:33 +0200 Subject: [PATCH 167/363] src/networking/oscsender.cpp: Moving check for file_name_or_port_number property to within statement checking for new_source in OscSender::set_source_mute (preventing accidental sending on server, before source is created). Moving check for file_channel property to within statement checking for new source in OscSender::set_source_properties_file (preventing accidental sending on server, before source is created). Moving check for file_channel > 0 to within statement checking for new source in OscSender::set_source_file_channel to prevent an unfinished source in _new_sources. Setting client check to <= GUI_CLIENT for OscSender::set_transport_state and to == GUI_CLIENT for OscSender::set_source_signal_level. Using std::string reference directly in VERBOSE messages of functions having string parameters and c_str() representation for sending OSC messages to not initialize an unneeded variable every time. --- src/networking/oscsender.cpp | 57 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 60abb83d..80627b42 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -417,7 +417,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("gain", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << _handler.bool_to_message_type( - _new_sources.at(id).get( "position_fixed", false)) << + _new_sources.at(id).get("position_fixed", false)) << _handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) << _handler.bool_to_message_type( @@ -892,10 +892,11 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) int32_t message_id = static_cast(id); if(_handler.is_server()) { - if(is_new_source(id) && - _new_sources.at(id).has_key("file_name_or_port_number")) + if(is_new_source(id)) { - _new_sources.at(id).set("mute", mute); + if(_new_sources.at(id).has_key("file_name_or_port_number")) + _new_sources.at(id).set("mute", mute); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -942,7 +943,6 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { int32_t message_id = static_cast(id); - const char * message_name = name.c_str(); if(_handler.is_server()) { if(is_new_source(id)) @@ -958,10 +958,10 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) if(client && client->active()) { client->address().send_from(_handler.server(), "/source/name", "is", - message_id, message_name); + message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << message_name << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + << name << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } @@ -969,9 +969,9 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) else if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), "/update/source/name", "is", - message_id, message_name); + message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server.hostname() << ":" << + << name << "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; @@ -993,12 +993,13 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { int32_t message_id = static_cast(id); - const char * file_name = name.c_str(); if(_handler.is_server()) { - if(is_new_source(id) && !name.empty()) + if(is_new_source(id)) { - _new_sources.at(id).set("properties_file", file_name); + if(name.compare("") && _new_sources.at(id).has_key("file_channel")) + _new_sources.at(id).set("properties_file", name); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1009,11 +1010,11 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/properties_file", "is", message_id, file_name); + "/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << - message_id << ", " << file_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + message_id << ", " << name << "] to client " << + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1021,10 +1022,10 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& else if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), - "/update/source/properties_file", "is", message_id, file_name); + "/update/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << file_name << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + message_id << ", " << name << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1150,8 +1151,8 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } /** - * Subscriber function called, when Publisher set a source's port_name. - * On server: Does nothing, as port_name is local and depends on prefix + * Subscriber function called, when Publisher set a source's port_name. On + * server: Does nothing, as port_name is local and depends on prefix * On client: Sends out OSC message to server about the successful updating of * the source's port_name. * @param id id_t representing the source @@ -1249,9 +1250,11 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) int32_t message_file_channel = static_cast(file_channel); if(_handler.is_server()) { - if(is_new_source(id) && file_channel > 0) + if(is_new_source(id)) { - _new_sources.at(id).set("file_channel", file_channel); + if(file_channel > 0) + _new_sources.at(id).set("file_channel", file_channel); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1553,8 +1556,8 @@ void ssr::OscSender::set_transport_state( const std::pairactive() && client->message_level() >= - MessageLevel::CLIENT) + if(client && client->active() && client->message_level() <= + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/transport/state", _handler.bool_to_message_type(state.first)); @@ -1734,7 +1737,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { for (const auto& client: _clients) { - if(client && client->active() && client->message_level() >= + if(client && client->active() && client->message_level() == MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/source/level", "if", From 86ecfffea645b035f2e910f86522f0e3982ca9a4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 21 Jun 2017 17:41:09 +0200 Subject: [PATCH 168/363] supercollider/workflows.scd: Adding workflow example for 'sclang is a client controlling the server' and 'sclang mimics a server, controls a client'. --- supercollider/workflows.scd | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 supercollider/workflows.scd diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd new file mode 100644 index 00000000..2dfac3c5 --- /dev/null +++ b/supercollider/workflows.scd @@ -0,0 +1,62 @@ +// workflows + +// sclang is a client, controlling a SSR server instance +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // move source 1 to -2.0/2.0 + ~address.sendMsg("/source/position", 1, -2.0, 2.0); + // move source 2 to 2.0/2.0 + ~address.sendMsg("/source/position", 2, 2.0, 2.0); + // remove all sources + ~address.sendMsg("/scene/clear"); + // unsubscribe from server + ~address.sendMsg("/subscribe", $F); +) + +// sclang is a server, controlling a SSR client instance +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // poll client instance to make it subscribe + ~address.sendMsg("/poll"); + // subsequent poll makes client emit /alive message + ~address.sendMsg("/poll"); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // set message level to GUI_SERVER (a lot of messages!) + ~address.sendMsg("/message_level", 3); + // move source 1 to -2.0/2.0 + ~address.sendMsg("/source/position", 1, -2.0, 2.0); + // move source 2 to 2.0/2.0 + ~address.sendMsg("/source/position", 2, 2.0, 2.0); + // set message level back to SERVER + ~address.sendMsg("/message_level", 1); + // remove all sources + ~address.sendMsg("/scene/clear"); +) + From ac12dd14900f5a96ce5310ec87f341937b540a45 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 24 Jun 2017 17:03:44 +0200 Subject: [PATCH 169/363] supercollider/tests.scd: Adding tests for server and client (subscribed and not subscribed). --- supercollider/tests.scd | 226 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 supercollider/tests.scd diff --git a/supercollider/tests.scd b/supercollider/tests.scd new file mode 100644 index 00000000..8f9398ed --- /dev/null +++ b/supercollider/tests.scd @@ -0,0 +1,226 @@ +// tests + +// evaluate block to add the test functions +( + +~processingTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/processing/state", [$F, $T].choose)}); +}; + +~referenceTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/reference/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/reference/position", 10.0.rand2, 10.0.rand2)}); + 100.do({address.sendMsg("/reference_offset/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/reference_offset/position", 10.0.rand2, 10.0.rand2)}); +}; + +~sceneTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/scene/amplitude_reference_distance", 10.0.rand2)}); + 10.do({address.sendMsg("/scene/auto_rotate_sources", [$F, $T].choose)}); + address.sendMsg("/scene/clear"); + 20.do({address.sendMsg("/scene/decay_exponent", rrand(-1, 10))}); + address.sendMsg("/scene/load", "some_file.asdf"); + address.sendMsg("/scene/save", "some_file.asdf"); + 100.do({address.sendMsg("/scene/master_signal_level", rrand(-100.0, 40.0))}); + 100.do({address.sendMsg("/scene/volume", rrand(-100.0, 40.0))}); +}; + +~sourceTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/source/delete", 10.rand2)}); + 20.do({address.sendMsg("/source/file_channel", 10.rand2, 10.rand)}); + 20.do({address.sendMsg("/source/file_name_or_port_number", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/source/gain", 10.rand2, rrand(-100.0, 40.0))}); + 100.do({address.sendMsg("/source/level", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/source/model", 10.rand2, ["unknown", "point", "plane", "line", "directional", "extended"].choose)}); + 20.do({address.sendMsg("/source/mute", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/source/name", 10.rand2, ("source_"++10.rand2.asString))}); + 20.do({address.sendMsg("/source/new", ("source_"++10.rand2.asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + 10.rand2.asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), rrand(-100.0, 40.0), + [$F, $T].choose, [$F, $T].choose, [$F, $T].choose) + }); + 20.do({address.sendMsg("/source/new", ("source_"++10.rand2.asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + 10.rand2.asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), rrand(-100.0, 40.0), + 10.rand2, ("file_"++10.rand2.asString), [$F, $T].choose, [$F, $T].choose, + [$F, $T].choose) + }); + 20.do({address.sendMsg("/source/orientation", 10.rand2, 360.0.rand2)}); + 20.do({address.sendMsg("/source/port_name", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/source/position", 10.rand2, 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/source/position_fixed", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/source/properties_file", 10.rand2, 10.rand2.asString)}); +}; + +~trackerTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 10.do({address.sendMsg("/tracker/reset")}); +}; + +~transportTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/transport/rewind")}); + 100.do({address.sendMsg("/transport/seek", (10.rand2.asString++":"++59.rand2.asString++":"++59.0.rand2.asString))}); + 100.do({address.sendMsg("/transport/state", [$F, $T].choose)}); +}; + +~updateTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/update/cpu_load", 100.0.rand)}); + 100.do({address.sendMsg("/update/processing/state", [$F, $T].choose)}); + 100.do({address.sendMsg("/update/reference/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/update/reference/position", 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/reference_offset/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/update/reference_offset/position", 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/scene/amplitude_reference_distance", 10.0.rand2)}); + 20.do({address.sendMsg("/update/scene/auto_rotate_sources", [$F, $T].choose)}); + 20.do({address.sendMsg("/update/scene/decay_exponent", rrand(-1.0, 10.0))}); + 20.do({address.sendMsg("/update/scene/master_signal_level", rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/scene/sample_rate", [22050, 44100, 48000, 88200, 96000].choose)}); + 20.do({address.sendMsg("/update/scene/volume", rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/delete", 10.rand2)}); + 20.do({address.sendMsg("/update/source/file_channel", 10.rand2, 10.rand2)}); + 20.do({address.sendMsg("/update/source/file_name_or_port_number", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/update/source/gain", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/level", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/model", 10.rand2, ["unknown", "point", "plane", "line", "directional", "extended"].choose)}); + 20.do({address.sendMsg("/update/source/mute", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/update/source/name", 10.rand2, ("source_"++10.rand2.asString))}); + 20.do({address.sendMsg("/update/source/new", 10.rand2)}); + 20.do({address.sendMsg("/update/source/orientation", 10.rand2, 360.0.rand2)}); + 20.do({address.sendMsg("/update/source/port_name", 10.rand2, ("in_"++10.rand2))}); + 20.do({address.sendMsg("/update/source/position", 10.rand2, 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/source/position_fixed", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/update/source/properties_file", 10.rand2, ("file_"++10.rand2.asString))}); + 20.do({address.sendMsg("/update/transport/seek", (10.rand2.asString++":"++59.rand2.asString++":"++59.0.rand2.asString))}); + 100.do({address.sendMsg("/update/transport/state", [$F, $T].choose)}); +}; + +~messageLevelTestServerRandomAll = { arg address = NetAddr("127.0.0.1", 50001), otherClient = NetAddr("127.0.0.1", 50002); + 20.do({address.sendMsg("/message_level", 10.rand2)}); + 20.do({address.sendMsg("/message_level", otherClient.ip.asString, otherClient.port.asString, 10.rand2)}); +}; + +~subscribeTestOtherClient = { arg address = NetAddr("127.0.0.1", 50001), otherClient = NetAddr("127.0.0.1", 50002); + 10.do({ + address.sendMsg("/subscribe", [$F, $T].choose, otherClient.ip, otherClient.port); + address.sendMsg("/subscribe", $T, otherClient.ip, otherClient.port, 10.rand2); + address.sendMsg("/subscribe", [$F, $T].choose); + address.sendMsg("/subscribe", $T, 10.rand2); + address.sendMsg("/subscribe", $F); + }); +}; + +~cpuLoadTestClient = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/cpu_load", 100.0.rand)}); +}; + +~messageLevelTestClientRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/message_level", 10.rand2)}); +}; + +~pollTestClientRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/poll")}); +}; + +~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; + amountOfSources.do({|item,i| + address.sendMsg("/source/new", ("source_"++(i+1).asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + (i+1).asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), + rrand(-100.0, 40.0), [$F, $T].choose, [$F, $T].choose, [$F, + $T].choose); + }); + amountOfSources.do({ |item, i| + address.sendMsg("/source/position_fixed", i+1, $F); + address.sendMsg("/source/mute", i+1, $F); + }); + 100.do({ + amountOfSources.do({|item, i| + address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); + }); + }); +}; + +) + + +// sclang tries to control/send to server (not subscribed) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + ~messageLevelTestServerRandomAll.value; + ~sourceTestRandomAll.value; + ~updateTestRandomAll.value; + ~subscribeTestOtherClient.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang controls server (subscribed) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // send alive message on subsequent poll + ~responder_poll = OSCFunc( + { |msg, time, addr, recvPort| + ~address.sendMsg("/alive"); + }, '/poll' + , ~address + ); + ~messageLevelTestServerRandomAll.value; + ~sourceTestRandomAll.value; + ~updateTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang tries to control client (not polled) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + ~messageLevelTestClientRandomAll.value; + ~cpuLoadTestClient.value; + ~sourceTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang tries to control client (polled) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + ~pollTestClientRandomAll.value; + ~messageLevelTestClientRandomAll.value; + ~cpuLoadTestClient.value; + ~sourceTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang controls a client (polled), adds sources and moves them +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + // poll client instance to make it subscribe + ~address.sendMsg("/poll"); + ~sourceTestMoving.value(amountOfSources: 20); +) + From a3b020b0742149b2aa0e4a86831af0de300b38f5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 28 Jun 2017 16:09:02 +0200 Subject: [PATCH 170/363] supercollider/tests.scd: Adding separate function to add n sources. Adding sourceTestAdding to source movement test. Making sourceTestMoving function use a Routine to move n sources randomly for 100 seconds, each 100ms. --- supercollider/tests.scd | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/supercollider/tests.scd b/supercollider/tests.scd index 8f9398ed..61c8099d 100644 --- a/supercollider/tests.scd +++ b/supercollider/tests.scd @@ -120,23 +120,23 @@ 100.do({address.sendMsg("/poll")}); }; -~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; +~sourceTestAdding = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; amountOfSources.do({|item,i| - address.sendMsg("/source/new", ("source_"++(i+1).asString), ["unknown", - "point", "plane", "line", "directional", "extended"].choose, - (i+1).asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), - rrand(-100.0, 40.0), [$F, $T].choose, [$F, $T].choose, [$F, - $T].choose); - }); - amountOfSources.do({ |item, i| - address.sendMsg("/source/position_fixed", i+1, $F); - address.sendMsg("/source/mute", i+1, $F); + address.sendMsg("/source/new", ("source_"++(i+1).asString), "point", + (i+1).asString, 10.0.rand2, 10.0.rand2, -6.0, -6.0, $F, $T, $F); }); - 100.do({ - amountOfSources.do({|item, i| - address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); +}; + +~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; + Routine{ + 1.wait; + 1000.do({ + amountOfSources.do({|item, i| + address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); + }); + 0.1.wait; }); - }); + }.play; }; ) @@ -221,6 +221,7 @@ ~address = NetAddr("127.0.0.1", 50001); // poll client instance to make it subscribe ~address.sendMsg("/poll"); + ~sourceTestAdding.value(amountOfSources: 20); ~sourceTestMoving.value(amountOfSources: 20); ) From 1d44008122182a5f131df27362d98e3a24f7174d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 28 Jun 2017 16:34:48 +0200 Subject: [PATCH 171/363] src/networking/oscreceiver.cpp: Switching to setting initial gain of a source on the logarithmic scale (to be coherent with the IP interface and how /source/gain handles things). --- src/networking/oscreceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e6927fca..6299a816 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -1025,7 +1025,7 @@ void ssr::OscReceiver::add_source_methods() std::string file_name_or_port_number(&(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); - float gain(argv[6]->f); + float gain(apf::math::dB2linear(argv[6]->f)); Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) { From ffb473cc18d6eb47a9ca78e7e5493932188a9e60 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 29 Jun 2017 10:26:57 +0200 Subject: [PATCH 172/363] src/networking/oscsender.cpp: Wrapping all VERBOSE output information about hostname:port in ''. Minor linewrap fixes. --- src/networking/oscsender.cpp | 231 ++++++++++++++++++----------------- 1 file changed, 117 insertions(+), 114 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 80627b42..dba68803 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -377,9 +377,9 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("gain", 0.0) << ", " << _new_sources.at(id).get("file_channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") - << "] to client " << + << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } _new_sources.erase(id); @@ -430,9 +430,9 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << _new_sources.at(id).get("gain", 0.0) - << "] to client " << + << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } _new_sources.erase(id); @@ -597,8 +597,8 @@ void ssr::OscSender::new_source(id_t id) _server.address().send_from(_handler.server(), "/update/source/new", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -621,8 +621,8 @@ void ssr::OscSender::delete_source(id_t id) client->address().send_from(_handler.server(), "/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -632,8 +632,8 @@ void ssr::OscSender::delete_source(id_t id) _server.address().send_from(_handler.server(), "/update/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -653,9 +653,9 @@ void ssr::OscSender::delete_all_sources() { client->address().send_from(_handler.server(), "/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -663,8 +663,8 @@ void ssr::OscSender::delete_all_sources() { _server.address().send_from(_handler.server(), "/update/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << - _server.hostname() << ":" << _server.port() << "."); + VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } _source_levels.clear(); } @@ -702,9 +702,9 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) client->address().send_from(_handler.server(), "/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << - position.x << ", " << position.y << "] to client " << + position.x << ", " << position.y << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } } @@ -714,8 +714,8 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) _server.address().send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << - ", " << position.x << ", " << position.y << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + ", " << position.x << ", " << position.y << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } return true; } @@ -755,8 +755,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << _handler.bool_to_message_type(fixed) << ", " << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -768,7 +768,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -807,9 +808,9 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& client->address().send_from(_handler.server(), "/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id - << ", " << message_orientation << "] to client " << + << ", " << message_orientation << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } } @@ -820,8 +821,8 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) - << "] to server " << _server.hostname() << ":" << _server.port() << - "."); + << "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -858,8 +859,8 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) client->address().send_from(_handler.server(), "/source/gain", "if", message_id, gain); VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " - << gain << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + << gain << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -870,7 +871,8 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -910,8 +912,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -922,8 +924,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << - apf::str::A2S(message_id) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_id) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } return true; } @@ -960,8 +962,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) client->address().send_from(_handler.server(), "/source/name", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << name << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + << name << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -971,8 +973,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << name << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << name << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1012,9 +1014,9 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& client->address().send_from(_handler.server(), "/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << - message_id << ", " << name << "] to client " << + message_id << ", " << name << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1024,8 +1026,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << name << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + message_id << ", " << name << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } return true; } @@ -1048,8 +1050,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) client->address().send_from(_handler.server(), "/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1058,8 +1060,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server.hostname() << ":" << _server.port() << - "."); + << "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } } @@ -1083,8 +1085,8 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/scene/amplitude_reference_distance, f, " << - distance << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + distance << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -1093,8 +1095,8 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) _server.address().send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " - << distance << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << distance << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1132,9 +1134,9 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) client->address().send_from(_handler.server(), "/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " - << message_model << "] to client " << + << message_model << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1144,8 +1146,8 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) _server.address().send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + ", " << message_model << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1170,8 +1172,8 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + ", " << port_name << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1213,9 +1215,9 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& "/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << - message_id << ", " << file_name << "] to client " << + message_id << ", " << file_name << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1226,8 +1228,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& "/update/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " - << message_id << ", " << file_name << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + << message_id << ", " << file_name << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } return true; } @@ -1267,9 +1269,9 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) client->address().send_from(_handler.server(), "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to client " << + << ", " << message_file_channel << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1279,8 +1281,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + << ", " << message_file_channel << "] to server '" << _server.hostname() + << ":" << _server.port() << "'."); } return true; } @@ -1304,8 +1306,8 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << - ", " << message_length << "] to server " << _server.hostname() << ":" - << _server.port() << "."); + ", " << message_length << "] to server '" << _server.hostname() << ":" + << _server.port() << "'."); } return true; } @@ -1329,8 +1331,8 @@ void ssr::OscSender::set_reference_position(const Position& position) client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + ", " << position.y << "] to client '" << client->address().hostname() + << ":" << client->address().port() << "'."); } } } @@ -1339,8 +1341,8 @@ void ssr::OscSender::set_reference_position(const Position& position) _server.address().send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << ", " << position.y << "] to server '" << _server.hostname() << ":" + << _server.port() << "'."); } } @@ -1363,9 +1365,9 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) client->address().send_from(_handler.server(), "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << - orientation.azimuth << "] to client " << + orientation.azimuth << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1374,8 +1376,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + orientation.azimuth << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1399,9 +1401,9 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) client->address().send_from(_handler.server(), "/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + position.x << ", " << position.y << "] to client '" << + client->address().hostname() << ":" << client->address().port() << + "'."); } } } @@ -1410,8 +1412,8 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) _server.address().send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + position.x << ", " << position.y << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } } @@ -1437,9 +1439,9 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& client->address().send_from(_handler.server(), "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << - orientation.azimuth << "] to client " << + orientation.azimuth << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1448,8 +1450,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + orientation.azimuth << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1473,8 +1475,8 @@ void ssr::OscSender::set_master_volume(float volume) client->address().send_from(_handler.server(), "/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1483,7 +1485,8 @@ void ssr::OscSender::set_master_volume(float volume) _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } } @@ -1523,9 +1526,9 @@ void ssr::OscSender::set_processing_state(bool state) client->address().send_from(_handler.server(), "/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << - _handler.bool_to_message_type(state) << "] to client " << + _handler.bool_to_message_type(state) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1534,8 +1537,8 @@ void ssr::OscSender::set_processing_state(bool state) _server.address().send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << - _handler.bool_to_message_type(state) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _handler.bool_to_message_type(state) << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } } @@ -1562,14 +1565,14 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/transport/state", _handler.bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << - _handler.bool_to_message_type(state.first) << "] to client " << + _handler.bool_to_message_type(state.first) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); client->address().send_from(_handler.server(), "/transport/seek", "i", message_nframes); VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1579,13 +1582,13 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1623,8 +1626,8 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) "/update/scene/auto_rotate_sources", _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << - _handler.bool_to_message_type(auto_rotate_sources) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _handler.bool_to_message_type(auto_rotate_sources) << "] to server '" + << _server.hostname() << ":" << _server.port() << "'."); } } @@ -1646,18 +1649,18 @@ void ssr::OscSender::set_cpu_load(float load) { client->address().send_from(_handler.server(), "/cpu_load", "f", load); VERBOSE3("OscSender: Sent [/cpu_load, f, " << apf::str::A2S(load) << - "] to client " << client->hostname() << ":" << client->port() << - "."); + "] to client '" << client->hostname() << ":" << client->port() << + "'."); } } } - else if(_handler.is_client() && !server_is_default() && _server.message_level() == - MessageLevel::GUI_SERVER) + else if(_handler.is_client() && !server_is_default() && + _server.message_level() == MessageLevel::GUI_SERVER) { _server.address().send_from(_handler.server(), "/update/cpu_load", "f", load); VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << "'."); } } @@ -1677,8 +1680,8 @@ void ssr::OscSender::set_sample_rate(int sr) _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_sr) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } } @@ -1702,9 +1705,9 @@ void ssr::OscSender::set_master_signal_level(float level) client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << + apf::str::A2S(message_level) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1714,8 +1717,8 @@ void ssr::OscSender::set_master_signal_level(float level) _server.address().send_from(_handler.server(), "/update/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_level) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } } @@ -1743,8 +1746,8 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + << message_level << "] to client '" << client->address().hostname() + << ":" << client->address().port() << "'."); } } } @@ -1755,7 +1758,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) "if", message_id, message_level); VERBOSE3("OscSender: Sent [/update/source/level, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << "'."); } return true; } From de68cce6665e611490226f5afde09a81f82d34f2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 10 Jul 2017 17:57:34 +0200 Subject: [PATCH 173/363] src/networking/*: Adding functionality to discard inactive clients automatically after 10 seconds. No more messages will be sent to them, as long as they don't subscribe again. --- src/networking/oscclient.cpp | 36 ++++++++++++++++++++++++++++++++-- src/networking/oscclient.h | 4 ++++ src/networking/oschandler.cpp | 12 ++++++++++++ src/networking/oschandler.h | 12 ++++++++---- src/networking/oscreceiver.cpp | 22 ++++++++++++++++++--- src/networking/oscreceiver.h | 2 ++ src/networking/oscsender.cpp | 29 +++++++++++++++++++++++---- src/networking/oscsender.h | 4 +++- 8 files changed, 107 insertions(+), 14 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 2206aede..47fa4795 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -15,10 +15,11 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel message_level) : _address(hostname, port) , _message_level(message_level) + , _alive_counter(10) { _active = true; - VERBOSE("OscClient: Initialized as " << _address.hostname() << ":" << - _address.port() << "."); + VERBOSE("OscClient: Initialized as '" << _address.hostname() << ":" << + _address.port() << "'."); } /** @@ -110,3 +111,34 @@ const std::string ssr::OscClient::port() { return _address.port(); } + +/** + * Function to increment the OscClient's _alive_counter + **/ +void ssr::OscClient::increment_alive_counter() +{ + _alive_counter++; +} + +/** + * Function to decrement the OscClient's _alive_counter. + * Deactivates the OscClient, in the case where _alive_counter <= 0 + **/ +void ssr::OscClient::decrement_alive_counter() +{ + _alive_counter--; + if(_alive_counter < 0) + { + deactivate(); + VERBOSE("OscClient: Deactivated '" << _address.hostname() << ":" << + _address.port() << "' due to inactivity."); + } +} + +/** + * Function to reset the OscClient's _alive counter + **/ +void ssr::OscClient::reset_alive_counter() +{ + _alive_counter=10; +} diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 085a38a1..fa0a1628 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -19,6 +19,7 @@ class OscClient lo::Address _address; MessageLevel _message_level; bool _active = false; + int _alive_counter; public: OscClient(std::string hostname, std::string port, MessageLevel @@ -34,6 +35,9 @@ class OscClient void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); + void increment_alive_counter(); + void decrement_alive_counter(); + void reset_alive_counter(); }; } diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 688f3811..97630302 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -275,6 +275,18 @@ bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& return self._osc_sender.client_has_message_level(hostname, port, message_level); } +/** + * OscHandler's friend function to increment an active client's alive counter. + * @param self reference to OscHandler holding OscSender + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + */ +void ssr::OscReceiver::increment_client_alive_counter(OscHandler& self, + std::string& hostname, std::string& port) +{ + self._osc_sender.increment_client_alive_counter(hostname, port); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index a49a8cfa..71d5840d 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -87,10 +87,14 @@ class OscHandler std::string port, ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, std::string hostname, std::string port); - friend void OscReceiver::set_client_message_level(OscHandler& self, std::string - hostname, std::string port, ssr::MessageLevel message_level); - friend bool OscReceiver::client_has_message_level(OscHandler& self, std::string& - hostname, std::string& port, ssr::MessageLevel message_level); + friend void OscReceiver::set_client_message_level(OscHandler& self, + std::string hostname, std::string port, ssr::MessageLevel + message_level); + friend bool OscReceiver::client_has_message_level(OscHandler& self, + std::string& hostname, std::string& port, ssr::MessageLevel + message_level); + friend void OscReceiver::increment_client_alive_counter(OscHandler& self, + std::string& hostname, std::string& port); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6299a816..6dc688a1 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -70,13 +70,27 @@ void ssr::OscReceiver::stop() } /** - * Adds callback handlers (for server) for subscribe and message level messages - * received from clients. + * Adds callback handlers (for server) for alive, subscribe and message level + * messages received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { + // incrementing alive_counter of subscribed client: "/alive" + _handler.server().add_method("/alive", NULL, [this](lo_arg **argv, + int, lo::Message message) + { + std::string hostname = message.source().hostname(); + std::string port = message.source().port(); + VERBOSE2("OscReceiver: Got [/alive] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + increment_client_alive_counter(_handler, hostname, port); + } + ); + VERBOSE("OscReceiver: Added callback for /alive."); + // setting MessageLevel of subscribed client: "/message_level, {i,ssi}" _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -647,8 +661,10 @@ void ssr::OscReceiver::add_server_to_client_methods() else { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << - ":" << from.port() << ". Sending alive signal."); + ":" << from.port() << "."); from.send_from(_handler.server(), "/alive", ""); + VERBOSE2("OscReceiver: Sent [/alive] to server " << from.hostname() << + ":" << from.port() << "."); } } ); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 9250cf8a..acc371b4 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -77,6 +77,8 @@ class OscReceiver std::string port, ssr::MessageLevel message_level); bool client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level); + void increment_client_alive_counter(OscHandler& self, std::string& + hostname, std::string& port); }; } // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index dba68803..6da5a15c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -115,6 +115,7 @@ void ssr::OscSender::poll_all_clients() if(client && client->active()) { client->address().send_from(_handler.server(), "/poll", ""); + client->decrement_alive_counter(); } } //TODO find better solution to compensate for execution time @@ -457,6 +458,7 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, if(client->message_level() != message_level) client->set_message_level(message_level); client->activate(); + client->reset_alive_counter(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << "."); @@ -474,8 +476,8 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, if (!setup) { _clients.push_back(new OscClient(hostname, port, message_level)); - VERBOSE2("OscSender: Added new client " << hostname << ":" << port << - " using message level " << static_cast(message_level) << + VERBOSE2("OscSender: Added new client '" << hostname << ":" << port << + "' using message level " << static_cast(message_level) << "."); } } @@ -506,8 +508,8 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) * @param message_level ssr::MessageLevel enum representing the message level * to use */ -void ssr::OscSender::set_client_message_level(std::string hostname, std::string - port, ssr::MessageLevel message_level) +void ssr::OscSender::set_client_message_level(std::string& hostname, + std::string& port, ssr::MessageLevel message_level) { for (auto& client: _clients) { @@ -521,6 +523,25 @@ void ssr::OscSender::set_client_message_level(std::string hostname, std::string } } +/** + * Increment the _alive_counter of an active client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + */ +void ssr::OscSender::increment_client_alive_counter(std::string& hostname, + std::string& port) +{ + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->active()) + { + client->increment_alive_counter(); + break; + } + } +} + /** * Compare MessageLevel of a client with one provided * @param hostname std::string representing the hostname of a client diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 148ec100..56918f99 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -75,11 +75,13 @@ class OscSender : public Subscriber void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port, ssr::MessageLevel message_level); - void set_client_message_level(std::string hostname, std::string port, + void set_client_message_level(std::string& hostname, std::string& port, ssr::MessageLevel message_level); bool client_has_message_level(std::string& hostname, std::string& port, ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); + void increment_client_alive_counter(std::string& hostname, std::string& + port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From d25f975d83b4fffa3a86f9527572f413c8e02fd2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Jul 2017 13:35:49 +0200 Subject: [PATCH 174/363] src/networking/*: Let calls to increment_client_alive_counter in OSCReceiver implicitely copy by value. --- src/networking/oschandler.cpp | 2 +- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 5 ++--- src/networking/oscreceiver.h | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 97630302..0227caae 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -282,7 +282,7 @@ bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& * @param port std::string representing the client's port */ void ssr::OscReceiver::increment_client_alive_counter(OscHandler& self, - std::string& hostname, std::string& port) + std::string hostname, std::string port) { self._osc_sender.increment_client_alive_counter(hostname, port); } diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 71d5840d..6de5a15e 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -94,7 +94,7 @@ class OscHandler std::string& hostname, std::string& port, ssr::MessageLevel message_level); friend void OscReceiver::increment_client_alive_counter(OscHandler& self, - std::string& hostname, std::string& port); + std::string hostname, std::string port); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6dc688a1..5e73edd3 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -81,12 +81,11 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/alive", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string hostname = message.source().hostname(); - std::string port = message.source().port(); VERBOSE2("OscReceiver: Got [/alive] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - increment_client_alive_counter(_handler, hostname, port); + increment_client_alive_counter(_handler, message.source().hostname(), + message.source().port()); } ); VERBOSE("OscReceiver: Added callback for /alive."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index acc371b4..8b271e3b 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -77,8 +77,8 @@ class OscReceiver std::string port, ssr::MessageLevel message_level); bool client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level); - void increment_client_alive_counter(OscHandler& self, std::string& - hostname, std::string& port); + void increment_client_alive_counter(OscHandler& self, std::string hostname, + std::string port); }; } // namespace ssr From 8eddc1f73c08f8c2d4e3790859d4eccb6839a650 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Jul 2017 16:41:30 +0200 Subject: [PATCH 175/363] src/ssr_global.h: Extending MessageLevel by MAX_VALUE. src/networking/*: Making assignment of client/server MessageLevel sane. --- src/networking/oscclient.cpp | 3 +++ src/networking/oscreceiver.cpp | 38 ++++++++++++++++++++++++---------- src/networking/oscreceiver.h | 1 + src/networking/oscsender.cpp | 3 +-- src/ssr_global.h | 3 ++- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 47fa4795..e8c2267d 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -92,6 +92,9 @@ void ssr::OscClient::set_address(std::string& hostname, std::string& port) void ssr::OscClient::set_message_level(MessageLevel message_level) { _message_level = message_level; + VERBOSE("OscClient: Message level of '" << _address.hostname() << ":" << + _address.port() << "' changed to " << static_cast(_message_level) + << "."); } /** diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 5e73edd3..c9f17af8 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -94,14 +94,14 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { + (void) argv; if(!message.types().compare("i")) { VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); set_client_message_level(_handler, message.source().hostname(), - message.source().port(), - static_cast(argv[0]->i)); + message.source().port(), get_sane_message_level(argv[0]->i)); } else if(!message.types().compare("ssi")) { @@ -112,7 +112,7 @@ void ssr::OscReceiver::add_client_to_server_methods() message.source().hostname() << ":" << message.source().port() << "'."); set_client_message_level(_handler, hostname, port, - static_cast(argv[2]->i)); + get_sane_message_level(argv[2]->i)); } } ); @@ -164,7 +164,7 @@ void ssr::OscReceiver::add_client_to_server_methods() message.source().hostname() << ":" << message.source().port() << "'."); add_client(_handler, hostname, port, - static_cast(argv[3]->i)); + get_sane_message_level(argv[3]->i)); } // subscribing client: "/subscribe, Ti, message_level" else if(!message.types().compare("Ti")) @@ -174,8 +174,7 @@ void ssr::OscReceiver::add_client_to_server_methods() "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); add_client(_handler, message.source().hostname(), - message.source().port(), - static_cast(argv[1]->i)); + message.source().port(), get_sane_message_level(argv[1]->i)); } } ); @@ -623,7 +622,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); VERBOSE("OscReceiver: Added callback for /cpu_load f."); - // set OscSender's _server _message_level through OscHandler: /message_level, i + // set OscSender's _server _message_level: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { @@ -633,10 +632,7 @@ void ssr::OscReceiver::add_server_to_client_methods() "] from server '" << message.source().hostname() << ":" << message.source().port() << "'."); if(is_server(_handler, hostname, port)) - { - set_server_message_level(_handler, - static_cast(argv[0]->i)); - } + set_server_message_level(_handler, get_sane_message_level(argv[0]->i)); } ); VERBOSE("OscReceiver: Added callback for /message_level i."); @@ -1686,3 +1682,23 @@ void ssr::OscReceiver::add_tracker_methods() VERBOSE("OscReceiver: Added callback for /tracker/reset."); } +/** + * Creates a sane MessageLevel from an int32_t + * @param message_level An int32_t + * @return a MessageLevel + */ +ssr::MessageLevel ssr::OscReceiver::get_sane_message_level(int32_t message_level) +{ + if(message_level <= 0){ + return ssr::MessageLevel::CLIENT; + } + else if(ssr::MessageLevel::MAX_VALUE < + static_cast(message_level)) + { + return ssr::MessageLevel::GUI_SERVER; + } + else + { + return static_cast(message_level); + } +} diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 8b271e3b..b3433fdf 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -45,6 +45,7 @@ class OscReceiver void add_processing_methods(); void add_transport_methods(); void add_tracker_methods(); + ssr::MessageLevel get_sane_message_level(int32_t message_level); public: OscReceiver(Publisher& controller, OscHandler& handler); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 6da5a15c..1c9b56b0 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -477,8 +477,7 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, { _clients.push_back(new OscClient(hostname, port, message_level)); VERBOSE2("OscSender: Added new client '" << hostname << ":" << port << - "' using message level " << static_cast(message_level) << - "."); + "' using message level " << static_cast(message_level) << "."); } } diff --git a/src/ssr_global.h b/src/ssr_global.h index eefb266d..e8dbdc63 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -56,7 +56,8 @@ enum class MessageLevel : id_t CLIENT = 0, GUI_CLIENT, SERVER, - GUI_SERVER + GUI_SERVER, + MAX_VALUE = GUI_SERVER }; } // namespace ssr From 7f2abb403c3e5c2b7e41430a498c1e5623d81b81 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Jul 2017 12:44:58 +0200 Subject: [PATCH 176/363] src/configuration.*: Adding function to retrieve a valid network port from a char. If chosen port is < 0, a well-known port, or not in the range of IANA suggested ephemeral ports, the standard port 50001 will be used. --- src/configuration.cpp | 62 ++++++++++++++++++++++++++++++++++--------- src/configuration.h | 2 +- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 4c09b4d0..7f20d69f 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -109,8 +109,43 @@ namespace // anonymous } } -/* This function removes all whitespaces from a string. +/** + * Function to retrieve a valid port from a char. + * Returns an ephemeral port according to IANA suggestions + * @param port a const char* holding a number + * @return An ephemeral port according to IANA suggestions + */ +int ssr::get_valid_network_port(const char* port) +{ + int port_number = atoi(port); + bool valid_port = true; + if (port_number < 1024 && port_number > 0) + { + ERROR("Port number is in the range of well-known ports!"); + valid_port = false; + } + else if(port_number < 0) + { + ERROR("Port number must not be negative!"); + valid_port = false; + } + else if (port_number < 49152 || port_number > 65535) + { + ERROR("Port number is not in the range of ephemeral ports suggested by IANA!"); + valid_port = false; + } + if (!valid_port) + { + WARNING("Using standard port."); + port_number = 50001; + } + return port_number; +} + +/* Function to remove all whitespaces from a string. * If the string is " " it will return an empty string. + * @param str a reference to a std::string + * @return a std::string without whitespaces */ std::string ssr::remove_whitespace(const std::string& str) { @@ -124,10 +159,17 @@ std::string ssr::remove_whitespace(const std::string& str) return str.substr(first, (last - first + 1)); } -/* This function retrieves tuples of key value pairs from a comma-separated - * string and stores it in a multimap. +/** + * Function to retrieves tuples of key value pairs from a comma-separated + * string and stores it in a multimap. The tuples should be of the form + * client:port, client2:port2, etc.. + * @param input a const char* holding a comma-separated list of clients:port + * tuples + * @param clients reference to a std::multimap to store + * information on client and port in. + * @return CONFIG_SUCCESS on successful completion */ -static int parse_network_clients(const char *input, +static int parse_network_clients(const char* input, std::multimap& clients) { std::istringstream iss(input); @@ -145,7 +187,7 @@ static int parse_network_clients(const char *input, // if no port supplied, insert standard if ( port_temp.empty() || port_temp == name ) { - port = 50002; + port = 50001; } else { @@ -156,7 +198,7 @@ static int parse_network_clients(const char *input, } VERBOSE("Read the following clients:"); for (const auto& client: clients) { - VERBOSE2(client.first << ":" << client.second); + VERBOSE(client.first << ":" << client.second); } return CONFIG_SUCCESS; } @@ -567,11 +609,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; case 'p': - //TODO: check if in port range - if (!S2A(optarg, conf.osc_port)) - { - ERROR("Invalid port for network receive specified!"); - } + conf.osc_port = get_valid_network_port(optarg); break; case 'r': @@ -895,7 +933,7 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ } else if (!strcmp(key, "OSC_PORT")) { - conf.osc_port = atoi(value); + conf.osc_port = get_valid_network_port(value); } else if (!strcmp(key, "NETWORK_INTERFACE")) { diff --git a/src/configuration.h b/src/configuration.h index d921d982..fa8c9d4a 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -85,7 +85,7 @@ conf_struct configuration(int& argc, char* argv[]); // static int is_comment_or_empty(const char *line); int load_config_file(const char *filename, conf_struct& conf); std::string remove_whitespace(const std::string& str); - +int get_valid_network_port(const char* port); } // namespace ssr From 82cfa57ec81b6c43cfff5343508a17edc0b0bccc Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Jul 2017 13:05:35 +0200 Subject: [PATCH 177/363] src/networking/oschandler.cpp: Adding exit with EXIT_FAILURE, in case the ServerThread could not be initialized (most likely due to port already being in use). --- src/networking/oschandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0227caae..8951c9f5 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -64,7 +64,9 @@ void ssr::OscHandler::start() VERBOSE("OscHandler: Starting"); // check if lo::ServerThread is valid if (!_server.is_valid()) { - ERROR("OscHandler: ServerThread could not be started!"); + ERROR("OscHandler: The liblo ServerThread could not be started!" << + " Is the port already in use?"); + exit(EXIT_FAILURE); } _server.set_callbacks([this]() { From e2eabb568f8c2ebd6f08475ab755b65781ad5745 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 13 Jul 2017 13:43:59 +0200 Subject: [PATCH 178/363] src/networking/oscreceiver.cpp: Adding check, if id > 0 to all source related callbacks. --- src/networking/oscreceiver.cpp | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c9f17af8..e002bd70 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -694,7 +694,7 @@ void ssr::OscReceiver::add_source_methods() { _controller.delete_all_sources(); } - else + else if (argv[0]->i > 0) { _controller.delete_source(argv[0]->i); } @@ -718,7 +718,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + if (argv[0]->i > 0) + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } } ); @@ -741,7 +742,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_file_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_file_name(argv[0]->i, name); } } ); @@ -763,8 +765,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + if (argv[0]->i > 0) + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); } } ); @@ -803,7 +806,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_model(argv[0]->i, model); + if (argv[0]->i > 0) + _controller.set_source_model(argv[0]->i, model); } } ); @@ -826,7 +830,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_mute(argv[0]->i, true); + if (argv[0]->i > 0) + _controller.set_source_mute(argv[0]->i, true); } } else if(!message.types().compare("iF")) @@ -842,7 +847,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_mute(argv[0]->i, false); + if (argv[0]->i > 0) + _controller.set_source_mute(argv[0]->i, false); } } } @@ -865,7 +871,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_name(argv[0]->i, name); } } ); @@ -1090,7 +1097,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + if (argv[0]->i > 0) + _controller.set_source_orientation(argv[0]->i, + Orientation(argv[1]->f)); } } ); @@ -1112,7 +1121,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_port_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_port_name(argv[0]->i, name); } } ); @@ -1133,8 +1143,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); + if (argv[0]->i > 0) + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); } } ); @@ -1157,7 +1168,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_position_fixed(argv[0]->i, true); + if (argv[0]->i > 0) + _controller.set_source_position_fixed(argv[0]->i, true); } } else if (!message.types().compare("iF")) @@ -1173,7 +1185,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_position_fixed(argv[0]->i, false); + if (argv[0]->i > 0) + _controller.set_source_position_fixed(argv[0]->i, false); } } } @@ -1196,7 +1209,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_properties_file(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_properties_file(argv[0]->i, name); } } ); From 927bf47d001ba023ac1fa62feca611b017248623 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 25 Jul 2017 17:39:21 +0200 Subject: [PATCH 179/363] Revert "Merge remote-tracking branch 'origin/gitignore-entries' into networking-with-osc" This reverts commit b8c0747c5836e60800c063ab3619a64d914c1bac, reversing changes made to 7f102e6c93cf19b3ee13412e774be324137d706d. --- .gitignore | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) diff --git a/.gitignore b/.gitignore index 30f5be28..66e82732 100644 --- a/.gitignore +++ b/.gitignore @@ -1,55 +1 @@ ssr_scene_autosave.asd -Makefile -Makefile.in -aclocal.m4 -autom4te.cache/ -autotools/ -compile_commands.json -config.log -config.status -configure -configure.orig -data/MacOSX/DMG-Layout.applescript -data/MacOSX/Info.plist -data/MacOSX/Makefile -data/MacOSX/Makefile.in -data/MacOSX/dylibbundler/src/.deps/ -data/Makefile -data/Makefile.in -data/ssr-aap -data/ssr-binaural -data/ssr-brs -data/ssr-generic -data/ssr-nfc-hoa -data/ssr-vbap -data/ssr-wfs -doc/*.pdf -doc/doxygen/ -doc/manual/_build/ -libtool -man/ -src/.deps/ -src/Makefile -src/Makefile.in -src/config.h* -src/gui/.deps/ -src/gui/.dirstamp -src/gui/*.o -src/gui/*_moc.cpp -src/network/.deps/ -src/network/.dirstamp -src/network/*.o -src/razor-ahrs/.deps/ -src/razor-ahrs/.dirstamp -src/razor-ahrs/RazorAHRS.o -src/ssr-aap -src/ssr-binaural -src/ssr-brs -src/ssr-generic -src/ssr-nfc-hoa -src/ssr-vbap -src/ssr-wfs -src/*.o -src/stamp-h1 -ssr-qt4.patch -tags From df44f14162139d1a65e7e0fc44bd74681207c736 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 25 Jul 2017 18:51:31 +0200 Subject: [PATCH 180/363] src/networking/oscreceiver.cpp: Using the linear scale, instead of logarithmic scale for setting source gain. A range form 0.0 - inf is used, where 1.0 signifies 100% source level. --- src/networking/oscreceiver.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e002bd70..6b280049 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -765,9 +765,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - if (argv[0]->i > 0) - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + if (argv[0]->i > 0 && argv[1]->f >= 0.0) + _controller.set_source_gain(argv[0]->i, argv[1]->f); } } ); @@ -1043,7 +1042,9 @@ void ssr::OscReceiver::add_source_methods() std::string file_name_or_port_number(&(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); - float gain(apf::math::dB2linear(argv[6]->f)); + float gain(argv[6]->f); + if (gain < 0.0) + gain = 0.0; Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) { From 80d9d3e1d48abf1f8ad8e9ddc06cc7dfb9e40633 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 27 Jul 2017 23:19:23 +0200 Subject: [PATCH 181/363] supercollider/workflows.scd: Adding Sensors2OSC example, setting reference orientation through orientation sensor and two sources through multi-touch interface. --- supercollider/workflows.scd | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd index 2dfac3c5..d3c2e1f5 100644 --- a/supercollider/workflows.scd +++ b/supercollider/workflows.scd @@ -60,3 +60,108 @@ ~address.sendMsg("/scene/clear"); ) +// sclang is a client, controlling a SSR server instance, while forwarding OSC +// commands from a smartphone, that uses Sensors2OSC (https://sensors2.org/osc/) +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang +// OSCFunc.trace(true, true); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // vectors for holding source position + ~source1 = [-1.0, -1.0]; + ~source2 = [-1.0, -1.0]; + // OSC functions to receive from Sensors2OSC and send to SSR + OSCFunc( + { + arg msg, time, addr, recvPort; + [msg, time, addr, recvPort].postln; + ~address.sendMsg("/reference/orientation", msg[1]); + }, + '/orientation/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source1[0] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 1, + ~source1[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source1[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch1/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source1[1] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 1, + ~source1[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source1[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch1/Y' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source2[0] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 2, + ~source2[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source2[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch2/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source2[1] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 2, + ~source2[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source2[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch2/Y' + ); +) + +// clear scene and unsubscribe from server instance +( + // remove all sources + ~address.sendMsg("/scene/clear"); + // unsubscribe from server + ~address.sendMsg("/subscribe", $F); +) + From 195fef29df5210747cc95157f581a5add8abd5eb Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 18 Aug 2017 19:20:30 +0200 Subject: [PATCH 182/363] supercollider/workflows.scd: Fixing input creation and source volume. Introducing /alive message on receiving /poll from server. Controlling /reference/orientation with /orientation/X from Sensors2OSC. Deactivating verbose printout on each received message. --- supercollider/workflows.scd | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd index d3c2e1f5..cf7a92e3 100644 --- a/supercollider/workflows.scd +++ b/supercollider/workflows.scd @@ -66,19 +66,14 @@ // set address of the client instance ~address = NetAddr("localhost", 50001); // print all OSC messages sent to sclang -// OSCFunc.trace(true, true); // subscribe to server with MessageLevel::SERVER ~address.sendMsg("/subscribe", $T, 2); // add new source with standard input at -1.0/1.0 - ~address.sendMsg("/source/new", "in_1", "point", "1", - -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + ~address.sendMsg("/source/new", "in_1", "point", "1", -1.0, 1.0, 0.0, 0.99, + $F, $F, $F); // add new source with standard input at 1.0/1.0 - ~address.sendMsg("/source/new", "in_2", "point", "2", - 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); - // unmute source 1 - ~address.sendMsg("/source/mute", 1, $F); - // unmute source 2 - ~address.sendMsg("/source/mute", 2, $F); + ~address.sendMsg("/source/new", "in_2", "point", "2", 1.0, 1.0, 0.0, 0.99, + $F, $F, $F); // vectors for holding source position ~source1 = [-1.0, -1.0]; ~source2 = [-1.0, -1.0]; @@ -86,8 +81,14 @@ OSCFunc( { arg msg, time, addr, recvPort; - [msg, time, addr, recvPort].postln; - ~address.sendMsg("/reference/orientation", msg[1]); + ~address.sendMsg("/alive"); + }, + '/poll' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + ~address.sendMsg("/reference/orientation", msg[1]+90); }, '/orientation/X' ); @@ -96,7 +97,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source1[0] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 1, @@ -112,7 +112,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source1[1] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 1, @@ -128,7 +127,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source2[0] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 2, @@ -144,7 +142,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source2[1] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 2, From f57b696bfb71b9f1c2ce056a61cbbdaf5139f4fb Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 27 Mar 2017 16:54:14 +0200 Subject: [PATCH 183/363] data/ssr.conf.example: Adding networking configuration. --- data/ssr.conf.example | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index eca99e30..67478ec4 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -95,6 +95,20 @@ # carriage return: 13) #END_OF_MESSAGE_CHARACTER = 10 +############################ Networking configuration ########################## + +# networking mode (client|server|off) +#NETWORK_MODE = server + +# networking port for sending (default: 50001) +#NETWORK_PORT_SEND = 50001 + +# networking port for receiving (default: 50002) +#NETWORK_PORT_RECEIVE = 50002 + +# networking clients by hostname:port +#NETWORK_CLIENTS = "test:50002 test:50002" + ############################## Verbosity Level ################################# # Set the level of system information From 06c9e742e6aa2e9169468aca8bc4ba2fd46662cc Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 27 Mar 2017 16:55:05 +0200 Subject: [PATCH 184/363] src/configuration.h: Adding struct members for networking mode. --- src/configuration.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index f4e0803d..63a02642 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,6 +57,10 @@ struct conf_struct std::string output_port_prefix; ///< e.g. "alsa_pcm:playback" std::string path_to_gui_images; ///< dto. std::string path_to_scene_menu; ///< path to scene_menu.conf + std::string network_mode; ///< network mode (client or server) + std::string network_clients; ///< list of network clients and ports + int network_port_send; ///< network sending port + int network_port_receive; ///< network receiving port int end_of_message_character; ///< ASCII bool auto_rotate_sources; ///< Automatic orientation of sources From a7bf9c87c6456d1f00e06c78e45c9a0d3ca68459 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:30:55 +0200 Subject: [PATCH 185/363] src/configuration.h: Turning network_clients field into a multimap to have unique keys. --- src/configuration.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/configuration.h b/src/configuration.h index 63a02642..0085d3c3 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -30,6 +30,7 @@ #ifndef SSR_CONFIGURATION_H #define SSR_CONFIGURATION_H +#include #include #include "apf/parameter_map.h" @@ -58,7 +59,8 @@ struct conf_struct std::string path_to_gui_images; ///< dto. std::string path_to_scene_menu; ///< path to scene_menu.conf std::string network_mode; ///< network mode (client or server) - std::string network_clients; ///< list of network clients and ports + ///< list of network clients and ports + std::multimap network_clients; int network_port_send; ///< network sending port int network_port_receive; ///< network receiving port int end_of_message_character; ///< ASCII From 13ede3900a14f24e53f396f7ff732e8a83922eeb Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:35:07 +0200 Subject: [PATCH 186/363] src/configuration.cpp: First version of functionality to parse network clients and ports from flag or configuration file. Adding flags for network-mode, network-port-receive, network-port-send and network-clients. --- src/configuration.cpp | 120 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 141fdd39..9bb99d1f 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -38,6 +38,7 @@ #include #include // std::this_thread::sleep_for #include // std::chrono::seconds +#include // for parse_network_clients #include "configuration.h" #include "posixpathtools.h" @@ -108,6 +109,55 @@ namespace // anonymous } } +/* This function removes all whitespaces from a string. + * If the string is " " it will return an empty string. + */ +std::string trim(const std::string& str) +{ + if (str == " ") return ""; + size_t first = str.find_first_not_of(' '); + if (std::string::npos == first) + { + return str; + } + size_t last = str.find_last_not_of(' '); + return str.substr(first, (last - first + 1)); +} + +/* This function retrieves tuples of key value pairs from a comma-separated + * string and stores it in a multimap. + */ +static int parse_network_clients(const char *input, + std::multimap clients){ + std::istringstream iss(input); + std::string name; + int port; + std::string token; + + while (std::getline(iss, token, ',')) { + size_t pos = token.find(':'); + std::string port_temp = trim(token.substr(pos+1)); + name = trim(token.substr(0, pos)); + + if (!name.empty()) + { + std::cout << name << "(" << name.length() << ")" << std::endl; + std::cout << port_temp << "(" << port_temp.length() << ")" << std::endl; + // if no port supplied, insert standard + if ( port_temp.empty() || port_temp == name ) + { + port = 50002; + } + else + { + port = std::stoi(port_temp); + } + clients.insert(make_pair(name, port)); + } + } + return CONFIG_SUCCESS; +} + /** parse command line options and configuration file(s) * @param argc number of command line arguments. * @param argv the arguments themselves. @@ -156,6 +206,10 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.renderer_params.set("decay_exponent", 1.0f); // 1 / r^1 conf.renderer_params.set("amplitude_reference_distance", 3.0f); // meters + // default network settings, also stated in data/ssr.conf.example + conf.network_mode = "client"; + conf.network_port_send = 50001; + conf.network_port_receive = 50002; conf.auto_rotate_sources = true; @@ -240,6 +294,16 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) " --no-auto-rotation\n" " Don't auto-rotate sound sources' orientation toward " "the reference\n" +" -N --network_mode=VALUE\n" +" Which network mode to use: client or server " + "(default: client)\n" +" -C --network_clients=VALUE\n" +" List of network clients and their ports (e.g. " + "client1:50002 client2:50002)\n" +" -P --network_port_send=VALUE\n" +" Port to send OSC messages from (default: 50001)\n" +" -p --network_port_receive=VALUE\n" +" Port to receive OSC messages on (default: 50002)\n" #ifdef ENABLE_IP_INTERFACE " -i, --ip-server[=PORT]\n" @@ -323,6 +387,10 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) {"master-volume-correction", required_argument, nullptr, 0}, {"auto-rotation", no_argument, nullptr, 0 }, {"no-auto-rotation", no_argument, nullptr, 0 }, + {"network-mode", required_argument, nullptr, 'N'}, + {"network-clients", required_argument, nullptr, 'C'}, + {"network-port-send", required_argument, nullptr, 'P'}, + {"network-port-receive", required_argument, nullptr, 'p'}, {"ip-server", optional_argument, nullptr, 'i'}, {"no-ip-server", no_argument, nullptr, 'I'}, {"end-of-message-character", required_argument, nullptr, 0}, @@ -341,7 +409,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) }; // one colon: required argument; two colons: optional argument // if first character is '-', non-option arguments return 1 (see case 1 below) - const char *optstring = "-c:fgGhi::In:o:r:s:t:TvV?"; + const char *optstring = "-c:C:fgGhi::IN:n:o:P:p:r:s:t:TvV?"; int opt; int longindex = 0; @@ -441,6 +509,9 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) + std::string(optarg) + "\"!"); } break; + case 'C': + parse_network_clients(optarg, conf.network_clients); + break; case 'f': conf.freewheeling = true; @@ -478,6 +549,16 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.ip_server = false; break; + case 'N': + //TODO: check if correct string + if (!strcasecmp(optarg, "client") || !strcasecmp(optarg, "server")) + { + conf.network_mode = optarg; + } + else { + ERROR("'"<< optarg << "' is not understood as option for network-mode."); + } + break; case 'n': conf.renderer_params.set("name", optarg); break; @@ -485,6 +566,20 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) case 'o': conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; + case 'P': + //TODO: check if in port range + if (!S2A(optarg, conf.network_port_send)) + { + ERROR("Invalid port for network send specified!"); + } + break; + case 'p': + //TODO: check if in port range + if (!S2A(optarg, conf.network_port_receive)) + { + ERROR("Invalid port for network receive specified!"); + } + break; case 'r': conf.audio_recorder_file_name = optarg; @@ -558,6 +653,7 @@ static int is_comment_or_empty(const char *line){ return (*line == '#') || (!*line); } + /******************************************************************************/ /* This function takes a line from the configuration file and splits @@ -790,6 +886,28 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ if (!strcasecmp(value, "on")) conf.gui = true; else conf.gui = false; } + else if (!strcmp(key, "NETWORK_MODE")) + { + if (!strcasecmp(value, "client") || !strcasecmp(value, "server")) + { + conf.network_mode = value; + } + else { + ERROR("'"<< value << "' is not understood as option for network-mode."); + } + } + else if (!strcmp(key, "NETWORK_CLIENTS")) + { + parse_network_clients(value, conf.network_clients); + } + else if (!strcmp(key, "NETWORK_PORT_SEND")) + { + conf.network_port_send = atoi(value); + } + else if (!strcmp(key, "NETWORK_PORT_RECEIVE")) + { + conf.network_port_receive = atoi(value); + } else if (!strcmp(key, "NETWORK_INTERFACE")) { #ifdef ENABLE_IP_INTERFACE From 312287116312c84734b15de2e3e80bdcfa136226 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 15:57:15 +0200 Subject: [PATCH 187/363] src/configuration.cpp: Renaming trim to remove_whitespace. Moving curly bracket to next line in parse_network_clients. --- src/configuration.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 9bb99d1f..5019ed7d 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -112,7 +112,7 @@ namespace // anonymous /* This function removes all whitespaces from a string. * If the string is " " it will return an empty string. */ -std::string trim(const std::string& str) +std::string remove_whitespace(const std::string& str) { if (str == " ") return ""; size_t first = str.find_first_not_of(' '); @@ -128,7 +128,8 @@ std::string trim(const std::string& str) * string and stores it in a multimap. */ static int parse_network_clients(const char *input, - std::multimap clients){ + std::multimap clients) +{ std::istringstream iss(input); std::string name; int port; @@ -136,8 +137,8 @@ static int parse_network_clients(const char *input, while (std::getline(iss, token, ',')) { size_t pos = token.find(':'); - std::string port_temp = trim(token.substr(pos+1)); - name = trim(token.substr(0, pos)); + std::string port_temp = remove_whitespace(token.substr(pos+1)); + name = remove_whitespace(token.substr(0, pos)); if (!name.empty()) { From 94beabaf2bd8aa08c376272ffc2b7672553a49fa Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Mar 2017 18:25:24 +0200 Subject: [PATCH 188/363] src/configuration.cpp: parse_network_clients removing printouts of names, adding VERBOSE2 messages about which clients are added. Moving remove_whitespace to ssr namespace. src/configuration.h: Defining remove_whitespace in ssr namespace. --- src/configuration.cpp | 12 +++++++----- src/configuration.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 5019ed7d..ce44015d 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -112,7 +112,7 @@ namespace // anonymous /* This function removes all whitespaces from a string. * If the string is " " it will return an empty string. */ -std::string remove_whitespace(const std::string& str) +std::string ssr::remove_whitespace(const std::string& str) { if (str == " ") return ""; size_t first = str.find_first_not_of(' '); @@ -137,13 +137,11 @@ static int parse_network_clients(const char *input, while (std::getline(iss, token, ',')) { size_t pos = token.find(':'); - std::string port_temp = remove_whitespace(token.substr(pos+1)); - name = remove_whitespace(token.substr(0, pos)); + std::string port_temp = ssr::remove_whitespace(token.substr(pos+1)); + name = ssr::remove_whitespace(token.substr(0, pos)); if (!name.empty()) { - std::cout << name << "(" << name.length() << ")" << std::endl; - std::cout << port_temp << "(" << port_temp.length() << ")" << std::endl; // if no port supplied, insert standard if ( port_temp.empty() || port_temp == name ) { @@ -156,6 +154,10 @@ static int parse_network_clients(const char *input, clients.insert(make_pair(name, port)); } } + VERBOSE2("Using the following network clients:"); + for (const auto& client: clients) { + VERBOSE2(client.first << ":" << client.second); + } return CONFIG_SUCCESS; } diff --git a/src/configuration.h b/src/configuration.h index 0085d3c3..e2277e6d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -85,6 +85,8 @@ conf_struct configuration(int& argc, char* argv[]); // static int parse(const char *line, char *key, char *value); // static int is_comment_or_empty(const char *line); int load_config_file(const char *filename, conf_struct& conf); +std::string remove_whitespace(const std::string& str); + } // namespace ssr From 3b0e427fbfe8fbed6b12eb1c04e5d42a00e7a174 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:43:05 +0200 Subject: [PATCH 189/363] src/configuration.cpp: Using the multimap of client information by reference. Fixing a missing comma in the help output of ssr. --- src/configuration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index ce44015d..a962e26f 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -128,7 +128,7 @@ std::string ssr::remove_whitespace(const std::string& str) * string and stores it in a multimap. */ static int parse_network_clients(const char *input, - std::multimap clients) + std::multimap& clients) { std::istringstream iss(input); std::string name; @@ -302,7 +302,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) "(default: client)\n" " -C --network_clients=VALUE\n" " List of network clients and their ports (e.g. " - "client1:50002 client2:50002)\n" + "client1:50002, client2:50002)\n" " -P --network_port_send=VALUE\n" " Port to send OSC messages from (default: 50001)\n" " -p --network_port_receive=VALUE\n" From fc0ae5f228f6f07d18e71bdf91e65b13411cbf1d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:43:48 +0200 Subject: [PATCH 190/363] data/ssr.conf.example: Fixing the example string used for clients. --- data/ssr.conf.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index 67478ec4..eb5bdb58 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -106,8 +106,8 @@ # networking port for receiving (default: 50002) #NETWORK_PORT_RECEIVE = 50002 -# networking clients by hostname:port -#NETWORK_CLIENTS = "test:50002 test:50002" +# networking clients, comma-separated by hostname:port +#NETWORK_CLIENTS = "client:50002, client:50002" ############################## Verbosity Level ################################# From 0d94ccad4f16e4afdd87d2ac718caeb7d8a6e494 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:11:05 +0200 Subject: [PATCH 191/363] src/configuration.cpp: Dropping network-port-{send,receive} in favor of osc-port. Using only hyphen instead of underscore for option strings. --- src/configuration.cpp | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index a962e26f..db470cef 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -154,7 +154,7 @@ static int parse_network_clients(const char *input, clients.insert(make_pair(name, port)); } } - VERBOSE2("Using the following network clients:"); + VERBOSE("Read the following clients:"); for (const auto& client: clients) { VERBOSE2(client.first << ":" << client.second); } @@ -211,8 +211,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.renderer_params.set("amplitude_reference_distance", 3.0f); // meters // default network settings, also stated in data/ssr.conf.example conf.network_mode = "client"; - conf.network_port_send = 50001; - conf.network_port_receive = 50002; + conf.osc_port = 50001; conf.auto_rotate_sources = true; @@ -297,16 +296,14 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) " --no-auto-rotation\n" " Don't auto-rotate sound sources' orientation toward " "the reference\n" -" -N --network_mode=VALUE\n" +" -N --network-mode=VALUE\n" " Which network mode to use: client or server " "(default: client)\n" -" -C --network_clients=VALUE\n" +" -C --network-clients=VALUE\n" " List of network clients and their ports (e.g. " - "client1:50002, client2:50002)\n" -" -P --network_port_send=VALUE\n" -" Port to send OSC messages from (default: 50001)\n" -" -p --network_port_receive=VALUE\n" -" Port to receive OSC messages on (default: 50002)\n" + "client1:50001, client2:50001)\n" +" -p --osc-port=VALUE\n" +" Port to use for OSC communication (default: 50001)\n" #ifdef ENABLE_IP_INTERFACE " -i, --ip-server[=PORT]\n" @@ -392,8 +389,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) {"no-auto-rotation", no_argument, nullptr, 0 }, {"network-mode", required_argument, nullptr, 'N'}, {"network-clients", required_argument, nullptr, 'C'}, - {"network-port-send", required_argument, nullptr, 'P'}, - {"network-port-receive", required_argument, nullptr, 'p'}, + {"osc-port", required_argument, nullptr, 'p'}, {"ip-server", optional_argument, nullptr, 'i'}, {"no-ip-server", no_argument, nullptr, 'I'}, {"end-of-message-character", required_argument, nullptr, 0}, @@ -412,7 +408,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) }; // one colon: required argument; two colons: optional argument // if first character is '-', non-option arguments return 1 (see case 1 below) - const char *optstring = "-c:C:fgGhi::IN:n:o:P:p:r:s:t:TvV?"; + const char *optstring = "-c:C:fgGhi::IN:n:o:p:r:s:t:TvV?"; int opt; int longindex = 0; @@ -569,16 +565,9 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) case 'o': conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; - case 'P': - //TODO: check if in port range - if (!S2A(optarg, conf.network_port_send)) - { - ERROR("Invalid port for network send specified!"); - } - break; case 'p': //TODO: check if in port range - if (!S2A(optarg, conf.network_port_receive)) + if (!S2A(optarg, conf.osc_port)) { ERROR("Invalid port for network receive specified!"); } @@ -903,13 +892,9 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ { parse_network_clients(value, conf.network_clients); } - else if (!strcmp(key, "NETWORK_PORT_SEND")) - { - conf.network_port_send = atoi(value); - } - else if (!strcmp(key, "NETWORK_PORT_RECEIVE")) + else if (!strcmp(key, "OSC_PORT")) { - conf.network_port_receive = atoi(value); + conf.osc_port = atoi(value); } else if (!strcmp(key, "NETWORK_INTERFACE")) { From 74e5142127b2e3c0bee6702eb9227e3190a1ccfc Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:11:37 +0200 Subject: [PATCH 192/363] src/configuration.h: Dropping network_port_{send,receive} in favor of osc_port. --- src/configuration.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index e2277e6d..644b9ee3 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -61,8 +61,7 @@ struct conf_struct std::string network_mode; ///< network mode (client or server) ///< list of network clients and ports std::multimap network_clients; - int network_port_send; ///< network sending port - int network_port_receive; ///< network receiving port + int osc_port; ///< osc communication port int end_of_message_character; ///< ASCII bool auto_rotate_sources; ///< Automatic orientation of sources From 9f1a8c831cb2a57c918c9a174b1c9f81a0a4332c Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:13:17 +0200 Subject: [PATCH 193/363] data/ssr.conf.example: Dropping NETWORK_PORT_{SEND,RECEIVE} in favor of OSC_PORT (which defaults to 50001). Updating NETWORK_CLIENTS example accordingly. Clarifying NETWORK_MODE comment. --- data/ssr.conf.example | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/data/ssr.conf.example b/data/ssr.conf.example index eb5bdb58..06c74fd1 100644 --- a/data/ssr.conf.example +++ b/data/ssr.conf.example @@ -97,17 +97,14 @@ ############################ Networking configuration ########################## -# networking mode (client|server|off) +# networking mode: client, server (default: client) #NETWORK_MODE = server # networking port for sending (default: 50001) -#NETWORK_PORT_SEND = 50001 - -# networking port for receiving (default: 50002) -#NETWORK_PORT_RECEIVE = 50002 +#OSC_PORT = 50001 # networking clients, comma-separated by hostname:port -#NETWORK_CLIENTS = "client:50002, client:50002" +#NETWORK_CLIENTS = "client:50001, client:50001" ############################## Verbosity Level ################################# From cac6fcdae588f0eff22b50d562e7b70d7a1d1442 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Jul 2017 12:44:58 +0200 Subject: [PATCH 194/363] src/configuration.*: Adding function to retrieve a valid network port from a char. If chosen port is < 0, a well-known port, or not in the range of IANA suggested ephemeral ports, the standard port 50001 will be used. --- src/configuration.cpp | 62 ++++++++++++++++++++++++++++++++++--------- src/configuration.h | 2 +- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index db470cef..0039dc60 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -109,8 +109,43 @@ namespace // anonymous } } -/* This function removes all whitespaces from a string. +/** + * Function to retrieve a valid port from a char. + * Returns an ephemeral port according to IANA suggestions + * @param port a const char* holding a number + * @return An ephemeral port according to IANA suggestions + */ +int ssr::get_valid_network_port(const char* port) +{ + int port_number = atoi(port); + bool valid_port = true; + if (port_number < 1024 && port_number > 0) + { + ERROR("Port number is in the range of well-known ports!"); + valid_port = false; + } + else if(port_number < 0) + { + ERROR("Port number must not be negative!"); + valid_port = false; + } + else if (port_number < 49152 || port_number > 65535) + { + ERROR("Port number is not in the range of ephemeral ports suggested by IANA!"); + valid_port = false; + } + if (!valid_port) + { + WARNING("Using standard port."); + port_number = 50001; + } + return port_number; +} + +/* Function to remove all whitespaces from a string. * If the string is " " it will return an empty string. + * @param str a reference to a std::string + * @return a std::string without whitespaces */ std::string ssr::remove_whitespace(const std::string& str) { @@ -124,10 +159,17 @@ std::string ssr::remove_whitespace(const std::string& str) return str.substr(first, (last - first + 1)); } -/* This function retrieves tuples of key value pairs from a comma-separated - * string and stores it in a multimap. +/** + * Function to retrieves tuples of key value pairs from a comma-separated + * string and stores it in a multimap. The tuples should be of the form + * client:port, client2:port2, etc.. + * @param input a const char* holding a comma-separated list of clients:port + * tuples + * @param clients reference to a std::multimap to store + * information on client and port in. + * @return CONFIG_SUCCESS on successful completion */ -static int parse_network_clients(const char *input, +static int parse_network_clients(const char* input, std::multimap& clients) { std::istringstream iss(input); @@ -145,7 +187,7 @@ static int parse_network_clients(const char *input, // if no port supplied, insert standard if ( port_temp.empty() || port_temp == name ) { - port = 50002; + port = 50001; } else { @@ -156,7 +198,7 @@ static int parse_network_clients(const char *input, } VERBOSE("Read the following clients:"); for (const auto& client: clients) { - VERBOSE2(client.first << ":" << client.second); + VERBOSE(client.first << ":" << client.second); } return CONFIG_SUCCESS; } @@ -566,11 +608,7 @@ ssr::conf_struct ssr::configuration(int& argc, char* argv[]) conf.renderer_params.set("ambisonics_order", atoi(optarg)); break; case 'p': - //TODO: check if in port range - if (!S2A(optarg, conf.osc_port)) - { - ERROR("Invalid port for network receive specified!"); - } + conf.osc_port = get_valid_network_port(optarg); break; case 'r': @@ -894,7 +932,7 @@ int ssr::load_config_file(const char *filename, conf_struct& conf){ } else if (!strcmp(key, "OSC_PORT")) { - conf.osc_port = atoi(value); + conf.osc_port = get_valid_network_port(value); } else if (!strcmp(key, "NETWORK_INTERFACE")) { diff --git a/src/configuration.h b/src/configuration.h index 644b9ee3..000fe7bb 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -85,7 +85,7 @@ conf_struct configuration(int& argc, char* argv[]); // static int is_comment_or_empty(const char *line); int load_config_file(const char *filename, conf_struct& conf); std::string remove_whitespace(const std::string& str); - +int get_valid_network_port(const char* port); } // namespace ssr From e8ed3365fee4ef1dd91a2d45dbb2c7304ec383dc Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 29 Mar 2017 23:28:38 +0200 Subject: [PATCH 195/363] src/networking/oschandler.*: Adding first attempt of OSC network interface. --- src/networking/oschandler.cpp | 15 ++++++++++++ src/networking/oschandler.h | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/networking/oschandler.cpp create mode 100644 src/networking/oschandler.h diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp new file mode 100644 index 00000000..0356a864 --- /dev/null +++ b/src/networking/oschandler.cpp @@ -0,0 +1,15 @@ +#include "oschandler.h" + +ssr::OscHandler::OscHandler(Publisher& controller, int port) + : _controller(controller), + , _serverThread(port), + , _serverAddress(port) +{} + +ssr::OscHandler::~OscHandler() +{} + +//ssr::OscHandler::setPort(int port) +//{ +// +//} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h new file mode 100644 index 00000000..4f16cbd3 --- /dev/null +++ b/src/networking/oschandler.h @@ -0,0 +1,44 @@ +#ifndef OSC_HANDLER_H +#define OSC_HANDLER_H + +#include // for ENABLE_* +#include +#include +#include +#include + +namespace ssr +{ +/* + * \class OscHandler + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscHandler +{ + private: + int _port; + lo::ServerThread *_serverThread; + lo::Address _serverAddress; + Publisher& _controller; + OscReceiver _oscReceiver; + OscSender _oscSender; + + public: + OscHandler(Publisher& controller, int port); + ~OscHandler(); + void setPort(int port); + int getPort(); + void start(); + void stop(); +}; + +} From fef9496202a39db534912694efd236f08439e26f Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:47:34 +0200 Subject: [PATCH 196/363] src/networking/*: Adding current stage of work. Added class for sending and receiving. --- src/networking/oschandler.cpp | 51 ++++- src/networking/oschandler.h | 42 +++- src/networking/oscreceiver.cpp | 387 +++++++++++++++++++++++++++++++++ src/networking/oscreceiver.h | 61 ++++++ src/networking/oscsender.cpp | 33 +++ src/networking/oscsender.h | 105 +++++++++ 6 files changed, 661 insertions(+), 18 deletions(-) create mode 100644 src/networking/oscreceiver.cpp create mode 100644 src/networking/oscreceiver.h create mode 100644 src/networking/oscsender.cpp create mode 100644 src/networking/oscsender.h diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0356a864..2a4a87c6 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -1,15 +1,52 @@ #include "oschandler.h" +#include -ssr::OscHandler::OscHandler(Publisher& controller, int port) +// client ctor +ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int + port_out, std::string mode) : _controller(controller), - , _serverThread(port), - , _serverAddress(port) + , _osc_receiver(controller, *this, port_in) + , _osc_sender(*this, port_out) + , _mode(mode) {} +// server ctor +ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, + std::string mode, std::multimap + clients) + : _controller(controller), + , _osc_receiver(controller, *this, port_in) + , _mode(mode) +{ + std::vector new_clients; + for (const auto& hostname: clients) + { + new_clients.push_back(new lo::Address(hostname.first, + std::to_string(hostname.second))); + } + _osc_sender(*this, port_out, new_clients); +} + ssr::OscHandler::~OscHandler() {} -//ssr::OscHandler::setPort(int port) -//{ -// -//} +ssr::OscHandler::start() +{ + _oscReceiver.start(); +} + +/** Implementation of friend function to set the OscSender's server_address + * @param OscHandler holding both OscReceiver and OscSender + * @param Hostname to be set + * @param Port to be set + */ +void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address + server_address) +{ + self->_osc_sender->set_server_address(server_address); +} + +lo::Address OscReceiver::server_address(OscHandler& self) +{ + return self->_osc_sender.server_address; +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 4f16cbd3..880a99cc 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -1,21 +1,32 @@ #ifndef OSC_HANDLER_H #define OSC_HANDLER_H +#endif +#ifdef HAVE_CONFIG_H #include // for ENABLE_* +#endif + +#include #include #include -#include -#include + +#include "oscreceiver.h" +#include "oscsender.h" namespace ssr { + +struct Publisher; + /* * \class OscHandler * \brief Class holding Publisher and Subscriber implementation, while being responsible for * sending and receiving OSC messages. * This class holds a Publisher implementation (OscReceiver), which turns * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which + * It also holds an implementation of Subscriber (OscSender), which turns + * Publisher functionality into outgoing OSC messages + * * \author David Runge * \version $Revision: 0.1 $ * \date $Date: 2017/03/29 @@ -25,20 +36,29 @@ namespace ssr class OscHandler { private: - int _port; - lo::ServerThread *_serverThread; - lo::Address _serverAddress; + // mode: client|server + std::string _mode; Publisher& _controller; - OscReceiver _oscReceiver; - OscSender _oscSender; + OscReceiver _osc_receiver; + OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port); + // client ctor + OscHandler(Publisher& controller, int port_in, int port_out, std::string + mode); + // server ctor + OscHandler(Publisher& controller, int port_in, int port_out, std::string + mode, std::multimap clients); ~OscHandler(); - void setPort(int port); - int getPort(); void start(); void stop(); + + //declare set_server_for_client() as friend of class OscReceiver + friend void OscReceiver::set_server_for_client(OscHandler& self, + lo::Address server_address); + //declare set_server_for_client() as friend of class OscReceiver + friend lo::Address OscReceiver::server_address(OscHandler& self); + }; } diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp new file mode 100644 index 00000000..ff5d15c4 --- /dev/null +++ b/src/networking/oscreceiver.cpp @@ -0,0 +1,387 @@ +#include "oscreiver.h" +#include "oschandler.h" +#include "publisher.h" +#include "apf/stringtools.h" +#include "apf/math.h" + +using namespace apf::str; + +ssr::OscReceiver::OscReceiver(Publisher& controller, int port) + : _controller(controller) + //TODO: add error handler here + , _receiver(port) +{} + +ssr::OscReceiver::~OscReceiver() +{ + _receiver.stop(); +} + + +void ssr::OscReceiver::start() +{ + // add method handlers for received messages + if (_mode == "server") + { + add_client_to_server_methods(); + } + else if (_mode == "client") + { + add_server_to_client_methods(); + } + // start server thread + _receiver.start(); + +// _controller.subscribe(&_subscriber); + +} + +lo::Address server_address(OscHandler& handler) +{ + return handler.server_address(handler->_osc_sender); +} + +/** Add callback handlers for OSC messages received from clients. + * + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + */ +void add_client_to_server_methods() +{ +//TODO: implement! +} + +/** Add callback handlers for OSC messages received from a server. + * + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + */ +void add_server_to_client_methods() +{ + // set _server_address for OscSender through OscHandler, depending on, if + // polled from given server before + _receiver.add_method("poll", NULL, [](lo_arg **argv, int, lo::Message + message) + { + lo::Address server = server_address(&_handler); + lo::Address from(message.source()); + if(server.hostname() != from.hostname() && server.port() != from.port()) + { + set_server_address(from); + } + } + ): + + // set source position: "source/position, iff, id, x, y" + _receiver.add_method("source/position", "iff", [](lo_arg **argv, int) + { + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f); + VERBOSE2("set source position: id = " << argv[0]->i << ", " << + Position(argv[1]->f, argv[2]->f)); + } + ); + + // set source fixed: "source/position_fixed, iT, id, true" + _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) + { + _controller.set_source_position_fixed(argv[0]->i, argv[1]->T); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " + << argv[1]->T); + } + ); + + // set source fixed: "source/position_fixed, iF, id, false" + _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) + { + _controller.set_source_position_fixed(argv[0]->i, argv[1]->F); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " + << argv[1]->F); + } + ); + + // set source orientation: "source/orientation, if, id, azimuth" + _receiver.add_method("source/orientation", "if", [](lo_arg **argv, int) + { + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + VERBOSE2("set source orientation: id = " << argv[0]->i << ", " + << Orientation(argv[1]->f)); + } + ); + + // set source volume: "source/volume, if, id, volume" + _receiver.add_method("source/volume", "if", [](lo_arg **argv, int) + { + _controller.set_source_gain(argv[0]->i, dB2linear(argv[1]->f)); + VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << + dB2linear(argv[1]->f)); + } + ); + + // set source mute: "source/mute, iT, id, true" + _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) + { + _controller.set_source_mute(argv[0]->i, argv[1]->T); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << + dB2linear(argv[1]->T)); + } + ); + + // set source mute: "source/mute, iF, id, false" + _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) + { + _controller.set_source_mute(argv[0]->i, argv[1]->F); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << + dB2linear(argv[1]->F)); + } + ); + + // set source name: "source/name, is, id, name" + _receiver.add_method("source/name", "is", [](lo_arg **argv, int) + { + _controller.set_source_name(argv[0]->i, argv[1]->s); + VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << + argv[1]->s); + } + ); + + // set source file: "source/file, is, id, file" + _receiver.add_method("source/file", "is", [](lo_arg **argv, int) + { + _controller.set_source_properties_file(argv[0]->i, argv[1]->s); + VERBOSE2("set source properties file name: id = " << argv[0]->i << ", + file = " << argv[1]->s); + } + ); + + // set source model: "source/model, is, id, model" + _receiver.add_method("source/model", "is", [](lo_arg **argv, int) + { + _controller.set_source_model(argv[0]->i, argv[1]->s); + VERBOSE2("set source model: id = " << argv[0]->i << ", + model = " << argv[1]->s); + } + ); + + // set source port name: "source/port_name, is, id, port_name" + _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) + { + _controller.set_source_port_name(argv[0]->i, argv[1]->s); + VERBOSE2("set source port name: id = " << argv[0]->i << ", + port = " << argv[1]->s); + } + ); + + //FIXME: spezialize with TF types + + // create new source: "source/new, sssffbfbfb, name, model, port_name, x, y, + // position_fixed, orientation, orientation_fixed, volume, muted" + _receiver.add_method("source/new", "sssffbfbfb", [](lo_arg **argv, int) + { + _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, + Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, + argv[8]->f, argv[9]->b, ""); + VERBOSE2("Creating source with following properties:" + "\nname: " << argv[0]->s << + "\nmodel: " << argv[1]->s << + "\nfile_or_port_name: " << argv[2]->s << + "\nchannel: 0" << + "\nposition: " << Position(argv[3]->f, argv[4]->f) << + "\nposition_fixed: " << argv[5]->b << + "\norientation: " << argv[6]->f << + "\norientation_fixed: " << argv[7]->b << + "\nvolume (linear): " << argv[8]->f << + "\nmuted: " << argv[9]->b << + "\nproperties_file: " << + "\n"); + } + ); + + // create new source: "source/new, sssiffbfbfbs, name, model, file, channel, + // x, y, position_fixed, orientation, orientation_fixed, volume, muted, + // properties_file" + _receiver.add_method("source/new", "sssiffbfbfbs", [](lo_arg **argv, int) + { + _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, + Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, + argv[8]->f, argv[9]->b, ""); + VERBOSE2("Creating source with following properties:" + "\nname: " << argv[0]->s << + "\nmodel: " << argv[1]->s << + "\nfile_or_port_name: " << argv[2]->s << + "\nchannel: " << argv[3]->i << + "\nposition: " << Position(argv[4]->f, argv[5]->f) << + "\nposition_fixed: " << argv[6]->b << + "\norientation: " << argv[7]->f << + "\norientation_fixed: " << argv[8]->b << + "\nvolume (linear): " << argv[9]->f << + "\nmuted: " << argv[10]->b << + "\nproperties_file: " << argv[11]->s << + "\n"); + } + ); + + // delete source: "source/delete, i, id" + // special case: i == 0 deletes all sources! + _receiver.add_method("source/delete", "i", [](lo_arg **argv, int) + { + if (argv[0]->i == 0) + { + _controller.delete_all_sources(); + VERBOSE2("delete all sources"); + } + else + { + _controller.delete_source(argv[0]->i); + VERBOSE2("delete source with id = " << argv[0]->i); + } + } + ); + + // set reference position: "reference/position, ff, x, y" + _receiver.add_method("reference/position", "ff", [](lo_arg **argv, int) + { + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f); + VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); + } + ); + + // set reference orientation: "reference/orientation, f, azimuth" + _receiver.add_method("reference/position", "f", [](lo_arg **argv, int) + { + _controller.set_reference_orientation(Orientation(argv[0]->f)); + VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); + } + ); + + // set reference offset position: "reference_offset/position, ff, x, y" + _receiver.add_method("reference_offset/position", "ff" + , [](lo_arg **argv, int) + { + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f); + VERBOSE2("set reference offset position: " << Position(argv[0]->f, + argv[1]->f)); + } + ); + + // set reference offset orientation: "reference_offset/orientation, f, + // azimuth" + _receiver.add_method("reference_offset/position", "f" + , [](lo_arg **argv, int) + { + _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + VERBOSE2("set reference offset orientation: " << + Orientation(argv[0]->f)); + } + ); + + // save scene to file: "scene/save, s, file" + _receiver.add_method("scene/save", "s" + , [](lo_arg **argv, int) + { + _controller.save_scene_as_XML(argv[0]->s); + VERBOSE2("saving theme as: " << argv[0]->s); + } + ); + + // load scene from file: "scene/load, s, file" + _receiver.add_method("scene/load", "s" + , [](lo_arg **argv, int) + { + _controller.load_scene(argv[0]->s); + VERBOSE2("loading scene: " << argv[0]->s); + } + ); + + // set master volume: "scene/volume, f, volume" + _receiver.add_method("scene/volume", "f" + , [](lo_arg **argv, int) + { + _controller.set_master_volume(dB2linear(argv[0]->f)); + VERBOSE2("set master volume: " << dB2linear(argv[0]->f) << " dB"); } + ); + + // clear scene: "scene/clear" + _receiver.add_method("scene/load", NULL + , [](lo_arg **argv, int) + { + _controller.delete_all_sources(); + VERBOSE2("clearing scene."); + } + ); + + // set processing state: "state/processing, T, true" + _receiver.add_method("state/processing", "T" + , [](lo_arg **argv, int) + { + _controller.start_processing(); + VERBOSE2("start processing."); + } + ); + + // set processing state: "state/processing, F, false" + _receiver.add_method("state/processing", "F" + , [](lo_arg **argv, int) + { + _controller.stop_processing(); + VERBOSE2("stop processing."); + } + ); + + // set transport state: "state/transport, T, true" + _receiver.add_method("state/transport", "T" + , [](lo_arg **argv, int) + { + _controller.transport_start(); + VERBOSE2("start transport."); + } + ); + + // set transport state: "state/transport, F, false" + _receiver.add_method("state/transport", "F" + , [](lo_arg **argv, int) + { + _controller.transport_stop(); + VERBOSE2("stop transport."); + } + ); + + // rewind transport state: "state/transport/rewind" + _receiver.add_method("state/transport/rewind", NULL + , [](lo_arg **argv, int) + { + _controller.transport_locate(0); + VERBOSE2("rewind transport."); + } + ); + + // seek transport state: "state/transport/seek, s, time" + _receiver.add_method("state/transport/seek", "s" + , [](lo_arg **argv, int) + { + float time; + if(string2time(argv[0]->s, time)) + { + _controller.transport_locate(time); + VERBOSE2("Seek transport to: " << time); + } + else + { + ERROR("Couldn't get the time out of the \"seek\" attribute (\"" + << argv[0]->s << "\")."); + } + } + ); + + // reset tracker: "tracker/reset" + _receiver.add_method("tracker/reset", NULL + , [](lo_arg **argv, int) + { + _controller.calibrate_client(); + VERBOSE2("calibrate tracker."); + } + ); + + +} diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h new file mode 100644 index 00000000..2fdc3e88 --- /dev/null +++ b/src/networking/oscreceiver.h @@ -0,0 +1,61 @@ +/** + * \file oscreceiver.h + * \brief Header for OscReceiver, defining a class, responsible for evaluating + * received OSC messages and interfacing the SSR's controller + */ + +#ifndef OSC_RECEIVER_H +#define OSC_RECEIVER_H +#endif + + +#ifdef HAVE_CONFIG_H +#include // for ENABLE_* +#endif + +#include +#include + +#include "ssr_global.h" + +namespace ssr +{ + +struct Publisher; + +// forward declaration for OscHandler friend functions +class OscHandler; + +/** OscReceiver + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscReceiver +{ + private: + lo::ServerThread _receiver; + Publisher& _controller; + ssr::OscHandler& _handler; + std::string _mode; + void add_client_to_server_methods(); + void add_server_to_client_methods(); + public: + OscReceiver(Publisher& controller, OscHandler& handler, int port); + ~OscReceiver(); + void start(); + void stop(); + + void set_server_for_client(OscHandler& handler, lo::Address + server_address); + lo::Address server_address(OscHandler& handler); +}; + +} // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp new file mode 100644 index 00000000..defcf0db --- /dev/null +++ b/src/networking/oscsender.cpp @@ -0,0 +1,33 @@ +#include "oschandler.h" +#include "oscsender.h" + +// client ctor +ssr::OscSender::OscSender(OscHandler& handler, int port_out) + : _handler(handler) + , _send_from(lo::ServerThread(port_out)) +{} + +// server ctor +ssr::OscSender::OscSender(OscHandler& handler, int port_out, + std::vector client_addresses) + : _handler(handler) + , _send_from(lo::ServerThread(port_out)) + , _client_addresses(client_addresses) +{} + +/** Implementation of function to return OscSender's _server_address + * @return _server_address + */ +lo::Address server_address() +{ + return this->_server_address; +} + +/** Implementation of function to set OscSender's _server_address + * @return _server_address + */ +void set_server_address(lo::Address server_address) +{ + this->_server_address = server_address; +} + diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h new file mode 100644 index 00000000..e6d17af8 --- /dev/null +++ b/src/networking/oscsender.h @@ -0,0 +1,105 @@ +#ifndef OSC_SENDER_H +#define OSC_SENDER_H +#endif + +#ifdef HAVE_CONFIG_H +#include // for ENABLE_* +#endif + +#include +#include +#include + +#include "ssr_global.h" +#include "subscriber.h" + +namespace ssr +{ + +/** OscSender + * \brief Class holding Publisher and Subscriber implementation, while being responsible for + * sending and receiving OSC messages. + * This class holds a Publisher implementation (OscReceiver), which turns + * incoming OSC messages into calls to the Controller. + * It also holds an implementation of Subscriber (OscSender), which + * \author David Runge + * \version $Revision: 0.1 $ + * \date $Date: 2017/03/29 + * Contact: dave@sleepmap.de + * + */ +class OscSender : public Subscriber +{ + private: + // address of server (only used for client -> server connection) + lo::Address _server_address; + // ServerThread to send from specific port (client <-> server) + lo::ServerThread _send_from; + // vector of client address objects (only for server -> clients) + std::vector _client_addresses; + // reference to handler + OscHandler& _handler; + + public: + OscSender(OscHandler& handler, int port); + OscSender(int port); + ~OscSender(); + void start(); + void stop(); + + // server -> clients + void poll_clients(); // poll the list of clients + + + void update_all_clients(std::string str); + void send_levels(); + + // Subscriber Interface + virtual void set_loudspeakers(const Loudspeaker::container_t& + loudspeakers); + virtual void new_source(id_t id); + virtual void delete_source(id_t id); + virtual void delete_all_sources(); + virtual bool set_source_position(id_t id, const Position& position); + virtual bool set_source_position_fixed(id_t id, const bool& fix); + virtual bool set_source_orientation(id_t id, const Orientation& + orientation); + virtual bool set_source_gain(id_t id, const float& gain); + virtual bool set_source_mute(id_t id, const bool& mute); + virtual bool set_source_name(id_t id, const std::string& name); + virtual bool set_source_properties_file(id_t id, const std::string& name); + virtual bool set_source_model(id_t id, const Source::model_t& model); + virtual bool set_source_port_name(id_t id, const std::string& port_name); + virtual bool set_source_file_name(id_t id, const std::string& file_name); + virtual bool set_source_file_channel(id_t id, const int& file_channel); + virtual bool set_source_file_length(id_t id, const long int& length); + virtual void set_reference_position(const Position& position); + virtual void set_reference_orientation(const Orientation& orientation); + virtual void set_reference_offset_position(const Position& position); + virtual void set_reference_offset_orientation(const Orientation& + orientation); + virtual void set_master_volume(float volume); + virtual void set_source_output_levels(id_t id, float* first, float* last); + virtual void set_processing_state(bool state); + virtual void set_transport_state( + const std::pair& state); + virtual void set_auto_rotation(bool auto_rotate_sources); + virtual void set_decay_exponent(float exponent); + virtual void set_amplitude_reference_distance(float distance); + virtual void set_master_signal_level(float level); + virtual void set_cpu_load(float load); + virtual void set_sample_rate(int sample_rate); + virtual bool set_source_signal_level(const id_t id, const float& level); + +// // declare set_server_address() as friend of class OscHandler +// friend void OscHandler::set_server_address(OscSender& self, lo::Address +// server_address); +// // declare server_address() as friend of class OscHandler +// friend lo::Address OscHandler::server_address(OscSender& self); + // declare set_server_address() as friend of class OscHandler + void set_server_address(lo::Address server_address); + // declare server_address() as friend of class OscHandler + lo::Address server_address(); +}; + +} // namespace ssr From a434c179be361c5494e2aeeba2e1eb0519108807 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:47:59 +0200 Subject: [PATCH 197/363] configure.ac: Adding check for liblo headers. --- configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configure.ac b/configure.ac index 98d3f29c..468f05c9 100644 --- a/configure.ac +++ b/configure.ac @@ -514,6 +514,14 @@ AS_IF([test x$have_gui = xyes], AC_SUBST(QTLIBDIR) AC_SUBST(MOCFLAGS) ]) +dnl check for liblo +ENABLE_FORCED([osc-interface], [OSC interface], + [ + AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) + AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) + AC_MSG_RESULT([$have_osc_interface]) + ] +) ENABLE_FORCED([ip-interface], [network (TCP/IP) interface (needs Asio, https://think-async.com/)], [ @@ -763,6 +771,7 @@ echo "| VRPN ................................ : $have_vrpn" echo "|" echo "| Build with Ecasound support ............ : $have_ecasound" echo "| Build with IP interface ................ : $have_ip_interface" +echo "| Build with OSC interface ............... : $have_osc_interface" echo "| Build with GUI ......................... : $gui_string" echo "|" echo "| Enable debugging/optimization .......... : $have_debugging/$have_optimization" From 0e6236f29d8df4350d11ab7f168705ae0ec58c8b Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:48:27 +0200 Subject: [PATCH 198/363] src/Makefile.am: Adding files in src/networking. --- src/Makefile.am | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index e4400861..ecb84379 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -182,6 +182,18 @@ SSRSOURCES += \ network/server.h endif +if ENABLE_OSC_INTERFACE +AM_CPPFLAGS += -I$(srcdir)/networking + +SSRSOURCES += \ + networking/oschandler.cpp \ + networking/oschandler.h \ + networking/oscreceiver.cpp \ + networking/oscreceiver.h \ + networking/oscsender.cpp \ + networking/oscsender.h +endif + if ENABLE_GUI AM_CPPFLAGS += -I$(srcdir)/gui From 198d456f07db28bc00f882d59623c2e1ff438eb2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 00:49:28 +0200 Subject: [PATCH 199/363] src/controller.h: Adding first batch of conditionals for osc interface. --- src/controller.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/controller.h b/src/controller.h index 823976d0..81d85982 100644 --- a/src/controller.h +++ b/src/controller.h @@ -61,6 +61,10 @@ #include "server.h" #endif +#ifdef ENABLE_OSC_INTERFACE +#include "oschandler.h" +#endif + #include "tracker.h" #ifdef ENABLE_INTERSENSE #include "trackerintersense.h" @@ -253,6 +257,11 @@ class Controller : public Publisher #ifdef ENABLE_IP_INTERFACE std::unique_ptr _network_interface; #endif + +#ifdef ENABLE_OSC_INTERFACE + std::unique_ptr _osc_interface; +#endif + std::unique_ptr _tracker; /// check if audio player is running and start it if necessary @@ -331,6 +340,16 @@ Controller::Controller(int argc, char* argv[]) } #endif +// throw error, if OSC interface is about to be used, but not compiled in +#ifndef ENABLE_OSC_INTERFACE + if (_conf.network_mode == "client" || _conf.network_mode == "server") + { + throw std::logic_error(_conf.exec_name + + " was compiled without OSC support!\n" + "Type '" + _conf.exec_name + " --help' for more information."); + } +#endif + #ifndef ENABLE_GUI if (_conf.gui) { @@ -403,6 +422,18 @@ Controller::Controller(int argc, char* argv[]) _network_interface->start(); } #endif // ENABLE_IP_INTERFACE + +// if OSC is compiled in and network-mode set, start OSC handler +#ifdef ENABLE_OSC_INTERFACE + if (_conf.network_mode == "client" || _conf.network_mode == "server") + { + VERBOSE("Starting OSC server on port " << _conf.network_port_receive << + "."); + _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, + _conf.network_mode)); + _osc_interface->start(); + } +#endif } template From 83b3835850fd43b2cab735d234fcffd9256e65bf Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:22:43 +0200 Subject: [PATCH 200/363] src/networking/oscsender.h: Added reference to controller as private member and to client/server constructor. --- src/networking/oscsender.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index e6d17af8..7c96bc22 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -39,10 +39,13 @@ class OscSender : public Subscriber std::vector _client_addresses; // reference to handler OscHandler& _handler; + // reference to controller + Publisher& _controller; + bool _is_subscribed; public: - OscSender(OscHandler& handler, int port); - OscSender(int port); + OscSender(Publisher& controller, OscHandler& handler, int port); + OscSender(Publisher& controller, int port); ~OscSender(); void start(); void stop(); From 1b1aeba7bd761018b223e403b04bf5ef5adff64f Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:26:01 +0200 Subject: [PATCH 201/363] src/networking/oschandler.cpp: Adding controller to initializer list for initializing OscSender. --- src/networking/oschandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2a4a87c6..ebd0a9ee 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -6,7 +6,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode) : _controller(controller), , _osc_receiver(controller, *this, port_in) - , _osc_sender(*this, port_out) + , _osc_sender(controller, *this, port_out) , _mode(mode) {} @@ -16,6 +16,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) + , _osc_sender(controller, *this, port_out) , _mode(mode) { std::vector new_clients; From a7d5e4b0939516efae97aeae0861c1efd5c37e45 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:28:59 +0200 Subject: [PATCH 202/363] src/networking/oscreceiver.cpp: Unifying callback function for creating new source. Implementing proper use of LO_TRUE and LO_FALSE types in all callback functions. Minor fixes to some VERBOSE2 output in callback functions. --- src/networking/oscreceiver.cpp | 223 ++++++++++++++++++++++++--------- 1 file changed, 166 insertions(+), 57 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index ff5d15c4..a1036208 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -68,6 +68,7 @@ void add_server_to_client_methods() if(server.hostname() != from.hostname() && server.port() != from.port()) { set_server_address(from); + // TODO: send reply to subscribed server } } ): @@ -85,18 +86,18 @@ void add_server_to_client_methods() // set source fixed: "source/position_fixed, iT, id, true" _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) { - _controller.set_source_position_fixed(argv[0]->i, argv[1]->T); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " - << argv[1]->T); + _controller.set_source_position_fixed(argv[0]->i, true); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + true"); } ); // set source fixed: "source/position_fixed, iF, id, false" _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) { - _controller.set_source_position_fixed(argv[0]->i, argv[1]->F); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = " - << argv[1]->F); + _controller.set_source_position_fixed(argv[0]->i, false); + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + false"); } ); @@ -121,18 +122,16 @@ void add_server_to_client_methods() // set source mute: "source/mute, iT, id, true" _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) { - _controller.set_source_mute(argv[0]->i, argv[1]->T); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << - dB2linear(argv[1]->T)); + _controller.set_source_mute(argv[0]->i, true); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); } ); // set source mute: "source/mute, iF, id, false" _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) { - _controller.set_source_mute(argv[0]->i, argv[1]->F); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = " << - dB2linear(argv[1]->F)); + _controller.set_source_mute(argv[0]->i, false); + VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); } ); @@ -172,52 +171,162 @@ void add_server_to_client_methods() } ); - //FIXME: spezialize with TF types - - // create new source: "source/new, sssffbfbfb, name, model, port_name, x, y, - // position_fixed, orientation, orientation_fixed, volume, muted" - _receiver.add_method("source/new", "sssffbfbfb", [](lo_arg **argv, int) - { - _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, - Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, - argv[8]->f, argv[9]->b, ""); - VERBOSE2("Creating source with following properties:" - "\nname: " << argv[0]->s << - "\nmodel: " << argv[1]->s << - "\nfile_or_port_name: " << argv[2]->s << - "\nchannel: 0" << - "\nposition: " << Position(argv[3]->f, argv[4]->f) << - "\nposition_fixed: " << argv[5]->b << - "\norientation: " << argv[6]->f << - "\norientation_fixed: " << argv[7]->b << - "\nvolume (linear): " << argv[8]->f << - "\nmuted: " << argv[9]->b << - "\nproperties_file: " << - "\n"); - } - ); - - // create new source: "source/new, sssiffbfbfbs, name, model, file, channel, - // x, y, position_fixed, orientation, orientation_fixed, volume, muted, - // properties_file" - _receiver.add_method("source/new", "sssiffbfbfbs", [](lo_arg **argv, int) + // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // port_name, x, y, orientation, volume, position_fixed, orientation_fixed, + // muted" + // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // port_name, x, y, orientation, volume, channel, properties_file, + // position_fixed, orientation_fixed, muted" + _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, + lo::Message message) { - _controller.new_source(argv[0]->s, argv[1]->s, argv[2]->s, 0, - Position(argv[3]->f, argv[4]->f), argv[5]->b, argv[6]->f, argv[7]->b, - argv[8]->f, argv[9]->b, ""); - VERBOSE2("Creating source with following properties:" - "\nname: " << argv[0]->s << - "\nmodel: " << argv[1]->s << - "\nfile_or_port_name: " << argv[2]->s << - "\nchannel: " << argv[3]->i << - "\nposition: " << Position(argv[4]->f, argv[5]->f) << - "\nposition_fixed: " << argv[6]->b << - "\norientation: " << argv[7]->f << - "\norientation_fixed: " << argv[8]->b << - "\nvolume (linear): " << argv[9]->f << - "\nmuted: " << argv[10]->b << - "\nproperties_file: " << argv[11]->s << - "\n"); + std::string name(argv[0]->s); + std::string model(argv[1]->s); + std::string file_or_portname(argv[2]->s); + float x(argv[3]->f); + float y(argv[4]->f); + float orientation(argv[5]->f); + float volume(argv[6]->f); + int channel = 0; + std::string properties_file = ""; + bool position_fixed; + bool orientation_fixed; + bool muted; + bool setup = false; + switch (message.types()) + { + case "sssffffTTT": + position_fixed = true; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffTTF": + position_fixed = true; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffTFF": + position_fixed = true; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffFFF": + position_fixed = false; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffTFT": + position_fixed = true; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffFTF": + position_fixed = false; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffFTT": + position_fixed = false; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffFFT": + position_fixed = false; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffisTTT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffisTTF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffisTFF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffisFFF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = false; + muted = false; + setup = true; + break; + case "sssffffisTFT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = true; + orientation_fixed = false; + muted = true; + setup = true; + break; + case "sssffffisFTF": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = true; + muted = false; + setup = true; + break; + case "sssffffisFTT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = true; + muted = true; + setup = true; + break; + case "sssffffisFFT": + channel = argv[7]->i; + properties_file = argv[8]->s; + position_fixed = false; + orientation_fixed = false; + muted = true; + setup = true; + break; + } + if (setup) + { + _controller.new_source(name, model, file_or_port_name, channel, + Position(x, y), position_fixed, orientation, orientation_fixed, + volume, muted, properties_file); + VERBOSE2("Creating source with following properties:" + "\nname: " << name << + "\nmodel: " << model << + "\nfile_or_port_name: " << file_or_port_name << + "\nchannel: " << channel << + "\nposition: " << Position(x, y) << + "\nposition_fixed: " << position_fixed << + "\norientation: " << orientation << + "\norientation_fixed: " << orientation_fixed << + "\nvolume (linear): " << volume << + "\nmuted: " << muted << + "\nproperties_file: " << properties_file << + "\n"); + } } ); From a7880925469a0cc3a92d2f23434df89ae36167eb Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Apr 2017 23:31:12 +0200 Subject: [PATCH 203/363] src/networking/oscsender.cpp: Adding reference to controller and handler to OscSender constructors. Adding start/stop functionality that subscribes/unsubscribes OscSender with/from the controller. --- src/networking/oscsender.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index defcf0db..0f3739ad 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -2,19 +2,36 @@ #include "oscsender.h" // client ctor -ssr::OscSender::OscSender(OscHandler& handler, int port_out) - : _handler(handler) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int + port_out) + : _controller(controller) + , _handler(handler) , _send_from(lo::ServerThread(port_out)) + , _is_subscribed(false) {} // server ctor -ssr::OscSender::OscSender(OscHandler& handler, int port_out, - std::vector client_addresses) - : _handler(handler) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int + port_out, std::vector client_addresses) + : _controller(controller) + , _handler(handler) , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) + , _is_subscribed(false) {} +ssr::OscSender::start() +{ + _controller.subscribe(*this); + _is_subscribed = true; +} + +ssr::OscSender::stop() +{ + _controller.unsubscribe(*this); + _is_subscribed = false; +} + /** Implementation of function to return OscSender's _server_address * @return _server_address */ From a927664ebfe7147864954bf79861ab44908eb786 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:52:08 +0200 Subject: [PATCH 204/363] src/controller.h: Extending messages for starting OSC interface by port numbers in use. --- src/controller.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controller.h b/src/controller.h index 81d85982..3d7b9e5b 100644 --- a/src/controller.h +++ b/src/controller.h @@ -427,8 +427,9 @@ Controller::Controller(int argc, char* argv[]) #ifdef ENABLE_OSC_INTERFACE if (_conf.network_mode == "client" || _conf.network_mode == "server") { - VERBOSE("Starting OSC server on port " << _conf.network_port_receive << - "."); + VERBOSE2("Starting OSC interface.\nReceiving on port " << + std::to_string(_conf.network_port_receive) << ".\nSending on port " << + std::to_string(_conf.network_port_send) << "."); _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, _conf.network_mode)); _osc_interface->start(); From 6831522f8e0bfe5735e2a9b13c0a7eb4beec2211 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:55:13 +0200 Subject: [PATCH 205/363] src/networking/oschandler.cpp: Adding documentation. Adding stop() and mode() methods. --- src/networking/oschandler.cpp | 64 +++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index ebd0a9ee..068ca258 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -1,7 +1,20 @@ +/** + * Implementation of oschandler.h + * @file oschandler.cpp + */ + #include "oschandler.h" #include -// client ctor +/** + * Constructor used to create client objects + * @param controller reference to a Publisher object + * @param port_in an integer describing the port number used for incoming + * traffic + * @param port_out an integer describing the port number used for outgoing + * traffic + * @param mode a string defining the mode (client|server) + */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode) : _controller(controller), @@ -10,13 +23,21 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int , _mode(mode) {} -// server ctor +/** + * Constructor used to create server objects + * @param controller reference to a Publisher object + * @param port_in an integer describing the port number used for incoming + * traffic + * @param port_out an integer describing the port number used for outgoing + * traffic + * @param mode a string defining the mode (client|server) + * @param clients a multimap holding hostname, port pairs + */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) , _mode(mode) { std::vector new_clients; @@ -28,18 +49,34 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, _osc_sender(*this, port_out, new_clients); } +/** + * Destructor + */ ssr::OscHandler::~OscHandler() {} +/** + * Stop this OscHandler by stopping its OscReceiver and OscSender + */ +ssr::OscHandler::stop() +{ + _oscSender.stop(); + _oscReceiver.stop(); +} + +/** + * Start this OscHandler by starting its OscReceiver and OscSender + */ ssr::OscHandler::start() { _oscReceiver.start(); + _oscSender.start(); } -/** Implementation of friend function to set the OscSender's server_address - * @param OscHandler holding both OscReceiver and OscSender - * @param Hostname to be set - * @param Port to be set +/** + * OscHandler's friend function to set the OscSender's server_address + * @param self reference to OscHandler holding OscSender + * @param server_address lo::Address object to be used for OscSender */ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address) @@ -47,7 +84,20 @@ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address self->_osc_sender->set_server_address(server_address); } +/** + * OscHandler's friend function return OscSender's server_address + * @param self reference to OscHandler holding the OscSender + * @return lo::Address server_address of OscSender + */ lo::Address OscReceiver::server_address(OscHandler& self) { return self->_osc_sender.server_address; } + +/** + * This function returns the OscHandler's mode + */ +std::string mode() +{ + return *this->_mode; +} From b33fdfd18fb1c4692080482cfed54c3c6893f6ed Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:56:09 +0200 Subject: [PATCH 206/363] src/networking/oschandler.h: Updating documentation. Adding mode() declaration. --- src/networking/oschandler.h | 40 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 880a99cc..11c90474 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -1,3 +1,9 @@ +/** + * Header for OscHandler, defining a class, responsible for sending OSC messages + * and subscribing to the SSR's Publisher. + * @file oschandler.h + */ + #ifndef OSC_HANDLER_H #define OSC_HANDLER_H #endif @@ -18,47 +24,33 @@ namespace ssr struct Publisher; -/* - * \class OscHandler - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which turns - * Publisher functionality into outgoing OSC messages - * - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscHandler + * This class holds a Subscriber derivate (OscSender), which turns actions of + * the referenced Publisher into OSC messages to clients or a server and an + * OscReceiver, responsible for callbacks on arriving OSC messages, that are + * delegated to the Publisher reference. */ class OscHandler { private: - // mode: client|server - std::string _mode; - Publisher& _controller; + std::string _mode; //< mode: client|server + Publisher& _controller; //< reference to Publisher object OscReceiver _osc_receiver; OscSender _osc_sender; public: - // client ctor OscHandler(Publisher& controller, int port_in, int port_out, std::string mode); - // server ctor OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients); ~OscHandler(); void start(); void stop(); - - //declare set_server_for_client() as friend of class OscReceiver + std::string mode(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); - //declare set_server_for_client() as friend of class OscReceiver friend lo::Address OscReceiver::server_address(OscHandler& self); - }; -} +} // namespace ssr From 606a90fa8a971147c5f6a44c057e5a77927c1dc9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:58:54 +0200 Subject: [PATCH 207/363] src/networking/oscreceiver.cpp: Removing superfluous implementations. Adding/updating documentation. --- src/networking/oscreceiver.cpp | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index a1036208..94458aef 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -1,3 +1,8 @@ +/** + * Implementation of oscreceiver.h + * @file oscreceiver.cpp + */ + #include "oscreiver.h" #include "oschandler.h" #include "publisher.h" @@ -6,18 +11,30 @@ using namespace apf::str; +/** + * Constructor + * @param controller reference to a Publisher object + * @param port integer representing a port to used for incoming OSC messages + * @todo add error handler for ServerThread + */ ssr::OscReceiver::OscReceiver(Publisher& controller, int port) : _controller(controller) - //TODO: add error handler here , _receiver(port) {} +/** + * Destructor + * Stops the lo::ServerThread, used for listening for OSC messages + */ ssr::OscReceiver::~OscReceiver() { _receiver.stop(); } - +/** + * Starts the OscReceiver, by adding client|server callback functions and + * starting the lo::ServerThread used for listening to OSC messages. + */ void ssr::OscReceiver::start() { // add method handlers for received messages @@ -31,18 +48,10 @@ void ssr::OscReceiver::start() } // start server thread _receiver.start(); - -// _controller.subscribe(&_subscriber); - -} - -lo::Address server_address(OscHandler& handler) -{ - return handler.server_address(handler->_osc_sender); } -/** Add callback handlers for OSC messages received from clients. - * +/** + * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ @@ -51,8 +60,8 @@ void add_client_to_server_methods() //TODO: implement! } -/** Add callback handlers for OSC messages received from a server. - * +/** + * Adds callback handlers for OSC messages received from a server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ From bf67f58dcdda071a61749686b5fc49c33eefed35 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 18:59:27 +0200 Subject: [PATCH 208/363] src/networking/oscreceiver.h: Updating documentation. --- src/networking/oscreceiver.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 2fdc3e88..3c2c503f 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -1,7 +1,7 @@ /** - * \file oscreceiver.h - * \brief Header for OscReceiver, defining a class, responsible for evaluating - * received OSC messages and interfacing the SSR's controller + * @file oscreceiver.h + * Header for OscReceiver, declaring a class, responsible for evaluating + * received OSC messages and interfacing the SSR's controller. */ #ifndef OSC_RECEIVER_H @@ -26,17 +26,11 @@ struct Publisher; // forward declaration for OscHandler friend functions class OscHandler; -/** OscReceiver - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscReceiver + * This class holds a Publisher and an OscHandler reference. + * It is responsible for all incoming OSC messages and using callback functions + * to trigger functionality in the Publisher. */ class OscReceiver { @@ -52,7 +46,6 @@ class OscReceiver ~OscReceiver(); void start(); void stop(); - void set_server_for_client(OscHandler& handler, lo::Address server_address); lo::Address server_address(OscHandler& handler); From 81f46a0c314bce994b49f9c0139103a7175f6777 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 19:00:27 +0200 Subject: [PATCH 209/363] src/networking/oscsender.cpp: Updating documentation. Implementing poll_clients(), send_to_server() methods. --- src/networking/oscsender.cpp | 98 +++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0f3739ad..ea876e0e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1,16 +1,36 @@ +/** + * Implementation of oscsender.h + * @file oscsender.cpp + */ + #include "oschandler.h" #include "oscsender.h" -// client ctor +/** + * Constructor used to create client objects + * @param controller reference to a Publisher object + * @param handler reference to an OscHandler object + * @param port_out an integer describing the port number to be used + * for outgoing traffic + */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out) : _controller(controller) , _handler(handler) , _send_from(lo::ServerThread(port_out)) , _is_subscribed(false) + , _mode(handler.mode()) {} -// server ctor +/** + * Constructor used to create server objects + * @param controller reference to a Publisher object + * @param handler reference to an OscHandler object + * @param port_out an integer describing the port number to be used + * for outgoing traffic + * @param client_addresses vector of lo::Address objects representing + * clients to this server + */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out, std::vector client_addresses) : _controller(controller) @@ -18,33 +38,95 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) , _is_subscribed(false) + , _mode(handler.mode()) {} -ssr::OscSender::start() +/** + * Destructor + */ +~OscSender(); + +/** Function to start the OscSender object + * This subscribes the OscSender to the Publisher and starts the + * lo::ServerThread to send from + */ +void ssr::OscSender::start() { _controller.subscribe(*this); _is_subscribed = true; + // check if lo::ServerThread is valid + if (!_send_from.is_valid()) { + ERROR("OSC ServerThread to send from could not be started!"); + return 1; + } + _send_from.set_callbacks([&_send_from]() + { + VERBOSE2("OSC ServerThread init: "<<&_send_from <<"."); + }, + []() + { + VERBOSE2("OSC ServerThread cleanup."); + } + ); + VERBOSE("OSC URL: " << _send_from.url()<<"."); + _send_from.start(); } -ssr::OscSender::stop() +/** + * Function to stop the OscSender object + * This unsubscribes the OscSender from the Publisher + */ +void ssr::OscSender::stop() { _controller.unsubscribe(*this); _is_subscribed = false; } -/** Implementation of function to return OscSender's _server_address - * @return _server_address +/** + * Function to return OscSender's _server_address + * @return a lo::Address object representing the current server for this client */ lo::Address server_address() { return this->_server_address; } -/** Implementation of function to set OscSender's _server_address - * @return _server_address +/** + * Function to set OscSender's _server_address + * @param server_address a lo::Address to be used as _server_address */ void set_server_address(lo::Address server_address) { this->_server_address = server_address; } +/** + * Function to send /poll OSC message to all clients + */ +void poll_clients() +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, "poll"); + } +} + +/** + * Function to send a lo::Message to the lo:Address setup as server + * @param message a predefined lo::Messge object to be sent + */ +void send_to_server(lo::Message message) +{ + _server_address.send_from(_send_from, msg); +} + +/** + * Function to send a lo::Bundle to the lo:Address setup as server + * @param bundle a predefined lo::Bundle object to be sent + */ +void send_to_server(lo::Bundle bundle) +{ + _server_address.send_from(_send_from, bundle); +} + + From 8e168a6981f9142bbf8679f1e4e3ac2d69f6887f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Apr 2017 19:04:39 +0200 Subject: [PATCH 210/363] src/networking/oscsender.h: Updating documentation. Adding declaration for send_to_server(), _mode string, _source_level and _master_level. Updating server constructor to include OscHandler reference and client_addresses vector. --- src/networking/oscsender.h | 59 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 7c96bc22..41a960d6 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -1,3 +1,9 @@ +/** + * Header for OscSender, declaring a class, responsible for sending OSC + * messages and subscribing to the SSR's Publisher. + * @file oscsender.h + */ + #ifndef OSC_SENDER_H #define OSC_SENDER_H #endif @@ -16,43 +22,45 @@ namespace ssr { -/** OscSender - * \brief Class holding Publisher and Subscriber implementation, while being responsible for - * sending and receiving OSC messages. - * This class holds a Publisher implementation (OscReceiver), which turns - * incoming OSC messages into calls to the Controller. - * It also holds an implementation of Subscriber (OscSender), which - * \author David Runge - * \version $Revision: 0.1 $ - * \date $Date: 2017/03/29 - * Contact: dave@sleepmap.de - * +/** + * OscSender + * This class holds a Publisher and an OscHandler reference, while implementing + * the Subscriber interface. + * The Publisher is subscribed to, using its interface to send out OSC messages + * on all events it emmits. */ class OscSender : public Subscriber { private: - // address of server (only used for client -> server connection) + // address of server (client) lo::Address _server_address; - // ServerThread to send from specific port (client <-> server) + // ServerThread to send from specific port (client|server) lo::ServerThread _send_from; - // vector of client address objects (only for server -> clients) + // vector of client address objects (server) std::vector _client_addresses; // reference to handler - OscHandler& _handler; + OscHandler& _handler; // TODO: really needed? // reference to controller Publisher& _controller; bool _is_subscribed; + std::string _mode; + typedef std::map source_level_map_t; + source_level_map_t _source_levels; + float _master_level; public: - OscSender(Publisher& controller, OscHandler& handler, int port); - OscSender(Publisher& controller, int port); + OscSender(Publisher& controller, OscHandler& handler, int port_out); + OscSender(Publisher& controller, OscHandler& handler, int port_out, + std::vector client_addresses); ~OscSender(); + void start(); void stop(); - - // server -> clients - void poll_clients(); // poll the list of clients - + void set_server_address(lo::Address server_address); + lo::Address server_address(); + void poll_clients(); + void send_to_server(lo::Message message); + void send_to_server(lo::Bundle bundle); void update_all_clients(std::string str); void send_levels(); @@ -94,15 +102,6 @@ class OscSender : public Subscriber virtual void set_sample_rate(int sample_rate); virtual bool set_source_signal_level(const id_t id, const float& level); -// // declare set_server_address() as friend of class OscHandler -// friend void OscHandler::set_server_address(OscSender& self, lo::Address -// server_address); -// // declare server_address() as friend of class OscHandler -// friend lo::Address OscHandler::server_address(OscSender& self); - // declare set_server_address() as friend of class OscHandler - void set_server_address(lo::Address server_address); - // declare server_address() as friend of class OscHandler - lo::Address server_address(); }; } // namespace ssr From f7bdd217eea5fc0532187abd4209517824996ce2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:19:37 +0200 Subject: [PATCH 211/363] src/controller.h: Updating VERBOSE2 messages for starting osc interface. Updating call to constructor of OSCHandler to include _conf.network_clients and _conf.network_port_send. --- src/controller.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controller.h b/src/controller.h index 3d7b9e5b..89d80762 100644 --- a/src/controller.h +++ b/src/controller.h @@ -427,11 +427,13 @@ Controller::Controller(int argc, char* argv[]) #ifdef ENABLE_OSC_INTERFACE if (_conf.network_mode == "client" || _conf.network_mode == "server") { - VERBOSE2("Starting OSC interface.\nReceiving on port " << - std::to_string(_conf.network_port_receive) << ".\nSending on port " << + VERBOSE2("Starting OSC interface as "<< _conf.network_mode << + ".\nReceiving messages on port " << + std::to_string(_conf.network_port_receive) << + ".\nSending messages from port " << std::to_string(_conf.network_port_send) << "."); _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, - _conf.network_mode)); + _conf.network_port_send, _conf.network_mode, _conf.network_clients)); _osc_interface->start(); } #endif From f99e4b4aa50fcf806282ce0ef89dcd29f75dd541 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:28:20 +0200 Subject: [PATCH 212/363] src/networking/oscreceiver.cpp: Updating OSCReceiver methods to be part of namespace ssr. Changing constructor to be more explicit. --- src/networking/oscreceiver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 94458aef..e29aa376 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -14,12 +14,12 @@ using namespace apf::str; /** * Constructor * @param controller reference to a Publisher object - * @param port integer representing a port to used for incoming OSC messages + * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, int port) +ssr::OscReceiver::OscReceiver(Publisher& controller, int port_in) : _controller(controller) - , _receiver(port) + , _receiver(port_in) {} /** @@ -55,7 +55,7 @@ void ssr::OscReceiver::start() * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void add_client_to_server_methods() +void ssr::OscReceiver::add_client_to_server_methods() { //TODO: implement! } @@ -65,7 +65,7 @@ void add_client_to_server_methods() * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void add_server_to_client_methods() +void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before From 7548d110d28886663867f22f4a034e34853a3e84 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:29:41 +0200 Subject: [PATCH 213/363] src/networking/oscreceiver.h: Changing constructor parameters to be more explicit. Adding friend functions to be able to send lo::Messages and lo::Bundles to clients/server in callbacks. --- src/networking/oscreceiver.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3c2c503f..56867ac3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -42,13 +42,21 @@ class OscReceiver void add_client_to_server_methods(); void add_server_to_client_methods(); public: - OscReceiver(Publisher& controller, OscHandler& handler, int port); + OscReceiver(Publisher& controller, OscHandler& handler, int port_in); ~OscReceiver(); void start(); void stop(); void set_server_for_client(OscHandler& handler, lo::Address server_address); lo::Address server_address(OscHandler& handler); + void send_to_client(OscHandler& self, lo::Address client_address, + std::string path, lo::Message message); + void send_to_client(OscHandler& self, lo::Address client_address, + lo::Bundle bundle); + void send_to_all_clients(OscHandler& self, std::string path, lo::Message message); + void send_to_all_clients(OscHandler& self, lo::Bundle bundle); + void send_to_server(OscHandler& self, std::string path, lo::Message message); + void send_to_server(OscHandler& self, lo::Bundle bundle); }; } // namespace ssr From 90b427f2a061a9b02fe3c03302c57d00c00bd6aa Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:36:31 +0200 Subject: [PATCH 214/363] src/networking/oscsender.cpp: Adding methods for sending OSC messages to all clients, server or specific client. Fixing all send methods to use a path std::string, where needed. Making all methods part of namespace ssr. Adding poll_all_clients method to send periodical '/poll' messages to all clients to make them subscribe to the server. Adding std::thread poll_thread to call poll_all_clients in a thread. --- src/networking/oscsender.cpp | 111 ++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 15 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index ea876e0e..9b9871b6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -3,6 +3,7 @@ * @file oscsender.cpp */ +#include #include "oschandler.h" #include "oscsender.h" @@ -38,7 +39,9 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int , _send_from(lo::ServerThread(port_out)) , _client_addresses(client_addresses) , _is_subscribed(false) + , _poll_all_clients(false) , _mode(handler.mode()) + , _poll_thread(0) {} /** @@ -70,23 +73,47 @@ void ssr::OscSender::start() ); VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); + _poll_all_clients = true; + _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients(), this); } /** * Function to stop the OscSender object - * This unsubscribes the OscSender from the Publisher + * This unsubscribes the OscSender from the Publisher and stops the client + * polling thread */ void ssr::OscSender::stop() { _controller.unsubscribe(*this); _is_subscribed = false; + VERBOSE2("Stopping client polling thread ..."); + _poll_all_clients = false; + if (_poll_thread) + { + _poll_thread->join(); + } + VERBOSE2("Client polling thread stopped."); +} + +/** + * Sends a '/poll' message to all client instances listed in _client_addresses, + * then makes the thread calling this function sleep for 1000 milliseconds + */ +void ssr::OscSender::poll_all_clients() +{ + while(_poll_all_clients) + { + send_to_all_clients("poll", lo::Message()); + //TODO find better solution to compensate for execution time + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } } /** * Function to return OscSender's _server_address * @return a lo::Address object representing the current server for this client */ -lo::Address server_address() +lo::Address ssr::OscSender::server_address() { return this->_server_address; } @@ -95,38 +122,92 @@ lo::Address server_address() * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address */ -void set_server_address(lo::Address server_address) +void ssr::OscSender::set_server_address(lo::Address server_address) { this->_server_address = server_address; } /** - * Function to send /poll OSC message to all clients + * Function to send a lo::Message to the lo:Address setup as server using a + * predefined path + * @param path a std::string defining the path to send to + * @param message a predefined lo::Messge object to be sent */ -void poll_clients() +void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - for (const auto& client_address: _client_addresses) - { - client_address.send_from(_send_from, "poll"); - } + _server_address.send_from(_send_from, path, message); +} + +/** + * Function to send a lo::Bundle to the lo:Address setup as server + * @param bundle a predefined lo::Bundle object to be sent + */ +void ssr::OscSender::send_to_server(lo::Bundle bundle) +{ + _server_address.send_from(_send_from, bundle); } /** - * Function to send a lo::Message to the lo:Address setup as server + * Function to send a lo::Message to a client. + * @param address a lo:Address that will be sent to, when found in + * _client_addresses. + * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ -void send_to_server(lo::Message message) +void ssr::OscSender::send_to_client(lo::Address address, std::string path, + lo::Message message) { - _server_address.send_from(_send_from, msg); + for (const auto& client _client_addresses) + { + if(client.hostname() == address.hostname() && client.port() == + address.port()) + { + client.send_from(_send_from, path, message); + } + } } /** - * Function to send a lo::Bundle to the lo:Address setup as server + * Function to send a lo::Bundle to a client. + * @param address a lo:Address that will be sent to, when found in + * _client_addresses. * @param bundle a predefined lo::Bundle object to be sent */ -void send_to_server(lo::Bundle bundle) +void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - _server_address.send_from(_send_from, bundle); + for (const auto& client _client_addresses) + { + if(client.hostname() == address.hostname() && client.port() == + address.port()) + { + client.send_from(_send_from, bundle); + } + } } +/** + * Function to send a lo::Message to all clients setup in _client_addresses + * vector. + * @param path a std::string defining the path to send to + * @param message a predefined lo::Messge object to be sent + */ +void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, path, message); + } +} +/** + * Function to send a lo::Bundle to all clients setup in _client_addresses + * vector. + * @param bundle a predefined lo::Bundle object to be sent + */ +void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) +{ + for (const auto& client_address: _client_addresses) + { + client_address.send_from(_send_from, bundle); + } +} From fe8d00ed84323256b31c94eed812ca9ae5490578 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:40:24 +0200 Subject: [PATCH 215/363] src/networking/oscsender.h: Adding bool and thread include for poll_all_clients method. Adding send_to_client and send_to_all_clients public methods. --- src/networking/oscsender.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 41a960d6..c922e382 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -13,6 +13,7 @@ #endif #include +#include #include #include @@ -42,11 +43,15 @@ class OscSender : public Subscriber OscHandler& _handler; // TODO: really needed? // reference to controller Publisher& _controller; + // thread used for calling poll_all_clients continuously + std::thread *_poll_thread; bool _is_subscribed; + bool _poll_all_clients; std::string _mode; typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; + void poll_all_clients(); public: OscSender(Publisher& controller, OscHandler& handler, int port_out); @@ -59,8 +64,13 @@ class OscSender : public Subscriber void set_server_address(lo::Address server_address); lo::Address server_address(); void poll_clients(); - void send_to_server(lo::Message message); + void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); + void send_to_client(lo::Address address, std::string path, lo::Message + message); + void send_to_client(lo::Address address, lo::Bundle bundle); + void send_to_all_client(std::string path, lo::Message message); + void send_to_all_client(lo::Bundle bundle); void update_all_clients(std::string str); void send_levels(); From 0c7f71a07ccd527528b7c95ae8ee5aab05522a15 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:42:42 +0200 Subject: [PATCH 216/363] src/networking/oschandler.cpp: Merging client and server constructor. Initializing _osc_sender in body instead of initializer list. Fixing call to set_server_address in friend function. Adding friend functions for sending to client(s) and server for OscReceiver. --- src/networking/oschandler.cpp | 140 +++++++++++++++++++++++++++------- 1 file changed, 113 insertions(+), 27 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 068ca258..fb5c044e 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -7,46 +7,36 @@ #include /** - * Constructor used to create client objects + * Constructor * @param controller reference to a Publisher object * @param port_in an integer describing the port number used for incoming * traffic * @param port_out an integer describing the port number used for outgoing * traffic * @param mode a string defining the mode (client|server) - */ -ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int - port_out, std::string mode) - : _controller(controller), - , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) - , _mode(mode) -{} - -/** - * Constructor used to create server objects - * @param controller reference to a Publisher object - * @param port_in an integer describing the port number used for incoming - * traffic - * @param port_out an integer describing the port number used for outgoing - * traffic - * @param mode a string defining the mode (client|server) - * @param clients a multimap holding hostname, port pairs + * @param clients a multimap holding hostname, port pairs (only used for + * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap - clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) { - std::vector new_clients; - for (const auto& hostname: clients) + if (mode == "server") + { + std::vector new_clients; + for (const auto& hostname: clients) + { + new_clients.push_back(new lo::Address(hostname.first, + std::to_string(hostname.second))); + } + _osc_sender(controller, *this, port_out, new_clients); + } + else if(mode == "client") { - new_clients.push_back(new lo::Address(hostname.first, - std::to_string(hostname.second))); + _osc_sender(controller, *this, port_out); } - _osc_sender(*this, port_out, new_clients); } /** @@ -81,7 +71,7 @@ ssr::OscHandler::start() void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address) { - self->_osc_sender->set_server_address(server_address); + self->_osc_sender.set_server_address(server_address); } /** @@ -94,6 +84,102 @@ lo::Address OscReceiver::server_address(OscHandler& self) return self->_osc_sender.server_address; } +/** + * OscHandler's friend function to send an OSC message to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, std::string path, lo::Message message) +{ + self->_osc_sender.send_to_client(client_address, path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, lo::Bundle bundle) +{ + self->_osc_sender.send_to_client(client_address, bundle); +} + +/** + * OscHandler's friend function to send an OSC message to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to a client, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param client_address lo::Address of client to send to (must be in _client_addresses) + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_all_clients(bundle); +} + +/** + * OscHandler's friend function to send an OSC message to all clients, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to all clients, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_all_clients(bundle); +} + +/** + * OscHandler's friend function to send an OSC message to the server, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Message to be sent + */ +void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, + lo::Message message) +{ + self->_osc_sender.send_to_all_clients(path, message); +} + +/** + * OscHandler's friend function to send an OSC bundle to the server, using + * OscSender. + * @param self reference to OscHandler holding OscSender + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) +{ + self->_osc_sender.send_to_server(bundle); +} + /** * This function returns the OscHandler's mode */ From c2ea971c97358057d1d38f963374aab5a4f020d9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 7 Apr 2017 16:43:36 +0200 Subject: [PATCH 217/363] src/networking/oschandler.h: Removing explicit client constructor for OscHandler. Adding friend functions for OscReceiver to send messages/bundles to server and client(s). --- src/networking/oschandler.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 11c90474..756074e8 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -40,8 +40,6 @@ class OscHandler OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port_in, int port_out, std::string - mode); OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients); ~OscHandler(); @@ -51,6 +49,18 @@ class OscHandler friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); + friend void OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, std::string path, lo::Message message); + friend void OscReceiver::send_to_client(OscHandler& self, lo::Address + client_address, lo::Bundle bundle); + friend void OscReceiver::send_to_all_clients(OscHandler& self, std::string + path, lo::Message message); + friend void OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle + bundle); + friend void OscReceiver::send_to_server(OscHandler& self, std::string path, + lo::Message message); + friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle + bundle); }; } // namespace ssr From 4e3cfe240c60e62d333e736089ebcd358becadca Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:04:37 +0200 Subject: [PATCH 218/363] src/networking/oscreceiver.cpp: Be more specific about the naming of OSC messages (especially source/properties_file) and the naming of variables (especially file_name_or_port_number). Fixing typo in OSC message for reference/orientation and reference_offset/orientation. --- src/networking/oscreceiver.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e29aa376..14f8805b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -153,8 +153,8 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); - // set source file: "source/file, is, id, file" - _receiver.add_method("source/file", "is", [](lo_arg **argv, int) + // set source file: "source/properties_file, is, id, properties_file" + _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, argv[1]->s); VERBOSE2("set source properties file name: id = " << argv[0]->i << ", @@ -181,17 +181,17 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, - // port_name, x, y, orientation, volume, position_fixed, orientation_fixed, - // muted" + // file_name_or_port_number, x, y, orientation, volume, position_fixed, + // orientation_fixed, muted" // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // port_name, x, y, orientation, volume, channel, properties_file, - // position_fixed, orientation_fixed, muted" + // file_name_or_port_number, x, y, orientation, volume, channel, + // properties_file, position_fixed, orientation_fixed, muted" _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, lo::Message message) { std::string name(argv[0]->s); std::string model(argv[1]->s); - std::string file_or_portname(argv[2]->s); + std::string file_name_or_portname(argv[2]->s); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); @@ -319,13 +319,13 @@ void ssr::OscReceiver::add_server_to_client_methods() } if (setup) { - _controller.new_source(name, model, file_or_port_name, channel, + _controller.new_source(name, model, file_name_or_port_number, channel, Position(x, y), position_fixed, orientation, orientation_fixed, volume, muted, properties_file); VERBOSE2("Creating source with following properties:" "\nname: " << name << "\nmodel: " << model << - "\nfile_or_port_name: " << file_or_port_name << + "\nfile_name_or_port_number: " << file_name_or_port_number << "\nchannel: " << channel << "\nposition: " << Position(x, y) << "\nposition_fixed: " << position_fixed << @@ -365,7 +365,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/position", "f", [](lo_arg **argv, int) + _receiver.add_method("reference/orientation", "f", [](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -385,7 +385,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/position", "f" + _receiver.add_method("reference_offset/orientation", "f" , [](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); From ce5a2ed735c58bfb492afdfca7c3f4dcc05da8c6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:07:03 +0200 Subject: [PATCH 219/363] src/networking/oscsender.h: Adding new private functions is_client, is_server, is_new_source, is_complete_source, send_new_source_message_from_id and a map for the collection of source message parts (_new_sources), requiring the adding of apf/parameter_map.h. --- src/networking/oscsender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index c922e382..cdf32f50 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -13,12 +13,14 @@ #endif #include +#include #include #include #include #include "ssr_global.h" #include "subscriber.h" +#include "apf/parameter_map.h" namespace ssr { @@ -39,6 +41,8 @@ class OscSender : public Subscriber lo::ServerThread _send_from; // vector of client address objects (server) std::vector _client_addresses; + // map of id/parameter_map pairs for new sources (server) + std::map _new_sources; // reference to handler OscHandler& _handler; // TODO: really needed? // reference to controller @@ -51,7 +55,13 @@ class OscSender : public Subscriber typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; + + bool is_client(); + bool is_server(); + bool is_new_source(id_t id); //< check, if source id is in _new_sources + bool is_complete_source(id_t id); //< check, if source is complete void poll_all_clients(); + void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: OscSender(Publisher& controller, OscHandler& handler, int port_out); From 9599f9a603e292baaee8b8248a44046d38953218 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Apr 2017 18:11:30 +0200 Subject: [PATCH 220/363] src/networking/oscsender.cpp: Adding implementation for is_client, is_server and all Subscriber interface functions. --- src/networking/oscsender.cpp | 1069 +++++++++++++++++++++++++++++++++- 1 file changed, 1067 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 9b9871b6..d22bd18e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -95,6 +95,38 @@ void ssr::OscSender::stop() VERBOSE2("Client polling thread stopped."); } +/** + * Returns true, if the instance of OscHandler is a 'client', false otherwise. + * @return true, if _oschandler.mode() returns 'client', false otherwise. + */ +bool ssr::OscSender::is_client() +{ + if(_oschandler.mode() == "client") + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the instance of OscHandler is a 'server', false otherwise. + * @return true, if _oschandler.mode() returns 'server', false otherwise. + */ +bool ssr::OscSender::is_server() +{ + if(_oschandler.mode() == "server") + { + return true; + } + else + { + return false; + } +} + /** * Sends a '/poll' message to all client instances listed in _client_addresses, * then makes the thread calling this function sleep for 1000 milliseconds @@ -200,8 +232,7 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) } /** - * Function to send a lo::Bundle to all clients setup in _client_addresses - * vector. + * Sends a lo::Bundle to all clients setup in _client_addresses vector. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) @@ -211,3 +242,1037 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) client_address.send_from(_send_from, bundle); } } + +/** + * Checks keys of _new_sources map against provided source id + * @return true, if source id is found in _new_sources, false otherwise + */ +bool ssr::OscSender::is_new_source(id_t id) +{ + if (_new_sources.empty()) + return false; + if(_new_sources.find(id) != _new_sources.end()) + { + return true; + } + else + { + return false; + } +} + +/** + * Checks, whether the settings stored in _new_sources under given source id + * are sufficient to send a '/source/new' message to all clients + * @return true, if sufficient fields are available, false otherwise + */ +bool ssr::OscSender::is_complete_source(id_t id) +{ + bool is_complete = false; + if(is_new_source(id)) + { + if((_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("properties_file") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted"))|| + (_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted"))) + is_complete = true; + } + return is_complete; +} + +/** + * Creates a lo::Message used to create a new source on clients. It will + * collect all parameters from a parameter_map in _new_sources according to an + * id. + * @param id id_t id of the local source a message will be created for. + */ +void ssr::OscSender::send_new_source_message_from_id(id_t id) +{ + lo::Message message; + if(_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("properties_file") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted") && + _new_sources.at(id).size() == 12 ) + { + message.add(_new_sources.at(id).get("name", "")); + message.add(_new_sources.at(id).get("model", "")); + message.add(_new_sources.at(id).get("file_name_or_port_number", "")); + message.add(_new_sources.at(id).get("x", 0.0)); + message.add(_new_sources.at(id).get("y", 0.0)); + message.add(_new_sources.at(id).get("orientation", 0.0)); + message.add(_new_sources.at(id).get("volume", 0.0)); + message.add(_new_sources.at(id).get("channel", 1)); + message.add(_new_sources.at(id).get("properties_file", "")); + message.add(_new_sources.at(id).get("position_fixed", false)); + message.add(_new_sources.at(id).get("orientation_fixed", false)); + message.add(_new_sources.at(id).get("muted", false)); + this->send_to_all_clients("source/new", message); + } + else if(_new_sources.at(id).has_key("name") && + _new_sources.at(id).has_key("model") && + _new_sources.at(id).has_key("file_name_or_port_number") && + _new_sources.at(id).has_key("x") && + _new_sources.at(id).has_key("y") && + _new_sources.at(id).has_key("orientation") && + _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("position_fixed") && + _new_sources.at(id).has_key("orientation_fixed") && + _new_sources.at(id).has_key("muted") && + _new_sources.at(id).size() == 10 ) + { + message.add(_new_sources.at(id).get("name", "")); + message.add(_new_sources.at(id).get("model", "")); + message.add(_new_sources.at(id).get("file_name_or_port_number", "")); + message.add(_new_sources.at(id).get("x", 0.0)); + message.add(_new_sources.at(id).get("y", 0.0)); + message.add(_new_sources.at(id).get("orientation", 0.0)); + message.add(_new_sources.at(id).get("volume", 0.0)); + message.add(_new_sources.at(id).get("position_fixed", false)); + message.add(_new_sources.at(id).get("orientation_fixed", false)); + message.add(_new_sources.at(id).get("muted", false)); + this->send_to_all_clients("source/new", message); + } +} + +// Subscriber interface (differentiating between client and server) + + +void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& + loudspeakers) +{ + (void) loudspeakers; + //not_implemented("OscSender::set_loudspeakers()"); +} + +/** + * Subscriber function called, when Publisher created a new source. + * On server: Creates new parameter_map in _new_sources if not present + * On client: Sends message about successful creation of source to server + * @param id id_t representing the source + */ +void ssr::OscSender::new_source(id_t id) +{ + if(is_server()) + { + if(!this->is_new_source(id)) + _new_sources.insert(make_pair(id, apf::parameter_map params)); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else if(is_client()) + { + lo::Message message; + message.add(id); + this->send_to_server("update/source/new", message); + } +} + +/** + * Subscriber function called, when Publisher deleted a source. + * On server: Sends out OSC message all clients to delete source with given id. + * On client: Sends out OSC message about successful deletion of source with id + * to server and erases complementing volume level from _source_levels. + * @param id id_t representing the source + */ +void ssr::OscSender::delete_source(id_t id) +{ + lo::Message message; + message.add(id); + if(is_server()) + { + this->send_to_all_clients("source/delete", id); + } + else if (is_client()) + { + this->send_to_server("update/source/delete", id); + _source_levels.erase(id); + } +} + +/** + * Subscriber function called, when Publisher deleted all sources. + * On server: Sends out OSC message to delete all sources on all clients. + * On client: Sends out OSC message about successful deletion to server. + * Clears local _source_levels. + */ +void ssr::OscSender::delete_all_sources() +{ + lo::Message message; + message.add(0); + if(is_server()) + this->send_to_all_clients("source/delete", message); + else if(is_client()) + this->send_to_server("update/source/delete", message); + + _source_levels.clear(); +} + +/** + * Subscriber function called, when Publisher set a source's position. + * On server: Sends out OSC message to set position of given source on all + * clients. If id is found in _new_sources, the Position will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message about successful positioning of source to + * server. + * @param id id_t representing the source + * @param position new Position of source + * @return true + */ +bool ssr::OscSender::set_source_position(id_t id, const Position& position) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("x", position.x); + _new_sources.at(id).set("y", position.y); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(position.x); + message.add(position.y); + this->send_to_all_clients("source/position", message); + } + } + else if (is_client()) + { + message.add(id); + message.add(position.x); + message.add(position.y); + this->send_to_server("update/source/position", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's position fixed + * state. + * On server: Sends out OSC message to set position fixed state of given source + * on all clients. If id is found in _new_sources, the position_fixed state + * will be stored in the parameter_map for id and an OSC message will be send + * to clients only, if the source is complete. + * On client: Sends out OSC message about the source's position_fixed state to + * server. + * @param id id_t representing the source + * @param fixed bool representing the source's position_fixed state + * @return true + */ +bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("position_fixed", fixed); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(fixed); + this->send_to_all_clients("source/position_fixed", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(fixed); + this->send_to_server("update/source/position_fixed", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's orientation. + * On server: Sends out OSC message to set Orientation of given source on all + * clients. If id is found in _new_sources, the Orientation will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message about new orientation of source to server. + * @param id id_t representing the source + * @param orientation new Orientation of source + * @return true + */ +bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& + orientation) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("orientation", orientation.azimuth); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(orientation.azimuth); + this->send_to_all_clients("source/orientation", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(orientation.azimuth); + this->send_to_server("update/source/orientation", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's volume. + * On server: Sends out OSC message to set volume of given source on all + * clients. If id is found in _new_sources, the volume will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's volume. + * @param id id_t representing the source + * @param gain new volume of source + * @return true + */ +bool ssr::OscSender::set_source_gain(id_t id, const float& gain) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("volume", gain); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(gain); + this->send_to_all_clients("source/volume", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(gain); + this->send_to_server("update/source/volume", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's mute state. + * On server: Sends out OSC message to set mute state of given source on all + * clients. If id is found in _new_sources, the mute state will be stored in + * the parameter_map for id and an OSC message will be send to clients only, if + * the source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's mute state. + * @param id id_t representing the source + * @param mute a bool representing the mute state of source + * @return true + */ +bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("mute", mute); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(mute); + this->send_to_all_clients("source/mute", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(mute); + this->send_to_server("update/source/mute", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's name. + * On server: Sends out OSC message to set the name of given source on all + * clients. If id is found in _new_sources, the name will be stored in + * the parameter_map for id and an OSC message will be send to clients only, if + * the source is complete. + * On client: Sends out OSC to server message about the successful updating of + * the source's name. + * @param id id_t representing the source + * @param name a std::string representing the name of source + * @return true + */ +bool ssr::OscSender::set_source_name(id_t id, const std::string& name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("name", mute); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(name); + this->send_to_all_clients("source/name", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(name); + this->send_to_server("update/source/name", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's properties_file. + * On server: Sends out OSC message to set the properties_file of given source + * on all clients. If id is found in _new_sources, the properties_file will be + * stored in the parameter_map for id and an OSC message will be send to + * clients only, if the source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's properties_file. + * @param id id_t representing the source + * @param name a std::string representing the properties_file of source + * @return true + */ +bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& + name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("properties_file", name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(name); + this->send_to_all_clients("source/properties_file", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(name); + this->send_to_server("update/source/properties_file", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set the decay exponent. + * On server: Sends out OSC message to set the decay_exponent on all clients. + * On client: Sends out OSC message to server about the updating of decay_exponent + * @param exponentn float representing the decay exponent + * @param name a std::string representing the properties_file of source + * @todo implement receiving in OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_decay_exponent(float exponent) +{ + lo::Message message; + message.add(exponent); + if(is_server()) + { + this->send_to_all_clients("scene/decay_exponent", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/decay_exponent", message); + } +} + +/** + * Subscriber function called, when Publisher set the amplitude reference + * distance. + * On server: Sends out OSC message to set the amplitude reference distance on + * all clients. + * On client: Sends out OSC message to server about the updating of the + * amplitude reference distance. + * @param distance a float representing the amplitude reference distance + * @todo implement receiving in OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_amplitude_reference_distance(float distance) +{ + lo::Message message; + message.add(distance); + if(is_server()) + { + this->send_to_all_clients("scene/amplitude_reference_distance", + message); + } + else if(is_client()) + { + this->send_to_server("update/scene/amplitude_reference_distance", + message); + } +} + +/** + * Subscriber function called, when Publisher set a source's model. + * On server: Sends out OSC message to set the model of given source on all + * clients. If id is found in _new_sources, the model will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's model. + * @param id id_t representing the source + * @param model a model_t representing the model of source + * @return true + */ +bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) +{ + lo::Message message; + std::string tmp_model; + tmp_model = apf::string::A2S(model); + if (tmp_model == "") return false; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("model", tmp_model); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(tmp_model); + this->send_to_all_clients("source/model", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(tmp_model); + this->send_to_server("update/source/model", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's port_name. + * On server: Sends out OSC message to set the port_name of given source on all + * clients. If id is found in _new_sources, the port_name will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the successful updating of + * the source's port_name. + * @param id id_t representing the source + * @param port_name a std::string representing the port_name of source + * @return true + * @todo check if it has to be ignored during _controller.new_source() + * @see Controller::new_source() + */ +bool ssr::OscSender::set_source_port_name(id_t id, const std::string& + port_name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("port_name", port_name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(port_name); + this->send_to_all_clients("source/port_name", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(port_name); + this->send_to_server("update/source/port_name", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's + * file_name_or_port_number member. + * On server: Sends out OSC message to set the file_name_or_port_number of + * given source on all clients. If id is found in _new_sources, the + * file_name_or_port_number will be stored in the parameter_map for id and an + * OSC message will be send to clients only, if the source is complete. + * On client: Sends out OSC message to server about the updating of the + * source's file_name_or_port_number. + * @param id id_t representing the source + * @param file_name a std::string representing the file name or + * port number of source + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_name(id_t id, const std::string& + file_name) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("file_name_or_port_number", + file_name); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(file_name); + this->send_to_all_clients("source/file_name_or_port_number", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(file_name); + this->send_to_server("update/source/file_name_or_port_number", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's channel. + * On server: Sends out OSC message to set the channel of given source on all + * clients. If id is found in _new_sources, the channel will be stored in the + * parameter_map for id and an OSC message will be send to clients only, if the + * source is complete. + * On client: Sends out OSC message to server about the updating of the + * source's channel. + * @param id id_t representing the source + * @param file_channel an int representing the channel in use for source + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) +{ + lo::Message message; + if(is_server()) + { + if(is_new_source(id)) + { + _new_sources.at(id).set("channel", file_channel); + if(is_complete_source(id)) + this->send_new_source_message_from_id(id); + } + else + { + message.add(id); + message.add(file_channel); + this->send_to_all_clients("source/channel", message); + } + } + else if(is_client()) + { + message.add(id); + message.add(file_channel); + this->send_to_server("update/source/channel", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set a source's file length. + * On server: Does nothing, as the Publisher only emits this on creation of a + * new source. + * On client: Sends out OSC message to server about the updating of the + * source's file length. + * @param id id_t representing the source + * @param length an int representing the source file's length + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) +{ + lo::Message message; + if(is_client()) + { + message.add(id); + message.add(length); + this->send_to_server("update/source/length", message); + } + return true; +} + +/** + * Subscriber function called, when Publisher set the reference position. + * On server: Sends out OSC message to all clients to update to the given + * reference position. + * On client: Sends out OSC message to server about the updating of the + * reference position. + * @param position a Position representing the new reference position + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_position(const Position& position) +{ + lo::Message message; + message.add(position.x); + message.add(position.y); + if(is_server()) + { + this->send_to_all_clients("reference/position", message); + } + else if(is_client()) + { + this->send_to_server("update/reference/position", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference orientation. + * On server: Sends out OSC message to all clients to update to the given + * reference orientation. + * On client: Sends out OSC message to server about the updating of the + * reference orientation. + * @param orientation an Orientation representing the new reference orientation + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_orientation(const Orientation& orientation) +{ + lo::Message message; + message.add(orientation.azimuth); + if(is_server()) + { + this->send_to_all_clients("reference/orientation", message); + } + else if(is_client()) + { + this->send_to_server("update/reference/orientation", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference offset + * position. + * On server: Sends out OSC message to all clients to update to the given + * reference offset position. + * On client: Sends out OSC message to server about the updating of the + * reference offset position. + * @param position a Position representing the new reference offset position + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_offset_position(const Position& position) +{ + lo::Message message; + message.add(position.x); + message.add(position.y); + if(is_server()) + { + this->send_to_all_clients("reference_offset/position", message); + } + else if(is_client()) + { + this->send_to_server("update/reference_offset/position", message); + } +} + +/** + * Subscriber function called, when Publisher set the reference offset + * orientation. + * On server: Sends out OSC message to all clients to update to the given + * reference offset orientation. + * On client: Sends out OSC message to server about the updating of the + * reference offset orientation. + * @param orientation an Orientation representing the new reference offset + * orientation + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_reference_offset_orientation(const Orientation& + orientation) +{ + lo::Message message; + message.add(orientation.azimuth); + if(is_server()) + { + this->send_to_all_clients("reference_offset/orientation", message); + } + else if(is_client()) + { + this->send_to_server("update/reference_offset/orientation", message); + } +} + +/** + * Subscriber function called, when Publisher set the master volume. + * On server: Sends out OSC message to all clients to update to the given + * master volume (submits in dB!). + * On client: Sends out OSC message to server about the updating of the master + * volume (submits in dB!). + * @param volume float representing the new volume (linear scale) + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_master_volume(float volume) +{ + lo::Message message; + message.add(apf::math::linear2dB(volume)); + if(is_server()) + { + this->send_to_all_clients("scene/volume", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/volume", message); + } +} + +/** + * Subscriber function called, when Publisher set a source's output levels. + * On server: + * On client: + * @param id id_t representing the source + * @param first float* + * @param last float* + * @todo understand what should actually be done here + */ +void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* + last) +{ + void (id); + void (first); + void (last); +} + +/** + * Subscriber function called, when Publisher set the processing state. + * On server: Sends out OSC message to all clients to update their processing + * state. + * On client: Sends out OSC message to server about the update of its + * processing state. + * @param state bool representing the processing state + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_processing_state(bool state) +{ + lo::Message message; + message.add(state); + if(is_server()) + { + this->send_to_all_clients("state/processing", message); + } + else if(is_client()) + { + this->send_to_server("update/state/processing", message); + } +} + +/** + * Subscriber function called, when Publisher set the processing state. + * On server: Sends out OSC message to all clients to update their processing + * state. + * On client: Sends out OSC message to server about the update of its + * processing state. + * @param state a std::pair of a bool representing the processing state and + * jack_nframes_t, representing the current location in the transport + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_transport_state( const std::pair& state) +{ + lo::Message message_state; + lo::Message message_time; + message_state.add(state.first); + message_time.add(std::to_string(state.second)); + if(is_server()) + { + lo::Bundle bundle({ + {"state/transport", message_state}, + {"state/transport/seek", message_time} + }); + this->send_to_all_clients(bundle); + } + else if(is_client()) + { + lo::Bundle bundle({ + {"update/state/transport", message_state}, + {"update/state/transport/seek", message_time} + }); + this->send_to_server(bundle); + } +} + +/** + * Subscriber function called, when Publisher set whether to auto rotate + * sources. + * On server: Sends out OSC message to all clients to update their + * auto rotate settings. + * On client: Sends out OSC message to server about the update of its + * auto rotate settings. + * @param auto_rotate_sources a bool representing the current + * auto_rotate_sources setting. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) +{ + lo::Message message; + message.add(auto_rotate_sources); + if(is_server()) + { + this->send_to_all_clients("scene/auto_rotate_sources", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/auto_rotate_sources", message); + } +} + +/** + * Subscriber function called, when Publisher set cpu_load. + * On server: Does nothing. + * On client: Sends out OSC message to server indicating the cpu_load. + * @param load a float representing the current cpu load + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_cpu_load(float load) +{ + lo::Message message; + message.add(load); + if(is_client()) + { + this->send_to_server("update/cpu_load", message); + } +} + +/** + * Subscriber function called, when Publisher set sample rate. + * On server: Sends out OSC message to all clients to update their + * sample rate. + * On client: Sends out OSC message to server about the update of its + * sample rate. + * @param sr an integer representing the current sample rate. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_sample_rate(int sr) +{ + lo::Message message; + message.add(sr); + if(is_server()) + { + this->send_to_all_clients("scene/sample_rate", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/sample_rate", message); + } +} + +/** + * Subscriber function called, when Publisher set the master signal level. + * On server: Sends out OSC message to all clients to update their master + * signal level. + * On client: Sends out OSC message to server about the update of its signal + * level. + * @param level a float representing the current master signal level. + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +void ssr::OscSender::set_master_signal_level(float level) +{ + lo::Message message; + message.add(apf::math::linear2dB(level)); + if(is_server()) + { + this->send_to_all_clients("scene/master_signal_level", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/master_signal_level", message); + } +} + +/** + * Subscriber function called, when Publisher set a source's signal level. + * On server: Sends out OSC message to all clients to update a source's signal + * level. + * On client: Sends out OSC message to server about the update of the source's + * signal level. + * @param id an id_t representing the source. + * @param level a float representing the signal level of the source. + * @return true + * @todo implement receiver callback in + * OscReceiver::add_server_to_client_methods() + */ +bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) +{ + lo::Message message; + message.add(apf::math::linear2dB(level)); + if(is_server()) + { + this->send_to_all_clients("scene/master_signal_level", message); + } + else if(is_client()) + { + this->send_to_server("update/scene/master_signal_level", message); + } + return true; +} + From 849171f599a3cf7e9895465f7ed3d8a111366189 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:28:01 +0200 Subject: [PATCH 221/363] src/networking/oscreceiver.cpp: Adding callback functions for client to server OSC messages. Fixing typos in server to client callback functions. Renaming processing/state and transport/{state,seek} for clearer interface. --- src/networking/oscreceiver.cpp | 382 +++++++++++++++++++++++++++++++-- 1 file changed, 364 insertions(+), 18 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 14f8805b..d33390d6 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -53,11 +53,363 @@ void ssr::OscReceiver::start() /** * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every - * callback, that interface with the Publisher's functionality. + * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { -//TODO: implement! + // update on new source: "update/source/new, i, id" + _receiver.add_method("update/source/new", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << " created."); + } + ); + + // update on deleted source: "update/source/delete, i, id" + _receiver.add_method("update/source/delete", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + if(agrv[0]->i == 0) + { + VERBOSE("Update: Client '" << client.hostname() << "', all sources + deleted."); } + else + { + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << " deleted."); + } + } + ); + + // update on source position: "update/source/position, iff, id, x, y" + _receiver.add_method("update/source/position", "iff", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", position: "<< argv[1]->f << "/"argv[2]->f << "."); + } + ); + + // update on source position fixation: "update/source/position_fixed, i{T,F}, + // id, {true,false}" + _receiver.add_method("update/source/position_fixed", NULL, [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + std::string position_fixed; + if(message.types() == "iT") + { + position_fixed = "true"; + } + else if(message.types() == "iF") + { + position_fixed = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", position_fixed: "<< position_fixed << "."); + } + ); + + // update on source orientation: "update/source/orientation, if, id, azimuth" + _receiver.add_method("update/source/orientation", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", orientation: "<< argv[1]->f << "."); + } + ); + + // update on source volume: "update/source/volume, if, id, volume" + _receiver.add_method("update/source/volume", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", volume: "<< argv[1]->f << "."); + } + ); + + // update on source position mute: "update/source/mute, i{T,F}, + // id, {true,false}" + _receiver.add_method("update/source/mute", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "iT") + { + state = "true"; + } + else if(message.types() == "iF") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", mute: "<< state < "."); + } + ); + + // update on source name: "update/source/name, is, id, name" + _receiver.add_method("update/source/name", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", name: "<< argv[1]->s << "."); + } + ); + + // update on source properties_file: "update/source/properties_file, is, id, + // properties_file" + _receiver.add_method("update/source/properties_file", "is", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", properties_file: "<< argv[1]->s << "."); + } + ); + + // update on scene decay exponent: "update/scene/decay_exponent, f, + // decay_exponent" + _receiver.add_method("update/scene/decay_exponent", "f", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: + "<< argv[0]->f << "."); } + ); + + // update on scene amplitude reference distance: + // "update/scene/amplitude_reference_distance, f, + // amplitude_reference_distance" + _receiver.add_method("update/scene/amplitude_reference_distance", "f", + [](lo_arg **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', + amplitude_reference_distance: "<< argv[0]->f << "."); } + ); + + // update on source model: "update/source/model, is, id, model" + _receiver.add_method("update/source/model", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", model: "<< argv[1]->s << "."); + } + ); + + // update on source port_name: "update/source/port_name, is, id, port_name" + _receiver.add_method("update/source/port_name", "is", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", port_name: "<< argv[1]->s << "."); + } + ); + + // update on source file_name_or_port_number: + // "update/source/file_name_or_port_number, is, id, file_name_or_port_number" + _receiver.add_method("update/source/file_name_or_port_number", "is", + [](lo_arg **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); + } + ); + + // update on source channel: "update/source/channel, ii, id, channel" + _receiver.add_method("update/source/channel", "ii", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", channel: "<< argv[1]->i << "."); + } + ); + + // update on source file length: "update/source/length, ii, id, length" + _receiver.add_method("update/source/length", "ii", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", length: "<< argv[1]->i << "."); + } + ); + + // update on reference position: "update/reference/position, ff, x, y" + _receiver.add_method("update/reference/position", "ff", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference + position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + } + ); + + // update on reference orientation: "update/reference/orientation, f, + // azimuth" + _receiver.add_method("update/reference/orientation", "f", [](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference + orientation: "<< argv[0]->f << " (azimuth)."); + } + ); + + // update on reference offset position: "update/reference_offset/position, + // ff, x, y" + _receiver.add_method("update/reference_offset/position", "ff", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference offset + position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + } + ); + + // update on reference offset orientation: + // "update/reference_offset/orientation, f, azimuth" + _receiver.add_method("update/reference_offset/orientation", "f", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', reference offset + orientation: "<< argv[0]->f << " (azimuth)."); + } + ); + + // update on scene volume: "update/scene/volume, f, volume" + _receiver.add_method("update/scene/volume", "f", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene volume: "<< + argv[0]->f << "dB."); + } + ); + + // update on state processing: "update/processing/state, {T,F}, {true,false}" + _receiver.add_method("update/processing/state", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', state processing: + "<< state < "."); + } + ); + + // update on transport state: "update/transport/state, {T,F}, {true,false}" + _receiver.add_method("update/transport/state", NULL, [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', transport state: + "<< state < "."); + } + ); + + // update on transport seek: "update/transport/seek, s, time" + _receiver.add_method("update/transport/seek", "s", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', transport seek: + "<< argv[0]->s << "."); + } + ); + + // update on scene source auto rotation: "update/scene/auto_rotate_sources, + // {T,F}, {true,false}" + _receiver.add_method("update/scene/auto_rotate_sources", NULL, [](lo_arg + **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + std::string state; + if(message.types() == "T") + { + state = "true"; + } + else if(message.types() == "F") + { + state = "false"; + } + VERBOSE("Update: Client '" << client.hostname() << "', scene + auto_rotate_sources: "<< state < "."); + } + ); + + // update on cpu_load: "update/cpu_load, f, load" + _receiver.add_method("update/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("Update: Client '" << client.hostname() << "', cpu_load: "<< + argv[0]->f << "%."); + } + ); + + // update on scene sample rate: "update/scene/sample_rate, i, sample_rate" + _receiver.add_method("update/scene/sample_rate", "i", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene sample_rate: + "<< argv[0]->i << "Hz."); + } + ); + + // update on scene master signal level: "update/scene/master_signal_level, f, + // master_signal_level" + _receiver.add_method("update/scene/master_signal_level", "f", [](lo_arg + **argv, int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE("Update: Client '" << client.hostname() << "', scene + master_signal_level: "<< argv[0]->f << "dB."); + } + ); + + // update on source signal level: "update/source/level, if, id, level" + _receiver.add_method("update/source/level", "if", [](lo_arg **argv, int, + lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("Update: Client '" << client.hostname() << "', source id = " << + argv[0]->i << ", level: "<< argv[1]->f << "dB."); + } + ); + } /** @@ -191,7 +543,7 @@ void ssr::OscReceiver::add_server_to_client_methods() { std::string name(argv[0]->s); std::string model(argv[1]->s); - std::string file_name_or_portname(argv[2]->s); + std::string file_name_or_port_number(argv[2]->s); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); @@ -421,7 +773,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // clear scene: "scene/clear" - _receiver.add_method("scene/load", NULL + _receiver.add_method("scene/clear", NULL , [](lo_arg **argv, int) { _controller.delete_all_sources(); @@ -430,8 +782,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set processing state: "state/processing, T, true" - _receiver.add_method("state/processing", "T" - , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "T" , [](lo_arg **argv, int) { _controller.start_processing(); VERBOSE2("start processing."); @@ -439,26 +790,23 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set processing state: "state/processing, F, false" - _receiver.add_method("state/processing", "F" - , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "F" , [](lo_arg **argv, int) { _controller.stop_processing(); VERBOSE2("stop processing."); } ); - // set transport state: "state/transport, T, true" - _receiver.add_method("state/transport", "T" - , [](lo_arg **argv, int) + // set transport state: "transport/state, T, true" + _receiver.add_method("transport/state", "T" , [](lo_arg **argv, int) { _controller.transport_start(); VERBOSE2("start transport."); } ); - // set transport state: "state/transport, F, false" - _receiver.add_method("state/transport", "F" - , [](lo_arg **argv, int) + // set transport state: "transport/state, F, false" + _receiver.add_method("transport/state", "F" , [](lo_arg **argv, int) { _controller.transport_stop(); VERBOSE2("stop transport."); @@ -466,8 +814,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // rewind transport state: "state/transport/rewind" - _receiver.add_method("state/transport/rewind", NULL - , [](lo_arg **argv, int) + _receiver.add_method("transport/rewind", NULL , [](lo_arg **argv, int) { _controller.transport_locate(0); VERBOSE2("rewind transport."); @@ -475,8 +822,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // seek transport state: "state/transport/seek, s, time" - _receiver.add_method("state/transport/seek", "s" - , [](lo_arg **argv, int) + _receiver.add_method("transport/seek", "s" , [](lo_arg **argv, int) { float time; if(string2time(argv[0]->s, time)) From a215b4728373b0d63b7d7db9343a1c9002e68990 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:29:54 +0200 Subject: [PATCH 222/363] src/networking/oscsender.h: Cleanup and adding TODO. --- src/networking/oscsender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cdf32f50..73e2d746 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -31,6 +31,7 @@ namespace ssr * the Subscriber interface. * The Publisher is subscribed to, using its interface to send out OSC messages * on all events it emmits. + * @todo implement sending levels periodically */ class OscSender : public Subscriber { @@ -82,7 +83,6 @@ class OscSender : public Subscriber void send_to_all_client(std::string path, lo::Message message); void send_to_all_client(lo::Bundle bundle); - void update_all_clients(std::string str); void send_levels(); // Subscriber Interface From e42e99d6768b794dabca8cddcbf1cd072a40370a Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:31:57 +0200 Subject: [PATCH 223/363] src/networking/oscsender.cpp: Adding documentation for set_loudspeakers function. Fixing copy stupidity in set_source_signal_level and changing to new OSC message format in set_transport_state and set_processing_state. --- src/networking/oscsender.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index d22bd18e..7a8a6725 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -364,11 +364,16 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) // Subscriber interface (differentiating between client and server) +/** + * Subscriber function called, when Publisher sets up the list of loudspeakers. + * Not implemented in OscSender. + * @param loudpspeakers Loudspeaker container representing the list of + * loudspeakers to set up. + */ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& loudspeakers) { (void) loudspeakers; - //not_implemented("OscSender::set_loudspeakers()"); } /** @@ -1113,11 +1118,11 @@ void ssr::OscSender::set_processing_state(bool state) message.add(state); if(is_server()) { - this->send_to_all_clients("state/processing", message); + this->send_to_all_clients("processing/state", message); } else if(is_client()) { - this->send_to_server("update/state/processing", message); + this->send_to_server("update/processing/state", message); } } @@ -1142,16 +1147,16 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients(bundle); } else if(is_client()) { lo::Bundle bundle({ - {"update/state/transport", message_state}, - {"update/state/transport/seek", message_time} + {"update/transport/state", message_state}, + {"update/transport/seek", message_time} }); this->send_to_server(bundle); } @@ -1267,11 +1272,11 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) message.add(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("scene/master_signal_level", message); + this->send_to_all_clients("source/level", message); } else if(is_client()) { - this->send_to_server("update/scene/master_signal_level", message); + this->send_to_server("update/source/level", message); } return true; } From 3b6337a1c45d691ba58784cf314fac6dbc3d8641 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Apr 2017 20:33:31 +0200 Subject: [PATCH 224/363] src/networking/oscreceiver.h: Adding TODO. --- src/networking/oscreceiver.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 56867ac3..3c19e907 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -31,6 +31,7 @@ class OscHandler; * This class holds a Publisher and an OscHandler reference. * It is responsible for all incoming OSC messages and using callback functions * to trigger functionality in the Publisher. + * @todo add functionality to only process a subset of incoming client messages */ class OscReceiver { From 4fc7bab9b0b4575e648d7bb19efc5d8e9637d8d7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 15:37:23 +0200 Subject: [PATCH 225/363] src/networking/oscsender.h: Adding more todos. --- src/networking/oscsender.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 73e2d746..59b427bf 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -31,7 +31,8 @@ namespace ssr * the Subscriber interface. * The Publisher is subscribed to, using its interface to send out OSC messages * on all events it emmits. - * @todo implement sending levels periodically + * @todo implement sending levels periodically using apf/cxx_thread_policy.h + * @todo implement polling clients periodically using apf/cxx_thread_policy.h */ class OscSender : public Subscriber { From e8f960027bbcac17645ee0f9ae0e6e6307fdacc2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:21:10 +0200 Subject: [PATCH 226/363] src/networking/oschandler.cpp: Fixing accidental std::multimap initialization in Constructor. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index fb5c044e..30b8e312 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -18,7 +18,7 @@ * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) From cb9a3a509e4a084b7a3f6d65e41dd1cde250c2d2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:30:21 +0200 Subject: [PATCH 227/363] src/networking/oschandler.cpp: Fixing type definition of std::multimap in constructor. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 30b8e312..f0476db1 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -18,7 +18,7 @@ * server) */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) + std::string mode, std::multimap clients) : _controller(controller), , _osc_receiver(controller, *this, port_in) , _mode(mode) From 1189248c2bb2594b73c7479ce2c92714efeeb457 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:36:37 +0200 Subject: [PATCH 228/363] src/networking/oschandler.cpp: Fixing accidental additional comma in initializer list. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index f0476db1..2b982b28 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -19,7 +19,7 @@ */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) - : _controller(controller), + : _controller(controller) , _osc_receiver(controller, *this, port_in) , _mode(mode) { From 28967ac133f78702f0734e4e31d44ab9184420de Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 16:50:24 +0200 Subject: [PATCH 229/363] src/networking/oschandler.cpp: Add TODO to fix initializer list warning during make. --- src/networking/oschandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2b982b28..bcd9a11f 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -16,6 +16,8 @@ * @param mode a string defining the mode (client|server) * @param clients a multimap holding hostname, port pairs (only used for * server) + * @todo add _osc_sender to initializer list, to circumvent reorder warning, + * create client list after initialization, when in server mode */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) From 06a876d28fcea8470586a05d5dece8a54fb780d0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 17:01:10 +0200 Subject: [PATCH 230/363] src/networking/oschandler.cpp: Fix start/stop functionality. The class members were wrongly named and the function declaration insufficient. --- src/networking/oschandler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bcd9a11f..7c4e0c9e 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -50,19 +50,19 @@ ssr::OscHandler::~OscHandler() /** * Stop this OscHandler by stopping its OscReceiver and OscSender */ -ssr::OscHandler::stop() +void ssr::OscHandler::stop() { - _oscSender.stop(); - _oscReceiver.stop(); + _osc_receiver.stop(); + _osc_sender.stop(); } /** * Start this OscHandler by starting its OscReceiver and OscSender */ -ssr::OscHandler::start() +void ssr::OscHandler::start() { - _oscReceiver.start(); - _oscSender.start(); + _osc_receiver.start(); + _osc_sender.start(); } /** From eddee2db2e40879a06b82ac883525c3e702aa388 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:08:51 +0200 Subject: [PATCH 231/363] src/networking/oscsender.cpp: Adding public function to add a lo::Address to the vector of clients. --- src/networking/oscsender.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 7a8a6725..c7aec020 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -361,6 +361,15 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) } } +/** + * Adds a new client to the vector of clients + * @param clients lo::Address of a client + */ +void add_client(lo::Address client) +{ + _client_addresses.push_back(client); +} + // Subscriber interface (differentiating between client and server) From 032d50d30fc861d4769e7050e36a2fe8a77b4c72 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:09:20 +0200 Subject: [PATCH 232/363] src/networking/oscsender.h: Adding add_client() to the public interface. --- src/networking/oscsender.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 59b427bf..1d8bdb17 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -75,6 +75,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(lo::Address server_address); lo::Address server_address(); + void add_client(lo::Address client); void poll_clients(); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From 419c50ad8a0c9157887c6bd6cb8cb9096ea3f833 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 18:11:15 +0200 Subject: [PATCH 233/363] src/networking/oschandler.cpp: Fixing ordering in constructor initializer list. Adding list of clients to _osc_sender (as lo::Address objects), if server mode is selected. Removing todo about reorder warning. --- src/networking/oschandler.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 7c4e0c9e..cfae55be 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -16,28 +16,21 @@ * @param mode a string defining the mode (client|server) * @param clients a multimap holding hostname, port pairs (only used for * server) - * @todo add _osc_sender to initializer list, to circumvent reorder warning, - * create client list after initialization, when in server mode */ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, std::string mode, std::multimap clients) - : _controller(controller) + : _mode(mode) + , _controller(controller) , _osc_receiver(controller, *this, port_in) - , _mode(mode) + , _osc_sender(controller, *this, port_out) { if (mode == "server") { - std::vector new_clients; for (const auto& hostname: clients) { - new_clients.push_back(new lo::Address(hostname.first, + _osc_sender.add_client(new lo::Address(hostname.first, std::to_string(hostname.second))); } - _osc_sender(controller, *this, port_out, new_clients); - } - else if(mode == "client") - { - _osc_sender(controller, *this, port_out); } } From f621afab3a1e8b7379e3151f90a81e375684161f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 19:14:08 +0200 Subject: [PATCH 234/363] src/networking/oschandler.cpp: Fixing broken operands of accessing members of _osc_sender. Clearly defining function heads for set_server_for_client and server_address to use ssr:OscHandler. --- src/networking/oschandler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index cfae55be..cdab5505 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -63,10 +63,10 @@ void ssr::OscHandler::start() * @param self reference to OscHandler holding OscSender * @param server_address lo::Address object to be used for OscSender */ -void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address +void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address server_address) { - self->_osc_sender.set_server_address(server_address); + self._osc_sender.set_server_address(server_address); } /** @@ -74,7 +74,7 @@ void ssr::OscReceiver::set_server_for_client(OscHandler& self, lo::Address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ -lo::Address OscReceiver::server_address(OscHandler& self) +lo::Address OscReceiver::server_address(ssr::OscHandler& self) { return self->_osc_sender.server_address; } @@ -89,7 +89,7 @@ lo::Address OscReceiver::server_address(OscHandler& self) void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message) { - self->_osc_sender.send_to_client(client_address, path, message); + self._osc_sender.send_to_client(client_address, path, message); } /** @@ -102,7 +102,7 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, lo::Bundle bundle) { - self->_osc_sender.send_to_client(client_address, bundle); + self._osc_sender.send_to_client(client_address, bundle); } /** @@ -114,7 +114,7 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, lo::Message message) { - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(path, message); } /** @@ -126,7 +126,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_all_clients(bundle); + self._osc_sender.send_to_all_clients(bundle); } /** From e9a9864da9e8e7e0451f076913fc4e309b3bd513 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:52:57 +0200 Subject: [PATCH 235/363] src/networking/oschandler.cpp: Removing accidental copies of send_to_all_clients functions. Properly implementing mode(), OscReceiver::server_address. Fixing access to _osc_sender member. --- src/networking/oschandler.cpp | 50 +++++------------------------------ 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index cdab5505..079a85d8 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -74,9 +74,9 @@ void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ -lo::Address OscReceiver::server_address(ssr::OscHandler& self) +lo::Address ssr::OscReceiver::server_address(ssr::OscHandler& self) { - return self->_osc_sender.server_address; + return self._osc_sender.server_address(); } /** @@ -105,30 +105,6 @@ void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address self._osc_sender.send_to_client(client_address, bundle); } -/** - * OscHandler's friend function to send an OSC message to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, - lo::Message message) -{ - self._osc_sender.send_to_all_clients(path, message); -} - -/** - * OscHandler's friend function to send an OSC bundle to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param client_address lo::Address of client to send to (must be in _client_addresses) - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) -{ - self._osc_sender.send_to_all_clients(bundle); -} - /** * OscHandler's friend function to send an OSC message to all clients, using * OscSender. @@ -138,7 +114,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, lo::Message message) { - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(path, message); } /** @@ -149,19 +125,7 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_all_clients(bundle); -} - -/** - * OscHandler's friend function to send an OSC message to the server, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, - lo::Message message) -{ - self->_osc_sender.send_to_all_clients(path, message); + self._osc_sender.send_to_all_clients(bundle); } /** @@ -172,13 +136,13 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, */ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) { - self->_osc_sender.send_to_server(bundle); + self._osc_sender.send_to_server(bundle); } /** * This function returns the OscHandler's mode */ -std::string mode() +std::string ssr::OscHandler::mode() { - return *this->_mode; + return _mode; } From 6c0e5ea3e78a5f2e94ca371cf27371b28edd68dc Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:53:52 +0200 Subject: [PATCH 236/363] src/networking/oscsender.h: Fixing naming typo of send_to_all_clients functions. --- src/networking/oscsender.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 1d8bdb17..20a28ae5 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -82,8 +82,8 @@ class OscSender : public Subscriber void send_to_client(lo::Address address, std::string path, lo::Message message); void send_to_client(lo::Address address, lo::Bundle bundle); - void send_to_all_client(std::string path, lo::Message message); - void send_to_all_client(lo::Bundle bundle); + void send_to_all_clients(std::string path, lo::Message message); + void send_to_all_clients(lo::Bundle bundle); void send_levels(); From 7e79dc10548a450c2e4b232849f9071846946f4d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 10 May 2017 23:54:29 +0200 Subject: [PATCH 237/363] src/networking/oscreceiver.cpp: Fixing typo for oscreceiver.h include. --- src/networking/oscreceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d33390d6..b4dd1bfb 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -3,7 +3,7 @@ * @file oscreceiver.cpp */ -#include "oscreiver.h" +#include "oscreceiver.h" #include "oschandler.h" #include "publisher.h" #include "apf/stringtools.h" From 44c5c3134790d4d93fe973606030f9012141eed8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 17:41:54 +0200 Subject: [PATCH 238/363] src/networking/oscreceiver.cpp: Fixing non-escaped linebreaks in VERBOSE messages. --- src/networking/oscreceiver.cpp | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b4dd1bfb..ca40e0c0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -74,7 +74,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Address client(message.source()); if(agrv[0]->i == 0) { - VERBOSE("Update: Client '" << client.hostname() << "', all sources + VERBOSE("Update: Client '" << client.hostname() << "', all sources \ deleted."); } else { @@ -181,7 +181,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: + VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: \ "<< argv[0]->f << "."); } ); @@ -192,7 +192,7 @@ void ssr::OscReceiver::add_client_to_server_methods() [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', + VERBOSE("Update: Client '" << client.hostname() << "', \ amplitude_reference_distance: "<< argv[0]->f << "."); } ); @@ -252,7 +252,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference + VERBOSE("Update: Client '" << client.hostname() << "', reference \ position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); } ); @@ -263,7 +263,7 @@ void ssr::OscReceiver::add_client_to_server_methods() int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference + VERBOSE("Update: Client '" << client.hostname() << "', reference \ orientation: "<< argv[0]->f << " (azimuth)."); } ); @@ -274,7 +274,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset + VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); } ); @@ -285,7 +285,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset + VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ orientation: "<< argv[0]->f << " (azimuth)."); } ); @@ -314,8 +314,8 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', state processing: - "<< state < "."); + VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ + " << state < "."); } ); @@ -333,7 +333,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', transport state: + VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ "<< state < "."); } ); @@ -343,7 +343,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', transport seek: + VERBOSE("Update: Client '" << client.hostname() << "', transport seek: \ "<< argv[0]->s << "."); } ); @@ -364,7 +364,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', scene + VERBOSE("Update: Client '" << client.hostname() << "', scene \ auto_rotate_sources: "<< state < "."); } ); @@ -384,8 +384,8 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene sample_rate: - "<< argv[0]->i << "Hz."); + VERBOSE("Update: Client '" << client.hostname() << "', scene \ + sample_rate: "<< argv[0]->i << "Hz."); } ); @@ -395,7 +395,7 @@ void ssr::OscReceiver::add_client_to_server_methods() **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene + VERBOSE("Update: Client '" << client.hostname() << "', scene \ master_signal_level: "<< argv[0]->f << "dB."); } ); @@ -448,7 +448,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ true"); } ); @@ -457,7 +457,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = + VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ false"); } ); @@ -509,7 +509,7 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, argv[1]->s); - VERBOSE2("set source properties file name: id = " << argv[0]->i << ", + VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ file = " << argv[1]->s); } ); @@ -518,8 +518,8 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/model", "is", [](lo_arg **argv, int) { _controller.set_source_model(argv[0]->i, argv[1]->s); - VERBOSE2("set source model: id = " << argv[0]->i << ", - model = " << argv[1]->s); + VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << + argv[1]->s); } ); @@ -527,8 +527,8 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, argv[1]->s); - VERBOSE2("set source port name: id = " << argv[0]->i << ", - port = " << argv[1]->s); + VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << + argv[1]->s); } ); From 2f2c3913952d280145a50cf88d36a19044006340 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:29:58 +0200 Subject: [PATCH 239/363] src/networking/oschandler.h: Fix header guard. --- src/networking/oschandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 756074e8..c60fa08a 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -6,7 +6,6 @@ #ifndef OSC_HANDLER_H #define OSC_HANDLER_H -#endif #ifdef HAVE_CONFIG_H #include // for ENABLE_* @@ -64,3 +63,4 @@ class OscHandler }; } // namespace ssr +#endif From 580f7851da63385295df7d28b0b42e1b10c518ab Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:30:35 +0200 Subject: [PATCH 240/363] src/networking/oscreceiver.h: Fix header guard. Remove redundant _mode std::string. --- src/networking/oscreceiver.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3c19e907..116d26b2 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -6,7 +6,6 @@ #ifndef OSC_RECEIVER_H #define OSC_RECEIVER_H -#endif #ifdef HAVE_CONFIG_H @@ -39,7 +38,6 @@ class OscReceiver lo::ServerThread _receiver; Publisher& _controller; ssr::OscHandler& _handler; - std::string _mode; void add_client_to_server_methods(); void add_server_to_client_methods(); public: @@ -61,3 +59,4 @@ class OscReceiver }; } // namespace ssr +#endif From ef45045073298b1445aebd3effd5194cbbe9c7a6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:30:57 +0200 Subject: [PATCH 241/363] src/networking/oscsender.h: Fix header guard. --- src/networking/oscsender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 20a28ae5..b180de74 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -6,7 +6,6 @@ #ifndef OSC_SENDER_H #define OSC_SENDER_H -#endif #ifdef HAVE_CONFIG_H #include // for ENABLE_* @@ -127,3 +126,4 @@ class OscSender : public Subscriber }; } // namespace ssr +#endif From 37aa3ec91f5c896c2c6b3eb76cd753e9002b9cb5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:33:05 +0200 Subject: [PATCH 242/363] src/networking/oscreceiver.cpp: Fix Constructor definition (OscHandler added to arguments, initializer list reorganized). Set check for client/server mode to use _handler instance. Fixing typo in add_client_to_server_methods, calling agrv instead of argv. --- src/networking/oscreceiver.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index ca40e0c0..2c37df54 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -17,9 +17,10 @@ using namespace apf::str; * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, int port_in) - : _controller(controller) - , _receiver(port_in) +ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int port_in) + : _receiver(port_in) + , _controller(controller) + , _handler(handler) {} /** @@ -38,11 +39,11 @@ ssr::OscReceiver::~OscReceiver() void ssr::OscReceiver::start() { // add method handlers for received messages - if (_mode == "server") + if (_handler.mode() == "server") { add_client_to_server_methods(); } - else if (_mode == "client") + else if (_handler.mode() == "client") { add_server_to_client_methods(); } @@ -72,7 +73,7 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Message message) { lo::Address client(message.source()); - if(agrv[0]->i == 0) + if(argv[0]->i == 0) { VERBOSE("Update: Client '" << client.hostname() << "', all sources \ deleted."); } From 643ec51d7550337ade918fd71188da1eeff3c574 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 18:56:54 +0200 Subject: [PATCH 243/363] src/networking/oscreceiver.cpp: Using apf::string::A2S() in VERBOSE output, where needed. Avoiding unused parameter warning with argv in some lambda functions. Using << in VERBOSE instead of <. --- src/networking/oscreceiver.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2c37df54..c0df7e6b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -91,7 +91,8 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position: "<< argv[1]->f << "/"argv[2]->f << "."); + argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << + "."); } ); @@ -151,7 +152,8 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", mute: "<< state < "."); + apf::str::A2S(argv[0]->i) << ", mute: "<< state << + "."); } ); @@ -307,6 +309,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -316,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ - " << state < "."); + " << state << "."); } ); @@ -326,6 +329,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -335,7 +339,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ - "<< state < "."); + "<< state << "."); } ); @@ -357,6 +361,7 @@ void ssr::OscReceiver::add_client_to_server_methods() { lo::Address client(message.source()); std::string state; + (void) argv; if(message.types() == "T") { state = "true"; @@ -366,7 +371,7 @@ void ssr::OscReceiver::add_client_to_server_methods() state = "false"; } VERBOSE("Update: Client '" << client.hostname() << "', scene \ - auto_rotate_sources: "<< state < "."); + auto_rotate_sources: "<< state << "."); } ); From f48100da1c88d80fa0697592205da6a2604d40cb Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:08:37 +0200 Subject: [PATCH 244/363] src/networking/oscreceiver.cpp: Using apf::str::A2S to convert members of lo::Message objects to std::string. Using apf::str::S2A for Source::model_t editing. Adding *this pointer to lambda functions, that require access to _controller. --- src/networking/oscreceiver.cpp | 67 +++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c0df7e6b..e87330a2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -427,31 +427,32 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _receiver.add_method("poll", NULL, [](lo_arg **argv, int, lo::Message + _receiver.add_method("poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server = server_address(&_handler); + lo::Address server = server_address(_handler); lo::Address from(message.source()); + (void) argv; if(server.hostname() != from.hostname() && server.port() != from.port()) { - set_server_address(from); + set_server_for_client(_handler, from); // TODO: send reply to subscribed server } } - ): + ); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("source/position", "iff", [](lo_arg **argv, int) + _receiver.add_method("source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f); + argv[2]->f)); VERBOSE2("set source position: id = " << argv[0]->i << ", " << Position(argv[1]->f, argv[2]->f)); } ); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("source/position_fixed", "iT", [](lo_arg **argv, int) + _receiver.add_method("source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ @@ -460,7 +461,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("source/position_fixed", "iF", [](lo_arg **argv, int) + _receiver.add_method("source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ @@ -469,7 +470,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("source/orientation", "if", [](lo_arg **argv, int) + _receiver.add_method("source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " @@ -478,16 +479,17 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("source/volume", "if", [](lo_arg **argv, int) + _receiver.add_method("source/volume", "if", [this](lo_arg **argv, int) { - _controller.set_source_gain(argv[0]->i, dB2linear(argv[1]->f)); + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << - dB2linear(argv[1]->f)); + apf::math::dB2linear(argv[1]->f)); } ); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("source/mute", "iT", [](lo_arg **argv, int) + _receiver.add_method("source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -495,7 +497,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("source/mute", "iF", [](lo_arg **argv, int) + _receiver.add_method("source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -503,38 +505,45 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set source name: "source/name, is, id, name" - _receiver.add_method("source/name", "is", [](lo_arg **argv, int) + _receiver.add_method("source/name", "is", [this](lo_arg **argv, int) { - _controller.set_source_name(argv[0]->i, argv[1]->s); + _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); // set source file: "source/properties_file, is, id, properties_file" - _receiver.add_method("source/properties_file", "is", [](lo_arg **argv, int) + _receiver.add_method("source/properties_file", "is", [this](lo_arg **argv, + int) { - _controller.set_source_properties_file(argv[0]->i, argv[1]->s); + _controller.set_source_properties_file(argv[0]->i, + apf::str::A2S(argv[1]->s)); VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ - file = " << argv[1]->s); + file = " << apf::str::A2S(argv[1]->s)); } ); // set source model: "source/model, is, id, model" - _receiver.add_method("source/model", "is", [](lo_arg **argv, int) + _receiver.add_method("source/model", "is", [this](lo_arg **argv, int) { - _controller.set_source_model(argv[0]->i, argv[1]->s); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + _controller.set_source_model(argv[0]->i, model); VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); // set source port name: "source/port_name, is, id, port_name" - _receiver.add_method("source/port_name", "is", [](lo_arg **argv, int) + _receiver.add_method("source/port_name", "is", [this](lo_arg **argv, int) { - _controller.set_source_port_name(argv[0]->i, argv[1]->s); + _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << - argv[1]->s); + apf::str::A2S(argv[1]->s)); } ); @@ -547,9 +556,9 @@ void ssr::OscReceiver::add_server_to_client_methods() _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, lo::Message message) { - std::string name(argv[0]->s); - std::string model(argv[1]->s); - std::string file_name_or_port_number(argv[2]->s); + std::string name(apf::str::A2S(argv[0]->s)); + std::string model(apf::str::A2S(argv[1]->s)); + std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); float orientation(argv[5]->f); From aee92c9a9498be839593591f2054841621743828 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:28:11 +0200 Subject: [PATCH 245/363] src/networking/oscreceiver.cpp: Using several if clauses, instead of a switch in the lambda responsible for setting up a new source. Initializing all dependant types earlier. --- src/networking/oscreceiver.cpp | 95 ++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e87330a2..45ea9700 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -553,15 +553,14 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("source/new", NULL, [](lo_arg **argv, int, + _receiver.add_method("source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); - std::string model(apf::str::A2S(argv[1]->s)); std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); + std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); - float orientation(argv[5]->f); float volume(argv[6]->f); int channel = 0; std::string properties_file = ""; @@ -569,132 +568,152 @@ void ssr::OscReceiver::add_server_to_client_methods() bool orientation_fixed; bool muted; bool setup = false; - switch (message.types()) + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); + if (types.compare("sssffffTTT") == 0) { - case "sssffffTTT": position_fixed = true; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffTTF": + } + if (types.compare("sssffffTTF") == 0) + { position_fixed = true; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffTFF": + } + if (types.compare("sssffffTFF") == 0) + { position_fixed = true; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffFFF": + } + if (types.compare("sssffffFFF") == 0) + { position_fixed = false; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffTFT": + } + if (types.compare("sssffffTFT") == 0) + { position_fixed = true; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffFTF": + } + if (types.compare("sssffffFTF") == 0) + { position_fixed = false; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffFTT": + } + if (types.compare("sssffffFTT") == 0) + { position_fixed = false; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffFFT": + } + if (types.compare("sssffffFFT") == 0) + { position_fixed = false; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffisTTT": + } + if (types.compare("sssffffisTTT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffisTTF": + } + if (types.compare("sssffffisTTF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffisTFF": + } + if (types.compare("sssffffisTFF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffisFFF": + } + if (types.compare("sssffffisFFF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = false; muted = false; setup = true; - break; - case "sssffffisTFT": + } + if (types.compare("sssffffisTFT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = true; orientation_fixed = false; muted = true; setup = true; - break; - case "sssffffisFTF": + } + if (types.compare("sssffffisFTF") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = true; muted = false; setup = true; - break; - case "sssffffisFTT": + } + if (types.compare("sssffffisFTT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = true; muted = true; setup = true; - break; - case "sssffffisFFT": + } + if (types.compare("sssffffisFFT") == 0) + { channel = argv[7]->i; properties_file = argv[8]->s; position_fixed = false; orientation_fixed = false; muted = true; setup = true; - break; } if (setup) { _controller.new_source(name, model, file_name_or_port_number, channel, - Position(x, y), position_fixed, orientation, orientation_fixed, + position, position_fixed, orientation, orientation_fixed, volume, muted, properties_file); VERBOSE2("Creating source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << "\nchannel: " << channel << - "\nposition: " << Position(x, y) << + "\nposition: " << position << "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << "\norientation_fixed: " << orientation_fixed << From 191ef7d7771a46bd146924befd53951ec0c55461 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 11 May 2017 21:48:39 +0200 Subject: [PATCH 246/363] src/networking/oscreceiver.cpp: Adding namespaces to apf functions in use. Adding this pointer capture to remaining functions needing it. Explicitely converting lo::Message members of type std::string using apf::str::A2S. --- src/networking/oscreceiver.cpp | 69 ++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 45ea9700..c945d1ea 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -727,7 +727,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("source/delete", "i", [](lo_arg **argv, int) + _receiver.add_method("source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -743,15 +743,15 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference position: "reference/position, ff, x, y" - _receiver.add_method("reference/position", "ff", [](lo_arg **argv, int) + _receiver.add_method("reference/position", "ff", [this](lo_arg **argv, int) { - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f); + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/orientation", "f", [](lo_arg **argv, int) + _receiver.add_method("reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -759,11 +759,11 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // set reference offset position: "reference_offset/position, ff, x, y" - _receiver.add_method("reference_offset/position", "ff" - , [](lo_arg **argv, int) + _receiver.add_method("reference_offset/position", "ff" , [this](lo_arg + **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f); + argv[1]->f)); VERBOSE2("set reference offset position: " << Position(argv[0]->f, argv[1]->f)); } @@ -771,8 +771,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/orientation", "f" - , [](lo_arg **argv, int) + _receiver.add_method("reference_offset/orientation", "f" , [this](lo_arg **argv, + int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference offset orientation: " << @@ -781,85 +781,89 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // save scene to file: "scene/save, s, file" - _receiver.add_method("scene/save", "s" - , [](lo_arg **argv, int) + _receiver.add_method("scene/save", "s" , [this](lo_arg **argv, int) { - _controller.save_scene_as_XML(argv[0]->s); - VERBOSE2("saving theme as: " << argv[0]->s); + _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); + VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); } ); // load scene from file: "scene/load, s, file" - _receiver.add_method("scene/load", "s" - , [](lo_arg **argv, int) + _receiver.add_method("scene/load", "s" , [this](lo_arg **argv, int) { - _controller.load_scene(argv[0]->s); - VERBOSE2("loading scene: " << argv[0]->s); + _controller.load_scene(apf::str::A2S(argv[0]->s)); + VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); } ); // set master volume: "scene/volume, f, volume" - _receiver.add_method("scene/volume", "f" - , [](lo_arg **argv, int) + _receiver.add_method("scene/volume", "f" , [this](lo_arg **argv, int) { - _controller.set_master_volume(dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << dB2linear(argv[0]->f) << " dB"); } + _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << " \ + dB"); + } ); // clear scene: "scene/clear" - _receiver.add_method("scene/clear", NULL - , [](lo_arg **argv, int) + _receiver.add_method("scene/clear", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.delete_all_sources(); VERBOSE2("clearing scene."); } ); // set processing state: "state/processing, T, true" - _receiver.add_method("processing/state", "T" , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "T" , [this](lo_arg **argv, int) { + (void) argv; _controller.start_processing(); VERBOSE2("start processing."); } ); // set processing state: "state/processing, F, false" - _receiver.add_method("processing/state", "F" , [](lo_arg **argv, int) + _receiver.add_method("processing/state", "F" , [this](lo_arg **argv, int) { + (void) argv; _controller.stop_processing(); VERBOSE2("stop processing."); } ); // set transport state: "transport/state, T, true" - _receiver.add_method("transport/state", "T" , [](lo_arg **argv, int) + _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_start(); VERBOSE2("start transport."); } ); // set transport state: "transport/state, F, false" - _receiver.add_method("transport/state", "F" , [](lo_arg **argv, int) + _receiver.add_method("transport/state", "F" , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_stop(); VERBOSE2("stop transport."); } ); // rewind transport state: "state/transport/rewind" - _receiver.add_method("transport/rewind", NULL , [](lo_arg **argv, int) + _receiver.add_method("transport/rewind", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.transport_locate(0); VERBOSE2("rewind transport."); } ); // seek transport state: "state/transport/seek, s, time" - _receiver.add_method("transport/seek", "s" , [](lo_arg **argv, int) + _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; - if(string2time(argv[0]->s, time)) + if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) { _controller.transport_locate(time); VERBOSE2("Seek transport to: " << time); @@ -873,13 +877,12 @@ void ssr::OscReceiver::add_server_to_client_methods() ); // reset tracker: "tracker/reset" - _receiver.add_method("tracker/reset", NULL - , [](lo_arg **argv, int) + _receiver.add_method("tracker/reset", NULL , [this](lo_arg **argv, int) { + (void) argv; _controller.calibrate_client(); VERBOSE2("calibrate tracker."); } ); - } From a33d902bada352c5864d3837ddf0caa5a52dd47f Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 13:20:59 +0200 Subject: [PATCH 247/363] src/networking/oscsender.h: Removing unused member _mode. Moving members around to reflect Constructor implementation. --- src/networking/oscsender.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index b180de74..920b8b29 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -36,23 +36,22 @@ namespace ssr class OscSender : public Subscriber { private: - // address of server (client) - lo::Address _server_address; + // reference to controller + Publisher& _controller; + // reference to handler + OscHandler& _handler; // ServerThread to send from specific port (client|server) lo::ServerThread _send_from; + bool _is_subscribed; + // address of server (client) + lo::Address _server_address; // vector of client address objects (server) std::vector _client_addresses; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; - // reference to handler - OscHandler& _handler; // TODO: really needed? - // reference to controller - Publisher& _controller; // thread used for calling poll_all_clients continuously std::thread *_poll_thread; - bool _is_subscribed; bool _poll_all_clients; - std::string _mode; typedef std::map source_level_map_t; source_level_map_t _source_levels; float _master_level; From 9d3ba25fc4cc31f571ff07b2a35cc53e7e984d8c Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 13:25:43 +0200 Subject: [PATCH 248/363] src/networking/oscsender.cpp: Adding publisher.h apf/{stringtools,math}.h to includes. Removing server specific constructor to reflect header. Fixing initializer list. Fixing Destructor. Fixing start() function VERBOSE printouts. Fixing calls to _handler.mode(). Introducing int32_t for id_t types, when sending OSC messages with id. Various small typo fixes. --- src/networking/oscsender.cpp | 137 +++++++++++++++++------------------ 1 file changed, 67 insertions(+), 70 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index c7aec020..ea3e5ef6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -6,6 +6,9 @@ #include #include "oschandler.h" #include "oscsender.h" +#include "publisher.h" +#include "apf/stringtools.h" +#include "apf/math.h" /** * Constructor used to create client objects @@ -18,36 +21,15 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int port_out) : _controller(controller) , _handler(handler) - , _send_from(lo::ServerThread(port_out)) - , _is_subscribed(false) - , _mode(handler.mode()) -{} - -/** - * Constructor used to create server objects - * @param controller reference to a Publisher object - * @param handler reference to an OscHandler object - * @param port_out an integer describing the port number to be used - * for outgoing traffic - * @param client_addresses vector of lo::Address objects representing - * clients to this server - */ -ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int - port_out, std::vector client_addresses) - : _controller(controller) - , _handler(handler) - , _send_from(lo::ServerThread(port_out)) - , _client_addresses(client_addresses) - , _is_subscribed(false) - , _poll_all_clients(false) - , _mode(handler.mode()) - , _poll_thread(0) + , _send_from(port_out) + , _server_address("none") {} /** * Destructor */ -~OscSender(); +ssr::OscSender::~OscSender() +{} /** Function to start the OscSender object * This subscribes the OscSender to the Publisher and starts the @@ -55,16 +37,15 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int */ void ssr::OscSender::start() { - _controller.subscribe(*this); + _controller.subscribe(this); _is_subscribed = true; // check if lo::ServerThread is valid if (!_send_from.is_valid()) { ERROR("OSC ServerThread to send from could not be started!"); - return 1; } - _send_from.set_callbacks([&_send_from]() + _send_from.set_callbacks([this]() { - VERBOSE2("OSC ServerThread init: "<<&_send_from <<"."); + VERBOSE2("OSC ServerThread init: "<<&this->_send_from <<"."); }, []() { @@ -74,7 +55,7 @@ void ssr::OscSender::start() VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); _poll_all_clients = true; - _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients(), this); + _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients()), this); } /** @@ -84,7 +65,7 @@ void ssr::OscSender::start() */ void ssr::OscSender::stop() { - _controller.unsubscribe(*this); + _controller.unsubscribe(this); _is_subscribed = false; VERBOSE2("Stopping client polling thread ..."); _poll_all_clients = false; @@ -101,7 +82,7 @@ void ssr::OscSender::stop() */ bool ssr::OscSender::is_client() { - if(_oschandler.mode() == "client") + if(_handler.mode() == "client") { return true; } @@ -117,7 +98,7 @@ bool ssr::OscSender::is_client() */ bool ssr::OscSender::is_server() { - if(_oschandler.mode() == "server") + if(_handler.mode() == "server") { return true; } @@ -189,7 +170,7 @@ void ssr::OscSender::send_to_server(lo::Bundle bundle) void ssr::OscSender::send_to_client(lo::Address address, std::string path, lo::Message message) { - for (const auto& client _client_addresses) + for (const auto& client: _client_addresses) { if(client.hostname() == address.hostname() && client.port() == address.port()) @@ -207,7 +188,7 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, */ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - for (const auto& client _client_addresses) + for (const auto& client: _client_addresses) { if(client.hostname() == address.hostname() && client.port() == address.port()) @@ -365,7 +346,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) * Adds a new client to the vector of clients * @param clients lo::Address of a client */ -void add_client(lo::Address client) +void ssr::OscSender::add_client(lo::Address client) { _client_addresses.push_back(client); } @@ -396,14 +377,15 @@ void ssr::OscSender::new_source(id_t id) if(is_server()) { if(!this->is_new_source(id)) - _new_sources.insert(make_pair(id, apf::parameter_map params)); + _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else if(is_client()) { lo::Message message; - message.add(id); + int32_t message_id = id; + message.add(message_id); this->send_to_server("update/source/new", message); } } @@ -418,14 +400,15 @@ void ssr::OscSender::new_source(id_t id) void ssr::OscSender::delete_source(id_t id) { lo::Message message; - message.add(id); + int32_t message_id = id; + message.add(message_id); if(is_server()) { - this->send_to_all_clients("source/delete", id); + this->send_to_all_clients("source/delete", message); } else if (is_client()) { - this->send_to_server("update/source/delete", id); + this->send_to_server("update/source/delete", message); _source_levels.erase(id); } } @@ -463,6 +446,7 @@ void ssr::OscSender::delete_all_sources() bool ssr::OscSender::set_source_position(id_t id, const Position& position) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -474,7 +458,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add(id); + message.add(message_id); message.add(position.x); message.add(position.y); this->send_to_all_clients("source/position", message); @@ -482,7 +466,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else if (is_client()) { - message.add(id); + message.add(message_id); message.add(position.x); message.add(position.y); this->send_to_server("update/source/position", message); @@ -506,6 +490,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -516,14 +501,14 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add(id); + message.add(message_id); message.add(fixed); this->send_to_all_clients("source/position_fixed", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(fixed); this->send_to_server("update/source/position_fixed", message); } @@ -545,6 +530,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& orientation) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -555,14 +541,14 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add(id); + message.add(message_id); message.add(orientation.azimuth); this->send_to_all_clients("source/orientation", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(orientation.azimuth); this->send_to_server("update/source/orientation", message); } @@ -584,6 +570,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -594,14 +581,14 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add(id); + message.add(message_id); message.add(gain); this->send_to_all_clients("source/volume", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(gain); this->send_to_server("update/source/volume", message); } @@ -623,6 +610,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -633,14 +621,14 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add(id); + message.add(message_id); message.add(mute); this->send_to_all_clients("source/mute", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(mute); this->send_to_server("update/source/mute", message); } @@ -662,24 +650,25 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) { - _new_sources.at(id).set("name", mute); + _new_sources.at(id).set("name", name); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else { - message.add(id); + message.add(message_id); message.add(name); this->send_to_all_clients("source/name", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(name); this->send_to_server("update/source/name", message); } @@ -702,6 +691,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -712,14 +702,14 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(name); this->send_to_all_clients("source/properties_file", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(name); this->send_to_server("update/source/properties_file", message); } @@ -789,8 +779,9 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { lo::Message message; + int32_t message_id = id; std::string tmp_model; - tmp_model = apf::string::A2S(model); + tmp_model = apf::str::A2S(model); if (tmp_model == "") return false; if(is_server()) { @@ -802,14 +793,14 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - message.add(id); + message.add(message_id); message.add(tmp_model); this->send_to_all_clients("source/model", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(tmp_model); this->send_to_server("update/source/model", message); } @@ -834,6 +825,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -844,14 +836,14 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(port_name); this->send_to_all_clients("source/port_name", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(port_name); this->send_to_server("update/source/port_name", message); } @@ -878,6 +870,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -889,14 +882,14 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add(id); + message.add(message_id); message.add(file_name); this->send_to_all_clients("source/file_name_or_port_number", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(file_name); this->send_to_server("update/source/file_name_or_port_number", message); } @@ -920,6 +913,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { lo::Message message; + int32_t message_id = id; if(is_server()) { if(is_new_source(id)) @@ -930,14 +924,14 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add(id); + message.add(message_id); message.add(file_channel); this->send_to_all_clients("source/channel", message); } } else if(is_client()) { - message.add(id); + message.add(message_id); message.add(file_channel); this->send_to_server("update/source/channel", message); } @@ -959,9 +953,10 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { lo::Message message; + int32_t message_id = id; if(is_client()) { - message.add(id); + message.add(message_id); message.add(length); this->send_to_server("update/source/length", message); } @@ -1106,9 +1101,9 @@ void ssr::OscSender::set_master_volume(float volume) void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* last) { - void (id); - void (first); - void (last); + (void) id; + (void) first; + (void) last; } /** @@ -1278,10 +1273,12 @@ void ssr::OscSender::set_master_signal_level(float level) bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { lo::Message message; + int32_t message_id = id; + message.add(message_id); message.add(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("source/level", message); + this->send_to_all_clients("source/volume", message); } else if(is_client()) { From 38ca305b2bb2b628d19227ce8277ef2fedcc49c5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 15:47:03 +0200 Subject: [PATCH 249/363] src/networking/oscsender.h: Changing std::thread pointer to object type for _poll_thread. Removing public function poll_clients() (unused). --- src/networking/oscsender.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 920b8b29..bec1ea8e 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -50,7 +50,7 @@ class OscSender : public Subscriber // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously - std::thread *_poll_thread; + std::thread _poll_thread; bool _poll_all_clients; typedef std::map source_level_map_t; source_level_map_t _source_levels; @@ -58,9 +58,9 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); + void poll_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete - void poll_all_clients(); void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: @@ -74,7 +74,6 @@ class OscSender : public Subscriber void set_server_address(lo::Address server_address); lo::Address server_address(); void add_client(lo::Address client); - void poll_clients(); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From 1dc41b58126bf4ac0b3a5945187305d6d6ecd942 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 15:48:23 +0200 Subject: [PATCH 250/363] src/networking/oscsender.cpp: Using a detached std::thread for polling all clients instead of joinable std::thread. Making this a server-exclusive feature. --- src/networking/oscsender.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index ea3e5ef6..f34829f5 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -54,8 +54,12 @@ void ssr::OscSender::start() ); VERBOSE("OSC URL: " << _send_from.url()<<"."); _send_from.start(); - _poll_all_clients = true; - _poll_thread = new std::thread(std::bind(&OscSender::poll_all_clients()), this); + if (is_server()) + { + _poll_all_clients = true; + std::thread _poll_thread(&OscSender::poll_all_clients, this); + _poll_thread.detach(); + } } /** @@ -67,13 +71,11 @@ void ssr::OscSender::stop() { _controller.unsubscribe(this); _is_subscribed = false; - VERBOSE2("Stopping client polling thread ..."); - _poll_all_clients = false; - if (_poll_thread) + if (is_server()) { - _poll_thread->join(); + _poll_all_clients = false; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - VERBOSE2("Client polling thread stopped."); } /** @@ -114,12 +116,14 @@ bool ssr::OscSender::is_server() */ void ssr::OscSender::poll_all_clients() { + VERBOSE("Polling all clients."); while(_poll_all_clients) { send_to_all_clients("poll", lo::Message()); //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } + VERBOSE("Stopped polling all clients."); } /** From 3f07df265f6aed7521ac7289524f13b79f172017 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:07:03 +0200 Subject: [PATCH 251/363] configure.ac: Adding linker flag for liblo. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 468f05c9..5f79d71d 100644 --- a/configure.ac +++ b/configure.ac @@ -517,6 +517,7 @@ AS_IF([test x$have_gui = xyes], dnl check for liblo ENABLE_FORCED([osc-interface], [OSC interface], [ + CPPFLAGS="$CPPFLAGS -llo" AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) AC_MSG_RESULT([$have_osc_interface]) From ce1fda16e3433cccf693ae81cfda4e076e04d075 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:40:47 +0200 Subject: [PATCH 252/363] configure.ac: Adding liblo libs to LIBS, by checking with pkg-config. Removing useless CPPFLAGS from header check for liblo. --- configure.ac | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 5f79d71d..7a965234 100644 --- a/configure.ac +++ b/configure.ac @@ -212,6 +212,14 @@ PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.0], LIBS="$LIBS $LIBXML_LIBS" ]) +dnl Checking for liblo +PKG_CHECK_MODULES([LIBLO], [liblo >= 0.28], + [ + PKG_FLAGS="$PKG_FLAGS $LIBLO_CFLAGS" + LIBS="$LIBS $LIBLO_LIBS" + ] +) + dnl by the way, AC_HELP_STRING is deprecated, use AS_HELP_STRING instead! ENABLE_EXPLICIT([debugging],[debugging symbols, asserts, ...]) @@ -514,15 +522,6 @@ AS_IF([test x$have_gui = xyes], AC_SUBST(QTLIBDIR) AC_SUBST(MOCFLAGS) ]) -dnl check for liblo -ENABLE_FORCED([osc-interface], [OSC interface], - [ - CPPFLAGS="$CPPFLAGS -llo" - AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) - AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) - AC_MSG_RESULT([$have_osc_interface]) - ] -) ENABLE_FORCED([ip-interface], [network (TCP/IP) interface (needs Asio, https://think-async.com/)], [ @@ -530,6 +529,13 @@ ENABLE_FORCED([ip-interface], [network (TCP/IP) interface (needs Asio, https://t AC_CHECK_HEADER([asio.hpp], , [have_ip_interface=no]) ]) +ENABLE_FORCED([osc-interface], [network OSC interface], +[ + AC_CHECK_HEADER([lo/lo.h], , [have_osc_interface=no]) + AC_CHECK_HEADER([lo/lo_cpp.h], , [have_osc_interface=no]) + AC_MSG_RESULT([$have_osc_interface]) +]) + ENABLE_FORCED([ecasound], [Ecasound soundfile playback/recording], [ dnl Checking for libecasoundc. It does not provide pkg-config and installs From 73ac865a1ad20b6701c913e294e8c4e8d6def7ab Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:46:10 +0200 Subject: [PATCH 253/363] src/networking/oscreceiver.cpp: Moving _receiver.stop() to the OscReceiver.stop() implementation, which wasn't there yet. --- src/networking/oscreceiver.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c945d1ea..9e4feac2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -25,12 +25,9 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po /** * Destructor - * Stops the lo::ServerThread, used for listening for OSC messages */ ssr::OscReceiver::~OscReceiver() -{ - _receiver.stop(); -} +{} /** * Starts the OscReceiver, by adding client|server callback functions and @@ -51,6 +48,15 @@ void ssr::OscReceiver::start() _receiver.start(); } +/** + * Stops the OscReceiver, by stopping the lo::ServerThread, used for listening + * for OSC messages + */ +void ssr::OscReceiver::stop() +{ + _receiver.stop(); +} + /** * Adds callback handlers for OSC messages received from clients. * This function uses C++11 lambda functions to define the behavior for every From ffc64daa69da5510eea5cbb6f0d4d2ee04c77a2c Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 12 May 2017 17:46:42 +0200 Subject: [PATCH 254/363] src/networking/oscsender.h: Removing redundant lo/lo.h include. --- src/networking/oscsender.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index bec1ea8e..6a64ce08 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -14,9 +14,7 @@ #include #include #include -#include #include - #include "ssr_global.h" #include "subscriber.h" #include "apf/parameter_map.h" From b6bfce8ec2f2429924c7585fb28a8ddc84cdbe92 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 12:48:57 +0200 Subject: [PATCH 255/363] src/networking/oschandler.cpp: Adding VERBOSE message to constructor. --- src/networking/oschandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 079a85d8..bb8f13f3 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -24,6 +24,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, , _osc_receiver(controller, *this, port_in) , _osc_sender(controller, *this, port_out) { + VERBOSE("Initialized OscHandler."); if (mode == "server") { for (const auto& hostname: clients) From 0ee234fc72ece1fedbceb96bf8c1e2e0fe29c7bb Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 12:49:31 +0200 Subject: [PATCH 256/363] src/networking/oscreceiver.cpp: Adding VERBOSE message to constructor and start(). --- src/networking/oscreceiver.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 9e4feac2..23886e2c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -21,7 +21,9 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po : _receiver(port_in) , _controller(controller) , _handler(handler) -{} +{ + VERBOSE("Initialized OscReceiver."); +} /** * Destructor @@ -38,14 +40,17 @@ void ssr::OscReceiver::start() // add method handlers for received messages if (_handler.mode() == "server") { + VERBOSE("Adding client-to-server callback methods."); add_client_to_server_methods(); } else if (_handler.mode() == "client") { + VERBOSE("Adding server-to-client callback methods."); add_server_to_client_methods(); } // start server thread _receiver.start(); + VERBOSE("Started ServerThread for receiving messages."); } /** From dcc794e4c6dabc8d4b7bbc006a40bed56b287f4a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 13 May 2017 13:00:30 +0200 Subject: [PATCH 257/363] src/networking/oscsender.cpp: Adding VERBOSE message to constructor. Fixing _server_address initialization by adding a port. --- src/networking/oscsender.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f34829f5..fe3b22cb 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -22,8 +22,10 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int : _controller(controller) , _handler(handler) , _send_from(port_out) - , _server_address("none") -{} + , _server_address("none", "50001") +{ + VERBOSE("Initialized OscSender."); +} /** * Destructor From ebcda0c763a66cffca92aad4832ec8ee0d740d80 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:23:03 +0200 Subject: [PATCH 258/363] src/networking/oschandler.cpp: Adding further VERBOSE messages to constructor and destructor, start() and stop(). Adding ssr::OscReceiver::send_to_server again, after accidentally deleting it. --- src/networking/oschandler.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bb8f13f3..bb355501 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -24,9 +24,10 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, , _osc_receiver(controller, *this, port_in) , _osc_sender(controller, *this, port_out) { - VERBOSE("Initialized OscHandler."); + VERBOSE("OscHandler: Initialized."); if (mode == "server") { + VERBOSE2("OscHandler: server mode."); for (const auto& hostname: clients) { _osc_sender.add_client(new lo::Address(hostname.first, @@ -39,13 +40,17 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, * Destructor */ ssr::OscHandler::~OscHandler() -{} +{ + stop(); + VERBOSE("OscHandler: Destructing."); +} /** * Stop this OscHandler by stopping its OscReceiver and OscSender */ void ssr::OscHandler::stop() { + VERBOSE("OscHandler: Stopping"); _osc_receiver.stop(); _osc_sender.stop(); } @@ -55,6 +60,7 @@ void ssr::OscHandler::stop() */ void ssr::OscHandler::start() { + VERBOSE("OscHandler: Starting"); _osc_receiver.start(); _osc_sender.start(); } @@ -129,6 +135,19 @@ void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) self._osc_sender.send_to_all_clients(bundle); } +/** + * OscHandler's friend function to send an OSC message to the server, using + * OscSender and a designated path. + * @param self reference to OscHandler holding OscSender + * @param path std::string defining the path to send on + * @param message lo::Bundle to be sent + */ +void ssr::OscReceiver::send_to_server(OscHandler& self, std::string path, + lo::Message message) +{ + self._osc_sender.send_to_server(path, message); +} + /** * OscHandler's friend function to send an OSC bundle to the server, using * OscSender. From bf979e833f86f40fd7b367e071b95771bd6164e6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:28:27 +0200 Subject: [PATCH 259/363] src/networking/oscreceiver.cpp: Adding VERBOSE message to constructur, destructor, start() and stop(). Adding VERBOSE message for each callback method. Adding leading / to all callback listeners (every high-level language, such as SuperCollider and Pd use it that way). --- src/networking/oscreceiver.cpp | 428 ++++++++++++++++++++------------- 1 file changed, 259 insertions(+), 169 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 23886e2c..e3954eec 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -22,14 +22,16 @@ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int po , _controller(controller) , _handler(handler) { - VERBOSE("Initialized OscReceiver."); + VERBOSE("OscReceiver: Initialized."); } /** * Destructor */ ssr::OscReceiver::~OscReceiver() -{} +{ + VERBOSE("OscReceiver: Destructing."); +} /** * Starts the OscReceiver, by adding client|server callback functions and @@ -37,20 +39,33 @@ ssr::OscReceiver::~OscReceiver() */ void ssr::OscReceiver::start() { + VERBOSE("OscReceiver: Starting."); // add method handlers for received messages if (_handler.mode() == "server") { - VERBOSE("Adding client-to-server callback methods."); add_client_to_server_methods(); + VERBOSE("OscReceiver: Added client-to-server callbacks."); } else if (_handler.mode() == "client") { - VERBOSE("Adding server-to-client callback methods."); add_server_to_client_methods(); + VERBOSE("OscReceiver: Added server-to-client callbacks."); } - // start server thread + // check if lo::ServerThread is valid + if (!_receiver.is_valid()) { + ERROR("OscReceiver: ServerThread could not be started!"); + } + _receiver.set_callbacks([this]() + { + VERBOSE("OscReceiver: Started ServerThread for receiving messages."); + }, + []() + { + VERBOSE2("OscReceiver: ServerThread cleanup."); + } + ); + VERBOSE("OscReceiver: url = " << _receiver.url() << "."); _receiver.start(); - VERBOSE("Started ServerThread for receiving messages."); } /** @@ -59,6 +74,7 @@ void ssr::OscReceiver::start() */ void ssr::OscReceiver::stop() { + VERBOSE("OscReceiver: Stopping."); _receiver.stop(); } @@ -69,47 +85,51 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { - // update on new source: "update/source/new, i, id" - _receiver.add_method("update/source/new", "i", [](lo_arg **argv, int, + // update on new source: "/update/source/new, i, id" + _receiver.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << " created."); } ); + VERBOSE("OscReceiver: Added method for /update/source/new."); - // update on deleted source: "update/source/delete, i, id" - _receiver.add_method("update/source/delete", "i", [](lo_arg **argv, int, + // update on deleted source: "/update/source/delete, i, id" + _receiver.add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); if(argv[0]->i == 0) { - VERBOSE("Update: Client '" << client.hostname() << "', all sources \ - deleted."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', all sources deleted."); + } else { - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << " deleted."); + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " + << argv[0]->i << " deleted."); } } ); + VERBOSE("OscReceiver: Added method for /update/source/delete."); - // update on source position: "update/source/position, iff, id, x, y" - _receiver.add_method("update/source/position", "iff", [](lo_arg **argv, int, + // update on source position: "/update/source/position, iff, id, x, y" + _receiver.add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/position."); - // update on source position fixation: "update/source/position_fixed, i{T,F}, + // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _receiver.add_method("update/source/position_fixed", NULL, [](lo_arg **argv, + _receiver.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -122,34 +142,37 @@ void ssr::OscReceiver::add_client_to_server_methods() { position_fixed = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", position_fixed: "<< position_fixed << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); - // update on source orientation: "update/source/orientation, if, id, azimuth" - _receiver.add_method("update/source/orientation", "if", [](lo_arg **argv, int, + // update on source orientation: "/update/source/orientation, if, id, azimuth" + _receiver.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", orientation: "<< argv[1]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/orientation."); - // update on source volume: "update/source/volume, if, id, volume" - _receiver.add_method("update/source/volume", "if", [](lo_arg **argv, int, + // update on source volume: "/update/source/volume, if, id, volume" + _receiver.add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", volume: "<< argv[1]->f << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/volume."); - // update on source position mute: "update/source/mute, i{T,F}, + // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _receiver.add_method("update/source/mute", NULL, [](lo_arg **argv, int, + _receiver.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -162,160 +185,181 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << - apf::str::A2S(argv[0]->i) << ", mute: "<< state << - "."); + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << + apf::str::A2S(argv[0]->i) << ", mute: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/mute."); - // update on source name: "update/source/name, is, id, name" - _receiver.add_method("update/source/name", "is", [](lo_arg **argv, int, + // update on source name: "/update/source/name, is, id, name" + _receiver.add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", name: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/name."); - // update on source properties_file: "update/source/properties_file, is, id, + // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _receiver.add_method("update/source/properties_file", "is", [](lo_arg **argv, + _receiver.add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", properties_file: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/properties_file."); - // update on scene decay exponent: "update/scene/decay_exponent, f, + // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _receiver.add_method("update/scene/decay_exponent", "f", [](lo_arg **argv, + _receiver.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', decay_exponent: \ - "<< argv[0]->f << "."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', decay_exponent: "<< argv[0]->f << "."); + } ); + VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _receiver.add_method("update/scene/amplitude_reference_distance", "f", + _receiver.add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', \ - amplitude_reference_distance: "<< argv[0]->f << "."); } + VERBOSE3("Update: Client '" << client.hostname() << + "', amplitude_reference_distance: "<< argv[0]->f << "."); + } ); + VERBOSE("OscReceiver: Added method for \ +/update/scene/amplitude_reference_distance."); - // update on source model: "update/source/model, is, id, model" - _receiver.add_method("update/source/model", "is", [](lo_arg **argv, int, + // update on source model: "/update/source/model, is, id, model" + _receiver.add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", model: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/model."); - // update on source port_name: "update/source/port_name, is, id, port_name" - _receiver.add_method("update/source/port_name", "is", [](lo_arg **argv, int, + // update on source port_name: "/update/source/port_name, is, id, port_name" + _receiver.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", port_name: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/port_name."); // update on source file_name_or_port_number: - // "update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _receiver.add_method("update/source/file_name_or_port_number", "is", + // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" + _receiver.add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); } ); + VERBOSE("OscReceiver: Added method for \ +/update/source/file_name_or_port_number."); - // update on source channel: "update/source/channel, ii, id, channel" - _receiver.add_method("update/source/channel", "ii", [](lo_arg **argv, int, + // update on source channel: "/update/source/channel, ii, id, channel" + _receiver.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", channel: "<< argv[1]->i << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/channel."); - // update on source file length: "update/source/length, ii, id, length" - _receiver.add_method("update/source/length", "ii", [](lo_arg **argv, int, + // update on source file length: "/update/source/length, ii, id, length" + _receiver.add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", length: "<< argv[1]->i << "."); } ); + VERBOSE("OscReceiver: Added method for /update/source/length."); - // update on reference position: "update/reference/position, ff, x, y" - _receiver.add_method("update/reference/position", "ff", [](lo_arg **argv, + // update on reference position: "/update/reference/position, ff, x, y" + _receiver.add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference \ - position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference position: "<< argv[0]->f << "/" << argv[1]->f << + " (x/y)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference/position."); - // update on reference orientation: "update/reference/orientation, f, + // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _receiver.add_method("update/reference/orientation", "f", [](lo_arg **argv, + _receiver.add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference \ - orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference orientation: "<< argv[0]->f << " (azimuth)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference/orientation."); - // update on reference offset position: "update/reference_offset/position, + // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _receiver.add_method("update/reference_offset/position", "ff", [](lo_arg + _receiver.add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ - position: "<< argv[0]->f << "/" << argv[1]->f << " (x/y)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference offset position: "<< argv[0]->f << "/" << argv[1]->f + << " (x/y)."); } ); + VERBOSE("OscReceiver: Added method for /update/reference_offset/position."); // update on reference offset orientation: - // "update/reference_offset/orientation, f, azimuth" - _receiver.add_method("update/reference_offset/orientation", "f", [](lo_arg + // "/update/reference_offset/orientation, f, azimuth" + _receiver.add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', reference offset \ - orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("Update: Client '" << client.hostname() << + "', reference offset orientation: "<< argv[0]->f << " (azimuth)."); } ); + VERBOSE("OscReceiver: Added method for \ +/update/reference_offset/orientation."); - // update on scene volume: "update/scene/volume, f, volume" - _receiver.add_method("update/scene/volume", "f", [](lo_arg **argv, int, + // update on scene volume: "/update/scene/volume, f, volume" + _receiver.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene volume: "<< + VERBOSE3("Update: Client '" << client.hostname() << "', scene volume: "<< argv[0]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/volume."); - // update on state processing: "update/processing/state, {T,F}, {true,false}" - _receiver.add_method("update/processing/state", NULL, [](lo_arg **argv, int, + // update on state processing: "/update/processing/state, {T,F}, {true,false}" + _receiver.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -329,13 +373,14 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', state processing: \ - " << state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', state processing: " << state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/processing/state."); - // update on transport state: "update/transport/state, {T,F}, {true,false}" - _receiver.add_method("update/transport/state", NULL, [](lo_arg **argv, int, + // update on transport state: "/update/transport/state, {T,F}, {true,false}" + _receiver.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -349,24 +394,26 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', transport state: \ - "<< state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', transport state: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/transport/state."); - // update on transport seek: "update/transport/seek, s, time" - _receiver.add_method("update/transport/seek", "s", [](lo_arg **argv, int, + // update on transport seek: "/update/transport/seek, s, time" + _receiver.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', transport seek: \ - "<< argv[0]->s << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', transport seek: "<< argv[0]->s << "."); } ); + VERBOSE("OscReceiver: Added method for /update/transport/seek."); - // update on scene source auto rotation: "update/scene/auto_rotate_sources, + // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _receiver.add_method("update/scene/auto_rotate_sources", NULL, [](lo_arg + _receiver.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -381,51 +428,56 @@ void ssr::OscReceiver::add_client_to_server_methods() { state = "false"; } - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - auto_rotate_sources: "<< state << "."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene auto_rotate_sources: "<< state << "."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); - // update on cpu_load: "update/cpu_load, f, load" - _receiver.add_method("update/cpu_load", "f", [](lo_arg **argv, int, + // update on cpu_load: "/update/cpu_load, f, load" + _receiver.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE2("Update: Client '" << client.hostname() << "', cpu_load: "<< + VERBOSE3("Update: Client '" << client.hostname() << "', cpu_load: "<< argv[0]->f << "%."); } ); + VERBOSE("OscReceiver: Added method for /update/cpu_load."); - // update on scene sample rate: "update/scene/sample_rate, i, sample_rate" - _receiver.add_method("update/scene/sample_rate", "i", [](lo_arg **argv, int, + // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" + _receiver.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - sample_rate: "<< argv[0]->i << "Hz."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene sample_rate: "<< argv[0]->i << "Hz."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/sample_rate."); - // update on scene master signal level: "update/scene/master_signal_level, f, + // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _receiver.add_method("update/scene/master_signal_level", "f", [](lo_arg + _receiver.add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE("Update: Client '" << client.hostname() << "', scene \ - master_signal_level: "<< argv[0]->f << "dB."); + VERBOSE3("Update: Client '" << client.hostname() << + "', scene master_signal_level: "<< argv[0]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); - // update on source signal level: "update/source/level, if, id, level" - _receiver.add_method("update/source/level", "if", [](lo_arg **argv, int, + // update on source signal level: "/update/source/level, if, id, level" + _receiver.add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - VERBOSE2("Update: Client '" << client.hostname() << "', source id = " << + VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << argv[0]->i << ", level: "<< argv[1]->f << "dB."); } ); + VERBOSE("OscReceiver: Added method for /update/source/level."); } @@ -438,22 +490,31 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _receiver.add_method("poll", NULL, [this](lo_arg **argv, int, lo::Message + this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server = server_address(_handler); lo::Address from(message.source()); (void) argv; - if(server.hostname() != from.hostname() && server.port() != from.port()) + VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << + from.port() << "."); + if((server.hostname() != from.hostname()) && + (server.port() != from.port()) && + (from.port() != "50001") && + (from.hostname() != "none") + ) { set_server_for_client(_handler, from); - // TODO: send reply to subscribed server + lo::Message reply; + reply.add_true(); + this->send_to_server(_handler, "/update/subscribe", reply); } } ); + VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("source/position", "iff", [this](lo_arg **argv, int) + _receiver.add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -461,36 +522,41 @@ void ssr::OscReceiver::add_server_to_client_methods() Position(argv[1]->f, argv[2]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("source/position_fixed", "iT", [this](lo_arg **argv, int) + _receiver.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + int) { _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ - true"); + VERBOSE2("set source position fixed: id = " << argv[0]->i << + ", fixed = true"); } ); + VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("source/position_fixed", "iF", [this](lo_arg **argv, int) + _receiver.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << ", fixed = \ - false"); + VERBOSE2("set source position fixed: id = " << argv[0]->i << + ", fixed = false"); } ); + VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("source/orientation", "if", [this](lo_arg **argv, int) + _receiver.add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - VERBOSE2("set source orientation: id = " << argv[0]->i << ", " - << Orientation(argv[1]->f)); + VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << + Orientation(argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("source/volume", "if", [this](lo_arg **argv, int) + _receiver.add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -498,45 +564,50 @@ void ssr::OscReceiver::add_server_to_client_methods() apf::math::dB2linear(argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("source/mute", "iT", [this](lo_arg **argv, int) + _receiver.add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); } ); + VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("source/mute", "iF", [this](lo_arg **argv, int) + _receiver.add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); } ); + VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _receiver.add_method("source/name", "is", [this](lo_arg **argv, int) + _receiver.add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/name."); - // set source file: "source/properties_file, is, id, properties_file" - _receiver.add_method("source/properties_file", "is", [this](lo_arg **argv, + // set source file: "/source/properties_file, is, id, properties_file" + _receiver.add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source properties file name: id = " << argv[0]->i << ", \ - file = " << apf::str::A2S(argv[1]->s)); + VERBOSE2("set source properties file name: id = " << argv[0]->i << + ", file = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/properties_file."); - // set source model: "source/model, is, id, model" - _receiver.add_method("source/model", "is", [this](lo_arg **argv, int) + // set source model: "/source/model, is, id, model" + _receiver.add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -548,23 +619,25 @@ void ssr::OscReceiver::add_server_to_client_methods() apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/model."); - // set source port name: "source/port_name, is, id, port_name" - _receiver.add_method("source/port_name", "is", [this](lo_arg **argv, int) + // set source port name: "/source/port_name, is, id, port_name" + _receiver.add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << apf::str::A2S(argv[1]->s)); } ); + VERBOSE("OscReceiver: Added method for /source/port_name."); - // create new source: "source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, position_fixed, // orientation_fixed, muted" - // create new source: "source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("source/new", NULL, [this](lo_arg **argv, int, + _receiver.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -735,10 +808,11 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /source/new."); - // delete source: "source/delete, i, id" + // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("source/delete", "i", [this](lo_arg **argv, int) + _receiver.add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -752,25 +826,28 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /source/delete."); - // set reference position: "reference/position, ff, x, y" - _receiver.add_method("reference/position", "ff", [this](lo_arg **argv, int) + // set reference position: "/reference/position, ff, x, y" + _receiver.add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /source/position."); - // set reference orientation: "reference/orientation, f, azimuth" - _receiver.add_method("reference/orientation", "f", [this](lo_arg **argv, int) + // set reference orientation: "/reference/orientation, f, azimuth" + _receiver.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference/orientation."); - // set reference offset position: "reference_offset/position, ff, x, y" - _receiver.add_method("reference_offset/position", "ff" , [this](lo_arg + // set reference offset position: "/reference_offset/position, ff, x, y" + _receiver.add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -779,69 +856,77 @@ void ssr::OscReceiver::add_server_to_client_methods() argv[1]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference_offset/position."); - // set reference offset orientation: "reference_offset/orientation, f, + // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _receiver.add_method("reference_offset/orientation", "f" , [this](lo_arg **argv, - int) + _receiver.add_method("/reference_offset/orientation", "f" , [this](lo_arg + **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference offset orientation: " << Orientation(argv[0]->f)); } ); + VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); - // save scene to file: "scene/save, s, file" - _receiver.add_method("scene/save", "s" , [this](lo_arg **argv, int) + // save scene to file: "/scene/save, s, file" + _receiver.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); } ); + VERBOSE("OscReceiver: Added method for /scene/save."); - // load scene from file: "scene/load, s, file" - _receiver.add_method("scene/load", "s" , [this](lo_arg **argv, int) + // load scene from file: "/scene/load, s, file" + _receiver.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); } ); + VERBOSE("OscReceiver: Added method for /scene/load."); - // set master volume: "scene/volume, f, volume" - _receiver.add_method("scene/volume", "f" , [this](lo_arg **argv, int) + // set master volume: "/scene/volume, f, volume" + _receiver.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << " \ - dB"); + VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << + " dB"); } ); + VERBOSE("OscReceiver: Added method for /scene/volume."); - // clear scene: "scene/clear" - _receiver.add_method("scene/clear", NULL , [this](lo_arg **argv, int) + // clear scene: "/scene/clear" + _receiver.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); VERBOSE2("clearing scene."); } ); + VERBOSE("OscReceiver: Added method for /scene/clear."); - // set processing state: "state/processing, T, true" - _receiver.add_method("processing/state", "T" , [this](lo_arg **argv, int) + // set processing state: "/processing/state, T, true" + _receiver.add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); VERBOSE2("start processing."); } ); + VERBOSE("OscReceiver: Added method for /processing/state true."); - // set processing state: "state/processing, F, false" - _receiver.add_method("processing/state", "F" , [this](lo_arg **argv, int) + // set processing state: "/processing/state, F, false" + _receiver.add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); VERBOSE2("stop processing."); } ); + VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) @@ -851,26 +936,29 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE2("start transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/state true."); - // set transport state: "transport/state, F, false" - _receiver.add_method("transport/state", "F" , [this](lo_arg **argv, int) + // set transport state: "/transport/state, F, false" + _receiver.add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); VERBOSE2("stop transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/state false."); - // rewind transport state: "state/transport/rewind" - _receiver.add_method("transport/rewind", NULL , [this](lo_arg **argv, int) + // rewind transport state: "/transport/rewind" + _receiver.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); VERBOSE2("rewind transport."); } ); + VERBOSE("OscReceiver: Added method for /transport/rewind."); - // seek transport state: "state/transport/seek, s, time" + // seek transport state: "/transport/seek, s, time" _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; @@ -886,14 +974,16 @@ void ssr::OscReceiver::add_server_to_client_methods() } } ); + VERBOSE("OscReceiver: Added method for /transport/seek."); - // reset tracker: "tracker/reset" - _receiver.add_method("tracker/reset", NULL , [this](lo_arg **argv, int) + // reset tracker: "/tracker/reset" + _receiver.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); VERBOSE2("calibrate tracker."); } ); + VERBOSE("OscReceiver: Added method for /tracker/reset."); } From c98b403a68c462cd82d9cf98e74eee9552a27960 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 00:39:40 +0200 Subject: [PATCH 260/363] src/networking/oscsender.cpp: Clarifying VERBOSE messages. Adding leading / to the path of every send_to_all_clients and send_to_server function call. Making all lo::Message.add() calls type explicit to circumvent ambiguity. --- src/networking/oscsender.cpp | 369 +++++++++++++++++++---------------- 1 file changed, 203 insertions(+), 166 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index fe3b22cb..45628bb4 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -22,9 +22,9 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int : _controller(controller) , _handler(handler) , _send_from(port_out) - , _server_address("none", "50001") + , _server_address("none", "50002") { - VERBOSE("Initialized OscSender."); + VERBOSE("OscSender: Initialized."); } /** @@ -43,18 +43,18 @@ void ssr::OscSender::start() _is_subscribed = true; // check if lo::ServerThread is valid if (!_send_from.is_valid()) { - ERROR("OSC ServerThread to send from could not be started!"); + ERROR("OscSender: ServerThread could not be started!"); } _send_from.set_callbacks([this]() { - VERBOSE2("OSC ServerThread init: "<<&this->_send_from <<"."); + VERBOSE("OscSender: Started ServerThread for sending messages."); }, []() { - VERBOSE2("OSC ServerThread cleanup."); + VERBOSE2("OscSender: ServerThread cleanup."); } ); - VERBOSE("OSC URL: " << _send_from.url()<<"."); + VERBOSE("OscSender: url = " << _send_from.url() << "."); _send_from.start(); if (is_server()) { @@ -114,18 +114,18 @@ bool ssr::OscSender::is_server() /** * Sends a '/poll' message to all client instances listed in _client_addresses, - * then makes the thread calling this function sleep for 1000 milliseconds + * then makes the thread calling this function sleep for 100 milliseconds */ void ssr::OscSender::poll_all_clients() { - VERBOSE("Polling all clients."); + VERBOSE2("OscSender: Polling all clients."); while(_poll_all_clients) { - send_to_all_clients("poll", lo::Message()); + send_to_all_clients("/poll", lo::Message()); //TODO find better solution to compensate for execution time std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - VERBOSE("Stopped polling all clients."); + VERBOSE2("OscSender: Stopped polling all clients."); } /** @@ -143,7 +143,9 @@ lo::Address ssr::OscSender::server_address() */ void ssr::OscSender::set_server_address(lo::Address server_address) { - this->_server_address = server_address; + this->_server_address = new lo::Address(server_address); + VERBOSE2("OscSender: Setting up new server_address: "<< + server_address.hostname() << ":" << server_address.port() << "."); } /** @@ -154,7 +156,14 @@ void ssr::OscSender::set_server_address(lo::Address server_address) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - _server_address.send_from(_send_from, path, message); + if((_server_address.hostname() != "none") && (_server_address.port() != + "50002")) + { + _server_address.send_from(_send_from, path, message.types(), message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } /** @@ -164,6 +173,9 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) void ssr::OscSender::send_to_server(lo::Bundle bundle) { _server_address.send_from(_send_from, bundle); + VERBOSE3("OscSender: Sending bundle (" << bundle.length() << + " messages) to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } /** @@ -181,7 +193,10 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, if(client.hostname() == address.hostname() && client.port() == address.port()) { - client.send_from(_send_from, path, message); + client.send_from(_send_from, path, message.types(), message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to client " << address.hostname() << ":" << address.port() << + "."); } } } @@ -200,7 +215,8 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) address.port()) { client.send_from(_send_from, bundle); - } + VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << + ":" << address.port() << "."); } } } @@ -215,6 +231,9 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) for (const auto& client_address: _client_addresses) { client_address.send_from(_send_from, path, message); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to client " << client_address.hostname() << ":" << + client_address.port() << "."); } } @@ -227,6 +246,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) for (const auto& client_address: _client_addresses) { client_address.send_from(_send_from, bundle); + VERBOSE3("OscSender: Sending bundle to all clients."); } } @@ -308,19 +328,23 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("muted") && _new_sources.at(id).size() == 12 ) { - message.add(_new_sources.at(id).get("name", "")); - message.add(_new_sources.at(id).get("model", "")); - message.add(_new_sources.at(id).get("file_name_or_port_number", "")); - message.add(_new_sources.at(id).get("x", 0.0)); - message.add(_new_sources.at(id).get("y", 0.0)); - message.add(_new_sources.at(id).get("orientation", 0.0)); - message.add(_new_sources.at(id).get("volume", 0.0)); - message.add(_new_sources.at(id).get("channel", 1)); - message.add(_new_sources.at(id).get("properties_file", "")); - message.add(_new_sources.at(id).get("position_fixed", false)); - message.add(_new_sources.at(id).get("orientation_fixed", false)); - message.add(_new_sources.at(id).get("muted", false)); - this->send_to_all_clients("source/new", message); + message.add_string(_new_sources.at(id).get("name", "")); + message.add_string(_new_sources.at(id).get("model", "")); + message.add_string(_new_sources.at(id).get("file_name_or_port_number", + "")); + message.add_float(_new_sources.at(id).get("x", 0.0)); + message.add_float(_new_sources.at(id).get("y", 0.0)); + message.add_float(_new_sources.at(id).get("orientation", 0.0)); + message.add_float(_new_sources.at(id).get("volume", 0.0)); + message.add_int32(_new_sources.at(id).get("channel", 1)); + message.add_string(_new_sources.at(id).get("properties_file", "")); + (_new_sources.at(id).get("position_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("orientation_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("muted", false)? + message.add_true(): message.add_false()); + this->send_to_all_clients("/source/new", message); } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -334,17 +358,21 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("muted") && _new_sources.at(id).size() == 10 ) { - message.add(_new_sources.at(id).get("name", "")); - message.add(_new_sources.at(id).get("model", "")); - message.add(_new_sources.at(id).get("file_name_or_port_number", "")); - message.add(_new_sources.at(id).get("x", 0.0)); - message.add(_new_sources.at(id).get("y", 0.0)); - message.add(_new_sources.at(id).get("orientation", 0.0)); - message.add(_new_sources.at(id).get("volume", 0.0)); - message.add(_new_sources.at(id).get("position_fixed", false)); - message.add(_new_sources.at(id).get("orientation_fixed", false)); - message.add(_new_sources.at(id).get("muted", false)); - this->send_to_all_clients("source/new", message); + message.add_string(_new_sources.at(id).get("name", "")); + message.add_string(_new_sources.at(id).get("model", "")); + message.add_string(_new_sources.at(id).get("file_name_or_port_number", + "")); + message.add_float(_new_sources.at(id).get("x", 0.0)); + message.add_float(_new_sources.at(id).get("y", 0.0)); + message.add_float(_new_sources.at(id).get("orientation", 0.0)); + message.add_float(_new_sources.at(id).get("volume", 0.0)); + (_new_sources.at(id).get("position_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("orientation_fixed", false)? + message.add_true(): message.add_false()); + (_new_sources.at(id).get("muted", false)? + message.add_true(): message.add_false()); + this->send_to_all_clients("/source/new", message); } } @@ -355,6 +383,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) void ssr::OscSender::add_client(lo::Address client) { _client_addresses.push_back(client); + VERBOSE2("OscSender: Added client " << client.hostname() << " to list."); } // Subscriber interface (differentiating between client and server) @@ -370,6 +399,7 @@ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& loudspeakers) { (void) loudspeakers; + VERBOSE3("OscSender: set_loudspeakers"); } /** @@ -391,8 +421,8 @@ void ssr::OscSender::new_source(id_t id) { lo::Message message; int32_t message_id = id; - message.add(message_id); - this->send_to_server("update/source/new", message); + message.add_int32(message_id); + this->send_to_server("/update/source/new", message); } } @@ -407,14 +437,14 @@ void ssr::OscSender::delete_source(id_t id) { lo::Message message; int32_t message_id = id; - message.add(message_id); + message.add_int32(message_id); if(is_server()) { - this->send_to_all_clients("source/delete", message); + this->send_to_all_clients("/source/delete", message); } else if (is_client()) { - this->send_to_server("update/source/delete", message); + this->send_to_server("/update/source/delete", message); _source_levels.erase(id); } } @@ -428,11 +458,11 @@ void ssr::OscSender::delete_source(id_t id) void ssr::OscSender::delete_all_sources() { lo::Message message; - message.add(0); + message.add_int32(0); if(is_server()) - this->send_to_all_clients("source/delete", message); + this->send_to_all_clients("/source/delete", message); else if(is_client()) - this->send_to_server("update/source/delete", message); + this->send_to_server("/update/source/delete", message); _source_levels.clear(); } @@ -464,18 +494,18 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add(message_id); - message.add(position.x); - message.add(position.y); - this->send_to_all_clients("source/position", message); + message.add_int32(message_id); + message.add_float(position.x); + message.add_float(position.y); + this->send_to_all_clients("/source/position", message); } } else if (is_client()) { - message.add(message_id); - message.add(position.x); - message.add(position.y); - this->send_to_server("update/source/position", message); + message.add_int32(message_id); + message.add_float(position.x); + message.add_float(position.y); + this->send_to_server("/update/source/position", message); } return true; } @@ -507,16 +537,16 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add(message_id); - message.add(fixed); - this->send_to_all_clients("source/position_fixed", message); + message.add_int32(message_id); + message.add_bool(fixed); + this->send_to_all_clients("/source/position_fixed", message); } } else if(is_client()) { - message.add(message_id); - message.add(fixed); - this->send_to_server("update/source/position_fixed", message); + message.add_int32(message_id); + message.add_bool(fixed); + this->send_to_server("/update/source/position_fixed", message); } return true; } @@ -547,16 +577,16 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add(message_id); - message.add(orientation.azimuth); - this->send_to_all_clients("source/orientation", message); + message.add_int32(message_id); + message.add_float(orientation.azimuth); + this->send_to_all_clients("/source/orientation", message); } } else if(is_client()) { - message.add(message_id); - message.add(orientation.azimuth); - this->send_to_server("update/source/orientation", message); + message.add_int32(message_id); + message.add_float(orientation.azimuth); + this->send_to_server("/update/source/orientation", message); } return true; } @@ -587,16 +617,16 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add(message_id); - message.add(gain); - this->send_to_all_clients("source/volume", message); + message.add_int32(message_id); + message.add_float(gain); + this->send_to_all_clients("/source/volume", message); } } else if(is_client()) { - message.add(message_id); - message.add(gain); - this->send_to_server("update/source/volume", message); + message.add_int32(message_id); + message.add_float(gain); + this->send_to_server("/update/source/volume", message); } return true; } @@ -627,16 +657,16 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add(message_id); - message.add(mute); - this->send_to_all_clients("source/mute", message); + message.add_int32(message_id); + message.add_bool(mute); + this->send_to_all_clients("/source/mute", message); } } else if(is_client()) { - message.add(message_id); - message.add(mute); - this->send_to_server("update/source/mute", message); + message.add_int32(message_id); + message.add_bool(mute); + this->send_to_server("/update/source/mute", message); } return true; } @@ -667,16 +697,16 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - message.add(message_id); - message.add(name); - this->send_to_all_clients("source/name", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_all_clients("/source/name", message); } } else if(is_client()) { - message.add(message_id); - message.add(name); - this->send_to_server("update/source/name", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_server("/update/source/name", message); } return true; } @@ -708,16 +738,16 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add(message_id); - message.add(name); - this->send_to_all_clients("source/properties_file", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_all_clients("/source/properties_file", message); } } else if(is_client()) { - message.add(message_id); - message.add(name); - this->send_to_server("update/source/properties_file", message); + message.add_int32(message_id); + message.add_string(name); + this->send_to_server("/update/source/properties_file", message); } return true; } @@ -733,14 +763,14 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& void ssr::OscSender::set_decay_exponent(float exponent) { lo::Message message; - message.add(exponent); + message.add_float(exponent); if(is_server()) { - this->send_to_all_clients("scene/decay_exponent", message); + this->send_to_all_clients("/scene/decay_exponent", message); } else if(is_client()) { - this->send_to_server("update/scene/decay_exponent", message); + this->send_to_server("/update/scene/decay_exponent", message); } } @@ -757,15 +787,15 @@ void ssr::OscSender::set_decay_exponent(float exponent) void ssr::OscSender::set_amplitude_reference_distance(float distance) { lo::Message message; - message.add(distance); + message.add_float(distance); if(is_server()) { - this->send_to_all_clients("scene/amplitude_reference_distance", + this->send_to_all_clients("/scene/amplitude_reference_distance", message); } else if(is_client()) { - this->send_to_server("update/scene/amplitude_reference_distance", + this->send_to_server("/update/scene/amplitude_reference_distance", message); } } @@ -799,16 +829,16 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - message.add(message_id); - message.add(tmp_model); - this->send_to_all_clients("source/model", message); + message.add_int32(message_id); + message.add_string(tmp_model); + this->send_to_all_clients("/source/model", message); } } else if(is_client()) { - message.add(message_id); - message.add(tmp_model); - this->send_to_server("update/source/model", message); + message.add_int32(message_id); + message.add_string(tmp_model); + this->send_to_server("/update/source/model", message); } return true; } @@ -842,16 +872,16 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add(message_id); - message.add(port_name); - this->send_to_all_clients("source/port_name", message); + message.add_int32(message_id); + message.add_string(port_name); + this->send_to_all_clients("/source/port_name", message); } } else if(is_client()) { - message.add(message_id); - message.add(port_name); - this->send_to_server("update/source/port_name", message); + message.add_int32(message_id); + message.add_string(port_name); + this->send_to_server("/update/source/port_name", message); } return true; } @@ -888,16 +918,16 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add(message_id); - message.add(file_name); - this->send_to_all_clients("source/file_name_or_port_number", message); + message.add_int32(message_id); + message.add_string(file_name); + this->send_to_all_clients("/source/file_name_or_port_number", message); } } else if(is_client()) { - message.add(message_id); - message.add(file_name); - this->send_to_server("update/source/file_name_or_port_number", message); + message.add_int32(message_id); + message.add_string(file_name); + this->send_to_server("/update/source/file_name_or_port_number", message); } return true; } @@ -920,6 +950,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { lo::Message message; int32_t message_id = id; + int32_t message_file_channel = file_channel; if(is_server()) { if(is_new_source(id)) @@ -930,16 +961,16 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add(message_id); - message.add(file_channel); - this->send_to_all_clients("source/channel", message); + message.add_int32(message_id); + message.add_int32(message_file_channel); + this->send_to_all_clients("/source/channel", message); } } else if(is_client()) { - message.add(message_id); - message.add(file_channel); - this->send_to_server("update/source/channel", message); + message.add_int32(message_id); + message.add_int32(message_file_channel); + this->send_to_server("/update/source/channel", message); } return true; } @@ -960,11 +991,12 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { lo::Message message; int32_t message_id = id; + int32_t message_length = length; if(is_client()) { - message.add(message_id); - message.add(length); - this->send_to_server("update/source/length", message); + message.add_int32(message_id); + message.add_int32(message_length); + this->send_to_server("/update/source/length", message); } return true; } @@ -982,15 +1014,15 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) void ssr::OscSender::set_reference_position(const Position& position) { lo::Message message; - message.add(position.x); - message.add(position.y); + message.add_float(position.x); + message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("reference/position", message); + this->send_to_all_clients("/reference/position", message); } else if(is_client()) { - this->send_to_server("update/reference/position", message); + this->send_to_server("/update/reference/position", message); } } @@ -1007,14 +1039,14 @@ void ssr::OscSender::set_reference_position(const Position& position) void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { lo::Message message; - message.add(orientation.azimuth); + message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("reference/orientation", message); + this->send_to_all_clients("/reference/orientation", message); } else if(is_client()) { - this->send_to_server("update/reference/orientation", message); + this->send_to_server("/update/reference/orientation", message); } } @@ -1032,15 +1064,15 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) void ssr::OscSender::set_reference_offset_position(const Position& position) { lo::Message message; - message.add(position.x); - message.add(position.y); + message.add_float(position.x); + message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("reference_offset/position", message); + this->send_to_all_clients("/reference_offset/position", message); } else if(is_client()) { - this->send_to_server("update/reference_offset/position", message); + this->send_to_server("/update/reference_offset/position", message); } } @@ -1060,14 +1092,14 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { lo::Message message; - message.add(orientation.azimuth); + message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("reference_offset/orientation", message); + this->send_to_all_clients("/reference_offset/orientation", message); } else if(is_client()) { - this->send_to_server("update/reference_offset/orientation", message); + this->send_to_server("/update/reference_offset/orientation", message); } } @@ -1084,14 +1116,14 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& void ssr::OscSender::set_master_volume(float volume) { lo::Message message; - message.add(apf::math::linear2dB(volume)); + message.add_float(apf::math::linear2dB(volume)); if(is_server()) { - this->send_to_all_clients("scene/volume", message); + this->send_to_all_clients("/scene/volume", message); } else if(is_client()) { - this->send_to_server("update/scene/volume", message); + this->send_to_server("/update/scene/volume", message); } } @@ -1125,14 +1157,14 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* void ssr::OscSender::set_processing_state(bool state) { lo::Message message; - message.add(state); + message.add_bool(state); if(is_server()) { - this->send_to_all_clients("processing/state", message); + this->send_to_all_clients("/processing/state", message); } else if(is_client()) { - this->send_to_server("update/processing/state", message); + this->send_to_server("/update/processing/state", message); } } @@ -1152,23 +1184,26 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients(bundle); + +// TODO: debug this! +// this->send_to_all_clients(bundle); } else if(is_client()) { lo::Bundle bundle({ - {"update/transport/state", message_state}, - {"update/transport/seek", message_time} + {"/update/transport/state", message_state}, + {"/update/transport/seek", message_time} }); - this->send_to_server(bundle); +// TODO: debug this! +// this->send_to_server(bundle); } } @@ -1187,14 +1222,14 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients("scene/auto_rotate_sources", message); + this->send_to_all_clients("/scene/auto_rotate_sources", message); } else if(is_client()) { - this->send_to_server("update/scene/auto_rotate_sources", message); + this->send_to_server("/update/scene/auto_rotate_sources", message); } } @@ -1209,10 +1244,10 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) void ssr::OscSender::set_cpu_load(float load) { lo::Message message; - message.add(load); + message.add_float(load); if(is_client()) { - this->send_to_server("update/cpu_load", message); + this->send_to_server("/update/cpu_load", message); } } @@ -1229,14 +1264,15 @@ void ssr::OscSender::set_cpu_load(float load) void ssr::OscSender::set_sample_rate(int sr) { lo::Message message; - message.add(sr); + int32_t message_sr = sr; + message.add_int32(message_sr); if(is_server()) { - this->send_to_all_clients("scene/sample_rate", message); + this->send_to_all_clients("/scene/sample_rate", message); } else if(is_client()) { - this->send_to_server("update/scene/sample_rate", message); + this->send_to_server("/update/scene/sample_rate", message); } } @@ -1253,14 +1289,15 @@ void ssr::OscSender::set_sample_rate(int sr) void ssr::OscSender::set_master_signal_level(float level) { lo::Message message; - message.add(apf::math::linear2dB(level)); + float message_level(apf::math::linear2dB(level)); + message.add_float(message_level); if(is_server()) { - this->send_to_all_clients("scene/master_signal_level", message); + this->send_to_all_clients("/scene/master_signal_level", message); } else if(is_client()) { - this->send_to_server("update/scene/master_signal_level", message); + this->send_to_server("/update/scene/master_signal_level", message); } } @@ -1280,15 +1317,15 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { lo::Message message; int32_t message_id = id; - message.add(message_id); - message.add(apf::math::linear2dB(level)); + message.add_int32(message_id); + message.add_float(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("source/volume", message); + this->send_to_all_clients("/source/volume", message); } else if(is_client()) { - this->send_to_server("update/source/level", message); + this->send_to_server("/update/source/level", message); } return true; } From 2bb729e48d21f3576f55fc1ce7cb7fdaacb4a595 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 19:30:12 +0200 Subject: [PATCH 261/363] src/networking/*: Using std::string compare() for all string based if clauses, checking for default server. Using lo:Address hostname() and port() functions to create new addresses. Copying by value in server_address(), to prevent double free. --- src/networking/oschandler.cpp | 2 +- src/networking/oscreceiver.cpp | 10 +++++----- src/networking/oscsender.cpp | 21 +++++++++++---------- src/networking/oscsender.h | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index bb355501..d60667a7 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -73,7 +73,7 @@ void ssr::OscHandler::start() void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address server_address) { - self._osc_sender.set_server_address(server_address); + self._osc_sender.set_server_address(server_address.hostname(), server_address.port()); } /** diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e3954eec..4216b609 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -493,15 +493,15 @@ void ssr::OscReceiver::add_server_to_client_methods() this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server = server_address(_handler); + lo::Address server(server_address(_handler)); lo::Address from(message.source()); (void) argv; VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << from.port() << "."); - if((server.hostname() != from.hostname()) && - (server.port() != from.port()) && - (from.port() != "50001") && - (from.hostname() != "none") + if((server.hostname().compare(from.hostname()) != 0) && + (server.port().compare(from.port()) != 0) && + (from.port().compare("50001") != 0) && + (from.hostname().compare("none") != 0) ) { set_server_for_client(_handler, from); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 45628bb4..861ebb73 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -134,18 +134,19 @@ void ssr::OscSender::poll_all_clients() */ lo::Address ssr::OscSender::server_address() { - return this->_server_address; + lo::Address server(_server_address.hostname(), _server_address.port()); + return server; } /** * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address */ -void ssr::OscSender::set_server_address(lo::Address server_address) +void ssr::OscSender::set_server_address(std::string hostname, std::string port) { - this->_server_address = new lo::Address(server_address); - VERBOSE2("OscSender: Setting up new server_address: "<< - server_address.hostname() << ":" << server_address.port() << "."); + _server_address = lo::Address(hostname, port); + VERBOSE2("OscSender: Setting up new server address: "<< + _server_address.hostname() << ":" << _server_address.port() << "."); } /** @@ -156,13 +157,13 @@ void ssr::OscSender::set_server_address(lo::Address server_address) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server_address.hostname() != "none") && (_server_address.port() != - "50002")) + if((_server_address.hostname().compare("none") != 0) && + (_server_address.port().compare("50002") != 0)) { _server_address.send_from(_send_from, path, message.types(), message); - VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 6a64ce08..9ccc8dfc 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -69,7 +69,7 @@ class OscSender : public Subscriber void start(); void stop(); - void set_server_address(lo::Address server_address); + void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(lo::Address client); void send_to_server(std::string path, lo::Message message); From c8867387631af166600fa58c65402ff0d8e7889c Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:33:20 +0200 Subject: [PATCH 262/363] src/networking/oscsender.*: Making _client_addresses a vector of pointers to lo::Address objects. Remodelling add_client() to use std::string for hostname and port instead of a lo::Address. Properly dereferencing all calls to member functions of client objects in _client_addresses. Setting sleep time for poll thread to 1s. --- src/networking/oscsender.cpp | 31 ++++++++++++++++--------------- src/networking/oscsender.h | 6 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 861ebb73..d6b6c2df 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -76,7 +76,7 @@ void ssr::OscSender::stop() if (is_server()) { _poll_all_clients = false; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } @@ -118,12 +118,12 @@ bool ssr::OscSender::is_server() */ void ssr::OscSender::poll_all_clients() { - VERBOSE2("OscSender: Polling all clients."); + VERBOSE("OscSender: Starting to poll all clients."); while(_poll_all_clients) { send_to_all_clients("/poll", lo::Message()); //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } VERBOSE2("OscSender: Stopped polling all clients."); } @@ -191,10 +191,10 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, { for (const auto& client: _client_addresses) { - if(client.hostname() == address.hostname() && client.port() == + if(client->hostname() == address.hostname() && client->port() == address.port()) { - client.send_from(_send_from, path, message.types(), message); + client->send_from(_send_from, path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -212,10 +212,10 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { for (const auto& client: _client_addresses) { - if(client.hostname() == address.hostname() && client.port() == + if(client->hostname() == address.hostname() && client->port() == address.port()) { - client.send_from(_send_from, bundle); + client->send_from(_send_from, bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } @@ -231,10 +231,10 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) { for (const auto& client_address: _client_addresses) { - client_address.send_from(_send_from, path, message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << client_address.hostname() << ":" << - client_address.port() << "."); + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + client_address->send_from(_send_from, path, message.types(), message); } } @@ -246,7 +246,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { for (const auto& client_address: _client_addresses) { - client_address.send_from(_send_from, bundle); + client_address->send_from(_send_from, bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } @@ -379,12 +379,13 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) /** * Adds a new client to the vector of clients - * @param clients lo::Address of a client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client */ -void ssr::OscSender::add_client(lo::Address client) +void ssr::OscSender::add_client(std::string hostname, std::string port) { - _client_addresses.push_back(client); - VERBOSE2("OscSender: Added client " << client.hostname() << " to list."); + _client_addresses.push_back(new lo::Address(hostname, port)); + VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); } // Subscriber interface (differentiating between client and server) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 9ccc8dfc..cd6fa5c7 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -43,8 +43,8 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; - // vector of client address objects (server) - std::vector _client_addresses; + // vector of pointers to client address objects (server) + std::vector _client_addresses; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously @@ -71,7 +71,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string hostname, std::string port); lo::Address server_address(); - void add_client(lo::Address client); + void add_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From d7b53e3d8b1615b4c8fdf6878abcf7dbad78ad4f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 14 May 2017 23:36:12 +0200 Subject: [PATCH 263/363] src/networking/oschandler.cpp: Adding VERBOSE message before adding clients. Adding clients using the new add_client() function. --- src/networking/oschandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index d60667a7..824610c0 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -27,11 +27,10 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, VERBOSE("OscHandler: Initialized."); if (mode == "server") { - VERBOSE2("OscHandler: server mode."); - for (const auto& hostname: clients) + VERBOSE("OscHandler: " << clients.size() << " client(s)."); + for (const auto& client: clients) { - _osc_sender.add_client(new lo::Address(hostname.first, - std::to_string(hostname.second))); + _osc_sender.add_client(client.first, std::to_string(client.second)); } } } From be394157396b0a7f979ba2e68e628cc0e9d9b8b6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 08:23:47 +0200 Subject: [PATCH 264/363] src/controller.h: Updating _osc_interface initialization to use _conf.osc_port. --- src/controller.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/controller.h b/src/controller.h index 89d80762..abe5c2dc 100644 --- a/src/controller.h +++ b/src/controller.h @@ -428,12 +428,10 @@ Controller::Controller(int argc, char* argv[]) if (_conf.network_mode == "client" || _conf.network_mode == "server") { VERBOSE2("Starting OSC interface as "<< _conf.network_mode << - ".\nReceiving messages on port " << - std::to_string(_conf.network_port_receive) << - ".\nSending messages from port " << - std::to_string(_conf.network_port_send) << "."); - _osc_interface.reset(new OscHandler(*this, _conf.network_port_receive, - _conf.network_port_send, _conf.network_mode, _conf.network_clients)); + " on port " << + std::to_string(_conf.osc_port) << "."); + _osc_interface.reset(new OscHandler(*this, _conf.osc_port, + _conf.network_mode, _conf.network_clients)); _osc_interface->start(); } #endif From 02a0e813753ddf0a7acd1ef2a28a310fec9d34bd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:30:13 +0200 Subject: [PATCH 265/363] src/networking/oschandler.h: Adding lo::ServerThread to OscHandler, to reflect change in configuration branch (only one OSC port needed). Replacing port_in/port_out parameters from Constructor with port. Adding public function declaration for getting a reference to _server. --- src/networking/oschandler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index c60fa08a..eaabad99 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -35,16 +35,18 @@ class OscHandler private: std::string _mode; //< mode: client|server Publisher& _controller; //< reference to Publisher object + lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; public: - OscHandler(Publisher& controller, int port_in, int port_out, std::string - mode, std::multimap clients); + OscHandler(Publisher& controller, int port, std::string mode, + std::multimap clients); ~OscHandler(); void start(); void stop(); std::string mode(); + const lo::ServerThread& server() const; friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 1ce818e1f370e1b532e17962f252ada3dfb3231b Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:33:11 +0200 Subject: [PATCH 266/363] src/networking/oschandler.cpp: Changing constructor to initialize ServerThread in OscHandler. Removing port_{in,out} usage in constructor. Starting lo::ServerThread in start() implementation. Starting _server after starting _osc_{receiver,sender}. Implementing server() function to return a reference to OscHandler's _server. --- src/networking/oschandler.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 824610c0..1b4c0b9c 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -17,12 +17,13 @@ * @param clients a multimap holding hostname, port pairs (only used for * server) */ -ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, - std::string mode, std::multimap clients) +ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, + std::multimap clients) : _mode(mode) , _controller(controller) - , _osc_receiver(controller, *this, port_in) - , _osc_sender(controller, *this, port_out) + , _server(port) + , _osc_receiver(controller, *this) + , _osc_sender(controller, *this) { VERBOSE("OscHandler: Initialized."); if (mode == "server") @@ -41,6 +42,7 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port_in, int port_out, ssr::OscHandler::~OscHandler() { stop(); + //TODO: delete members of _client_addresses VERBOSE("OscHandler: Destructing."); } @@ -60,8 +62,23 @@ void ssr::OscHandler::stop() void ssr::OscHandler::start() { VERBOSE("OscHandler: Starting"); + // check if lo::ServerThread is valid + if (!_server.is_valid()) { + ERROR("OscHandler: ServerThread could not be started!"); + } + _server.set_callbacks([this]() + { + VERBOSE("OscHandler: Started ServerThread."); + }, + []() + { + VERBOSE2("OscHandler: ServerThread cleanup."); + } + ); + VERBOSE("OscHandler: url = " << _server.url() << "."); _osc_receiver.start(); _osc_sender.start(); + _server.start(); } /** @@ -160,8 +177,18 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) /** * This function returns the OscHandler's mode + * @return std::string (either server or client) */ std::string ssr::OscHandler::mode() { return _mode; } + +/** + * Return reference to OscHandler's lo::ServerThread + * @return lo::ServerThread& reference to _server + */ +const lo::ServerThread& ssr::OscHandler::server() const +{ + return _server; +} From 59d8301bd2f4189083ada2c72521b222ff70d3b2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:34:12 +0200 Subject: [PATCH 267/363] src/networking/oscreceiver.h: Removing lo::ServerThread member from OscReceiver. Removing port_in argument to constructor. --- src/networking/oscreceiver.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 116d26b2..6327b3d6 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -35,13 +35,12 @@ class OscHandler; class OscReceiver { private: - lo::ServerThread _receiver; Publisher& _controller; ssr::OscHandler& _handler; void add_client_to_server_methods(); void add_server_to_client_methods(); public: - OscReceiver(Publisher& controller, OscHandler& handler, int port_in); + OscReceiver(Publisher& controller, OscHandler& handler); ~OscReceiver(); void start(); void stop(); From 38ef6c0103278599c850fd9107b83fea1dce548a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:35:41 +0200 Subject: [PATCH 268/363] src/networking/oscreceiver.cpp: Removing usage of port_in in constructor. Removing initialization of a lo::ServerThread in OscReceiver. Replacing all calls to _receiver with _handler.server(). --- src/networking/oscreceiver.cpp | 135 ++++++++++++++------------------- 1 file changed, 59 insertions(+), 76 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 4216b609..0772d19b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -17,8 +17,7 @@ using namespace apf::str; * @param port_in integer representing a port to used for incoming OSC messages * @todo add error handler for ServerThread */ -ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler, int port_in) - : _receiver(port_in) +ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) , _controller(controller) , _handler(handler) { @@ -51,21 +50,6 @@ void ssr::OscReceiver::start() add_server_to_client_methods(); VERBOSE("OscReceiver: Added server-to-client callbacks."); } - // check if lo::ServerThread is valid - if (!_receiver.is_valid()) { - ERROR("OscReceiver: ServerThread could not be started!"); - } - _receiver.set_callbacks([this]() - { - VERBOSE("OscReceiver: Started ServerThread for receiving messages."); - }, - []() - { - VERBOSE2("OscReceiver: ServerThread cleanup."); - } - ); - VERBOSE("OscReceiver: url = " << _receiver.url() << "."); - _receiver.start(); } /** @@ -75,7 +59,6 @@ void ssr::OscReceiver::start() void ssr::OscReceiver::stop() { VERBOSE("OscReceiver: Stopping."); - _receiver.stop(); } /** @@ -86,7 +69,7 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // update on new source: "/update/source/new, i, id" - _receiver.add_method("/update/source/new", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -97,7 +80,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - _receiver.add_method("/update/source/delete", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -116,7 +99,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - _receiver.add_method("/update/source/position", "iff", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -129,7 +112,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _receiver.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -149,7 +132,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _receiver.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -160,7 +143,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - _receiver.add_method("/update/source/volume", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -172,7 +155,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _receiver.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -192,7 +175,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - _receiver.add_method("/update/source/name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -204,7 +187,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _receiver.add_method("/update/source/properties_file", "is", [](lo_arg **argv, + _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -216,7 +199,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _receiver.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -229,7 +212,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _receiver.add_method("/update/scene/amplitude_reference_distance", "f", + _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -241,7 +224,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - _receiver.add_method("/update/source/model", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -252,7 +235,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _receiver.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -264,7 +247,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _receiver.add_method("/update/source/file_name_or_port_number", "is", + _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -276,7 +259,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - _receiver.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -287,7 +270,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - _receiver.add_method("/update/source/length", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -298,7 +281,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - _receiver.add_method("/update/reference/position", "ff", [](lo_arg **argv, + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -311,7 +294,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _receiver.add_method("/update/reference/orientation", "f", [](lo_arg **argv, + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -323,7 +306,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _receiver.add_method("/update/reference_offset/position", "ff", [](lo_arg + _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -336,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _receiver.add_method("/update/reference_offset/orientation", "f", [](lo_arg + _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -348,7 +331,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - _receiver.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -359,7 +342,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _receiver.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -380,7 +363,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _receiver.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -401,7 +384,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - _receiver.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -413,7 +396,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _receiver.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -435,7 +418,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - _receiver.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -446,7 +429,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _receiver.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -458,7 +441,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _receiver.add_method("/update/scene/master_signal_level", "f", [](lo_arg + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -469,7 +452,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - _receiver.add_method("/update/source/level", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -490,7 +473,7 @@ void ssr::OscReceiver::add_server_to_client_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - this->_receiver.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -514,7 +497,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _receiver.add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -525,7 +508,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _receiver.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -536,7 +519,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _receiver.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -546,7 +529,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _receiver.add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -556,7 +539,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _receiver.add_method("/source/volume", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -567,7 +550,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _receiver.add_method("/source/mute", "iT", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -576,7 +559,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _receiver.add_method("/source/mute", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -585,7 +568,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _receiver.add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -595,7 +578,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - _receiver.add_method("/source/properties_file", "is", [this](lo_arg **argv, + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -607,7 +590,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - _receiver.add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -622,7 +605,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - _receiver.add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -637,7 +620,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _receiver.add_method("/source/new", NULL, [this](lo_arg **argv, int, + _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -812,7 +795,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _receiver.add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -829,7 +812,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/delete."); // set reference position: "/reference/position, ff, x, y" - _receiver.add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -838,7 +821,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - _receiver.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -847,7 +830,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - _receiver.add_method("/reference_offset/position", "ff" , [this](lo_arg + _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -860,7 +843,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _receiver.add_method("/reference_offset/orientation", "f" , [this](lo_arg + _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -871,7 +854,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); // save scene to file: "/scene/save, s, file" - _receiver.add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); @@ -880,7 +863,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - _receiver.add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); @@ -889,7 +872,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - _receiver.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -899,7 +882,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - _receiver.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -909,7 +892,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/clear."); // set processing state: "/processing/state, T, true" - _receiver.add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -919,7 +902,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - _receiver.add_method("/processing/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -929,7 +912,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" - _receiver.add_method("transport/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -939,7 +922,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - _receiver.add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -949,7 +932,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - _receiver.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -959,7 +942,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _receiver.add_method("transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -977,7 +960,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/seek."); // reset tracker: "/tracker/reset" - _receiver.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); From 61bcea18c195a1419ca9a0f5025ceb43d009472f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:36:46 +0200 Subject: [PATCH 269/363] src/networking/oscsender.h: Removing lo::ServerThread as member of OscSender. Removing obsolete OscSender Constructor. Removing port_out argument of remaining constructor. --- src/networking/oscsender.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cd6fa5c7..0673140a 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -38,8 +38,6 @@ class OscSender : public Subscriber Publisher& _controller; // reference to handler OscHandler& _handler; - // ServerThread to send from specific port (client|server) - lo::ServerThread _send_from; bool _is_subscribed; // address of server (client) lo::Address _server_address; @@ -62,9 +60,7 @@ class OscSender : public Subscriber void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message public: - OscSender(Publisher& controller, OscHandler& handler, int port_out); - OscSender(Publisher& controller, OscHandler& handler, int port_out, - std::vector client_addresses); + OscSender(Publisher& controller, OscHandler& handler); ~OscSender(); void start(); From d50157b3672aa2eb925677f197bab1fcf7aac427 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 20:38:24 +0200 Subject: [PATCH 270/363] src/networking/oscsender.cpp: Removing port_out argument from constructor. Updating default server_address to use port 50001. Removing initialization of lo::ServerThread in OscSender. Replacing all calls to _send_from with _handler.server(). --- src/networking/oscsender.cpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index d6b6c2df..f20abd3e 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -17,12 +17,10 @@ * @param port_out an integer describing the port number to be used * for outgoing traffic */ -ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler, int - port_out) +ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) - , _send_from(port_out) - , _server_address("none", "50002") + , _server_address("none", "50001") { VERBOSE("OscSender: Initialized."); } @@ -41,21 +39,6 @@ void ssr::OscSender::start() { _controller.subscribe(this); _is_subscribed = true; - // check if lo::ServerThread is valid - if (!_send_from.is_valid()) { - ERROR("OscSender: ServerThread could not be started!"); - } - _send_from.set_callbacks([this]() - { - VERBOSE("OscSender: Started ServerThread for sending messages."); - }, - []() - { - VERBOSE2("OscSender: ServerThread cleanup."); - } - ); - VERBOSE("OscSender: url = " << _send_from.url() << "."); - _send_from.start(); if (is_server()) { _poll_all_clients = true; @@ -158,9 +141,9 @@ void ssr::OscSender::set_server_address(std::string hostname, std::string port) void ssr::OscSender::send_to_server(std::string path, lo::Message message) { if((_server_address.hostname().compare("none") != 0) && - (_server_address.port().compare("50002") != 0)) + (_server_address.port().compare("50001") != 0)) { - _server_address.send_from(_send_from, path, message.types(), message); + _server_address.send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -173,7 +156,7 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server_address.send_from(_send_from, bundle); + _server_address.send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle (" << bundle.length() << " messages) to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -194,7 +177,7 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_send_from, path, message.types(), message); + client->send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -215,7 +198,7 @@ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_send_from, bundle); + client->send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } @@ -234,7 +217,7 @@ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << client_address->hostname() << ":" << client_address->port() << "."); - client_address->send_from(_send_from, path, message.types(), message); + client_address->send_from(_handler.server(), path, message.types(), message); } } @@ -246,7 +229,7 @@ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { for (const auto& client_address: _client_addresses) { - client_address->send_from(_send_from, bundle); + client_address->send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } From 0200518fc907fc19cb0df887f7de78ae8f362036 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:25:07 +0200 Subject: [PATCH 271/363] src/networking/oschandler.h: Making access to lo::ServerThread non-static. --- src/networking/oschandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index eaabad99..2d7e1f57 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -46,7 +46,7 @@ class OscHandler void start(); void stop(); std::string mode(); - const lo::ServerThread& server() const; + lo::ServerThread& server(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 1379d47b0a51323c8534e4397e9f5b390473a7c3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:26:46 +0200 Subject: [PATCH 272/363] src/networking/oschandler.cpp: Making ssr::OscHandler::server() non-static. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 1b4c0b9c..54f2f27f 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -188,7 +188,7 @@ std::string ssr::OscHandler::mode() * Return reference to OscHandler's lo::ServerThread * @return lo::ServerThread& reference to _server */ -const lo::ServerThread& ssr::OscHandler::server() const +lo::ServerThread& ssr::OscHandler::server() { return _server; } From 45c472e77e36014d1f5953a76ae2e77fccfa2e8b Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 21 May 2017 21:28:46 +0200 Subject: [PATCH 273/363] src/networking/oscreceiver.cpp: Fixing initializer list in constructor. Adding initialization of lo::ServerThread reference to add_client_to_server_methods() and add_server_to_client_methods() to properly access the OscHandler's _server member. --- src/networking/oscreceiver.cpp | 120 +++++++++++++++++---------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0772d19b..2618fd8d 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -18,7 +18,7 @@ using namespace apf::str; * @todo add error handler for ServerThread */ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) - , _controller(controller) + : _controller(controller) , _handler(handler) { VERBOSE("OscReceiver: Initialized."); @@ -68,8 +68,9 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + lo::ServerThread& server = _handler.server(); // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, + server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -80,7 +81,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, + server.add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -99,7 +100,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, + server.add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -112,7 +113,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + server.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -132,7 +133,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + server.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -143,7 +144,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, + server.add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -155,7 +156,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + server.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -175,7 +176,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, + server.add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -187,7 +188,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, + server.add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -199,7 +200,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + server.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -212,7 +213,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", + server.add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -224,7 +225,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, + server.add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -235,7 +236,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + server.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -247,7 +248,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - _handler.server().add_method("/update/source/file_name_or_port_number", "is", + server.add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -259,7 +260,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + server.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -270,7 +271,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, + server.add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -281,7 +282,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, + server.add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -294,7 +295,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, + server.add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -306,7 +307,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg + server.add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -319,7 +320,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg + server.add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -331,7 +332,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + server.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -342,7 +343,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + server.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -363,7 +364,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + server.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -384,7 +385,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + server.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -396,7 +397,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + server.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -418,7 +419,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + server.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -429,7 +430,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + server.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -441,7 +442,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg + server.add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -452,7 +453,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, + server.add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -471,9 +472,10 @@ void ssr::OscReceiver::add_client_to_server_methods() */ void ssr::OscReceiver::add_server_to_client_methods() { + lo::ServerThread& server = _handler.server(); // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + server.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -497,7 +499,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /poll."); // set source position: "source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) + server.add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -508,7 +510,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + server.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -519,7 +521,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + server.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -529,7 +531,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) + server.add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -539,7 +541,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) + server.add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -550,7 +552,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) + server.add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -559,7 +561,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) + server.add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -568,7 +570,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) + server.add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -578,7 +580,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, + server.add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -590,7 +592,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) + server.add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -605,7 +607,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) + server.add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -620,7 +622,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, + server.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { std::string name(apf::str::A2S(argv[0]->s)); @@ -795,7 +797,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) + server.add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -812,7 +814,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/delete."); // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) + server.add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -821,7 +823,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + server.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -830,7 +832,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg + server.add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -843,7 +845,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg + server.add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -854,7 +856,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) + server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); @@ -863,7 +865,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) + server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(apf::str::A2S(argv[0]->s)); VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); @@ -872,7 +874,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + server.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -882,7 +884,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + server.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -892,7 +894,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/clear."); // set processing state: "/processing/state, T, true" - _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) + server.add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -902,7 +904,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) + server.add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -912,7 +914,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state false."); // set transport state: "transport/state, T, true" - _handler.server().add_method("transport/state", "T" , [this](lo_arg **argv, int) + server.add_method("transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -922,7 +924,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) + server.add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -932,7 +934,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + server.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -942,7 +944,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _handler.server().add_method("transport/seek", "s" , [this](lo_arg **argv, int) + server.add_method("transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -960,7 +962,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/seek."); // reset tracker: "/tracker/reset" - _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + server.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); From 01a12f88883b88a3629604f12f6b7dcbf05887e0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 18:51:53 +0200 Subject: [PATCH 274/363] src/networking/oschandler.h: Adding global int _message_level, defining the type of OSC messages sent (very verbose). This should ultimately be a client address based setting, so clients can subscribe to several layers of messages. Adding message_leve() function for returning _message_level. Adding friend functions add_client(), remove_client() for OscReceiver to add and remove clients from the list of clients in OscSender. --- src/networking/oschandler.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 2d7e1f57..9ae8e70c 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -38,6 +38,7 @@ class OscHandler lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; + const unsigned int _message_level = 2; public: OscHandler(Publisher& controller, int port, std::string mode, @@ -47,6 +48,7 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); + const unsigned int& message_level(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); @@ -62,6 +64,8 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); + friend void OscReceiver::add_client(OscHandler& self, lo::Address client); + friend void OscReceiver::remove_client(OscHandler& self, lo::Address client); }; } // namespace ssr From 994fa0a01ad9f26e5fe6431bb5a0433693e6bc6f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 18:53:44 +0200 Subject: [PATCH 275/363] src/networking/oschandler.cpp: Adding implementations of OscReceiver's friend functions add_client() and remove_client(). Adding implementation of message_level() function. --- src/networking/oschandler.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 54f2f27f..9b6703fd 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -175,6 +175,29 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) self._osc_sender.send_to_server(bundle); } +/** + * OscHandler's friend function to add a client to the list of OscSender's + * _client_addresses. + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be added + */ +void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) +{ + self._osc_sender.add_client(client.hostname(), client.port()); +} + +/** + * OscHandler's friend function to remove a client from the list of OscSender's + * _client_addresses. + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be removed + */ +void ssr::OscReceiver::remove_client(OscHandler& self, lo::Address client) +{ + self._osc_sender.remove_client(client.hostname(), client.port()); +} + + /** * This function returns the OscHandler's mode * @return std::string (either server or client) @@ -192,3 +215,12 @@ lo::ServerThread& ssr::OscHandler::server() { return _server; } + +/** + * Return reference to current _message_level + * @return const unsigned int& + */ +const unsigned int& ssr::OscHandler::message_level() +{ + return _message_level; +} From e79797be443aee9cb4fff0bbdd2116fdee0b08b3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:03:31 +0200 Subject: [PATCH 276/363] src/networking/oscreceiver.h: Adding functions add_client() and remove_client() to add and remove clients on OscSender. --- src/networking/oscreceiver.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 6327b3d6..4cd2b9df 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -55,6 +55,8 @@ class OscReceiver void send_to_all_clients(OscHandler& self, lo::Bundle bundle); void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); + void add_client(OscHandler& self, lo::Address client); + void remove_client(OscHandler& self, lo::Address client); }; } // namespace ssr From ab0480ea9db1083c8c990284197ba26a93416e8d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:14:08 +0200 Subject: [PATCH 277/363] src/networking/oscreceiver.cpp: Adding callback function for /subscribe message (adds client to the list of clients). Updating comments for start() and stop(). Changing the /poll callback to use /subscribe by directly calling send_from() on the calling address, instead of using the friend function. Using references for all calls to strings from a lo::Message argument list. Fixing typo in /transport/seek callback function. --- src/networking/oscreceiver.cpp | 73 ++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2618fd8d..0374a70b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -33,8 +33,7 @@ ssr::OscReceiver::~OscReceiver() } /** - * Starts the OscReceiver, by adding client|server callback functions and - * starting the lo::ServerThread used for listening to OSC messages. + * Starts the OscReceiver, by adding client/ server callback functions. */ void ssr::OscReceiver::start() { @@ -53,8 +52,7 @@ void ssr::OscReceiver::start() } /** - * Stops the OscReceiver, by stopping the lo::ServerThread, used for listening - * for OSC messages + * Stops the OscReceiver */ void ssr::OscReceiver::stop() { @@ -68,7 +66,32 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + // add local reference to OscHandler's lo::ServerThread for add_method() lo::ServerThread& server = _handler.server(); + + // adding new subscribing client: "/subscribe, T" + server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message + message) + { + lo::Address client(message.source()); + (void) argv; + VERBOSE2("Subscribe called with " << message.types() << "."); + if(message.types().compare("T") == 0) + { + add_client(_handler, client); + VERBOSE("Client '" << client.hostname() << ":" << client.port() << + "' subscribed."); + } + else if(message.types().compare("F") == 0) + { + remove_client(_handler, client); + VERBOSE("Client '" << client.hostname() << ":" << client.port() << + "' unsubscribed."); + } + } + ); + VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + // update on new source: "/update/source/new, i, id" server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) @@ -481,8 +504,6 @@ void ssr::OscReceiver::add_server_to_client_methods() lo::Address server(server_address(_handler)); lo::Address from(message.source()); (void) argv; - VERBOSE3("OscReceiver: Received /poll from " << from.hostname() << ":" << - from.port() << "."); if((server.hostname().compare(from.hostname()) != 0) && (server.port().compare(from.port()) != 0) && (from.port().compare("50001") != 0) && @@ -490,9 +511,9 @@ void ssr::OscReceiver::add_server_to_client_methods() ) { set_server_for_client(_handler, from); - lo::Message reply; - reply.add_true(); - this->send_to_server(_handler, "/update/subscribe", reply); + from.send_from(_handler.server(), "/subscribe", "T"); + VERBOSE2("OscReceiver: Got /poll from server " << from.hostname() << + ":" << from.port() << ". Subscribing..."); } } ); @@ -625,8 +646,9 @@ void ssr::OscReceiver::add_server_to_client_methods() server.add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string name(apf::str::A2S(argv[0]->s)); - std::string file_name_or_port_number(apf::str::A2S(argv[2]->s)); + VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); @@ -703,7 +725,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTTT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = true; muted = true; @@ -712,7 +734,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTTF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = true; muted = false; @@ -721,7 +743,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTFF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = false; muted = false; @@ -730,7 +752,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFFF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = false; muted = false; @@ -739,7 +761,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisTFT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = true; orientation_fixed = false; muted = true; @@ -748,7 +770,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFTF") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = true; muted = false; @@ -757,7 +779,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFTT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = true; muted = true; @@ -766,7 +788,7 @@ void ssr::OscReceiver::add_server_to_client_methods() if (types.compare("sssffffisFFT") == 0) { channel = argv[7]->i; - properties_file = argv[8]->s; + properties_file = &(argv[8]->s); position_fixed = false; orientation_fixed = false; muted = true; @@ -788,8 +810,7 @@ void ssr::OscReceiver::add_server_to_client_methods() "\norientation_fixed: " << orientation_fixed << "\nvolume (linear): " << volume << "\nmuted: " << muted << - "\nproperties_file: " << properties_file << - "\n"); + "\nproperties_file: " << properties_file); } } ); @@ -858,8 +879,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // save scene to file: "/scene/save, s, file" server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) { - _controller.save_scene_as_XML(apf::str::A2S(argv[0]->s)); - VERBOSE2("saving theme as: " << apf::str::A2S(argv[0]->s)); + _controller.save_scene_as_XML(std::string(&(argv[0]->s))); + VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); } ); VERBOSE("OscReceiver: Added method for /scene/save."); @@ -867,8 +888,8 @@ void ssr::OscReceiver::add_server_to_client_methods() // load scene from file: "/scene/load, s, file" server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) { - _controller.load_scene(apf::str::A2S(argv[0]->s)); - VERBOSE2("loading scene: " << apf::str::A2S(argv[0]->s)); + _controller.load_scene(std::string(&(argv[0]->s))); + VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); } ); VERBOSE("OscReceiver: Added method for /scene/load."); @@ -944,7 +965,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - server.add_method("transport/seek", "s" , [this](lo_arg **argv, int) + server.add_method("/transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) From 282f225d8de45a3a7f1f9c8625ddfcc9578ac627 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:17:35 +0200 Subject: [PATCH 278/363] src/networking/oscsender.h: Creating anonymous namespace for _message_type_false and _message_type_true const std::strings. Adding function server_is_default(), bool_to_message_type(), remove_all_clients() and remove_client(). --- src/networking/oscsender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 0673140a..b8d62b58 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -19,6 +19,12 @@ #include "subscriber.h" #include "apf/parameter_map.h" +namespace +{ + const std::string _message_type_false{"F"}; + const std::string _message_type_true{"T"}; +} + namespace ssr { @@ -54,7 +60,10 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); + bool server_is_default(); + const std::string bool_to_message_type(const bool& message); void poll_all_clients(); + void remove_all_client_addresses(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message @@ -68,6 +77,7 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(std::string hostname, std::string port); + void remove_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From ad7219a0957430b0d0dd5148b757521a2fbf0112 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 28 May 2017 19:27:25 +0200 Subject: [PATCH 279/363] src/networking/oscsender.cpp: Adding implementations for server_is_default(), bool_to_message_type(), remove_client() and remove_all_clients(). Changing all subscriber interface functions to directly send OSC messages to server/clients (this is very redundant, but needed, as lo::Message loses scope of some data types, if used as before - bug?). Adding VERBOSE messaging to all subscriber interface functions. Adding several layers of OSC message sending verbosity (ultimately planend to be settable by each client individually). --- src/networking/oscsender.cpp | 748 +++++++++++++++++++++++++---------- 1 file changed, 530 insertions(+), 218 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f20abd3e..b3214ce3 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -58,6 +58,7 @@ void ssr::OscSender::stop() _is_subscribed = false; if (is_server()) { + remove_all_client_addresses(); _poll_all_clients = false; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -95,6 +96,39 @@ bool ssr::OscSender::is_server() } } +/** + * Returns true, if the _server_address is the default (setup at initialization) + * @return true, if _server_address is the default, false otherwise. + */ +bool ssr::OscSender::server_is_default() +{ + if((_server_address.hostname().compare("none") == 0) && + (_server_address.port().compare("50001") == 0)) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the _server_address is the default (setup at initialization) + * @return true, if _server_address is the default, false otherwise. + */ +const std::string ssr::OscSender::bool_to_message_type(const bool& message) +{ + if(message) + { + return _message_type_true; + } + else + { + return _message_type_false; + } +} + /** * Sends a '/poll' message to all client instances listed in _client_addresses, * then makes the thread calling this function sleep for 100 milliseconds @@ -371,6 +405,41 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); } +/** + * Removes a client from the vector of clients + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + */ +void ssr::OscSender::remove_client(std::string hostname, std::string port) +{ + for (auto client = _client_addresses.begin(); client != + _client_addresses.end(); ) + { + if(!((*client)->hostname().compare(hostname)) && + !((*client)->port().compare(port))) + { + delete *client; + client = _client_addresses.erase(client); + VERBOSE2("OscSender: Removed client " << hostname << ":" << port << "."); + } + else + { + ++client; + } + } +} + +/** + * Removes all clients from the vector of clients. + */ +void ssr::OscSender::remove_all_client_addresses() +{ + for (auto client: _client_addresses ) delete client; + _client_addresses.clear(); + VERBOSE2("OscSender: Removed all clients."); +} + + // Subscriber interface (differentiating between client and server) @@ -404,10 +473,12 @@ void ssr::OscSender::new_source(id_t id) } else if(is_client()) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); - this->send_to_server("/update/source/new", message); + int32_t message_id = static_cast(id); + _server_address.send_from(_handler.server(), "/update/source/new", "i", + message_id); + VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -420,17 +491,26 @@ void ssr::OscSender::new_source(id_t id) */ void ssr::OscSender::delete_source(id_t id) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); + int32_t message_id = static_cast(id); if(is_server()) { - this->send_to_all_clients("/source/delete", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/delete", "i", + message_id); + VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if (is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/source/delete", message); _source_levels.erase(id); + _server_address.send_from(_handler.server(), "/update/source/delete", + "i", message_id); + VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -442,13 +522,23 @@ void ssr::OscSender::delete_source(id_t id) */ void ssr::OscSender::delete_all_sources() { - lo::Message message; - message.add_int32(0); if(is_server()) - this->send_to_all_clients("/source/delete", message); - else if(is_client()) - this->send_to_server("/update/source/delete", message); - + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/delete", "i", 0); + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } + } + else if(is_client() && !server_is_default()) + { + _server_address.send_from(_handler.server(), "/update/source/delete", + "i", 0); + VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + } _source_levels.clear(); } @@ -466,8 +556,7 @@ void ssr::OscSender::delete_all_sources() */ bool ssr::OscSender::set_source_position(id_t id, const Position& position) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -479,18 +568,24 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - message.add_int32(message_id); - message.add_float(position.x); - message.add_float(position.y); - this->send_to_all_clients("/source/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/position", "iff", + message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << + position.x << ", " << position.y << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if (is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(position.x); - message.add_float(position.y); - this->send_to_server("/update/source/position", message); + _server_address.send_from(_handler.server(), "/update/source/position", + "iff", message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << + ", " << position.x << ", " << position.y << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -510,8 +605,8 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) */ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { - lo::Message message; - int32_t message_id = id; +// lo::Message message; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -522,16 +617,24 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - message.add_int32(message_id); - message.add_bool(fixed); - this->send_to_all_clients("/source/position_fixed", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/position_fixed", + "i"+bool_to_message_type(fixed), message_id); + VERBOSE3("OscSender: Sent [/source/position_fixed, i" << + bool_to_message_type(fixed) << ", " << message_id << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_bool(fixed); - this->send_to_server("/update/source/position_fixed", message); + _server_address.send_from(_handler.server(), "/update/source/position_fixed", + "i"+bool_to_message_type(fixed), message_id); + VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" + +bool_to_message_type(fixed) << ", " << message_id << "] to server " + << _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -550,8 +653,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& orientation) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + float message_orientation = orientation.azimuth; if(is_server()) { if(is_new_source(id)) @@ -562,16 +665,25 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - message.add_int32(message_id); - message.add_float(orientation.azimuth); - this->send_to_all_clients("/source/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/orientation", + "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/source/orientation, if, " << + message_id << ", " << message_orientation << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(orientation.azimuth); - this->send_to_server("/update/source/orientation", message); + _server_address.send_from(_handler.server(), "/update/source/orientation", + "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + apf::str::A2S(message_id) << ", " << + apf::str::A2S(message_orientation) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -590,8 +702,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& */ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -602,16 +713,25 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - message.add_int32(message_id); - message.add_float(gain); - this->send_to_all_clients("/source/volume", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/volume", "if", + message_id, gain); + VERBOSE3("OscSender: Sent [/source/volume, if, " << + message_id << ", " << gain << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_float(gain); - this->send_to_server("/update/source/volume", message); + _server_address.send_from(_handler.server(), "/update/source/volume", + "if", message_id, gain); + VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } @@ -630,8 +750,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) */ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -642,16 +761,24 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - message.add_int32(message_id); - message.add_bool(mute); - this->send_to_all_clients("/source/mute", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/source/mute, i" << + bool_to_message_type(mute) << ", " << message_id << "] to client " + << client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_bool(mute); - this->send_to_server("/update/source/mute", message); + _server_address.send_from(_handler.server(), "/update/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/update/source/mute, i" << bool_to_message_type(mute) << + ", " << apf::str::A2S(message_id) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -670,8 +797,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) */ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + const char * message_name = name.c_str(); if(is_server()) { if(is_new_source(id)) @@ -682,16 +809,23 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - message.add_int32(message_id); - message.add_string(name); - this->send_to_all_clients("/source/name", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/name", "is", + message_id, message_name); + VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << + message_name << "] to client " << client_address->hostname() << ":" + << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(name); - this->send_to_server("/update/source/name", message); + _server_address.send_from(_handler.server(), "/update/source/name", "is", + message_id, message_name); + VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " + << message_name << "] to server " << _server_address.hostname() << ":" + << _server_address.port() << "."); } return true; } @@ -712,7 +846,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); + const char * file_name = name.c_str(); if(is_server()) { if(is_new_source(id)) @@ -723,16 +858,24 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(name); - this->send_to_all_clients("/source/properties_file", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/properties_file", + "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id + << ", " << file_name << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(name); - this->send_to_server("/update/source/properties_file", message); + _server_address.send_from(_handler.server(), + "/update/source/properties_file", "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << + message_id << ", " << file_name << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -747,15 +890,24 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& */ void ssr::OscSender::set_decay_exponent(float exponent) { - lo::Message message; - message.add_float(exponent); if(is_server()) { - this->send_to_all_clients("/scene/decay_exponent", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/decay_exponent", + "f", exponent); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/decay_exponent", message); + _server_address.send_from(_handler.server(), + "/update/scene/decay_exponent", "f", exponent); + VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -771,17 +923,24 @@ void ssr::OscSender::set_decay_exponent(float exponent) */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { - lo::Message message; - message.add_float(distance); if(is_server()) { - this->send_to_all_clients("/scene/amplitude_reference_distance", - message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/amplitude_reference_distance", - message); + _server_address.send_from(_handler.server(), + "/update/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " + << distance << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -799,31 +958,36 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) */ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { - lo::Message message; - int32_t message_id = id; - std::string tmp_model; - tmp_model = apf::str::A2S(model); - if (tmp_model == "") return false; + int32_t message_id = static_cast(id); + std::string message_model = apf::str::A2S(model); + if (message_model == "") return false; if(is_server()) { if(is_new_source(id)) { - _new_sources.at(id).set("model", tmp_model); + _new_sources.at(id).set("model", message_model); if(is_complete_source(id)) this->send_new_source_message_from_id(id); } else { - message.add_int32(message_id); - message.add_string(tmp_model); - this->send_to_all_clients("/source/model", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/model", "is", + message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " + << message_model << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(tmp_model); - this->send_to_server("/update/source/model", message); + _server_address.send_from(_handler.server(), "/update/source/model", "is", + message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << + ", " << message_model << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } return true; } @@ -845,8 +1009,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -857,16 +1020,23 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(port_name); - this->send_to_all_clients("/source/port_name", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/port_name", "is", + message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << + ", " << port_name << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(port_name); - this->send_to_server("/update/source/port_name", message); + _server_address.send_from(_handler.server(), "/update/source/port_name", + "is", message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << + ", " << port_name << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } return true; } @@ -890,8 +1060,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { - lo::Message message; - int32_t message_id = id; + int32_t message_id = static_cast(id); if(is_server()) { if(is_new_source(id)) @@ -903,16 +1072,26 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - message.add_int32(message_id); - message.add_string(file_name); - this->send_to_all_clients("/source/file_name_or_port_number", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << + message_id << ", " << file_name << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_string(file_name); - this->send_to_server("/update/source/file_name_or_port_number", message); + _server_address.send_from(_handler.server(), + "/update/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " + << message_id << ", " << file_name << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -933,9 +1112,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& */ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { - lo::Message message; - int32_t message_id = id; - int32_t message_file_channel = file_channel; + int32_t message_id = static_cast(id); + int32_t message_file_channel = static_cast(file_channel); if(is_server()) { if(is_new_source(id)) @@ -946,16 +1124,24 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - message.add_int32(message_id); - message.add_int32(message_file_channel); - this->send_to_all_clients("/source/channel", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/file_channel", + "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << + ", " << message_file_channel << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_int32(message_file_channel); - this->send_to_server("/update/source/channel", message); + _server_address.send_from(_handler.server(), + "/update/source/file_channel", "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id + << ", " << message_file_channel << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -974,14 +1160,15 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) */ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { - lo::Message message; - int32_t message_id = id; - int32_t message_length = length; - if(is_client()) + int32_t message_id = static_cast(id); + int32_t message_length = static_cast(length); + if(is_client() && !server_is_default()) { - message.add_int32(message_id); - message.add_int32(message_length); - this->send_to_server("/update/source/length", message); + _server_address.send_from(_handler.server(), "/update/source/length", "ii", + message_id, message_length); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id + << ", " << message_length << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } return true; } @@ -998,16 +1185,24 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) */ void ssr::OscSender::set_reference_position(const Position& position) { - lo::Message message; - message.add_float(position.x); - message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("/reference/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/reference/position", "ff", + position.x, position.y); + VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << + ", " << position.y << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference/position", message); + _server_address.send_from(_handler.server(), "/update/reference/position", + "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x + << ", " << position.y << "] to server " << _server_address.hostname() + << ":" << _server_address.port() << "."); } } @@ -1023,15 +1218,24 @@ void ssr::OscSender::set_reference_position(const Position& position) */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { - lo::Message message; - message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("/reference/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/reference/orientation", + "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference/orientation, f, " << + orientation.azimuth << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference/orientation", message); + _server_address.send_from(_handler.server(), + "/update/reference/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << + orientation.azimuth << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } } @@ -1048,16 +1252,24 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) */ void ssr::OscSender::set_reference_offset_position(const Position& position) { - lo::Message message; - message.add_float(position.x); - message.add_float(position.y); if(is_server()) { - this->send_to_all_clients("/reference_offset/position", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference_offset/position", message); + _server_address.send_from(_handler.server(), + "/update/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1076,15 +1288,24 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { - lo::Message message; - message.add_float(orientation.azimuth); if(is_server()) { - this->send_to_all_clients("/reference_offset/orientation", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << + orientation.azimuth << "] to client " << client_address->hostname() + << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/reference_offset/orientation", message); + _server_address.send_from(_handler.server(), + "/update/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << + orientation.azimuth << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); } } @@ -1100,15 +1321,25 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& */ void ssr::OscSender::set_master_volume(float volume) { - lo::Message message; - message.add_float(apf::math::linear2dB(volume)); + float message_volume = apf::math::linear2dB(volume); if(is_server()) { - this->send_to_all_clients("/scene/volume", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/volume", message); + _server_address.send_from(_handler.server(), "/update/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1141,20 +1372,29 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* */ void ssr::OscSender::set_processing_state(bool state) { - lo::Message message; - message.add_bool(state); if(is_server()) { - this->send_to_all_clients("/processing/state", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/processing/state, " << + bool_to_message_type(state) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/processing/state", message); + _server_address.send_from(_handler.server(), "/update/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/update/processing/state, " << + bool_to_message_type(state) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } /** - * Subscriber function called, when Publisher set the processing state. + * Subscriber function called, when Publisher sets the transport state. * On server: Sends out OSC message to all clients to update their processing * state. * On client: Sends out OSC message to server about the update of its @@ -1167,28 +1407,42 @@ void ssr::OscSender::set_processing_state(bool state) void ssr::OscSender::set_transport_state( const std::pair& state) { - lo::Message message_state; - lo::Message message_time; - message_state.add_bool(state.first); - message_time.add_string(std::to_string(state.second)); + int32_t message_nframes = static_cast(state.second); if(is_server()) { - lo::Bundle bundle({ - {"/transport/state", message_state}, - {"/transport/seek", message_time} - }); - -// TODO: debug this! -// this->send_to_all_clients(bundle); + if(_handler.message_level() >= 2) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + client_address->send_from(_handler.server(), "/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << + "] to client " << client_address->hostname() << ":" << + client_address->port() << "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - lo::Bundle bundle({ - {"/update/transport/state", message_state}, - {"/update/transport/seek", message_time} - }); -// TODO: debug this! -// this->send_to_server(bundle); + if(_handler.message_level() >= 2) + { + _server_address.send_from(_handler.server(), "/update/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/update/transport/state, " << + bool_to_message_type(state.first) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + _server_address.send_from(_handler.server(), "/update/transport/seek", + "i", message_nframes); + VERBOSE3("OscSender: Sent [/update/transport/state, i, " << + message_nframes << "] to server " << _server_address.hostname() << + ":" << _server_address.port() << "."); + } } } @@ -1206,15 +1460,26 @@ void ssr::OscSender::set_transport_state( const std::pairsend_to_all_clients("/scene/auto_rotate_sources", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/auto_rotate_sources", message); + _server_address.send_from(_handler.server(), + "/update/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1228,11 +1493,17 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) */ void ssr::OscSender::set_cpu_load(float load) { - lo::Message message; - message.add_float(load); - if(is_client()) + //TODO: implement pooling of cpu_load updates + if(is_client() && !server_is_default()) { - this->send_to_server("/update/cpu_load", message); + if(_handler.message_level() >= 2) + { + _server_address.send_from(_handler.server(), "/update/cpu_load", "f", + load); + VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } } @@ -1248,16 +1519,25 @@ void ssr::OscSender::set_cpu_load(float load) */ void ssr::OscSender::set_sample_rate(int sr) { - lo::Message message; - int32_t message_sr = sr; - message.add_int32(message_sr); + int32_t message_sr = static_cast(sr); if(is_server()) { - this->send_to_all_clients("/scene/sample_rate", message); + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/scene/sample_rate", "i", + message_sr); + VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to client " << + client_address->hostname() << ":" << client_address->port() << "."); + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/sample_rate", message); + _server_address.send_from(_handler.server(), "/update/scene/sample_rate", + "i", message_sr); + VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1273,16 +1553,32 @@ void ssr::OscSender::set_sample_rate(int sr) */ void ssr::OscSender::set_master_signal_level(float level) { - lo::Message message; float message_level(apf::math::linear2dB(level)); - message.add_float(message_level); if(is_server()) { - this->send_to_all_clients("/scene/master_signal_level", message); + if(_handler.message_level() >= 1) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + client_address->hostname() << ":" << client_address->port() << + "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/scene/master_signal_level", message); + if(_handler.message_level() >= 1) + { + _server_address.send_from(_handler.server(), + "/update/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + } } } @@ -1300,17 +1596,33 @@ void ssr::OscSender::set_master_signal_level(float level) */ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { - lo::Message message; - int32_t message_id = id; - message.add_int32(message_id); - message.add_float(apf::math::linear2dB(level)); + int32_t message_id = static_cast(id); + float message_level(apf::math::linear2dB(level)); if(is_server()) { - this->send_to_all_clients("/source/volume", message); + if(_handler.message_level() >= 1) + { + for (const auto& client_address: _client_addresses) + { + client_address->send_from(_handler.server(), "/source/level", "if", + message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << client_address->hostname() << + ":" << client_address->port() << "."); + } + } } - else if(is_client()) + else if(is_client() && !server_is_default()) { - this->send_to_server("/update/source/level", message); + if(_handler.message_level() >= 1) + { + _server_address.send_from(_handler.server(), "/update/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/update/source/level, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); + } } return true; } From 2367dd8c9e0d6de63817be06312eed898d9b3255 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 00:38:11 +0200 Subject: [PATCH 280/363] src/networking/oscclient.*: Adding class definition and implementation for OSC client, which is defined by a lo::Address and an enum class defining the message level. --- src/networking/oscclient.cpp | 60 ++++++++++++++++++++++++++++++++++++ src/networking/oscclient.h | 39 +++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/networking/oscclient.cpp create mode 100644 src/networking/oscclient.h diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp new file mode 100644 index 00000000..91004d81 --- /dev/null +++ b/src/networking/oscclient.cpp @@ -0,0 +1,60 @@ +/** + * Implementation of oscclient.h + * @file oscclient.cpp + */ + +#include "oscclient.h" + +/** + * Constructor used to create OSC client objects + * @param hostname a std::string used in the object's address + * @param port a std::string used in the object's address + * @param message_level the MessageLevel defining the clients level of messages + */ +ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel + message_level) + : _address(hostname, port) + , _message_level(message_level) +{} + +/** + * Destructor + **/ +ssr::OscClient::~OscClient() +{} + +/** + * Function to get the OscClient's _message_level. + * @return message_level a MessageLevel used for the OscClient + **/ +ssr::MessageLevel ssr::OscClient::message_level() +{ + return _message_level; +} + +/** + * Function to set the OscClient's _message_level. + * @param message_level a MessageLevel to be used for the OscClient + **/ +void ssr::OscClient::set_message_level(MessageLevel message_level) +{ + _message_level = message_level; +} + +/** + * Function to get the OscClient's hostname. + * @return std::string representing the OscClient's hostname + **/ +const std::string ssr::OscClient::hostname() +{ + return _address.hostname(); +} + +/** + * Function to get the OscClient's port. + * @return std::string representing the OscClient's port + **/ +const std::string ssr::OscClient::port() +{ + return _address.port(); +} diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h new file mode 100644 index 00000000..956f4f04 --- /dev/null +++ b/src/networking/oscclient.h @@ -0,0 +1,39 @@ +/** + * Header for OscClient, defining a class, holding client information + * @file oscclient.h + */ + +#ifndef OSC_CLIENT_H +#define OSC_CLIENT_H + +#include +#include + +namespace ssr +{ + +enum class MessageLevel : unsigned int +{ + MESSAGE_LEVEL_SERVER = 0, + MESSAGE_LEVEL_THIN_CLIENT = 1, + MESSAGE_LEVEL_CLIENT = 2 +}; + +class OscClient +{ + private: + const lo::Address _address; + MessageLevel _message_level; + public: + OscClient(std::string hostname, std::string port, MessageLevel + message_level); + ~OscClient(); + + ssr::MessageLevel message_level(); + void set_message_level(MessageLevel message_level); + const std::string hostname(); + const std::string port(); +}; + +} +#endif From 02969e615e961ff3e43a27a5303a416328052cee Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 00:38:51 +0200 Subject: [PATCH 281/363] src/Makefile.am: Adding src/networking/oscclient.{h,cpp}. --- src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index ecb84379..8a814dfa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -186,6 +186,8 @@ if ENABLE_OSC_INTERFACE AM_CPPFLAGS += -I$(srcdir)/networking SSRSOURCES += \ + networking/oscclient.cpp \ + networking/oscclient.h \ networking/oschandler.cpp \ networking/oschandler.h \ networking/oscreceiver.cpp \ From 8b2c641bb22e4de9ca33de6a471167725b6eea45 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 14:40:59 +0200 Subject: [PATCH 282/363] src/networking/oscclient.h: Adding function to retrieve lo::Address from OscClient. --- src/networking/oscclient.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 956f4f04..27c7b953 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -30,6 +30,7 @@ class OscClient ~OscClient(); ssr::MessageLevel message_level(); + lo::Address address(); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); From 1a0fa21db19b670ee4dea47d9e6eb96cd40cffc0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 14:41:39 +0200 Subject: [PATCH 283/363] src/networking/oscclient.cpp: Adding implementation for address(). --- src/networking/oscclient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 91004d81..897981c6 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -32,6 +32,15 @@ ssr::MessageLevel ssr::OscClient::message_level() return _message_level; } +/** + * Function to get the OscClient's _address + * @return a lo::Address used for the OscClient + **/ +lo::Address ssr::OscClient::address() +{ + return _address; +} + /** * Function to set the OscClient's _message_level. * @param message_level a MessageLevel to be used for the OscClient From 3c0da3947573769ae4a151d8b2ec6d39e5b3053e Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 29 May 2017 15:18:59 +0200 Subject: [PATCH 284/363] src/networking/oscsender.cpp: Fixing documentation for constructor and start(). --- src/networking/oscsender.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b3214ce3..80bc36fa 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -11,11 +11,9 @@ #include "apf/math.h" /** - * Constructor used to create client objects + * Constructor used to create OscSender objects * @param controller reference to a Publisher object * @param handler reference to an OscHandler object - * @param port_out an integer describing the port number to be used - * for outgoing traffic */ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) @@ -31,7 +29,8 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) ssr::OscSender::~OscSender() {} -/** Function to start the OscSender object +/** + * Function to start the OscSender object * This subscribes the OscSender to the Publisher and starts the * lo::ServerThread to send from */ From 24df01832e03b45bd8112ee3f34d9c9abe54737f Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 30 May 2017 14:19:30 +0200 Subject: [PATCH 285/363] src/networking/oscclient.h: Adding bool for active state. Adding public functions to retrieve the _active state of OscClient objects and deactivating them. --- src/networking/oscclient.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 27c7b953..88616f19 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -24,6 +24,8 @@ class OscClient private: const lo::Address _address; MessageLevel _message_level; + bool _active = false; + public: OscClient(std::string hostname, std::string port, MessageLevel message_level); @@ -31,6 +33,8 @@ class OscClient ssr::MessageLevel message_level(); lo::Address address(); + bool active(); + void deactivate(); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); From a1d658b3f970bdd55aaaf710087700771d8f5e72 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 30 May 2017 14:20:58 +0200 Subject: [PATCH 286/363] src/networking/oscclient.cpp: Extending constructor to set _active state of OscClient objects to true on initialization. Adding implementation to retrieve the object's _active state. Adding function to deactivate instances of the objects. --- src/networking/oscclient.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 897981c6..a7b18009 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -15,7 +15,9 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel message_level) : _address(hostname, port) , _message_level(message_level) -{} +{ + _active = true; +} /** * Destructor @@ -32,6 +34,25 @@ ssr::MessageLevel ssr::OscClient::message_level() return _message_level; } +/** + * Function to get the OscClient's _active state + * @return a bool, representing the OscClient's state + **/ +bool ssr::OscClient::active() +{ + return _active; +} + +/** + * Function to set the OscClient's _active state + * @param bool, representing the OscClient's new state + **/ +void ssr::OscClient::deactivate() +{ + _active = false; +} + + /** * Function to get the OscClient's _address * @return a lo::Address used for the OscClient From 70fdfb5959311f2be65b4d4bf757817fc97b673d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 14:30:06 +0200 Subject: [PATCH 287/363] src/networking/oscclient.h: Shortening member names of enum class MessageLevel. Changing _address to be non-const. Returning _address by reference in address(). --- src/networking/oscclient.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 88616f19..45a57702 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -14,15 +14,15 @@ namespace ssr enum class MessageLevel : unsigned int { - MESSAGE_LEVEL_SERVER = 0, - MESSAGE_LEVEL_THIN_CLIENT = 1, - MESSAGE_LEVEL_CLIENT = 2 + SERVER = 0, + THIN_CLIENT = 1, + CLIENT = 2 }; class OscClient { private: - const lo::Address _address; + lo::Address _address; MessageLevel _message_level; bool _active = false; @@ -32,7 +32,7 @@ class OscClient ~OscClient(); ssr::MessageLevel message_level(); - lo::Address address(); + lo::Address& address(); bool active(); void deactivate(); void set_message_level(MessageLevel message_level); From c9ba5181d96b995448ec18208954f378b6c11575 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 14:32:17 +0200 Subject: [PATCH 288/363] src/networking/oscclient.cpp: Adding VERBOSE message to constructor. Changing return type of address() to be a lo::Address reference. --- src/networking/oscclient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index a7b18009..91655c71 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -4,6 +4,7 @@ */ #include "oscclient.h" +#include "ssr_global.h" /** * Constructor used to create OSC client objects @@ -17,6 +18,8 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel , _message_level(message_level) { _active = true; + VERBOSE("OscClient: Initialized as " << _address.hostname() << ":" << + _address.port() << "."); } /** @@ -57,7 +60,7 @@ void ssr::OscClient::deactivate() * Function to get the OscClient's _address * @return a lo::Address used for the OscClient **/ -lo::Address ssr::OscClient::address() +lo::Address& ssr::OscClient::address() { return _address; } From fa4cdea4d6a7f8adc5ab0e0efb803e826a04a331 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:51:37 +0200 Subject: [PATCH 289/363] src/networking/oscclient.h: Adding definition of activate(). --- src/networking/oscclient.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 45a57702..c43d02b0 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -34,6 +34,7 @@ class OscClient ssr::MessageLevel message_level(); lo::Address& address(); bool active(); + void activate(); void deactivate(); void set_message_level(MessageLevel message_level); const std::string hostname(); From a41446912cc89dc24a6d95ea9fc9faa314f92094 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:53:39 +0200 Subject: [PATCH 290/363] src/networking/oscclient.cpp: Adding implementation of activate(). Deleting false @param documentation for deactivate(). --- src/networking/oscclient.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 91655c71..7e9e88fc 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -47,14 +47,21 @@ bool ssr::OscClient::active() } /** - * Function to set the OscClient's _active state - * @param bool, representing the OscClient's new state + * Function to set the OscClient's _active state to false **/ void ssr::OscClient::deactivate() { _active = false; } +/** + * Function to set the OscClient's _active state to true + **/ +void ssr::OscClient::activate() +{ + _active = true; +} + /** * Function to get the OscClient's _address From 935ddf61268d9225022b649a44689ab2cdc8a87d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:56:07 +0200 Subject: [PATCH 291/363] src/networking/oschandler.h: Renaming remove_client() friend function to deactivate_client(). --- src/networking/oschandler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 9ae8e70c..c696df8f 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -65,7 +65,8 @@ class OscHandler friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); friend void OscReceiver::add_client(OscHandler& self, lo::Address client); - friend void OscReceiver::remove_client(OscHandler& self, lo::Address client); + friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address + client); }; } // namespace ssr From b341bf8d606e5b637387c0c1b18e960b83d39c76 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 15:57:35 +0200 Subject: [PATCH 292/363] src/networking/oschandler.cpp: Changing implementation of remove_client() to deactivate_client(). --- src/networking/oschandler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 9b6703fd..2b42e576 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -187,14 +187,14 @@ void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) } /** - * OscHandler's friend function to remove a client from the list of OscSender's - * _client_addresses. + * OscHandler's friend function to deactivate a client from the list of + * OscSender's _clients * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be removed + * @param client lo::Address representing client to be deactivated */ -void ssr::OscReceiver::remove_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) { - self._osc_sender.remove_client(client.hostname(), client.port()); + self._osc_sender.deactivate_client(client.hostname(), client.port()); } From d555638ac8758f0e50a8773a879581abad35426d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:00:59 +0200 Subject: [PATCH 293/363] src/networking/oscreceiver.h: Changing definition of remove_client() to deactivate_client. src/networking/oscreceiver.cpp: Changing call to remove_client() to deactivate_client(). --- src/networking/oscreceiver.cpp | 2 +- src/networking/oscreceiver.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0374a70b..007b8c2a 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -84,7 +84,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } else if(message.types().compare("F") == 0) { - remove_client(_handler, client); + deactivate_client(_handler, client); VERBOSE("Client '" << client.hostname() << ":" << client.port() << "' unsubscribed."); } diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 4cd2b9df..01453b4a 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -56,7 +56,7 @@ class OscReceiver void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); void add_client(OscHandler& self, lo::Address client); - void remove_client(OscHandler& self, lo::Address client); + void deactivate_client(OscHandler& self, lo::Address client); }; } // namespace ssr From cfa64efb322b5489df96b443acaa9def725aa4fc Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:34:13 +0200 Subject: [PATCH 294/363] src/networking/oscsender.h: Adding OscClient by including oscclient.h and adding std::vector _clients, (making the std::vector _client_addresses obsolete. Replacing remove_all_client_addresses() by remove_all_clients(). Replacing remove_client() by deactivate_client(). Fixing line wrap. --- src/networking/oscsender.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index b8d62b58..cd145d60 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -15,6 +15,7 @@ #include #include #include +#include "oscclient.h" #include "ssr_global.h" #include "subscriber.h" #include "apf/parameter_map.h" @@ -47,8 +48,10 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; - // vector of pointers to client address objects (server) + // (obsolete) vector of pointers to client address objects (server) std::vector _client_addresses; + // vector of pointers to OscClient objects (server) + std::vector _clients; // map of id/parameter_map pairs for new sources (server) std::map _new_sources; // thread used for calling poll_all_clients continuously @@ -63,7 +66,7 @@ class OscSender : public Subscriber bool server_is_default(); const std::string bool_to_message_type(const bool& message); void poll_all_clients(); - void remove_all_client_addresses(); + void remove_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources bool is_complete_source(id_t id); //< check, if source is complete void send_new_source_message_from_id(id_t id); //< creates a 'new source' OSC message @@ -77,7 +80,7 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void add_client(std::string hostname, std::string port); - void remove_client(std::string hostname, std::string port); + void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message @@ -115,8 +118,8 @@ class OscSender : public Subscriber virtual void set_master_volume(float volume); virtual void set_source_output_levels(id_t id, float* first, float* last); virtual void set_processing_state(bool state); - virtual void set_transport_state( - const std::pair& state); + virtual void set_transport_state( const std::pair& + state); virtual void set_auto_rotation(bool auto_rotate_sources); virtual void set_decay_exponent(float exponent); virtual void set_amplitude_reference_distance(float distance); From 0afaab3431550faabcd2c702adeb2cd61744ce63 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 16:49:05 +0200 Subject: [PATCH 295/363] src/networking/oscsender.cpp: Replacing calls to remove_all_client_addresses() with remove_all_clients(). Sending /poll only to activated clients. Rewriting add_client() to use _clients, reusing clients that were once subscribed and otherwise adding a new OscClient with MessageLevel::CLIENT. Replacing remove_client() by deactivate_client(), which only deactivates the client object, but never deletes it (this is somewhat a memory leak, if too many clients subscribe, that never reconnect again, as clients are only added to the list/reused from the list, but never deleted). Rewriting all functions in Subscriber interface (that require it) to use _clients instead _client_addresses. This makes proper checks to the client objects activate state (and checks for MessageLevel in the future) possible. --- src/networking/oscsender.cpp | 494 +++++++++++++++++++++-------------- 1 file changed, 300 insertions(+), 194 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 80bc36fa..a0a54e3a 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -57,7 +57,7 @@ void ssr::OscSender::stop() _is_subscribed = false; if (is_server()) { - remove_all_client_addresses(); + remove_all_clients(); _poll_all_clients = false; std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -129,15 +129,21 @@ const std::string ssr::OscSender::bool_to_message_type(const bool& message) } /** - * Sends a '/poll' message to all client instances listed in _client_addresses, - * then makes the thread calling this function sleep for 100 milliseconds + * Sends a '/poll' message to all client instances listed in _clients, then + * makes the thread calling this function sleep for 1000 milliseconds */ void ssr::OscSender::poll_all_clients() { VERBOSE("OscSender: Starting to poll all clients."); while(_poll_all_clients) { - send_to_all_clients("/poll", lo::Message()); + for(const auto& client: _clients) + { + if(client && (*client).active()) + { + (*client).address().send_from(_handler.server(), "/poll", ""); + } + } //TODO find better solution to compensate for execution time std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } @@ -400,30 +406,41 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) */ void ssr::OscSender::add_client(std::string hostname, std::string port) { - _client_addresses.push_back(new lo::Address(hostname, port)); - VERBOSE2("OscSender: Added client " << hostname << ":" << port << "."); + bool setup = false; + for (auto& client: _clients) + { + if(client && !((*client).active()) && + (*client).address().hostname().compare(hostname) == 0 && + (*client).address().port().compare(port) == 0 ) + { + (*client).activate(); + setup = true; + VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << + "."); + break; + } + } + if (!setup) + { + _clients.push_back(new OscClient(hostname, port, MessageLevel::CLIENT)); + VERBOSE2("OscSender: Added new client " << hostname << ":" << port << "."); + } } /** - * Removes a client from the vector of clients + * Deactivate a client * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client */ -void ssr::OscSender::remove_client(std::string hostname, std::string port) +void ssr::OscSender::deactivate_client(std::string hostname, std::string port) { - for (auto client = _client_addresses.begin(); client != - _client_addresses.end(); ) + for (auto& client: _clients) { - if(!((*client)->hostname().compare(hostname)) && - !((*client)->port().compare(port))) + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->active()) { - delete *client; - client = _client_addresses.erase(client); - VERBOSE2("OscSender: Removed client " << hostname << ":" << port << "."); - } - else - { - ++client; + (*client).deactivate(); + VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); } } } @@ -431,10 +448,10 @@ void ssr::OscSender::remove_client(std::string hostname, std::string port) /** * Removes all clients from the vector of clients. */ -void ssr::OscSender::remove_all_client_addresses() +void ssr::OscSender::remove_all_clients() { - for (auto client: _client_addresses ) delete client; - _client_addresses.clear(); + for (auto client: _clients) delete client; + _clients.clear(); VERBOSE2("OscSender: Removed all clients."); } @@ -493,13 +510,16 @@ void ssr::OscSender::delete_source(id_t id) int32_t message_id = static_cast(id); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/delete", "i", - message_id); - VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/delete", "i", + message_id); + VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -523,12 +543,15 @@ void ssr::OscSender::delete_all_sources() { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/delete", "i", 0); + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -567,14 +590,17 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/position", "iff", - message_id, position.x, position.y); - VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << - position.x << ", " << position.y << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/position", + "iff", message_id, position.x, position.y); + VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << + position.x << ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -616,14 +642,18 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/position_fixed", - "i"+bool_to_message_type(fixed), message_id); - VERBOSE3("OscSender: Sent [/source/position_fixed, i" << - bool_to_message_type(fixed) << ", " << message_id << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/position_fixed", "i"+bool_to_message_type(fixed), + message_id); + VERBOSE3("OscSender: Sent [/source/position_fixed, i" << + bool_to_message_type(fixed) << ", " << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -664,14 +694,17 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/orientation", - "if", message_id, message_orientation); - VERBOSE3("OscSender: Sent [/source/orientation, if, " << - message_id << ", " << message_orientation << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/orientation", "if", message_id, message_orientation); + VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id + << ", " << message_orientation << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -712,14 +745,16 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/volume", "if", - message_id, gain); - VERBOSE3("OscSender: Sent [/source/volume, if, " << - message_id << ", " << gain << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/volume", + "if", message_id, gain); + VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << + ", " << gain << "] to client " << (*client).address().hostname() + << ":" << (*client).address().port() << "."); + } } } } @@ -760,14 +795,17 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/mute", - "i"+bool_to_message_type(mute), message_id); - VERBOSE3("OscSender: Sent [/source/mute, i" << - bool_to_message_type(mute) << ", " << message_id << "] to client " - << client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/mute", + "i"+bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/source/mute, i" << + bool_to_message_type(mute) << ", " << message_id << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -808,13 +846,17 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/name", "is", - message_id, message_name); - VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << - message_name << "] to client " << client_address->hostname() << ":" - << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/name", + "is", message_id, message_name); + VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " + << message_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -857,14 +899,17 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/properties_file", - "is", message_id, file_name); - VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id - << ", " << file_name << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/properties_file", "is", message_id, file_name); + VERBOSE3("OscSender: Sent [/source/properties_file, is, " << + message_id << ", " << file_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -891,13 +936,16 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/decay_exponent", - "f", exponent); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/decay_exponent", "f", exponent); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -924,13 +972,16 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/amplitude_reference_distance", "f", distance); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/amplitude_reference_distance", "f", distance); + VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -970,13 +1021,17 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/model", "is", - message_id, message_model.c_str()); - VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " - << message_model << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/model", + "is", message_id, message_model.c_str()); + VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " + << message_model << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1019,13 +1074,17 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/port_name", "is", - message_id, port_name.c_str()); - VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << - ", " << port_name << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/port_name", + "is", message_id, port_name.c_str()); + VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << + ", " << port_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1071,15 +1130,18 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/source/file_name_or_port_number", "is", message_id, - file_name.c_str()); - VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << - message_id << ", " << file_name << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/file_name_or_port_number", "is", message_id, + file_name.c_str()); + VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << + message_id << ", " << file_name << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1123,14 +1185,17 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/file_channel", - "ii", message_id, message_file_channel); - VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << - ", " << message_file_channel << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/source/file_channel", "ii", message_id, message_file_channel); + VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id + << ", " << message_file_channel << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1186,13 +1251,17 @@ void ssr::OscSender::set_reference_position(const Position& position) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/reference/position", "ff", - position.x, position.y); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/reference/position", + "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1219,13 +1288,17 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/reference/orientation", - "f", orientation.azimuth); - VERBOSE3("OscSender: Sent [/reference/orientation, f, " << - orientation.azimuth << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference/orientation, f, " << + orientation.azimuth << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1253,13 +1326,17 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/reference_offset/position", "ff", position.x, position.y); - VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference_offset/position", "ff", position.x, position.y); + VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << + position.x << ", " << position.y << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1289,13 +1366,17 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/reference_offset/orientation", "f", orientation.azimuth); - VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << - orientation.azimuth << "] to client " << client_address->hostname() - << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/reference_offset/orientation", "f", orientation.azimuth); + VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << + orientation.azimuth << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1323,13 +1404,16 @@ void ssr::OscSender::set_master_volume(float volume) float message_volume = apf::math::linear2dB(volume); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/volume", "f", - message_volume); - VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/scene/volume", "f", + message_volume); + VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << + "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } else if(is_client() && !server_is_default()) @@ -1373,13 +1457,17 @@ void ssr::OscSender::set_processing_state(bool state) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/processing/state", - bool_to_message_type(state)); - VERBOSE3("OscSender: Sent [/processing/state, " << - bool_to_message_type(state) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/processing/state", + bool_to_message_type(state)); + VERBOSE3("OscSender: Sent [/processing/state, " << + bool_to_message_type(state) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1411,19 +1499,22 @@ void ssr::OscSender::set_transport_state( const std::pair= 2) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); - client_address->send_from(_handler.server(), "/transport/seek", "i", - message_nframes); - VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + (*client).address().send_from(_handler.server(), "/transport/seek", + "i", message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes + << "] to client " << (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1461,14 +1552,18 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); - VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/auto_rotate_sources", + bool_to_message_type(auto_rotate_sources)); + VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << + bool_to_message_type(auto_rotate_sources) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1489,10 +1584,10 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) * @param load a float representing the current cpu load * @todo implement receiver callback in * OscReceiver::add_server_to_client_methods() + * @todo implement pooling of cpu_load updates */ void ssr::OscSender::set_cpu_load(float load) { - //TODO: implement pooling of cpu_load updates if(is_client() && !server_is_default()) { if(_handler.message_level() >= 2) @@ -1521,13 +1616,17 @@ void ssr::OscSender::set_sample_rate(int sr) int32_t message_sr = static_cast(sr); if(is_server()) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/scene/sample_rate", "i", - message_sr); - VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to client " << - client_address->hostname() << ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/scene/sample_rate", + "i", message_sr); + VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << + apf::str::A2S(message_sr) << "] to client " << + (*client).address().hostname() << ":" << (*client).address().port() + << "."); + } } } else if(is_client() && !server_is_default()) @@ -1557,14 +1656,17 @@ void ssr::OscSender::set_master_signal_level(float level) { if(_handler.message_level() >= 1) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), - "/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << - client_address->hostname() << ":" << client_address->port() << - "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } @@ -1601,13 +1703,17 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { if(_handler.message_level() >= 1) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), "/source/level", "if", - message_id, message_level); - VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << client_address->hostname() << - ":" << client_address->port() << "."); + if(client && client->active()) + { + (*client).address().send_from(_handler.server(), "/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << + (*client).address().hostname() << ":" << + (*client).address().port() << "."); + } } } } From ed5333bf04136fdcabae235e0d02bd52514cc3b7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 22:33:47 +0200 Subject: [PATCH 296/363] src/networking/oscclient.h: Adding GUI_CLIENT to MessageLevel enum. --- src/networking/oscclient.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index c43d02b0..2a830de4 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -16,7 +16,8 @@ enum class MessageLevel : unsigned int { SERVER = 0, THIN_CLIENT = 1, - CLIENT = 2 + CLIENT = 2, + GUI_CLIENT = 3 }; class OscClient From 8823dc900d13031b7ffa0d52088054847d63c944 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 31 May 2017 22:37:01 +0200 Subject: [PATCH 297/363] src/networking/oscsender.cpp: Removing unneeded calls through this pointer. Changing all calls to clients to use -> --- src/networking/oscsender.cpp | 184 +++++++++++++++++------------------ 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index a0a54e3a..cefdec20 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -139,9 +139,9 @@ void ssr::OscSender::poll_all_clients() { for(const auto& client: _clients) { - if(client && (*client).active()) + if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/poll", ""); + client->address().send_from(_handler.server(), "/poll", ""); } } //TODO find better solution to compensate for execution time @@ -409,11 +409,11 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) bool setup = false; for (auto& client: _clients) { - if(client && !((*client).active()) && - (*client).address().hostname().compare(hostname) == 0 && - (*client).address().port().compare(port) == 0 ) + if(client && !(client->active()) && + !(client->address().hostname().compare(hostname)) && + !(client->address().port().compare(port)) ) { - (*client).activate(); + client->activate(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << "."); @@ -439,7 +439,7 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) if(!(client->hostname().compare(hostname)) && !(client->port().compare(port)) && client->active()) { - (*client).deactivate(); + client->deactivate(); VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); } } @@ -482,10 +482,10 @@ void ssr::OscSender::new_source(id_t id) { if(is_server()) { - if(!this->is_new_source(id)) + if(!is_new_source(id)) _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else if(is_client()) { @@ -514,11 +514,11 @@ void ssr::OscSender::delete_source(id_t id) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/delete", "i", + client->address().send_from(_handler.server(), "/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -547,9 +547,9 @@ void ssr::OscSender::delete_all_sources() { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/delete", "i", 0); + client->address().send_from(_handler.server(), "/source/delete", "i", 0); VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -586,7 +586,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) _new_sources.at(id).set("x", position.x); _new_sources.at(id).set("y", position.y); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -594,12 +594,12 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/position", + client->address().send_from(_handler.server(), "/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -638,7 +638,7 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { _new_sources.at(id).set("position_fixed", fixed); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -646,13 +646,13 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/position_fixed", "i"+bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << bool_to_message_type(fixed) << ", " << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -690,7 +690,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { _new_sources.at(id).set("orientation", orientation.azimuth); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -698,12 +698,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id << ", " << message_orientation << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -741,7 +741,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { _new_sources.at(id).set("volume", gain); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -749,11 +749,11 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/volume", + client->address().send_from(_handler.server(), "/source/volume", "if", message_id, gain); VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << - ", " << gain << "] to client " << (*client).address().hostname() - << ":" << (*client).address().port() << "."); + ", " << gain << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } @@ -799,12 +799,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/mute", + client->address().send_from(_handler.server(), "/source/mute", "i"+bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << bool_to_message_type(mute) << ", " << message_id << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -842,7 +842,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { _new_sources.at(id).set("name", name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -850,12 +850,12 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/name", + client->address().send_from(_handler.server(), "/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " << message_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -895,7 +895,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { _new_sources.at(id).set("properties_file", name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -903,12 +903,12 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << message_id << ", " << file_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -940,11 +940,11 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -976,11 +976,11 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1017,7 +1017,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { _new_sources.at(id).set("model", message_model); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1025,12 +1025,12 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/model", + client->address().send_from(_handler.server(), "/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " << message_model << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1070,7 +1070,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& { _new_sources.at(id).set("port_name", port_name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1078,12 +1078,12 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/port_name", + client->address().send_from(_handler.server(), "/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << ", " << port_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1126,7 +1126,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& _new_sources.at(id).set("file_name_or_port_number", file_name); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1134,13 +1134,13 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1181,7 +1181,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { _new_sources.at(id).set("channel", file_channel); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -1189,12 +1189,12 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1255,11 +1255,11 @@ void ssr::OscSender::set_reference_position(const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/reference/position", + client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1292,11 +1292,11 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << orientation.azimuth << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1330,11 +1330,11 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << position.x << ", " << position.y << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1370,11 +1370,11 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << orientation.azimuth << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1408,11 +1408,11 @@ void ssr::OscSender::set_master_volume(float volume) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/scene/volume", "f", + client->address().send_from(_handler.server(), "/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1461,11 +1461,11 @@ void ssr::OscSender::set_processing_state(bool state) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/processing/state", + client->address().send_from(_handler.server(), "/processing/state", bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << bool_to_message_type(state) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1503,17 +1503,17 @@ void ssr::OscSender::set_transport_state( const std::pairactive()) { - (*client).address().send_from(_handler.server(), "/transport/state", + client->address().send_from(_handler.server(), "/transport/state", bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << bool_to_message_type(state.first) << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); - (*client).address().send_from(_handler.server(), "/transport/seek", + client->address().hostname() << ":" << + client->address().port() << "."); + client->address().send_from(_handler.server(), "/transport/seek", "i", message_nframes); VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes - << "] to client " << (*client).address().hostname() << ":" << - (*client).address().port() << "."); + << "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1556,12 +1556,12 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/auto_rotate_sources", bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << bool_to_message_type(auto_rotate_sources) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1620,11 +1620,11 @@ void ssr::OscSender::set_sample_rate(int sr) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/scene/sample_rate", + client->address().send_from(_handler.server(), "/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << apf::str::A2S(message_sr) << "] to client " << - (*client).address().hostname() << ":" << (*client).address().port() + client->address().hostname() << ":" << client->address().port() << "."); } } @@ -1660,12 +1660,12 @@ void ssr::OscSender::set_master_signal_level(float level) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), + client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << apf::str::A2S(message_level) << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1707,12 +1707,12 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { if(client && client->active()) { - (*client).address().send_from(_handler.server(), "/source/level", + client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " << message_level << "] to client " << - (*client).address().hostname() << ":" << - (*client).address().port() << "."); + client->address().hostname() << ":" << + client->address().port() << "."); } } } From c3d0eab80d54991673da0c9ff92eb554e4c86e61 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 02:26:07 +0200 Subject: [PATCH 298/363] src/networking/oscsender.cpp: Adding check for size to is_complete_source(). Implementing send_new_source_message_from_id(). Fixing various calls to _new_sources, as it would otherwise trigger multiple calls to send_new_source_message_from_id(). Removing server-side execution in set_port_name(), as port_name is a local setting and depends on port_name prefix (which must always be kept local). --- src/networking/oscsender.cpp | 189 ++++++++++++++++++++--------------- 1 file changed, 111 insertions(+), 78 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index cefdec20..57e99f42 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -312,7 +312,8 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted"))|| + _new_sources.at(id).has_key("mute") && + _new_sources.at(id).size() == 12)|| (_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && _new_sources.at(id).has_key("file_name_or_port_number") && @@ -322,21 +323,21 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("volume") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted"))) + _new_sources.at(id).has_key("mute") && + _new_sources.at(id).size() == 10)) is_complete = true; } return is_complete; } /** - * Creates a lo::Message used to create a new source on clients. It will + * Creates a message used to create a new source on clients. It will * collect all parameters from a parameter_map in _new_sources according to an * id. * @param id id_t id of the local source a message will be created for. */ void ssr::OscSender::send_new_source_message_from_id(id_t id) { - lo::Message message; if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && _new_sources.at(id).has_key("file_name_or_port_number") && @@ -348,26 +349,53 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted") && - _new_sources.at(id).size() == 12 ) - { - message.add_string(_new_sources.at(id).get("name", "")); - message.add_string(_new_sources.at(id).get("model", "")); - message.add_string(_new_sources.at(id).get("file_name_or_port_number", - "")); - message.add_float(_new_sources.at(id).get("x", 0.0)); - message.add_float(_new_sources.at(id).get("y", 0.0)); - message.add_float(_new_sources.at(id).get("orientation", 0.0)); - message.add_float(_new_sources.at(id).get("volume", 0.0)); - message.add_int32(_new_sources.at(id).get("channel", 1)); - message.add_string(_new_sources.at(id).get("properties_file", "")); - (_new_sources.at(id).get("position_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("orientation_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("muted", false)? - message.add_true(): message.add_false()); - this->send_to_all_clients("/source/new", message); + _new_sources.at(id).has_key("mute")) + { + for (const auto& client: _clients) + { + if(client && client->active()) + { + client->address().send_from(_handler.server(), "/source/new", + "sssffffis"+ + bool_to_message_type(_new_sources.at(id).get( + "position_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get( + "orientation_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get( + "mute", false)), + _new_sources.at(id).get("name", "").c_str(), + _new_sources.at(id).get("model", "").c_str(), + _new_sources.at(id).get( + "file_name_or_port_number","").c_str(), + _new_sources.at(id).get("x", 0.0), + _new_sources.at(id).get("y", 0.0), + _new_sources.at(id).get("orientation", 0.0), + _new_sources.at(id).get("volume", 0.0), + _new_sources.at(id).get("channel", 1), + _new_sources.at(id).get("properties_file", "")); + VERBOSE2("OscSender: Sent [/source/new, sssffffis" << + bool_to_message_type(_new_sources.at(id).get( + "position_fixed", false)) << + bool_to_message_type(_new_sources.at(id).get( + "orientation_fixed", false)) << + bool_to_message_type(_new_sources.at(id).get("mute", + false)) << + ", " << + _new_sources.at(id).get("name", "") << ", " << + _new_sources.at(id).get("model", "") << ", " << + _new_sources.at(id).get("file_name_or_port_number","") + << ", " << + _new_sources.at(id).get("x", 0.0) << ", " << + _new_sources.at(id).get("y", 0.0) << ", " << + _new_sources.at(id).get("orientation", 0.0) << ", " << + _new_sources.at(id).get("volume", 0.0) << ", " << + _new_sources.at(id).get("channel", 1) << ", " << + _new_sources.at(id).get("properties_file", "") + << "] to client " << + client->address().hostname() << ":" << + client->address().port() << "."); + } + } } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -378,24 +406,48 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("volume") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && - _new_sources.at(id).has_key("muted") && - _new_sources.at(id).size() == 10 ) - { - message.add_string(_new_sources.at(id).get("name", "")); - message.add_string(_new_sources.at(id).get("model", "")); - message.add_string(_new_sources.at(id).get("file_name_or_port_number", - "")); - message.add_float(_new_sources.at(id).get("x", 0.0)); - message.add_float(_new_sources.at(id).get("y", 0.0)); - message.add_float(_new_sources.at(id).get("orientation", 0.0)); - message.add_float(_new_sources.at(id).get("volume", 0.0)); - (_new_sources.at(id).get("position_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("orientation_fixed", false)? - message.add_true(): message.add_false()); - (_new_sources.at(id).get("muted", false)? - message.add_true(): message.add_false()); - this->send_to_all_clients("/source/new", message); + _new_sources.at(id).has_key("mute")) + { + for (const auto& client: _clients) + { + if(client && client->active()) + { + client->address().send_from(_handler.server(), "/source/new", + "sssffff"+ + bool_to_message_type( + _new_sources.at(id).get("position_fixed", false)) + +bool_to_message_type( + _new_sources.at(id).get("orientation_fixed", false)) + +bool_to_message_type(_new_sources.at(id).get("mute", + false)), + _new_sources.at(id).get("name", "").c_str(), + _new_sources.at(id).get("model", "").c_str(), + _new_sources.at(id).get( + "file_name_or_port_number","").c_str(), + _new_sources.at(id).get("x", 0.0), + _new_sources.at(id).get("y", 0.0), + _new_sources.at(id).get("orientation", 0.0), + _new_sources.at(id).get("volume", 0.0)); + VERBOSE2("OscSender: Sent [/source/new, sssffff" << + bool_to_message_type( + _new_sources.at(id).get( "position_fixed", false)) << + bool_to_message_type( + _new_sources.at(id).get("orientation_fixed", false)) << + bool_to_message_type( + _new_sources.at(id).get("mute", false)) << ", " << + _new_sources.at(id).get("name", "") << ", " << + _new_sources.at(id).get("model", "") << ", " << + _new_sources.at(id).get("file_name_or_port_number","") + << ", " << + _new_sources.at(id).get("x", 0.0) << ", " << + _new_sources.at(id).get("y", 0.0) << ", " << + _new_sources.at(id).get("orientation", 0.0) << ", " << + _new_sources.at(id).get("volume", 0.0) + << "] to client " << + client->address().hostname() << ":" << + client->address().port() << "."); + } + } } } @@ -419,6 +471,14 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) "."); break; } + else if(client && client->active() && + !(client->address().hostname().compare(hostname)) && + !(client->address().port().compare(port)) ) + { + setup = true; + VERBOSE2("OscSender: Client " << hostname << ":" << port << + " already active."); + } } if (!setup) { @@ -630,7 +690,6 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) */ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { -// lo::Message message; int32_t message_id = static_cast(id); if(is_server()) { @@ -689,6 +748,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& if(is_new_source(id)) { _new_sources.at(id).set("orientation", orientation.azimuth); + _new_sources.at(id).set("orientation_fixed", false); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -787,11 +847,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) int32_t message_id = static_cast(id); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && + _new_sources.at(id).has_key("file_name_or_port_number")) { _new_sources.at(id).set("mute", mute); if(is_complete_source(id)) - this->send_new_source_message_from_id(id); + send_new_source_message_from_id(id); } else { @@ -886,14 +947,13 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { - lo::Message message; int32_t message_id = static_cast(id); const char * file_name = name.c_str(); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && !name.empty()) { - _new_sources.at(id).set("properties_file", name); + _new_sources.at(id).set("properties_file", file_name); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1048,10 +1108,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) /** * Subscriber function called, when Publisher set a source's port_name. - * On server: Sends out OSC message to set the port_name of given source on all - * clients. If id is found in _new_sources, the port_name will be stored in the - * parameter_map for id and an OSC message will be send to clients only, if the - * source is complete. + * On server: Does nothing, as port_name is local and depends on prefix * On client: Sends out OSC message to server about the successful updating of * the source's port_name. * @param id id_t representing the source @@ -1064,31 +1121,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { int32_t message_id = static_cast(id); - if(is_server()) - { - if(is_new_source(id)) - { - _new_sources.at(id).set("port_name", port_name); - if(is_complete_source(id)) - send_new_source_message_from_id(id); - } - else - { - for (const auto& client: _clients) - { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/source/port_name", - "is", message_id, port_name.c_str()); - VERBOSE3("OscSender: Sent [/source/port_name, is, " << message_id << - ", " << port_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } - } - } - } - else if(is_client() && !server_is_default()) + if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); @@ -1177,7 +1210,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) int32_t message_file_channel = static_cast(file_channel); if(is_server()) { - if(is_new_source(id)) + if(is_new_source(id) && file_channel > 0) { _new_sources.at(id).set("channel", file_channel); if(is_complete_source(id)) From 995386671c1098078059ba18c9c3e0f2df396c8d Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:34:27 +0200 Subject: [PATCH 299/363] src/networking/oschandler.h: Removing definition of _message_level and message_level(). src/networking/oschandler.cpp: Removing implementation of message_level(). --- src/networking/oschandler.cpp | 8 -------- src/networking/oschandler.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 2b42e576..4a9fe469 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -216,11 +216,3 @@ lo::ServerThread& ssr::OscHandler::server() return _server; } -/** - * Return reference to current _message_level - * @return const unsigned int& - */ -const unsigned int& ssr::OscHandler::message_level() -{ - return _message_level; -} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index c696df8f..67258345 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -38,7 +38,6 @@ class OscHandler lo::ServerThread _server; //< ServerThread used for OSC communication OscReceiver _osc_receiver; OscSender _osc_sender; - const unsigned int _message_level = 2; public: OscHandler(Publisher& controller, int port, std::string mode, @@ -48,7 +47,6 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); - const unsigned int& message_level(); friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 3d7c37ca58a9329fcf12d345944eb1241129351d Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:35:45 +0200 Subject: [PATCH 300/363] src/networking/oscsender.h: Adding MessageLevel type _message_level to store a clients level of messages sent towards their server. This can be set with the set_message_level() function, defined here. --- src/networking/oscsender.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index cd145d60..88c799dd 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -48,6 +48,8 @@ class OscSender : public Subscriber bool _is_subscribed; // address of server (client) lo::Address _server_address; + // level of messages to send to server (client) + MessageLevel _message_level; // (obsolete) vector of pointers to client address objects (server) std::vector _client_addresses; // vector of pointers to OscClient objects (server) @@ -79,6 +81,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string hostname, std::string port); lo::Address server_address(); + void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); From 5a1f74d4286f3578e6316610f7fd423b770ecbc4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 03:39:02 +0200 Subject: [PATCH 301/363] src/networking/oscsender.cpp: Unifying use of compare for is_client()/is_server(). Switching to using _message_level of OscSender instead of (now deleted) OscHandler in all very fast client to server messages. --- src/networking/oscsender.cpp | 160 +++++++++++++++++------------------ 1 file changed, 78 insertions(+), 82 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 57e99f42..5b90f71d 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -19,6 +19,7 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) , _server_address("none", "50001") + , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); } @@ -69,7 +70,7 @@ void ssr::OscSender::stop() */ bool ssr::OscSender::is_client() { - if(_handler.mode() == "client") + if(!_handler.mode().compare("client")) { return true; } @@ -85,7 +86,7 @@ bool ssr::OscSender::is_client() */ bool ssr::OscSender::is_server() { - if(_handler.mode() == "server") + if(!_handler.mode().compare("server")) { return true; } @@ -160,6 +161,16 @@ lo::Address ssr::OscSender::server_address() return server; } +/** + * Function to set OscSender's _message_level. + * If the message level is out of + * @param MessageLevel enum representing the new message level + */ +void ssr::OscSender::set_message_level(const unsigned int& message_level) +{ + _message_level = static_cast(message_level); +} + /** * Function to set OscSender's _server_address * @param server_address a lo::Address to be used as _server_address @@ -1530,42 +1541,38 @@ void ssr::OscSender::set_transport_state( const std::pair(state.second); if(is_server()) { - if(_handler.message_level() >= 2) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - client->address().send_from(_handler.server(), "/transport/seek", - "i", message_nframes); - VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes - << "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), "/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/transport/state, " << + bool_to_message_type(state.first) << "] to client " << + client->address().hostname() << ":" << client->address().port() << + "."); + client->address().send_from(_handler.server(), "/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 2) - { - _server_address.send_from(_handler.server(), "/update/transport/state", - bool_to_message_type(state.first)); - VERBOSE3("OscSender: Sent [/update/transport/state, " << - bool_to_message_type(state.first) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); - _server_address.send_from(_handler.server(), "/update/transport/seek", - "i", message_nframes); - VERBOSE3("OscSender: Sent [/update/transport/state, i, " << - message_nframes << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/transport/state", + bool_to_message_type(state.first)); + VERBOSE3("OscSender: Sent [/update/transport/state, " << + bool_to_message_type(state.first) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); + _server_address.send_from(_handler.server(), "/update/transport/seek", "i", + message_nframes); + VERBOSE3("OscSender: Sent [/update/transport/state, i, " << message_nframes + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1621,16 +1628,14 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) */ void ssr::OscSender::set_cpu_load(float load) { - if(is_client() && !server_is_default()) + if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 2) - { - _server_address.send_from(_handler.server(), "/update/cpu_load", "f", - load); - VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) - << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/cpu_load", "f", + load); + VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) + << "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } } @@ -1687,32 +1692,28 @@ void ssr::OscSender::set_master_signal_level(float level) float message_level(apf::math::linear2dB(level)); if(is_server()) { - if(_handler.message_level() >= 1) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), - "/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), + "/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to client " << + client->address().hostname() << ":" << client->address().port() << + "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 1) - { - _server_address.send_from(_handler.server(), - "/update/scene/master_signal_level", "f", message_level); - VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), + "/update/scene/master_signal_level", "f", message_level); + VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << + apf::str::A2S(message_level) << "] to server " << + _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1734,33 +1735,28 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) float message_level(apf::math::linear2dB(level)); if(is_server()) { - if(_handler.message_level() >= 1) + for (const auto& client: _clients) { - for (const auto& client: _clients) + if(client && client->active() && client->message_level() >= + MessageLevel::CLIENT) { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/source/level", - "if", message_id, message_level); - VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); - } + client->address().send_from(_handler.server(), "/source/level", "if", + message_id, message_level); + VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " + << message_level << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } - else if(is_client() && !server_is_default()) + else if(is_client() && !server_is_default() && _message_level == + MessageLevel::GUI_CLIENT) { - if(_handler.message_level() >= 1) - { - _server_address.send_from(_handler.server(), "/update/source/level", - "if", message_id, message_level); - VERBOSE3("OscSender: Sent [/update/source/level, if, " << - apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); - } + _server_address.send_from(_handler.server(), "/update/source/level", + "if", message_id, message_level); + VERBOSE3("OscSender: Sent [/update/source/level, if, " << + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } From 9c2535c425cf1d4560e1be234160c8d8d3a28eba Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 19:56:07 +0200 Subject: [PATCH 302/363] src/ssr_global.h: Adding enum class MessageLevel for easier include. --- src/ssr_global.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ssr_global.h b/src/ssr_global.h index 9e269eb2..efb117c4 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -51,6 +51,13 @@ extern float c; ///< speed of sound (meters per second) extern float c_inverse; ///< reciprocal value of c /// time to sleep after connecting a new soundfile with ecasound extern unsigned int usleeptime; +enum class MessageLevel : id_t +{ + SERVER = 0, + THIN_CLIENT = 1, + CLIENT = 2, + GUI_CLIENT = 3 +}; } // namespace ssr From cdfa31f595d06f353ea3aeb04739243a67025f57 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:04:13 +0200 Subject: [PATCH 303/363] src/networking/oscclient.h: Adding include for ssr_global.h for VERBOSE and MessageLevel. Removing enum class MessageLevel (now in ssr_global). src/networking/oscclient.cpp: Removing include for ssr_global.h (now in header). --- src/networking/oscclient.cpp | 1 - src/networking/oscclient.h | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 7e9e88fc..f1030028 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -4,7 +4,6 @@ */ #include "oscclient.h" -#include "ssr_global.h" /** * Constructor used to create OSC client objects diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 2a830de4..e975c94c 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -8,18 +8,11 @@ #include #include +#include "ssr_global.h" // for VERBOSE, MessageLevel namespace ssr { -enum class MessageLevel : unsigned int -{ - SERVER = 0, - THIN_CLIENT = 1, - CLIENT = 2, - GUI_CLIENT = 3 -}; - class OscClient { private: From 0d5f5b9c18722df0f08f3511e6a9a7bf95d05871 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:10:03 +0200 Subject: [PATCH 304/363] src/networking/oscreceiver.h: Adding comment for include. Adding set_message_level() (friend function for OscHandler). Changing add_client to use a MessageLevel parameter. Line wraps. src/networking/oscreceiver.cpp: Style changes for string compare in start(). Updating callback handler for /subscribe message to also be able to set an inital message_level for the client subscribing. Prettifying VERBOSE output in /subscribe callback handler. Adding callback handler for /message_level, enabling clients to set their own message_level (the amount of messages received from the server, defaults to MessageLevel::CLIENT - which is a lot of messages (some unneeded probably) already). --- src/networking/oscreceiver.cpp | 42 ++++++++++++++++++++++++---------- src/networking/oscreceiver.h | 13 +++++++---- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 007b8c2a..6f0c5859 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -39,12 +39,12 @@ void ssr::OscReceiver::start() { VERBOSE("OscReceiver: Starting."); // add method handlers for received messages - if (_handler.mode() == "server") + if (!_handler.mode().compare("server")) { add_client_to_server_methods(); VERBOSE("OscReceiver: Added client-to-server callbacks."); } - else if (_handler.mode() == "client") + else if (!_handler.mode().compare("client")) { add_server_to_client_methods(); VERBOSE("OscReceiver: Added server-to-client callbacks."); @@ -69,29 +69,47 @@ void ssr::OscReceiver::add_client_to_server_methods() // add local reference to OscHandler's lo::ServerThread for add_method() lo::ServerThread& server = _handler.server(); - // adding new subscribing client: "/subscribe, T" + // adding new subscribing client: "/subscribe, {T,Ti,F}" server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); - (void) argv; - VERBOSE2("Subscribe called with " << message.types() << "."); - if(message.types().compare("T") == 0) + if(!message.types().compare("T")) { - add_client(_handler, client); - VERBOSE("Client '" << client.hostname() << ":" << client.port() << - "' subscribed."); + VERBOSE2("OscReceiver: Got subscribe request from '" << + client.hostname() << ":" << client.port() << "'."); + add_client(_handler, client, ssr::MessageLevel::CLIENT); } - else if(message.types().compare("F") == 0) + else if(!message.types().compare("F")) { + VERBOSE2("OscReceiver: Got unsubscribe request from '" << + client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); - VERBOSE("Client '" << client.hostname() << ":" << client.port() << - "' unsubscribed."); + } + else if(!message.types().compare("Ti")) + { + VERBOSE2("OscReceiver: Got subscribe request from '" << + client.hostname() << ":" << client.port() << + "' for message level: " << argv[1]->i); + add_client(_handler, client, static_cast(argv[1]->i)); } } ); VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + // adding new subscribing client: "/message_level, i" + server.add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message + message) + { + lo::Address client(message.source()); + VERBOSE2("OscReceiver: Got request to set message level for client '" << + client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + set_message_level(_handler, client, + static_cast(argv[0]->i)); + } + ); + VERBOSE("OscReceiver: Added method for /message_level."); + // update on new source: "/update/source/new, i, id" server.add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 01453b4a..696da2b3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -15,7 +15,7 @@ #include #include -#include "ssr_global.h" +#include "ssr_global.h" // for VERBOSE, MessageLevel namespace ssr { @@ -51,12 +51,17 @@ class OscReceiver std::string path, lo::Message message); void send_to_client(OscHandler& self, lo::Address client_address, lo::Bundle bundle); - void send_to_all_clients(OscHandler& self, std::string path, lo::Message message); + void send_to_all_clients(OscHandler& self, std::string path, lo::Message + message); void send_to_all_clients(OscHandler& self, lo::Bundle bundle); - void send_to_server(OscHandler& self, std::string path, lo::Message message); + void send_to_server(OscHandler& self, std::string path, lo::Message + message); void send_to_server(OscHandler& self, lo::Bundle bundle); - void add_client(OscHandler& self, lo::Address client); + void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel + message_level); void deactivate_client(OscHandler& self, lo::Address client); + void set_message_level(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level); }; } // namespace ssr From a59a95e005993825d21711fd709d0540bb6e9b17 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:13:51 +0200 Subject: [PATCH 305/363] src/networking/oscsender.h: Adding comment for include. Updating add_client() to use an additional parameter for MessageLevel. Adding set_client_message_level(). src/networking/oscsender.cpp: Adding implementation of set_client_message_level(). Changing add_client() to use the MessageLevel provided as parameter. Updating VERBOSE output for add_client(). --- src/networking/oscsender.cpp | 33 ++++++++++++++++++++++++++++++--- src/networking/oscsender.h | 7 +++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 5b90f71d..0d5df6fa 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -467,7 +467,8 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client */ -void ssr::OscSender::add_client(std::string hostname, std::string port) +void ssr::OscSender::add_client(std::string hostname, std::string port, + ssr::MessageLevel message_level) { bool setup = false; for (auto& client: _clients) @@ -476,6 +477,8 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) !(client->address().hostname().compare(hostname)) && !(client->address().port().compare(port)) ) { + if(client->message_level() != message_level) + client->set_message_level(message_level); client->activate(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << @@ -493,8 +496,10 @@ void ssr::OscSender::add_client(std::string hostname, std::string port) } if (!setup) { - _clients.push_back(new OscClient(hostname, port, MessageLevel::CLIENT)); - VERBOSE2("OscSender: Added new client " << hostname << ":" << port << "."); + _clients.push_back(new OscClient(hostname, port, message_level)); + VERBOSE2("OscSender: Added new client " << hostname << ":" << port << + " using message level " << static_cast(message_level) << + "."); } } @@ -516,6 +521,28 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) } } +/** + * Set message level of a client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + * @param message_level ssr::MessageLevel enum representing the message level + * to use + */ +void ssr::OscSender::set_client_message_level(std::string hostname, std::string + port, ssr::MessageLevel message_level) +{ + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port))) + { + client->set_message_level(message_level); + VERBOSE2("OscSender: Set message level of client '" << hostname << ":" << + port << "' to: " << static_cast(message_level) << "."); + } + } +} + /** * Removes all clients from the vector of clients. */ diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 88c799dd..4453337f 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -16,7 +16,7 @@ #include #include #include "oscclient.h" -#include "ssr_global.h" +#include "ssr_global.h" // for VERBOSE, MessageLevel #include "subscriber.h" #include "apf/parameter_map.h" @@ -82,7 +82,10 @@ class OscSender : public Subscriber void set_server_address(std::string hostname, std::string port); lo::Address server_address(); void set_message_level(const unsigned int& message_level); - void add_client(std::string hostname, std::string port); + void add_client(std::string hostname, std::string port, ssr::MessageLevel + message_level); + void set_client_message_level(std::string hostname, std::string port, + ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From f6ff6a581c47c598ca03595b1300266304f2eee6 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 1 Jun 2017 20:16:57 +0200 Subject: [PATCH 306/363] src/networking/oschandler.h: Adding include ssr_global.h for MessageLevel. Updating friend function add_client() to include MessageLevel parameter. adding friend function set_message_level(). src/networking/oschandler.cpp: Updating call to add_client() in constructor and implementation of add_client() to incorporate MessageLevel parameter. Adding implementation of friend function set_message_level(). --- src/networking/oschandler.cpp | 20 +++++++++++++++++--- src/networking/oschandler.h | 7 +++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 4a9fe469..27810c98 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -31,7 +31,8 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, VERBOSE("OscHandler: " << clients.size() << " client(s)."); for (const auto& client: clients) { - _osc_sender.add_client(client.first, std::to_string(client.second)); + _osc_sender.add_client(client.first, std::to_string(client.second), + ssr::MessageLevel::CLIENT); } } } @@ -181,9 +182,10 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) * @param self reference to OscHandler holding OscSender * @param client lo::Address representing client to be added */ -void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level = ssr::MessageLevel::CLIENT) { - self._osc_sender.add_client(client.hostname(), client.port()); + self._osc_sender.add_client(client.hostname(), client.port(), message_level); } /** @@ -197,6 +199,18 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) self._osc_sender.deactivate_client(client.hostname(), client.port()); } +/** + * OscHandler's friend function to set a client's message_level + * @param self reference to OscHandler holding OscSender + * @param client lo::Address representing client to be deactivated + */ +void ssr::OscReceiver::set_message_level(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level) +{ + self._osc_sender.set_client_message_level(client.hostname(), client.port(), + message_level); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 67258345..371d71fa 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -14,7 +14,7 @@ #include #include #include - +#include "ssr_global.h" // for VERBOSE, MessageLevel #include "oscreceiver.h" #include "oscsender.h" @@ -62,9 +62,12 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); - friend void OscReceiver::add_client(OscHandler& self, lo::Address client); + friend void OscReceiver::add_client(OscHandler& self, lo::Address client, + ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address client); + friend void OscReceiver::set_message_level(OscHandler& self, lo::Address + client, ssr::MessageLevel message_level); }; } // namespace ssr From 1885a08b58f8dede23ecc52d8a6ccfd6f0be3967 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 2 Jun 2017 15:25:46 +0200 Subject: [PATCH 307/363] src/networking/oscreceiver.h: Splitting add_server_to_client_methods() into several functions, so they can be applied to server objects as well. src/networking/oscreceiver.cpp: Splitting the implementation of callback handler adding into several functions, so they can be more easily applied fine-grained to server objects as well. --- src/networking/oscreceiver.cpp | 240 +++++++++++++++++++++++---------- src/networking/oscreceiver.h | 10 +- 2 files changed, 175 insertions(+), 75 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6f0c5859..3a595b61 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -42,12 +42,23 @@ void ssr::OscReceiver::start() if (!_handler.mode().compare("server")) { add_client_to_server_methods(); - VERBOSE("OscReceiver: Added client-to-server callbacks."); + add_update_notification_methods(); + add_source_methods(); + add_reference_methods(); + add_scene_methods(); + add_processing_methods(); + add_transport_methods(); + add_tracker_methods(); } else if (!_handler.mode().compare("client")) { - add_server_to_client_methods(); - VERBOSE("OscReceiver: Added server-to-client callbacks."); + add_poll_methods(); + add_source_methods(); + add_reference_methods(); + add_scene_methods(); + add_processing_methods(); + add_transport_methods(); + add_tracker_methods(); } } @@ -60,17 +71,15 @@ void ssr::OscReceiver::stop() } /** - * Adds callback handlers for OSC messages received from clients. + * Adds callback handlers (for server) for subscribe and message level messages + * received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { - // add local reference to OscHandler's lo::ServerThread for add_method() - lo::ServerThread& server = _handler.server(); - // adding new subscribing client: "/subscribe, {T,Ti,F}" - server.add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -95,10 +104,10 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added method for /subscribe {T|F}."); + VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" - server.add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -108,10 +117,19 @@ void ssr::OscReceiver::add_client_to_server_methods() static_cast(argv[0]->i)); } ); - VERBOSE("OscReceiver: Added method for /message_level."); + VERBOSE("OscReceiver: Added method for /message_level i."); +} +/** + * Adds callback handlers (for server) for update messages received from + * clients. + * This function uses C++11 lambda functions to define the behavior for every + * callback. + */ +void ssr::OscReceiver::add_update_notification_methods() +{ // update on new source: "/update/source/new, i, id" - server.add_method("/update/source/new", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -122,7 +140,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/new."); // update on deleted source: "/update/source/delete, i, id" - server.add_method("/update/source/delete", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -141,7 +159,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/delete."); // update on source position: "/update/source/position, iff, id, x, y" - server.add_method("/update/source/position", "iff", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -154,7 +172,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - server.add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -174,7 +192,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - server.add_method("/update/source/orientation", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -185,7 +203,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/orientation."); // update on source volume: "/update/source/volume, if, id, volume" - server.add_method("/update/source/volume", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -197,7 +215,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source position mute: "/update/source/mute, i{T,F}, // id, {true,false}" - server.add_method("/update/source/mute", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -217,7 +235,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/mute."); // update on source name: "/update/source/name, is, id, name" - server.add_method("/update/source/name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -229,7 +247,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - server.add_method("/update/source/properties_file", "is", [](lo_arg **argv, + _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -241,7 +259,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - server.add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -254,7 +272,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - server.add_method("/update/scene/amplitude_reference_distance", "f", + _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -266,7 +284,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/scene/amplitude_reference_distance."); // update on source model: "/update/source/model, is, id, model" - server.add_method("/update/source/model", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -277,7 +295,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/model."); // update on source port_name: "/update/source/port_name, is, id, port_name" - server.add_method("/update/source/port_name", "is", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -289,7 +307,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" - server.add_method("/update/source/file_name_or_port_number", "is", + _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -301,7 +319,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/source/file_name_or_port_number."); // update on source channel: "/update/source/channel, ii, id, channel" - server.add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -312,7 +330,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/channel."); // update on source file length: "/update/source/length, ii, id, length" - server.add_method("/update/source/length", "ii", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -323,7 +341,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/source/length."); // update on reference position: "/update/reference/position, ff, x, y" - server.add_method("/update/reference/position", "ff", [](lo_arg **argv, + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -336,7 +354,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference orientation: "/update/reference/orientation, f, // azimuth" - server.add_method("/update/reference/orientation", "f", [](lo_arg **argv, + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -348,7 +366,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - server.add_method("/update/reference_offset/position", "ff", [](lo_arg + _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -361,7 +379,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - server.add_method("/update/reference_offset/orientation", "f", [](lo_arg + _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -373,7 +391,7 @@ void ssr::OscReceiver::add_client_to_server_methods() /update/reference_offset/orientation."); // update on scene volume: "/update/scene/volume, f, volume" - server.add_method("/update/scene/volume", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -384,7 +402,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/volume."); // update on state processing: "/update/processing/state, {T,F}, {true,false}" - server.add_method("/update/processing/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -405,7 +423,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/processing/state."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - server.add_method("/update/transport/state", NULL, [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -426,7 +444,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/transport/state."); // update on transport seek: "/update/transport/seek, s, time" - server.add_method("/update/transport/seek", "s", [](lo_arg **argv, int, + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -438,7 +456,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - server.add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg **argv, int, lo::Message message) { @@ -460,7 +478,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); // update on cpu_load: "/update/cpu_load, f, load" - server.add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -471,7 +489,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/cpu_load."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - server.add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -483,7 +501,7 @@ void ssr::OscReceiver::add_client_to_server_methods() // update on scene master signal level: "/update/scene/master_signal_level, f, // master_signal_level" - server.add_method("/update/scene/master_signal_level", "f", [](lo_arg + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -494,7 +512,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); // update on source signal level: "/update/source/level, if, id, level" - server.add_method("/update/source/level", "if", [](lo_arg **argv, int, + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); @@ -503,20 +521,19 @@ void ssr::OscReceiver::add_client_to_server_methods() } ); VERBOSE("OscReceiver: Added method for /update/source/level."); - } /** - * Adds callback handlers for OSC messages received from a server. + * Adds callback handlers (for clients) for poll messages received from a + * server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. */ -void ssr::OscReceiver::add_server_to_client_methods() +void ssr::OscReceiver::add_poll_methods() { - lo::ServerThread& server = _handler.server(); // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - server.add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { lo::Address server(server_address(_handler)); @@ -536,9 +553,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /poll."); +} +/** + * Adds callback handlers (for clients and server) for source related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * set source related settings). + */ +void ssr::OscReceiver::add_source_methods() +{ // set source position: "source/position, iff, id, x, y" - server.add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) { _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); @@ -549,7 +578,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set source fixed: "source/position_fixed, iT, id, true" - server.add_method("/source/position_fixed", "iT", [this](lo_arg **argv, + _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, true); @@ -560,7 +589,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed true."); // set source fixed: "source/position_fixed, iF, id, false" - server.add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) { _controller.set_source_position_fixed(argv[0]->i, false); VERBOSE2("set source position fixed: id = " << argv[0]->i << @@ -570,7 +599,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position_fixed false."); // set source orientation: "source/orientation, if, id, azimuth" - server.add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) { _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << @@ -580,7 +609,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/orientation."); // set source volume: "source/volume, if, id, volume" - server.add_method("/source/volume", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) { _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); @@ -591,7 +620,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/volume."); // set source mute: "source/mute, iT, id, true" - server.add_method("/source/mute", "iT", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, true); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); @@ -600,7 +629,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute true."); // set source mute: "source/mute, iF, id, false" - server.add_method("/source/mute", "iF", [this](lo_arg **argv, int) + _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) { _controller.set_source_mute(argv[0]->i, false); VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); @@ -609,7 +638,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/mute false."); // set source name: "source/name, is, id, name" - server.add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) { _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << @@ -619,7 +648,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/name."); // set source file: "/source/properties_file, is, id, properties_file" - server.add_method("/source/properties_file", "is", [this](lo_arg **argv, + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, int) { _controller.set_source_properties_file(argv[0]->i, @@ -631,7 +660,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/properties_file."); // set source model: "/source/model, is, id, model" - server.add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) { Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) @@ -646,7 +675,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/model."); // set source port name: "/source/port_name, is, id, port_name" - server.add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) { _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << @@ -661,7 +690,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, channel, // properties_file, position_fixed, orientation_fixed, muted" - server.add_method("/source/new", NULL, [this](lo_arg **argv, int, + _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); @@ -836,7 +865,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - server.add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) { if (argv[0]->i == 0) { @@ -851,9 +880,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /source/delete."); +} +/** + * Adds callback handlers (for clients and server) for reference related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_reference_methods() +{ // set reference position: "/reference/position, ff, x, y" - server.add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) { _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); @@ -862,7 +904,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /source/position."); // set reference orientation: "/reference/orientation, f, azimuth" - server.add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) { _controller.set_reference_orientation(Orientation(argv[0]->f)); VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); @@ -871,7 +913,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /reference/orientation."); // set reference offset position: "/reference_offset/position, ff, x, y" - server.add_method("/reference_offset/position", "ff" , [this](lo_arg + _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg **argv, int) { _controller.set_reference_offset_position(Position(argv[0]->f, @@ -884,7 +926,7 @@ void ssr::OscReceiver::add_server_to_client_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - server.add_method("/reference_offset/orientation", "f" , [this](lo_arg + _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg **argv, int) { _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); @@ -893,9 +935,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); +} +/** + * Adds callback handlers (for clients and server) for scene related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_scene_methods() +{ // save scene to file: "/scene/save, s, file" - server.add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) { _controller.save_scene_as_XML(std::string(&(argv[0]->s))); VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); @@ -904,7 +958,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/save."); // load scene from file: "/scene/load, s, file" - server.add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) { _controller.load_scene(std::string(&(argv[0]->s))); VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); @@ -913,7 +967,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/load."); // set master volume: "/scene/volume, f, volume" - server.add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) { _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << @@ -923,7 +977,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /scene/volume."); // clear scene: "/scene/clear" - server.add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.delete_all_sources(); @@ -931,9 +985,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /scene/clear."); +} +/** + * Adds callback handlers (for clients and server) for processing related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_processing_methods() +{ // set processing state: "/processing/state, T, true" - server.add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.start_processing(); @@ -943,7 +1010,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /processing/state true."); // set processing state: "/processing/state, F, false" - server.add_method("/processing/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.stop_processing(); @@ -951,9 +1018,22 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /processing/state false."); +} +/** + * Adds callback handlers (for clients and server) for transport related + * messages received from a server or a client with MessageLevel::SERVER + * (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_transport_methods() +{ // set transport state: "transport/state, T, true" - server.add_method("transport/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_start(); @@ -963,7 +1043,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state true."); // set transport state: "/transport/state, F, false" - server.add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) { (void) argv; _controller.transport_stop(); @@ -973,7 +1053,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/state false."); // rewind transport state: "/transport/rewind" - server.add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.transport_locate(0); @@ -983,7 +1063,7 @@ void ssr::OscReceiver::add_server_to_client_methods() VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - server.add_method("/transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int) { float time; if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) @@ -999,9 +1079,21 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /transport/seek."); +} +/** + * Adds callback handlers (for clients and server) for tracker related messages + * received from a server or a client with MessageLevel::SERVER (respectively). + * This function uses C++11 lambda functions to define the behavior for every + * callback, that interface with the Publisher's functionality. + * @todo add checks for client MessageLevel when this is used for a server + * (only clients with message_level MessageLevel::SERVER ought to be able to + * interact) + */ +void ssr::OscReceiver::add_tracker_methods() +{ // reset tracker: "/tracker/reset" - server.add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) { (void) argv; _controller.calibrate_client(); @@ -1009,5 +1101,5 @@ void ssr::OscReceiver::add_server_to_client_methods() } ); VERBOSE("OscReceiver: Added method for /tracker/reset."); - } + diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 696da2b3..4011a46b 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -38,7 +38,15 @@ class OscReceiver Publisher& _controller; ssr::OscHandler& _handler; void add_client_to_server_methods(); - void add_server_to_client_methods(); + void add_update_notification_methods(); + void add_poll_methods(); + void add_source_methods(); + void add_reference_methods(); + void add_scene_methods(); + void add_processing_methods(); + void add_transport_methods(); + void add_tracker_methods(); + public: OscReceiver(Publisher& controller, OscHandler& handler); ~OscReceiver(); From c90d857c903b4acf969b0d3d51dfc32aaeb34797 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:21:56 +0200 Subject: [PATCH 308/363] src/networking/oschandler.h: Adding anonymous namespace for some bool2string representations. Adding bool_to_message_type() and bool_to_string() to public interface for VERBOSE messages used throughout OscSender and OscReceiver. src/networking/oschandler.cpp: Adding implementation of bool_to_message_type() and bool_to_string(). --- src/networking/oschandler.cpp | 33 +++++++++++++++++++++++++++++++++ src/networking/oschandler.h | 11 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 27810c98..99fb56be 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -230,3 +230,36 @@ lo::ServerThread& ssr::OscHandler::server() return _server; } +/** + * Returns a std::string representing the message type of a boolean type + * @param message bool + * @return _message_type_true if message true, _message_type_false otherwise + */ +const std::string ssr::OscHandler::bool_to_message_type(const bool& message) +{ + if(message) + { + return _message_type_true; + } + else + { + return _message_type_false; + } +} + +/** + * Returns a std::string representing the string of a boolean type + * @param message bool + * @return 'true' if message true, 'false' otherwise + */ +const std::string ssr::OscHandler::bool_to_string(const bool& message) +{ + if(message) + { + return _string_true; + } + else + { + return _string_false; + } +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 371d71fa..f42d01f3 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -18,6 +18,14 @@ #include "oscreceiver.h" #include "oscsender.h" +namespace +{ + const std::string _message_type_false{"F"}; + const std::string _message_type_true{"T"}; + const std::string _string_false{"false"}; + const std::string _string_true{"true"}; +} + namespace ssr { @@ -47,6 +55,9 @@ class OscHandler void stop(); std::string mode(); lo::ServerThread& server(); + const std::string bool_to_message_type(const bool& message); + const std::string bool_to_string(const bool& message); + // OscReceiver friend functions friend void OscReceiver::set_server_for_client(OscHandler& self, lo::Address server_address); friend lo::Address OscReceiver::server_address(OscHandler& self); From 8bba979b40463a1d1f724ca89f0e861fa0bb1594 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:23:55 +0200 Subject: [PATCH 309/363] src/networking/oscsender.h: Removing anonymous namespace and function bool_to_message_type. src/networking/oscsender.cpp: Removing implementation of bool_to_message_type() and replacing all calls to it by the version now held by OscHandler. --- src/networking/oscsender.cpp | 109 ++++++++++++++++++----------------- src/networking/oscsender.h | 7 --- 2 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0d5df6fa..f66b3c80 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -113,21 +113,21 @@ bool ssr::OscSender::server_is_default() } } -/** - * Returns true, if the _server_address is the default (setup at initialization) - * @return true, if _server_address is the default, false otherwise. - */ -const std::string ssr::OscSender::bool_to_message_type(const bool& message) -{ - if(message) - { - return _message_type_true; - } - else - { - return _message_type_false; - } -} +///** +// * Returns true, if the _server_address is the default (setup at initialization) +// * @return true, if _server_address is the default, false otherwise. +// */ +//const std::string ssr::OscSender::bool_to_message_type(const bool& message) +//{ +// if(message) +// { +// return _message_type_true; +// } +// else +// { +// return _message_type_false; +// } +//} /** * Sends a '/poll' message to all client instances listed in _clients, then @@ -368,11 +368,11 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) { client->address().send_from(_handler.server(), "/source/new", "sssffffis"+ - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "position_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get( + +_handler.bool_to_message_type(_new_sources.at(id).get( "orientation_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get( + +_handler.bool_to_message_type(_new_sources.at(id).get( "mute", false)), _new_sources.at(id).get("name", "").c_str(), _new_sources.at(id).get("model", "").c_str(), @@ -385,13 +385,12 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "position_fixed", false)) << - bool_to_message_type(_new_sources.at(id).get( + _handler.bool_to_message_type(_new_sources.at(id).get( "orientation_fixed", false)) << - bool_to_message_type(_new_sources.at(id).get("mute", - false)) << - ", " << + _handler.bool_to_message_type(_new_sources.at(id).get( + "mute", false)) << ", " << _new_sources.at(id).get("name", "") << ", " << _new_sources.at(id).get("model", "") << ", " << _new_sources.at(id).get("file_name_or_port_number","") @@ -425,12 +424,12 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) { client->address().send_from(_handler.server(), "/source/new", "sssffff"+ - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("position_fixed", false)) - +bool_to_message_type( + +_handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) - +bool_to_message_type(_new_sources.at(id).get("mute", - false)), + +_handler.bool_to_message_type(_new_sources.at(id).get( + "mute", false)), _new_sources.at(id).get("name", "").c_str(), _new_sources.at(id).get("model", "").c_str(), _new_sources.at(id).get( @@ -440,11 +439,11 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("orientation", 0.0), _new_sources.at(id).get("volume", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get( "position_fixed", false)) << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) << - bool_to_message_type( + _handler.bool_to_message_type( _new_sources.at(id).get("mute", false)) << ", " << _new_sources.at(id).get("name", "") << ", " << _new_sources.at(id).get("model", "") << ", " << @@ -744,10 +743,10 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/position_fixed", "i"+bool_to_message_type(fixed), + "/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << - bool_to_message_type(fixed) << ", " << message_id << + _handler.bool_to_message_type(fixed) << ", " << message_id << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -757,10 +756,11 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position_fixed", - "i"+bool_to_message_type(fixed), message_id); + "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" - +bool_to_message_type(fixed) << ", " << message_id << "] to server " - << _server_address.hostname() << ":" << _server_address.port() << "."); + +_handler.bool_to_message_type(fixed) << ", " << message_id << + "] to server " << _server_address.hostname() << ":" << + _server_address.port() << "."); } return true; } @@ -899,9 +899,9 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) if(client && client->active()) { client->address().send_from(_handler.server(), "/source/mute", - "i"+bool_to_message_type(mute), message_id); + "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << - bool_to_message_type(mute) << ", " << message_id << + _handler.bool_to_message_type(mute) << ", " << message_id << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -911,9 +911,10 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/mute", - "i"+bool_to_message_type(mute), message_id); - VERBOSE3("OscSender: Sent [/update/source/mute, i" << bool_to_message_type(mute) << - ", " << apf::str::A2S(message_id) << "] to server " << + "i"+_handler.bool_to_message_type(mute), message_id); + VERBOSE3("OscSender: Sent [/update/source/mute, i" << + _handler.bool_to_message_type(mute) << ", " << + apf::str::A2S(message_id) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } return true; @@ -1533,9 +1534,9 @@ void ssr::OscSender::set_processing_state(bool state) if(client && client->active()) { client->address().send_from(_handler.server(), "/processing/state", - bool_to_message_type(state)); + _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << - bool_to_message_type(state) << "] to client " << + _handler.bool_to_message_type(state) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -1544,9 +1545,9 @@ void ssr::OscSender::set_processing_state(bool state) else if(is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/processing/state", - bool_to_message_type(state)); + _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << - bool_to_message_type(state) << "] to server " << + _handler.bool_to_message_type(state) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } } @@ -1574,9 +1575,9 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/transport/state", - bool_to_message_type(state.first)); + _handler.bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << - bool_to_message_type(state.first) << "] to client " << + _handler.bool_to_message_type(state.first) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); client->address().send_from(_handler.server(), "/transport/seek", "i", @@ -1591,9 +1592,9 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); + _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + _handler.bool_to_message_type(auto_rotate_sources) << + "] to client " << client->address().hostname() << ":" << + client->address().port() << "."); } } } @@ -1637,9 +1638,9 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) { _server_address.send_from(_handler.server(), "/update/scene/auto_rotate_sources", - bool_to_message_type(auto_rotate_sources)); + _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << - bool_to_message_type(auto_rotate_sources) << "] to server " << + _handler.bool_to_message_type(auto_rotate_sources) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 4453337f..d8849439 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -20,12 +20,6 @@ #include "subscriber.h" #include "apf/parameter_map.h" -namespace -{ - const std::string _message_type_false{"F"}; - const std::string _message_type_true{"T"}; -} - namespace ssr { @@ -66,7 +60,6 @@ class OscSender : public Subscriber bool is_client(); bool is_server(); bool server_is_default(); - const std::string bool_to_message_type(const bool& message); void poll_all_clients(); void remove_all_clients(); bool is_new_source(id_t id); //< check, if source id is in _new_sources From ebcf35c44c4476ff08e60417abe3c0007ed7e3fd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 00:25:42 +0200 Subject: [PATCH 310/363] src/networking/oscreceiver.cpp: Fixing linewraps. Improving readability of all source related VERBOSE messages by adding more relevant output derived from incoming message. --- src/networking/oscreceiver.cpp | 204 ++++++++++++++++++++------------- 1 file changed, 122 insertions(+), 82 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 3a595b61..e72c5920 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -172,8 +172,8 @@ void ssr::OscReceiver::add_update_notification_methods() // update on source position fixation: "/update/source/position_fixed, i{T,F}, // id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg + **argv, int, lo::Message message) { lo::Address client(message.source()); std::string position_fixed; @@ -192,8 +192,8 @@ void ssr::OscReceiver::add_update_notification_methods() VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); // update on source orientation: "/update/source/orientation, if, id, azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << @@ -213,10 +213,9 @@ void ssr::OscReceiver::add_update_notification_methods() ); VERBOSE("OscReceiver: Added method for /update/source/volume."); - // update on source position mute: "/update/source/mute, i{T,F}, - // id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, - lo::Message message) + // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" + _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, + int, lo::Message message) { lo::Address client(message.source()); std::string state; @@ -567,122 +566,144 @@ void ssr::OscReceiver::add_poll_methods() void ssr::OscReceiver::add_source_methods() { // set source position: "source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int) + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << + argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); - VERBOSE2("set source position: id = " << argv[0]->i << ", " << - Position(argv[1]->f, argv[2]->f)); - } - ); - VERBOSE("OscReceiver: Added method for /source/position."); - - // set source fixed: "source/position_fixed, iT, id, true" - _handler.server().add_method("/source/position_fixed", "iT", [this](lo_arg **argv, - int) - { - _controller.set_source_position_fixed(argv[0]->i, true); - VERBOSE2("set source position fixed: id = " << argv[0]->i << - ", fixed = true"); } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed true."); + VERBOSE("OscReceiver: Added method for /source/position iff."); - // set source fixed: "source/position_fixed, iF, id, false" - _handler.server().add_method("/source/position_fixed", "iF", [this](lo_arg **argv, int) + // set source fixed: "source/position_fixed, i{T,F}, id, true|false" + _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg + **argv, int, lo::Message message) { - _controller.set_source_position_fixed(argv[0]->i, false); - VERBOSE2("set source position fixed: id = " << argv[0]->i << - ", fixed = false"); + if (!message.types().compare("iT")) + { + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", true] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, true); + } + else if (!message.types().compare("iF")) + { + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", false] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, false); + } } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed false."); + VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); // set source orientation: "source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int) + _handler.server().add_method("/source/orientation", "if", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - VERBOSE2("set source orientation: id = " << argv[0]->i << ", " << - Orientation(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/orientation."); + VERBOSE("OscReceiver: Added method for /source/orientation if."); - // set source volume: "source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, int) + // set source volume: "/source/volume, if, id, volume" + _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/volume, " << argv[0]->i << ", " << + argv[1]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); - VERBOSE2("set source volume: id = " << argv[0]->i << ", volume = " << - apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/volume."); + VERBOSE("OscReceiver: Added method for /source/volume if."); - // set source mute: "source/mute, iT, id, true" - _handler.server().add_method("/source/mute", "iT", [this](lo_arg **argv, int) - { - _controller.set_source_mute(argv[0]->i, true); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = true"); - } - ); - VERBOSE("OscReceiver: Added method for /source/mute true."); - - // set source mute: "source/mute, iF, id, false" - _handler.server().add_method("/source/mute", "iF", [this](lo_arg **argv, int) + // set source mute: "source/mute, i{T,F}, id, true|false" + _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, + lo::Message message) { - _controller.set_source_mute(argv[0]->i, false); - VERBOSE2("set source mute: id = " << argv[0]->i << ", mute = false"); + if(!message.types().compare("iT")) + { + VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << + ", true] from client '"<< message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_mute(argv[0]->i, true); + } + else if(!message.types().compare("iF")) + { + VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << + ", false] from client '"<< message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_mute(argv[0]->i, false); + } } ); - VERBOSE("OscReceiver: Added method for /source/mute false."); + VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); // set source name: "source/name, is, id, name" - _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, + lo::Message message) { - _controller.set_source_name(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source name: id = " << argv[0]->i << ", name = " << - apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); + _controller.set_source_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/name."); + VERBOSE("OscReceiver: Added method for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, - int) + int, lo::Message message) { - _controller.set_source_properties_file(argv[0]->i, - apf::str::A2S(argv[1]->s)); - VERBOSE2("set source properties file name: id = " << argv[0]->i << - ", file = " << apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << + ", " << name << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_properties_file(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/properties_file."); + VERBOSE("OscReceiver: Added method for /source/properties_file is."); // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, + int, lo::Message message) { + std::string name(&argv[1]->s); Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + if (!apf::str::S2A(name, model)) { model = Source::point; } + VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_source_model(argv[0]->i, model); - VERBOSE2("set source model: id = " << argv[0]->i << ", model = " << - apf::str::A2S(argv[1]->s)); } ); - VERBOSE("OscReceiver: Added method for /source/model."); + VERBOSE("OscReceiver: Added method for /source/model is."); // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int) + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, + int, lo::Message message) { - _controller.set_source_port_name(argv[0]->i, apf::str::A2S(argv[1]->s)); - VERBOSE2("set source port name: id = " << argv[0]->i << ", port = " << - apf::str::A2S(argv[1]->s)); + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_port_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/port_name."); + VERBOSE("OscReceiver: Added method for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, volume, position_fixed, @@ -693,7 +714,6 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: [/source/new, " << message.types() << "]."); std::string name(&(argv[0]->s)); std::string file_name_or_port_number(&(argv[2]->s)); std::string types(message.types()); @@ -702,6 +722,7 @@ void ssr::OscReceiver::add_source_methods() float volume(argv[6]->f); int channel = 0; std::string properties_file = ""; + std::string channel_and_properties = ""; bool position_fixed; bool orientation_fixed; bool muted; @@ -773,6 +794,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = true; @@ -782,6 +804,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = false; @@ -791,6 +814,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = false; @@ -800,6 +824,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = false; @@ -809,6 +834,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = true; @@ -818,6 +844,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = false; @@ -827,6 +854,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = true; @@ -836,6 +864,7 @@ void ssr::OscReceiver::add_source_methods() { channel = argv[7]->i; properties_file = &(argv[8]->s); + channel_and_properties = (channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = true; @@ -843,10 +872,19 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { + VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << + ", " << file_name_or_port_number << ", " << x << ", " << y << ", " + << orientation.azimuth << ", " << volume << ", " << + channel_and_properties << ", " << + _handler.bool_to_string(position_fixed) << ", " << + _handler.bool_to_string(orientation_fixed) << ", " << + _handler.bool_to_string(muted) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, - volume, muted, properties_file); - VERBOSE2("Creating source with following properties:" + position, position_fixed, orientation, orientation_fixed, volume, + muted, properties_file); + VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << @@ -861,25 +899,27 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new."); + VERBOSE("OscReceiver: Added method for /source/new {sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int) + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); if (argv[0]->i == 0) { _controller.delete_all_sources(); - VERBOSE2("delete all sources"); } else { _controller.delete_source(argv[0]->i); - VERBOSE2("delete source with id = " << argv[0]->i); } } ); - VERBOSE("OscReceiver: Added method for /source/delete."); + VERBOSE("OscReceiver: Added method for /source/delete i."); } /** From 9331db62c54939add054c0d143547b5de1653fc0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 23:46:47 +0200 Subject: [PATCH 311/363] src/networking/oschandler.*: Adding public definition and implementation of is_server() and is_client(). --- src/networking/oschandler.cpp | 32 ++++++++++++++++++++++++++++++++ src/networking/oschandler.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 99fb56be..e0d4b375 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -221,6 +221,38 @@ std::string ssr::OscHandler::mode() return _mode; } +/** + * Returns true, if the instance of OscHandler is a 'client', false otherwise. + * @return true, if _oschandler.mode() returns 'client', false otherwise. + */ +bool ssr::OscHandler::is_client() +{ + if(!_mode.compare("client")) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the instance of OscHandler is a 'server', false otherwise. + * @return true, if _oschandler.mode() returns 'server', false otherwise. + */ +bool ssr::OscHandler::is_server() +{ + if(!_mode.compare("server")) + { + return true; + } + else + { + return false; + } +} + /** * Return reference to OscHandler's lo::ServerThread * @return lo::ServerThread& reference to _server diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index f42d01f3..0faaa5ee 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -54,6 +54,8 @@ class OscHandler void start(); void stop(); std::string mode(); + bool is_client(); + bool is_server(); lo::ServerThread& server(); const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); From e9dd3da73a824b044feb40c78f166de077d78a90 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 4 Jun 2017 23:52:45 +0200 Subject: [PATCH 312/363] src/networking/oscsender.*: Replacing all calls to is_server() and is_client() by the versions from OscHandler. Removing is_client() and is_server() declarations and implementations. --- src/networking/oscsender.cpp | 146 ++++++++++++++--------------------- src/networking/oscsender.h | 2 - 2 files changed, 57 insertions(+), 91 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index f66b3c80..62b1efbd 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -39,7 +39,7 @@ void ssr::OscSender::start() { _controller.subscribe(this); _is_subscribed = true; - if (is_server()) + if (_handler.is_server()) { _poll_all_clients = true; std::thread _poll_thread(&OscSender::poll_all_clients, this); @@ -56,7 +56,7 @@ void ssr::OscSender::stop() { _controller.unsubscribe(this); _is_subscribed = false; - if (is_server()) + if (_handler.is_server()) { remove_all_clients(); _poll_all_clients = false; @@ -64,38 +64,6 @@ void ssr::OscSender::stop() } } -/** - * Returns true, if the instance of OscHandler is a 'client', false otherwise. - * @return true, if _oschandler.mode() returns 'client', false otherwise. - */ -bool ssr::OscSender::is_client() -{ - if(!_handler.mode().compare("client")) - { - return true; - } - else - { - return false; - } -} - -/** - * Returns true, if the instance of OscHandler is a 'server', false otherwise. - * @return true, if _oschandler.mode() returns 'server', false otherwise. - */ -bool ssr::OscSender::is_server() -{ - if(!_handler.mode().compare("server")) - { - return true; - } - else - { - return false; - } -} - /** * Returns true, if the _server_address is the default (setup at initialization) * @return true, if _server_address is the default, false otherwise. @@ -577,14 +545,14 @@ void ssr::OscSender::set_loudspeakers(const Loudspeaker::container_t& */ void ssr::OscSender::new_source(id_t id) { - if(is_server()) + if(_handler.is_server()) { if(!is_new_source(id)) _new_sources.insert(make_pair(id, apf::parameter_map())); if(is_complete_source(id)) send_new_source_message_from_id(id); } - else if(is_client()) + else if(_handler.is_client()) { int32_t message_id = static_cast(id); _server_address.send_from(_handler.server(), "/update/source/new", "i", @@ -605,7 +573,7 @@ void ssr::OscSender::new_source(id_t id) void ssr::OscSender::delete_source(id_t id) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -619,7 +587,7 @@ void ssr::OscSender::delete_source(id_t id) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _source_levels.erase(id); _server_address.send_from(_handler.server(), "/update/source/delete", @@ -638,7 +606,7 @@ void ssr::OscSender::delete_source(id_t id) */ void ssr::OscSender::delete_all_sources() { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -651,7 +619,7 @@ void ssr::OscSender::delete_all_sources() } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/delete", "i", 0); @@ -676,7 +644,7 @@ void ssr::OscSender::delete_all_sources() bool ssr::OscSender::set_source_position(id_t id, const Position& position) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -701,7 +669,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); @@ -728,7 +696,7 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -753,7 +721,7 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); @@ -781,7 +749,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { int32_t message_id = static_cast(id); float message_orientation = orientation.azimuth; - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -806,7 +774,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); @@ -833,7 +801,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -856,7 +824,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/volume", "if", message_id, gain); @@ -883,7 +851,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && _new_sources.at(id).has_key("file_name_or_port_number")) @@ -908,7 +876,7 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/mute", "i"+_handler.bool_to_message_type(mute), message_id); @@ -936,7 +904,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { int32_t message_id = static_cast(id); const char * message_name = name.c_str(); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -960,7 +928,7 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); @@ -988,7 +956,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& { int32_t message_id = static_cast(id); const char * file_name = name.c_str(); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && !name.empty()) { @@ -1012,7 +980,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); @@ -1033,7 +1001,7 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& */ void ssr::OscSender::set_decay_exponent(float exponent) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1047,7 +1015,7 @@ void ssr::OscSender::set_decay_exponent(float exponent) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); @@ -1069,7 +1037,7 @@ void ssr::OscSender::set_decay_exponent(float exponent) */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1083,7 +1051,7 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); @@ -1110,7 +1078,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) int32_t message_id = static_cast(id); std::string message_model = apf::str::A2S(model); if (message_model == "") return false; - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -1134,7 +1102,7 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); @@ -1160,7 +1128,7 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& port_name) { int32_t message_id = static_cast(id); - if(is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); @@ -1191,7 +1159,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) { int32_t message_id = static_cast(id); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id)) { @@ -1217,7 +1185,7 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/file_name_or_port_number", "is", message_id, @@ -1247,7 +1215,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { int32_t message_id = static_cast(id); int32_t message_file_channel = static_cast(file_channel); - if(is_server()) + if(_handler.is_server()) { if(is_new_source(id) && file_channel > 0) { @@ -1271,7 +1239,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); @@ -1298,7 +1266,7 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { int32_t message_id = static_cast(id); int32_t message_length = static_cast(length); - if(is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); @@ -1321,7 +1289,7 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) */ void ssr::OscSender::set_reference_position(const Position& position) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1336,7 +1304,7 @@ void ssr::OscSender::set_reference_position(const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); @@ -1358,7 +1326,7 @@ void ssr::OscSender::set_reference_position(const Position& position) */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1373,7 +1341,7 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); @@ -1396,7 +1364,7 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) */ void ssr::OscSender::set_reference_offset_position(const Position& position) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1411,7 +1379,7 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); @@ -1436,7 +1404,7 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1451,7 +1419,7 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); @@ -1474,7 +1442,7 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& void ssr::OscSender::set_master_volume(float volume) { float message_volume = apf::math::linear2dB(volume); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1488,7 +1456,7 @@ void ssr::OscSender::set_master_volume(float volume) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/volume", "f", message_volume); @@ -1527,7 +1495,7 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* */ void ssr::OscSender::set_processing_state(bool state) { - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1542,7 +1510,7 @@ void ssr::OscSender::set_processing_state(bool state) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); @@ -1567,7 +1535,7 @@ void ssr::OscSender::set_transport_state( const std::pair& state) { int32_t message_nframes = static_cast(state.second); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1588,7 +1556,7 @@ void ssr::OscSender::set_transport_state( const std::pair(sr); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1695,7 +1663,7 @@ void ssr::OscSender::set_sample_rate(int sr) } } } - else if(is_client() && !server_is_default()) + else if(_handler.is_client() && !server_is_default()) { _server_address.send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); @@ -1718,7 +1686,7 @@ void ssr::OscSender::set_sample_rate(int sr) void ssr::OscSender::set_master_signal_level(float level) { float message_level(apf::math::linear2dB(level)); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1734,7 +1702,7 @@ void ssr::OscSender::set_master_signal_level(float level) } } } - else if(is_client() && !server_is_default() && _message_level == + else if(_handler.is_client() && !server_is_default() && _message_level == MessageLevel::GUI_CLIENT) { _server_address.send_from(_handler.server(), @@ -1761,7 +1729,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { int32_t message_id = static_cast(id); float message_level(apf::math::linear2dB(level)); - if(is_server()) + if(_handler.is_server()) { for (const auto& client: _clients) { @@ -1776,7 +1744,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) } } } - else if(is_client() && !server_is_default() && _message_level == + else if(_handler.is_client() && !server_is_default() && _message_level == MessageLevel::GUI_CLIENT) { _server_address.send_from(_handler.server(), "/update/source/level", diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index d8849439..3b280f00 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -57,8 +57,6 @@ class OscSender : public Subscriber source_level_map_t _source_levels; float _master_level; - bool is_client(); - bool is_server(); bool server_is_default(); void poll_all_clients(); void remove_all_clients(); From ddcf7e3ef67ae9e0c4c12f9901830624520741ab Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 00:01:43 +0200 Subject: [PATCH 313/363] src/networking/oscreceiver.cpp: Using is_server() and is_client() in start(). Improving VERBOSE output of reference, reference_offset, scene, processing and transport message handlers by adding information on caller and displaying whole message sent properly. --- src/networking/oscreceiver.cpp | 179 ++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 68 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e72c5920..e0588cdd 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -39,7 +39,7 @@ void ssr::OscReceiver::start() { VERBOSE("OscReceiver: Starting."); // add method handlers for received messages - if (!_handler.mode().compare("server")) + if (_handler.is_server()) { add_client_to_server_methods(); add_update_notification_methods(); @@ -50,7 +50,7 @@ void ssr::OscReceiver::start() add_transport_methods(); add_tracker_methods(); } - else if (!_handler.mode().compare("client")) + else if (_handler.is_client()) { add_poll_methods(); add_source_methods(); @@ -544,10 +544,10 @@ void ssr::OscReceiver::add_poll_methods() (from.hostname().compare("none") != 0) ) { + VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << + ":" << from.port() << ". Subscribing..."); set_server_for_client(_handler, from); from.send_from(_handler.server(), "/subscribe", "T"); - VERBOSE2("OscReceiver: Got /poll from server " << from.hostname() << - ":" << from.port() << ". Subscribing..."); } } ); @@ -935,46 +935,55 @@ void ssr::OscReceiver::add_source_methods() void ssr::OscReceiver::add_reference_methods() { // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/position", "ff", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); - VERBOSE2("set reference position: " << Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/position."); + VERBOSE("OscReceiver: Added method for /reference/position ff."); // set reference orientation: "/reference/orientation, f, azimuth" - _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int) + _handler.server().add_method("/reference/orientation", "f", [this](lo_arg + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/orientation, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_reference_orientation(Orientation(argv[0]->f)); - VERBOSE2("set reference orientation: " << Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/orientation."); + VERBOSE("OscReceiver: Added method for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg - **argv, int) + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_offset_position(Position(argv[0]->f, argv[1]->f)); - VERBOSE2("set reference offset position: " << Position(argv[0]->f, - argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/position."); + VERBOSE("OscReceiver: Added method for /reference_offset/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg - **argv, int) + **argv, int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); - VERBOSE2("set reference offset orientation: " << - Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/orientation."); + VERBOSE("OscReceiver: Added method for /reference_offset/orientation f."); } /** @@ -989,39 +998,52 @@ void ssr::OscReceiver::add_reference_methods() void ssr::OscReceiver::add_scene_methods() { // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, + lo::Message message) { - _controller.save_scene_as_XML(std::string(&(argv[0]->s))); - VERBOSE2("saving scene as: " << std::string(&(argv[0]->s))); + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.save_scene_as_XML(name); } ); - VERBOSE("OscReceiver: Added method for /scene/save."); + VERBOSE("OscReceiver: Added method for /scene/save s."); // load scene from file: "/scene/load, s, file" - _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, + lo::Message message) { - _controller.load_scene(std::string(&(argv[0]->s))); - VERBOSE2("loading scene: " << std::string(&(argv[0]->s))); + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.load_scene(name); } ); - VERBOSE("OscReceiver: Added method for /scene/load."); + VERBOSE("OscReceiver: Added method for /scene/load s."); // set master volume: "/scene/volume, f, volume" - _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, + int, lo::Message message) { + VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); - VERBOSE2("set master volume: " << apf::math::dB2linear(argv[0]->f) << - " dB"); } ); - VERBOSE("OscReceiver: Added method for /scene/volume."); + VERBOSE("OscReceiver: Added method for /scene/volume f."); // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: [/scene/clear] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.delete_all_sources(); - VERBOSE2("clearing scene."); } ); VERBOSE("OscReceiver: Added method for /scene/clear."); @@ -1040,24 +1062,30 @@ void ssr::OscReceiver::add_scene_methods() void ssr::OscReceiver::add_processing_methods() { // set processing state: "/processing/state, T, true" - _handler.server().add_method("/processing/state", "T" , [this](lo_arg **argv, int) + _handler.server().add_method("/processing/state", NULL, [this](lo_arg **argv, + int, lo::Message message) { (void) argv; - _controller.start_processing(); - VERBOSE2("start processing."); + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/processing/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.start_processing(); + } + else if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/processing/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.stop_processing(); + } } ); - VERBOSE("OscReceiver: Added method for /processing/state true."); + VERBOSE("OscReceiver: Added method for /processing/state {T,F}."); - // set processing state: "/processing/state, F, false" - _handler.server().add_method("/processing/state", "F" , [this](lo_arg **argv, int) - { - (void) argv; - _controller.stop_processing(); - VERBOSE2("stop processing."); - } - ); - VERBOSE("OscReceiver: Added method for /processing/state false."); } /** @@ -1073,52 +1101,64 @@ void ssr::OscReceiver::add_processing_methods() void ssr::OscReceiver::add_transport_methods() { // set transport state: "transport/state, T, true" - _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, int) - { - (void) argv; - _controller.transport_start(); - VERBOSE2("start transport."); - } - ); - VERBOSE("OscReceiver: Added method for /transport/state true."); - - // set transport state: "/transport/state, F, false" - _handler.server().add_method("/transport/state", "F" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; - _controller.transport_stop(); - VERBOSE2("stop transport."); + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_start(); + } + if(!message.types().compare("F")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_stop(); + } } ); - VERBOSE("OscReceiver: Added method for /transport/state false."); + VERBOSE("OscReceiver: Added method for /transport/state {T,F}."); // rewind transport state: "/transport/rewind" - _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg + **argv, int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: Got [/transport/rewind] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.transport_locate(0); - VERBOSE2("rewind transport."); } ); VERBOSE("OscReceiver: Added method for /transport/rewind."); // seek transport state: "/transport/seek, s, time" - _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int) + _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, + int, lo::Message message) { float time; - if(apf::str::string2time(apf::str::A2S(argv[0]->s), time)) + std::string message_time(&argv[0]->s); + if(apf::str::string2time(message_time, time)) { + VERBOSE2("OscReceiver: Got [/transport/seek, " << message_time << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_locate(time); - VERBOSE2("Seek transport to: " << time); } else { ERROR("Couldn't get the time out of the \"seek\" attribute (\"" - << argv[0]->s << "\")."); + << message_time << "\")."); } } ); - VERBOSE("OscReceiver: Added method for /transport/seek."); + VERBOSE("OscReceiver: Added method for /transport/seek s."); } /** @@ -1133,11 +1173,14 @@ void ssr::OscReceiver::add_transport_methods() void ssr::OscReceiver::add_tracker_methods() { // reset tracker: "/tracker/reset" - _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, int) + _handler.server().add_method("/tracker/reset", NULL , [this](lo_arg **argv, + int, lo::Message message) { (void) argv; + VERBOSE2("OscReceiver: Got [/tracker/reset] from client " << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.calibrate_client(); - VERBOSE2("calibrate tracker."); } ); VERBOSE("OscReceiver: Added method for /tracker/reset."); From 60055969e43e93b0744e7491ed607c2a322b41c3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 13:48:41 +0200 Subject: [PATCH 314/363] src/networking/oscsender.cpp, src/networking/oscsender.cpp: Renaming all source related mentions of volume to gain to be consistent with the Publisher/Subscriber interface. --- src/networking/oscreceiver.cpp | 28 ++++++++++++------------ src/networking/oscsender.cpp | 40 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e0588cdd..1da0f0f2 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -202,16 +202,16 @@ void ssr::OscReceiver::add_update_notification_methods() ); VERBOSE("OscReceiver: Added method for /update/source/orientation."); - // update on source volume: "/update/source/volume, if, id, volume" - _handler.server().add_method("/update/source/volume", "if", [](lo_arg **argv, int, + // update on source gain: "/update/source/gain, if, id, gain" + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", volume: "<< argv[1]->f << "."); + argv[0]->i << ", gain: "<< argv[1]->f << "."); } ); - VERBOSE("OscReceiver: Added method for /update/source/volume."); + VERBOSE("OscReceiver: Added method for /update/source/gain."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, @@ -612,18 +612,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/orientation if."); - // set source volume: "/source/volume, if, id, volume" - _handler.server().add_method("/source/volume", "if", [this](lo_arg **argv, + // set source gain: "/source/gain, if, id, gain" + _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/volume, " << argv[0]->i << ", " << + VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/volume if."); + VERBOSE("OscReceiver: Added method for /source/gain if."); // set source mute: "source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, @@ -706,10 +706,10 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, volume, position_fixed, + // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, volume, channel, + // file_name_or_port_number, x, y, orientation, gain, channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -719,7 +719,7 @@ void ssr::OscReceiver::add_source_methods() std::string types(message.types()); float x(argv[3]->f); float y(argv[4]->f); - float volume(argv[6]->f); + float gain(argv[6]->f); int channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; @@ -874,7 +874,7 @@ void ssr::OscReceiver::add_source_methods() { VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << ", " - << orientation.azimuth << ", " << volume << ", " << + << orientation.azimuth << ", " << gain<< ", " << channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << @@ -882,7 +882,7 @@ void ssr::OscReceiver::add_source_methods() message.source().hostname() << ":" << message.source().port() << "'."); _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, volume, + position, position_fixed, orientation, orientation_fixed, gain, muted, properties_file); VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << @@ -893,7 +893,7 @@ void ssr::OscReceiver::add_source_methods() "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << "\norientation_fixed: " << orientation_fixed << - "\nvolume (linear): " << volume << + "\ngain (linear): " << gain << "\nmuted: " << muted << "\nproperties_file: " << properties_file); } diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 62b1efbd..29225784 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -286,7 +286,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && @@ -299,7 +299,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && _new_sources.at(id).has_key("mute") && @@ -323,7 +323,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && @@ -349,7 +349,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0), _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), - _new_sources.at(id).get("volume", 0.0), + _new_sources.at(id).get("gain", 0.0), _new_sources.at(id).get("channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << @@ -366,7 +366,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0) << ", " << _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << - _new_sources.at(id).get("volume", 0.0) << ", " << + _new_sources.at(id).get("gain", 0.0) << ", " << _new_sources.at(id).get("channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") << "] to client " << @@ -381,7 +381,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("x") && _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && - _new_sources.at(id).has_key("volume") && + _new_sources.at(id).has_key("gain") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && _new_sources.at(id).has_key("mute")) @@ -405,7 +405,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0), _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), - _new_sources.at(id).get("volume", 0.0)); + _new_sources.at(id).get("gain", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << _handler.bool_to_message_type( _new_sources.at(id).get( "position_fixed", false)) << @@ -420,7 +420,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("x", 0.0) << ", " << _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << - _new_sources.at(id).get("volume", 0.0) + _new_sources.at(id).get("gain", 0.0) << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); @@ -567,7 +567,7 @@ void ssr::OscSender::new_source(id_t id) * Subscriber function called, when Publisher deleted a source. * On server: Sends out OSC message all clients to delete source with given id. * On client: Sends out OSC message about successful deletion of source with id - * to server and erases complementing volume level from _source_levels. + * to server and erases complementing gain level from _source_levels. * @param id id_t representing the source */ void ssr::OscSender::delete_source(id_t id) @@ -778,7 +778,7 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { _server_address.send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); - VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); @@ -787,15 +787,15 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } /** - * Subscriber function called, when Publisher set a source's volume. - * On server: Sends out OSC message to set volume of given source on all - * clients. If id is found in _new_sources, the volume will be stored in the + * Subscriber function called, when Publisher set a source's gain. + * On server: Sends out OSC message to set gain of given source on all + * clients. If id is found in _new_sources, the gain will be stored in the * parameter_map for id and an OSC message will be send to clients only, if the * source is complete. * On client: Sends out OSC to server message about the successful updating of - * the source's volume. + * the source's gain. * @param id id_t representing the source - * @param gain new volume of source + * @param gain new gain of source * @return true */ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) @@ -805,7 +805,7 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(is_new_source(id)) { - _new_sources.at(id).set("volume", gain); + _new_sources.at(id).set("gain", gain); if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -815,9 +815,9 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/volume", + client->address().send_from(_handler.server(), "/source/gain", "if", message_id, gain); - VERBOSE3("OscSender: Sent [/source/volume, if, " << message_id << + VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " << gain << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); } @@ -826,9 +826,9 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/volume", + _server_address.send_from(_handler.server(), "/update/source/gain", "if", message_id, gain); - VERBOSE3("OscSender: Sent [/update/source/volume, if, " << + VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << "] to server " << _server_address.hostname() << ":" << _server_address.port() << "."); From 3570ed40f55f98af7dcd34572f160f1e6b14a61c Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 14:57:28 +0200 Subject: [PATCH 315/363] src/networking/oscreceiver.cpp: Minor fixes in comments. TODO for exception handling in is_new_source(). Erasing source information from _new_sources after the /source/new message has been sent to clients. --- src/networking/oscreceiver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 1da0f0f2..b5a678ff 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -565,7 +565,7 @@ void ssr::OscReceiver::add_poll_methods() */ void ssr::OscReceiver::add_source_methods() { - // set source position: "source/position, iff, id, x, y" + // set source position: "/source/position, iff, id, x, y" _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, int, lo::Message message) { @@ -578,7 +578,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position iff."); - // set source fixed: "source/position_fixed, i{T,F}, id, true|false" + // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -600,7 +600,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); - // set source orientation: "source/orientation, if, id, azimuth" + // set source orientation: "/source/orientation, if, id, azimuth" _handler.server().add_method("/source/orientation", "if", [this](lo_arg **argv, int, lo::Message message) { @@ -625,7 +625,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/gain if."); - // set source mute: "source/mute, i{T,F}, id, true|false" + // set source mute: "/source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -647,7 +647,7 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); - // set source name: "source/name, is, id, name" + // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, lo::Message message) { From d239eff30dc8c1b9967f875bc45def8b0288f7d9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 15:32:47 +0200 Subject: [PATCH 316/363] src/networking/oscsender.cpp: Erasing source from _new_sources once the assembled /source/new message has been sent out to clients. TODO about exception handling in is_new_source(). --- src/networking/oscsender.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 29225784..09d28f98 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -260,6 +260,7 @@ bool ssr::OscSender::is_new_source(id_t id) { if (_new_sources.empty()) return false; + //TODO: introduce exception handling for this call if(_new_sources.find(id) != _new_sources.end()) { return true; @@ -374,6 +375,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) client->address().port() << "."); } } + _new_sources.erase(id); } else if(_new_sources.at(id).has_key("name") && _new_sources.at(id).has_key("model") && @@ -426,6 +428,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) client->address().port() << "."); } } + _new_sources.erase(id); } } From 0f6ea8c343a78b3957688210807b4a33e3aef9e2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 15:57:58 +0200 Subject: [PATCH 317/363] src/networking/oscsender.*: Adding private member for setting the /poll message frequency in milliseconds. Removing commented, now obsolete function bool_to_message_type(). --- src/networking/oscsender.cpp | 22 +++------------------- src/networking/oscsender.h | 1 + 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 09d28f98..0bfed9c2 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -58,9 +58,9 @@ void ssr::OscSender::stop() _is_subscribed = false; if (_handler.is_server()) { - remove_all_clients(); _poll_all_clients = false; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(_poll_milliseconds)); + remove_all_clients(); } } @@ -81,22 +81,6 @@ bool ssr::OscSender::server_is_default() } } -///** -// * Returns true, if the _server_address is the default (setup at initialization) -// * @return true, if _server_address is the default, false otherwise. -// */ -//const std::string ssr::OscSender::bool_to_message_type(const bool& message) -//{ -// if(message) -// { -// return _message_type_true; -// } -// else -// { -// return _message_type_false; -// } -//} - /** * Sends a '/poll' message to all client instances listed in _clients, then * makes the thread calling this function sleep for 1000 milliseconds @@ -114,7 +98,7 @@ void ssr::OscSender::poll_all_clients() } } //TODO find better solution to compensate for execution time - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(_poll_milliseconds)); } VERBOSE2("OscSender: Stopped polling all clients."); } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 3b280f00..6bc4eb1c 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -52,6 +52,7 @@ class OscSender : public Subscriber std::map _new_sources; // thread used for calling poll_all_clients continuously std::thread _poll_thread; + const unsigned int _poll_milliseconds{1000}; bool _poll_all_clients; typedef std::map source_level_map_t; source_level_map_t _source_levels; From 2ad7515d95826fc44c2ad417a0c5322e5c07ac1b Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 20:24:43 +0200 Subject: [PATCH 318/363] src/publisher.h: Adding set_source_file_channel() to public Publisher interface. --- src/publisher.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/publisher.h b/src/publisher.h index f8f7ea87..3f4c1739 100644 --- a/src/publisher.h +++ b/src/publisher.h @@ -113,6 +113,7 @@ struct Publisher set_source_port_name(id_t id, const std::string& port_name) = 0; virtual void set_source_position_fixed(id_t id, const bool fix) = 0; + virtual void set_source_file_channel(id_t id, const int& channel) = 0; /// set position of the reference /// @param position well, the position From a6605f05a5f38d2434e412bc08982055c86b26c8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 20:27:13 +0200 Subject: [PATCH 319/363] src/networking/oscreceiver.cpp: Adding callback function for /source/file_channel. Renaming all channel variables to file_channel for consistency. src/networking/oscsender.cpp: Renaming all channel variables to file_channel for consistency. --- src/networking/oscreceiver.cpp | 64 ++++++++++++++++++++-------------- src/networking/oscsender.cpp | 10 +++--- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b5a678ff..14f2fc3b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -317,16 +317,16 @@ void ssr::OscReceiver::add_update_notification_methods() VERBOSE("OscReceiver: Added method for \ /update/source/file_name_or_port_number."); - // update on source channel: "/update/source/channel, ii, id, channel" - _handler.server().add_method("/update/source/channel", "ii", [](lo_arg **argv, int, + // update on source file_channel: "/update/source/file_channel, ii, id, file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { lo::Address client(message.source()); VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", channel: "<< argv[1]->i << "."); + argv[0]->i << ", file_channel: "<< argv[1]->i << "."); } ); - VERBOSE("OscReceiver: Added method for /update/source/channel."); + VERBOSE("OscReceiver: Added method for /update/source/file_channel."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, @@ -612,6 +612,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added method for /source/orientation if."); + // set source file_channel: "/source/file_channel, ii, id, file_channel" + _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " + << argv[1]->i << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + } + ); + VERBOSE("OscReceiver: Added method for /source/file_channel ii."); + // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) @@ -709,7 +721,7 @@ void ssr::OscReceiver::add_source_methods() // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, - // file_name_or_port_number, x, y, orientation, gain, channel, + // file_name_or_port_number, x, y, orientation, gain, file_channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -720,7 +732,7 @@ void ssr::OscReceiver::add_source_methods() float x(argv[3]->f); float y(argv[4]->f); float gain(argv[6]->f); - int channel = 0; + int file_channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; bool position_fixed; @@ -792,9 +804,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTTT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = true; @@ -802,9 +814,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTTF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = true; muted = false; @@ -812,9 +824,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTFF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = false; @@ -822,9 +834,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFFF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = false; @@ -832,9 +844,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisTFT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = true; orientation_fixed = false; muted = true; @@ -842,9 +854,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFTF") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = false; @@ -852,9 +864,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFTT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = true; muted = true; @@ -862,9 +874,9 @@ void ssr::OscReceiver::add_source_methods() } if (types.compare("sssffffisFFT") == 0) { - channel = argv[7]->i; + file_channel = argv[7]->i; properties_file = &(argv[8]->s); - channel_and_properties = (channel+", "+properties_file); + channel_and_properties = (file_channel+", "+properties_file); position_fixed = false; orientation_fixed = false; muted = true; @@ -881,14 +893,14 @@ void ssr::OscReceiver::add_source_methods() _handler.bool_to_string(muted) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.new_source(name, model, file_name_or_port_number, channel, - position, position_fixed, orientation, orientation_fixed, gain, - muted, properties_file); + _controller.new_source(name, model, file_name_or_port_number, + file_channel, position, position_fixed, orientation, + orientation_fixed, gain, muted, properties_file); VERBOSE2("OscReceiver: Created source with following properties:" "\nname: " << name << "\nmodel: " << model << "\nfile_name_or_port_number: " << file_name_or_port_number << - "\nchannel: " << channel << + "\nfile_channel: " << file_channel << "\nposition: " << position << "\nposition_fixed: " << position_fixed << "\norientation: " << orientation << diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 0bfed9c2..5d607887 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -272,7 +272,7 @@ bool ssr::OscSender::is_complete_source(id_t id) _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && _new_sources.at(id).has_key("gain") && - _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("file_channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && @@ -309,7 +309,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).has_key("y") && _new_sources.at(id).has_key("orientation") && _new_sources.at(id).has_key("gain") && - _new_sources.at(id).has_key("channel") && + _new_sources.at(id).has_key("file_channel") && _new_sources.at(id).has_key("properties_file") && _new_sources.at(id).has_key("position_fixed") && _new_sources.at(id).has_key("orientation_fixed") && @@ -335,7 +335,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0), _new_sources.at(id).get("orientation", 0.0), _new_sources.at(id).get("gain", 0.0), - _new_sources.at(id).get("channel", 1), + _new_sources.at(id).get("file_channel", 1), _new_sources.at(id).get("properties_file", "")); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << _handler.bool_to_message_type(_new_sources.at(id).get( @@ -352,7 +352,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << _new_sources.at(id).get("gain", 0.0) << ", " << - _new_sources.at(id).get("channel", 1) << ", " << + _new_sources.at(id).get("file_channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") << "] to client " << client->address().hostname() << ":" << @@ -1206,7 +1206,7 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { if(is_new_source(id) && file_channel > 0) { - _new_sources.at(id).set("channel", file_channel); + _new_sources.at(id).set("file_channel", file_channel); if(is_complete_source(id)) send_new_source_message_from_id(id); } From 1a6ebabd04338394dab11d0d896820fcfb80b272 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:24:44 +0200 Subject: [PATCH 320/363] src/networking/oscreceiver.cpp: Making VERBOSE output of /update callback handlers more readable, adhering to the output of the other handlers. Fixing line wraps. --- src/networking/oscreceiver.cpp | 468 +++++++++++++++++---------------- 1 file changed, 244 insertions(+), 224 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 14f2fc3b..d3bf01f0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -79,8 +79,8 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // adding new subscribing client: "/subscribe, {T,Ti,F}" - _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, + lo::Message message) { lo::Address client(message.source()); if(!message.types().compare("T")) @@ -100,15 +100,16 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got subscribe request from '" << client.hostname() << ":" << client.port() << "' for message level: " << argv[1]->i); - add_client(_handler, client, static_cast(argv[1]->i)); + add_client(_handler, client, + static_cast(argv[1]->i)); } } ); VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) { lo::Address client(message.source()); VERBOSE2("OscReceiver: Got request to set message level for client '" << @@ -129,141 +130,142 @@ void ssr::OscReceiver::add_client_to_server_methods() void ssr::OscReceiver::add_update_notification_methods() { // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << " created."); + VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/new."); + VERBOSE("OscReceiver: Added method for /update/source/new i."); // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - if(argv[0]->i == 0) - { - VERBOSE3("Update: Client '" << client.hostname() << - "', all sources deleted."); - } - else - { - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " - << argv[0]->i << " deleted."); - } + VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/delete."); + VERBOSE("OscReceiver: Added method for /update/source/delete i."); // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/position", "iff", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position: "<< argv[1]->f << "/" << argv[2]->f << - "."); + VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position."); + VERBOSE("OscReceiver: Added method for /update/source/position iff."); - // update on source position fixation: "/update/source/position_fixed, i{T,F}, - // id, {true,false}" + // update on source position fixation: "/update/source/position_fixed, + // i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string position_fixed; - if(message.types() == "iT") + bool state; + if(!message.types().compare("iT")) { - position_fixed = "true"; + state = true; } - else if(message.types() == "iF") + else if(!message.types().compare("iF")) { - position_fixed = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", position_fixed: "<< position_fixed << "."); + VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(state) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position_fixed."); + VERBOSE("OscReceiver: Added method for /update/source/position_fixed\ +i{F,T}."); - // update on source orientation: "/update/source/orientation, if, id, azimuth" + // update on source orientation: "/update/source/orientation, if, id, + // azimuth" _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", orientation: "<< argv[1]->f << "."); + VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/orientation."); + VERBOSE("OscReceiver: Added method for /update/source/orientation if."); // update on source gain: "/update/source/gain, if, id, gain" - _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", gain: "<< argv[1]->f << "."); + VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/gain."); + VERBOSE("OscReceiver: Added method for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; - if(message.types() == "iT") + bool state; + if(!message.types().compare("iT")) { - state = "true"; + state = true; } - else if(message.types() == "iF") + else if(!message.types().compare("iF")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - apf::str::A2S(argv[0]->i) << ", mute: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << + ", " << _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/mute."); + VERBOSE("OscReceiver: Added method for /update/source/mute i{F,T}."); // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", name: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/name."); + VERBOSE("OscReceiver: Added method for /update/source/name is."); // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/properties_file", "is", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", properties_file: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/properties_file."); + VERBOSE("OscReceiver: Added method for /update/source/properties_file is."); // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', decay_exponent: "<< argv[0]->f << "."); + VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); @@ -271,255 +273,272 @@ void ssr::OscReceiver::add_update_notification_methods() // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", - [](lo_arg **argv, int, lo::Message message) + _handler.server().add_method("/update/scene/amplitude_reference_distance", + "f", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', amplitude_reference_distance: "<< argv[0]->f << "."); + VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + << argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/scene/amplitude_reference_distance."); +/update/scene/amplitude_reference_distance f."); // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", model: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/model."); + VERBOSE("OscReceiver: Added method for /update/source/model is."); // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", port_name: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/port_name."); + VERBOSE("OscReceiver: Added method for /update/source/port_name is."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" _handler.server().add_method("/update/source/file_name_or_port_number", "is", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", file_name_or_port_number: "<< argv[1]->s << "."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/file_name_or_port_number, " << + argv[0]->i << ", " << name << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/source/file_name_or_port_number."); +/update/source/file_name_or_port_number is."); - // update on source file_channel: "/update/source/file_channel, ii, id, file_channel" - _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, - lo::Message message) + // update on source file_channel: "/update/source/file_channel, ii, id, + // file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", file_channel: "<< argv[1]->i << "."); + VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/file_channel."); + VERBOSE("OscReceiver: Added method for /update/source/file_channel ii."); // update on source file length: "/update/source/length, ii, id, length" - _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", length: "<< argv[1]->i << "."); + VERBOSE3("OscReceiver: Got [/update/source/length, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/length."); + VERBOSE("OscReceiver: Added method for /update/source/length ii."); // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference position: "<< argv[0]->f << "/" << argv[1]->f << - " (x/y)."); + VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/position."); + VERBOSE("OscReceiver: Added method for /update/reference/position ff."); // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/orientation."); + VERBOSE("OscReceiver: Added method for /update/reference/orientation f."); // update on reference offset position: "/update/reference_offset/position, // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/reference_offset/position", "ff", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference offset position: "<< argv[0]->f << "/" << argv[1]->f - << " (x/y)."); + VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + argv[0]->f << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference_offset/position."); + VERBOSE("OscReceiver: Added method for /update/reference_offset/position \ +ff."); // update on reference offset orientation: // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/reference_offset/orientation", "f", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', reference offset orientation: "<< argv[0]->f << " (azimuth)."); + VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << + message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added method for \ -/update/reference_offset/orientation."); +/update/reference_offset/orientation f."); // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', scene volume: "<< - argv[0]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/volume."); + VERBOSE("OscReceiver: Added method for /update/scene/volume f."); - // update on state processing: "/update/processing/state, {T,F}, {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg **argv, int, - lo::Message message) + // update on state processing: "/update/processing/state, {T,F}, + // {true,false}" + _handler.server().add_method("/update/processing/state", NULL, [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', state processing: " << state << "."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/processing/state."); + VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/transport/state", NULL, [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', transport state: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/transport/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/state."); + VERBOSE("OscReceiver: Added method for /update/transport/state {F,T}."); // update on transport seek: "/update/transport/seek, s, time" - _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', transport seek: "<< argv[0]->s << "."); + std::string seek = &argv[0]->s; + VERBOSE3("OscReceiver: Got [/update/transport/seek, " << seek << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/seek."); + VERBOSE("OscReceiver: Added method for /update/transport/seek s."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, [](lo_arg - **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - std::string state; + bool state; (void) argv; - if(message.types() == "T") + if(!message.types().compare("T")) { - state = "true"; + state = true; } - else if(message.types() == "F") + else if(!message.types().compare("F")) { - state = "false"; + state = false; } - VERBOSE3("Update: Client '" << client.hostname() << - "', scene auto_rotate_sources: "<< state << "."); + VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources."); + VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources \ +{F,T}."); // update on cpu_load: "/update/cpu_load, f, load" _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', cpu_load: "<< - argv[0]->f << "%."); + VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/cpu_load."); + VERBOSE("OscReceiver: Added method for /update/cpu_load f."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg + **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', scene sample_rate: "<< argv[0]->i << "Hz."); + VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/sample_rate."); + VERBOSE("OscReceiver: Added method for /update/scene/sample_rate i."); - // update on scene master signal level: "/update/scene/master_signal_level, f, - // master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg - **argv, int, lo::Message message) + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/update/scene/master_signal_level", "f", + [](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << - "', scene master_signal_level: "<< argv[0]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level."); + VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level \ +f."); // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, int, - lo::Message message) + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, + int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE3("Update: Client '" << client.hostname() << "', source id = " << - argv[0]->i << ", level: "<< argv[1]->f << "dB."); + VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << + ", "<< argv[1]->f << "] from client '" << message.source().hostname() + << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/level."); + VERBOSE("OscReceiver: Added method for /update/source/level if."); } /** @@ -532,8 +551,8 @@ void ssr::OscReceiver::add_poll_methods() { // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before - _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message - message) + _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, + lo::Message message) { lo::Address server(server_address(_handler)); lo::Address from(message.source()); @@ -613,8 +632,8 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/orientation if."); // set source file_channel: "/source/file_channel, ii, id, file_channel" - _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg + **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << @@ -661,7 +680,7 @@ void ssr::OscReceiver::add_source_methods() // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, - lo::Message message) + lo::Message message) { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << @@ -674,8 +693,8 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added method for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg + **argv, int, lo::Message message) { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << @@ -911,7 +930,8 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new {sssffff,sssffffis}{F,T}{F,T}{F,T}."); + VERBOSE("OscReceiver: Added method for /source/new \ +{sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" // special case: i == 0 deletes all sources! @@ -971,8 +991,8 @@ void ssr::OscReceiver::add_reference_methods() VERBOSE("OscReceiver: Added method for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , [this](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/reference_offset/position", "ff" , + [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << @@ -986,8 +1006,8 @@ void ssr::OscReceiver::add_reference_methods() // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" - _handler.server().add_method("/reference_offset/orientation", "f" , [this](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/reference_offset/orientation", "f" , + [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" From 50eac355980965333ae9d2ac34079d2db423933d Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:31:24 +0200 Subject: [PATCH 321/363] src/networking/oscreceiver.cpp: Capturing *this for callbacks, that need to access its functions. --- src/networking/oscreceiver.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d3bf01f0..0ed6577c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -165,8 +165,8 @@ void ssr::OscReceiver::add_update_notification_methods() // update on source position fixation: "/update/source/position_fixed, // i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, [](lo_arg - **argv, int, lo::Message message) + _handler.server().add_method("/update/source/position_fixed", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; if(!message.types().compare("iT")) @@ -212,8 +212,8 @@ i{F,T}."); VERBOSE("OscReceiver: Added method for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [](lo_arg **argv, - int, lo::Message message) + _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg + **argv, int, lo::Message message) { bool state; if(!message.types().compare("iT")) @@ -415,7 +415,7 @@ ff."); // update on state processing: "/update/processing/state, {T,F}, // {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [](lo_arg + _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg **argv, int, lo::Message message) { bool state; @@ -437,7 +437,7 @@ ff."); VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [](lo_arg + _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg **argv, int, lo::Message message) { bool state; @@ -473,7 +473,7 @@ ff."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, - [](lo_arg **argv, int, lo::Message message) + [this](lo_arg **argv, int, lo::Message message) { bool state; (void) argv; From d186620ad5bd130f9d94b7fd54e689f5a52230d8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 21:34:28 +0200 Subject: [PATCH 322/363] src/networking/oscreceiver.cpp: Changing VERBOSE output to 'Added callback...' instead of 'Added method...' for each callback add. --- src/networking/oscreceiver.cpp | 114 ++++++++++++++++----------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 0ed6577c..8253612b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -105,7 +105,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added method for /subscribe {T,F,Ti}."); + VERBOSE("OscReceiver: Added callback for /subscribe {T,F,Ti}."); // adding new subscribing client: "/message_level, i" _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, @@ -118,7 +118,7 @@ void ssr::OscReceiver::add_client_to_server_methods() static_cast(argv[0]->i)); } ); - VERBOSE("OscReceiver: Added method for /message_level i."); + VERBOSE("OscReceiver: Added callback for /message_level i."); } /** @@ -138,7 +138,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/new i."); + VERBOSE("OscReceiver: Added callback for /update/source/new i."); // update on deleted source: "/update/source/delete, i, id" _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, @@ -149,7 +149,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/delete i."); + VERBOSE("OscReceiver: Added callback for /update/source/delete i."); // update on source position: "/update/source/position, iff, id, x, y" _handler.server().add_method("/update/source/position", "iff", [](lo_arg @@ -161,7 +161,7 @@ void ssr::OscReceiver::add_update_notification_methods() "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position iff."); + VERBOSE("OscReceiver: Added callback for /update/source/position iff."); // update on source position fixation: "/update/source/position_fixed, // i{T,F}, id, {true,false}" @@ -183,7 +183,7 @@ void ssr::OscReceiver::add_update_notification_methods() message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/position_fixed\ + VERBOSE("OscReceiver: Added callback for /update/source/position_fixed\ i{F,T}."); // update on source orientation: "/update/source/orientation, if, id, @@ -197,7 +197,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/orientation if."); + VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); // update on source gain: "/update/source/gain, if, id, gain" _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, @@ -209,7 +209,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/gain if."); + VERBOSE("OscReceiver: Added callback for /update/source/gain if."); // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg @@ -230,7 +230,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/mute i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); // update on source name: "/update/source/name, is, id, name" _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, @@ -242,7 +242,7 @@ i{F,T}."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/name is."); + VERBOSE("OscReceiver: Added callback for /update/source/name is."); // update on source properties_file: "/update/source/properties_file, is, id, // properties_file" @@ -256,7 +256,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); // update on scene decay exponent: "/update/scene/decay_exponent, f, // decay_exponent" @@ -268,7 +268,7 @@ i{F,T}."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); // update on scene amplitude reference distance: // "update/scene/amplitude_reference_distance, f, @@ -281,7 +281,7 @@ i{F,T}."); ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/scene/amplitude_reference_distance f."); // update on source model: "/update/source/model, is, id, model" @@ -295,7 +295,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/model is."); + VERBOSE("OscReceiver: Added callback for /update/source/model is."); // update on source port_name: "/update/source/port_name, is, id, port_name" _handler.server().add_method("/update/source/port_name", "is", [](lo_arg @@ -308,7 +308,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/port_name is."); + VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" @@ -322,7 +322,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/source/file_name_or_port_number is."); // update on source file_channel: "/update/source/file_channel, ii, id, @@ -336,7 +336,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, @@ -348,7 +348,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/length ii."); + VERBOSE("OscReceiver: Added callback for /update/source/length ii."); // update on reference position: "/update/reference/position, ff, x, y" _handler.server().add_method("/update/reference/position", "ff", [](lo_arg @@ -360,7 +360,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/position ff."); + VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); // update on reference orientation: "/update/reference/orientation, f, // azimuth" @@ -372,7 +372,7 @@ i{F,T}."); << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); // update on reference offset position: "/update/reference_offset/position, // ff, x, y" @@ -385,7 +385,7 @@ i{F,T}."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/reference_offset/position \ + VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ ff."); // update on reference offset orientation: @@ -399,7 +399,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for \ + VERBOSE("OscReceiver: Added callback for \ /update/reference_offset/orientation f."); // update on scene volume: "/update/scene/volume, f, volume" @@ -411,7 +411,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/volume f."); + VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); // update on state processing: "/update/processing/state, {T,F}, // {true,false}" @@ -434,7 +434,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/processing/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); // update on transport state: "/update/transport/state, {T,F}, {true,false}" _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg @@ -456,7 +456,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); // update on transport seek: "/update/transport/seek, s, time" _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, @@ -468,7 +468,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/transport/seek s."); + VERBOSE("OscReceiver: Added callback for /update/transport/seek s."); // update on scene source auto rotation: "/update/scene/auto_rotate_sources, // {T,F}, {true,false}" @@ -491,7 +491,7 @@ ff."); "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/auto_rotate_sources \ + VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ {F,T}."); // update on cpu_load: "/update/cpu_load, f, load" @@ -503,7 +503,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/cpu_load f."); + VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg @@ -514,7 +514,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/sample_rate i."); + VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); // update on scene master signal level: "/update/scene/master_signal_level, // f, master_signal_level" @@ -526,7 +526,7 @@ ff."); << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/scene/master_signal_level \ + VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ f."); // update on source signal level: "/update/source/level, if, id, level" @@ -538,7 +538,7 @@ f."); << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added method for /update/source/level if."); + VERBOSE("OscReceiver: Added callback for /update/source/level if."); } /** @@ -570,7 +570,7 @@ void ssr::OscReceiver::add_poll_methods() } } ); - VERBOSE("OscReceiver: Added method for /poll."); + VERBOSE("OscReceiver: Added callback for /poll."); } /** @@ -595,7 +595,7 @@ void ssr::OscReceiver::add_source_methods() argv[2]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/position iff."); + VERBOSE("OscReceiver: Added callback for /source/position iff."); // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg @@ -617,7 +617,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/position_fixed i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/position_fixed i{T,F}."); // set source orientation: "/source/orientation, if, id, azimuth" _handler.server().add_method("/source/orientation", "if", [this](lo_arg @@ -629,7 +629,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/orientation if."); + VERBOSE("OscReceiver: Added callback for /source/orientation if."); // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg @@ -641,7 +641,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } ); - VERBOSE("OscReceiver: Added method for /source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, @@ -654,7 +654,7 @@ void ssr::OscReceiver::add_source_methods() apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /source/gain if."); + VERBOSE("OscReceiver: Added callback for /source/gain if."); // set source mute: "/source/mute, i{T,F}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, @@ -676,7 +676,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/mute i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/mute i{T,F}."); // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, @@ -690,7 +690,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/name is."); + VERBOSE("OscReceiver: Added callback for /source/name is."); // set source file: "/source/properties_file, is, id, properties_file" _handler.server().add_method("/source/properties_file", "is", [this](lo_arg @@ -703,7 +703,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_properties_file(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /source/properties_file is."); // set source model: "/source/model, is, id, model" _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, @@ -721,7 +721,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_model(argv[0]->i, model); } ); - VERBOSE("OscReceiver: Added method for /source/model is."); + VERBOSE("OscReceiver: Added callback for /source/model is."); // set source port name: "/source/port_name, is, id, port_name" _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, @@ -734,7 +734,7 @@ void ssr::OscReceiver::add_source_methods() _controller.set_source_port_name(argv[0]->i, name); } ); - VERBOSE("OscReceiver: Added method for /source/port_name is."); + VERBOSE("OscReceiver: Added callback for /source/port_name is."); // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, // file_name_or_port_number, x, y, orientation, gain, position_fixed, @@ -930,7 +930,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/new \ + VERBOSE("OscReceiver: Added callback for /source/new \ {sssffff,sssffffis}{F,T}{F,T}{F,T}."); // delete source: "/source/delete, i, id" @@ -951,7 +951,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added method for /source/delete i."); + VERBOSE("OscReceiver: Added callback for /source/delete i."); } /** @@ -976,7 +976,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/position ff."); + VERBOSE("OscReceiver: Added callback for /reference/position ff."); // set reference orientation: "/reference/orientation, f, azimuth" _handler.server().add_method("/reference/orientation", "f", [this](lo_arg @@ -988,7 +988,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_orientation(Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /reference/orientation f."); // set reference offset position: "/reference_offset/position, ff, x, y" _handler.server().add_method("/reference_offset/position", "ff" , @@ -1002,7 +1002,7 @@ void ssr::OscReceiver::add_reference_methods() argv[1]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/position ff."); + VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" @@ -1015,7 +1015,7 @@ void ssr::OscReceiver::add_reference_methods() _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /reference_offset/orientation f."); + VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); } /** @@ -1040,7 +1040,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.save_scene_as_XML(name); } ); - VERBOSE("OscReceiver: Added method for /scene/save s."); + VERBOSE("OscReceiver: Added callback for /scene/save s."); // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, @@ -1053,7 +1053,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.load_scene(name); } ); - VERBOSE("OscReceiver: Added method for /scene/load s."); + VERBOSE("OscReceiver: Added callback for /scene/load s."); // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, @@ -1065,7 +1065,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); } ); - VERBOSE("OscReceiver: Added method for /scene/volume f."); + VERBOSE("OscReceiver: Added callback for /scene/volume f."); // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, @@ -1078,7 +1078,7 @@ void ssr::OscReceiver::add_scene_methods() _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added method for /scene/clear."); + VERBOSE("OscReceiver: Added callback for /scene/clear."); } /** @@ -1116,7 +1116,7 @@ void ssr::OscReceiver::add_processing_methods() } } ); - VERBOSE("OscReceiver: Added method for /processing/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /processing/state {T,F}."); } @@ -1155,7 +1155,7 @@ void ssr::OscReceiver::add_transport_methods() } } ); - VERBOSE("OscReceiver: Added method for /transport/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /transport/state {T,F}."); // rewind transport state: "/transport/rewind" _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg @@ -1168,7 +1168,7 @@ void ssr::OscReceiver::add_transport_methods() _controller.transport_locate(0); } ); - VERBOSE("OscReceiver: Added method for /transport/rewind."); + VERBOSE("OscReceiver: Added callback for /transport/rewind."); // seek transport state: "/transport/seek, s, time" _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, @@ -1190,7 +1190,7 @@ void ssr::OscReceiver::add_transport_methods() } } ); - VERBOSE("OscReceiver: Added method for /transport/seek s."); + VERBOSE("OscReceiver: Added callback for /transport/seek s."); } /** @@ -1215,6 +1215,6 @@ void ssr::OscReceiver::add_tracker_methods() _controller.calibrate_client(); } ); - VERBOSE("OscReceiver: Added method for /tracker/reset."); + VERBOSE("OscReceiver: Added callback for /tracker/reset."); } From 976dbda044c8e643d8e26b1209bb7d26fdc34605 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 22:33:37 +0200 Subject: [PATCH 323/363] src/networking/oscreceiver.cpp: Ordering all callback handlers alphabetically for readability. Unifying output style of message types. --- src/networking/oscreceiver.cpp | 827 +++++++++++++++++---------------- 1 file changed, 414 insertions(+), 413 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 8253612b..e96a0027 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -42,23 +42,23 @@ void ssr::OscReceiver::start() if (_handler.is_server()) { add_client_to_server_methods(); - add_update_notification_methods(); - add_source_methods(); + add_processing_methods(); add_reference_methods(); add_scene_methods(); - add_processing_methods(); - add_transport_methods(); + add_source_methods(); add_tracker_methods(); + add_transport_methods(); + add_update_notification_methods(); } else if (_handler.is_client()) { add_poll_methods(); - add_source_methods(); add_reference_methods(); add_scene_methods(); + add_source_methods(); add_processing_methods(); - add_transport_methods(); add_tracker_methods(); + add_transport_methods(); } } @@ -78,6 +78,19 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { + // adding new subscribing client: "/message_level, i" + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) + { + lo::Address client(message.source()); + VERBOSE2("OscReceiver: Got request to set message level for client '" << + client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + set_message_level(_handler, client, + static_cast(argv[0]->i)); + } + ); + VERBOSE("OscReceiver: Added callback for /message_level i."); + // adding new subscribing client: "/subscribe, {T,Ti,F}" _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -105,20 +118,7 @@ void ssr::OscReceiver::add_client_to_server_methods() } } ); - VERBOSE("OscReceiver: Added callback for /subscribe {T,F,Ti}."); - - // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, - int, lo::Message message) - { - lo::Address client(message.source()); - VERBOSE2("OscReceiver: Got request to set message level for client '" << - client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); - set_message_level(_handler, client, - static_cast(argv[0]->i)); - } - ); - VERBOSE("OscReceiver: Added callback for /message_level i."); + VERBOSE("OscReceiver: Added callback for /subscribe {F,T,Ti}."); } /** @@ -129,186 +129,200 @@ void ssr::OscReceiver::add_client_to_server_methods() */ void ssr::OscReceiver::add_update_notification_methods() { - // update on new source: "/update/source/new, i, id" - _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, - int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i - << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/new i."); - - // update on deleted source: "/update/source/delete, i, id" - _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, - int, lo::Message message) + // update on cpu_load: "/update/cpu_load, f, load" + _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i - << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/delete i."); + VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); - // update on source position: "/update/source/position, iff, id, x, y" - _handler.server().add_method("/update/source/position", "iff", [](lo_arg + // update on state processing: "/update/processing/state, {F,T}, + // false|true" + _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << - ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/position iff."); - - // update on source position fixation: "/update/source/position_fixed, - // i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/position_fixed", NULL, - [this](lo_arg **argv, int, lo::Message message) { bool state; - if(!message.types().compare("iT")) + (void) argv; + if(!message.types().compare("T")) { state = true; } - else if(!message.types().compare("iF")) + else if(!message.types().compare("F")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << - argv[0]->i << ", " << _handler.bool_to_string(state) << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + VERBOSE3("OscReceiver: Got [/update/processing/state, " << + _handler.bool_to_string(state) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/position_fixed\ -i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); - // update on source orientation: "/update/source/orientation, if, id, + // update on reference orientation: "/update/reference/orientation, f, // azimuth" - _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); + + // update on reference position: "/update/reference/position, ff, x, y" + _handler.server().add_method("/update/reference/position", "ff", [](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); + VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); - // update on source gain: "/update/source/gain, if, id, gain" - _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, - int, lo::Message message) + // update on reference offset orientation: + // "/update/reference_offset/orientation, f, azimuth" + _handler.server().add_method("/update/reference_offset/orientation", "f", + [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i - << ", " << argv[1]->f << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for \ +/update/reference_offset/orientation f."); + + // update on reference offset position: "/update/reference_offset/position, + // ff, x, y" + _handler.server().add_method("/update/reference_offset/position", "ff", + [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/gain if."); + VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ +ff."); - // update on source mute: "/update/source/mute, i{T,F}, id, {true,false}" - _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg - **argv, int, lo::Message message) + // update on scene amplitude reference distance: + // "update/scene/amplitude_reference_distance, f, + // amplitude_reference_distance" + _handler.server().add_method("/update/scene/amplitude_reference_distance", + "f", [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + << argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for \ +/update/scene/amplitude_reference_distance f."); + + // update on scene source auto rotation: "/update/scene/auto_rotate_sources, + // {F,T}, false|true" + _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; - if(!message.types().compare("iT")) + (void) argv; + if(!message.types().compare("T")) { state = true; } - else if(!message.types().compare("iF")) + else if(!message.types().compare("F")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << - ", " << _handler.bool_to_string(state) << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); + VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ +{F,T}."); - // update on source name: "/update/source/name, is, id, name" - _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, - int, lo::Message message) + // update on scene decay exponent: "/update/scene/decay_exponent, f, + // decay_exponent" + _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " - << name << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/name is."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); - // update on source properties_file: "/update/source/properties_file, is, id, - // properties_file" - _handler.server().add_method("/update/source/properties_file", "is", + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/update/scene/master_signal_level", "f", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << - argv[0]->i << ", " << name << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << + argv[0]->f << "] from client '" << message.source().hostname() << ":" + << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); + VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ +f."); - // update on scene decay exponent: "/update/scene/decay_exponent, f, - // decay_exponent" - _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg + // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" + _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f - << "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); - // update on scene amplitude reference distance: - // "update/scene/amplitude_reference_distance, f, - // amplitude_reference_distance" - _handler.server().add_method("/update/scene/amplitude_reference_distance", - "f", [](lo_arg **argv, int, lo::Message message) + // update on scene volume: "/update/scene/volume, f, volume" + _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " - << argv[0]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for \ -/update/scene/amplitude_reference_distance f."); + VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); - // update on source model: "/update/source/model, is, id, model" - _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + // update on deleted source: "/update/source/delete, i, id" + _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " - << name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/model is."); + VERBOSE("OscReceiver: Added callback for /update/source/delete i."); - // update on source port_name: "/update/source/port_name, is, id, port_name" - _handler.server().add_method("/update/source/port_name", "is", [](lo_arg + // update on source file_channel: "/update/source/file_channel, ii, id, + // file_channel" + _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { - std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/port_name, " << - argv[0]->i << ", " << name << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); + VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); // update on source file_name_or_port_number: // "/update/source/file_name_or_port_number, is, id, file_name_or_port_number" @@ -325,18 +339,17 @@ i{F,T}."); VERBOSE("OscReceiver: Added callback for \ /update/source/file_name_or_port_number is."); - // update on source file_channel: "/update/source/file_channel, ii, id, - // file_channel" - _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg - **argv, int, lo::Message message) + // update on source gain: "/update/source/gain, if, id, gain" + _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i - << ", " << argv[1]->i << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/source/file_channel ii."); + VERBOSE("OscReceiver: Added callback for /update/source/gain if."); // update on source file length: "/update/source/length, ii, id, length" _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, @@ -350,113 +363,148 @@ i{F,T}."); ); VERBOSE("OscReceiver: Added callback for /update/source/length ii."); - // update on reference position: "/update/reference/position, ff, x, y" - _handler.server().add_method("/update/reference/position", "ff", [](lo_arg - **argv, int, lo::Message message) + // update on source signal level: "/update/source/level, if, id, level" + _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << + ", "<< argv[1]->f << "] from client '" << message.source().hostname() + << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference/position ff."); + VERBOSE("OscReceiver: Added callback for /update/source/level if."); - // update on reference orientation: "/update/reference/orientation, f, - // azimuth" - _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg - **argv, int, lo::Message message) + // update on source model: "/update/source/model, is, id, model" + _handler.server().add_method("/update/source/model", "is", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << + "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/source/model is."); - // update on reference offset position: "/update/reference_offset/position, - // ff, x, y" - _handler.server().add_method("/update/reference_offset/position", "ff", - [](lo_arg **argv, int, lo::Message message) + // update on source mute: "/update/source/mute, i{F,T}, id, false|true" + _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg + **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << - argv[0]->f << ", " << argv[1]->f << "] from client '" << + bool state; + if(!message.types().compare("iT")) + { + state = true; + } + else if(!message.types().compare("iF")) + { + state = false; + } + VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << + ", " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/reference_offset/position \ -ff."); + VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); - // update on reference offset orientation: - // "/update/reference_offset/orientation, f, azimuth" - _handler.server().add_method("/update/reference_offset/orientation", "f", - [](lo_arg **argv, int, lo::Message message) + // update on source name: "/update/source/name, is, id, name" + _handler.server().add_method("/update/source/name", "is", [](lo_arg **argv, + int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for \ -/update/reference_offset/orientation f."); + VERBOSE("OscReceiver: Added callback for /update/source/name is."); - // update on scene volume: "/update/scene/volume, f, volume" - _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, + // update on source orientation: "/update/source/orientation, if, id, + // azimuth" + _handler.server().add_method("/update/source/orientation", "if", [](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/orientation if."); + + // update on new source: "/update/source/new, i, id" + _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << + VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/volume f."); + VERBOSE("OscReceiver: Added callback for /update/source/new i."); - // update on state processing: "/update/processing/state, {T,F}, - // {true,false}" - _handler.server().add_method("/update/processing/state", NULL, [this](lo_arg + // update on source port_name: "/update/source/port_name, is, id, port_name" + _handler.server().add_method("/update/source/port_name", "is", [](lo_arg **argv, int, lo::Message message) { - bool state; - (void) argv; - if(!message.types().compare("T")) - { - state = true; - } - else if(!message.types().compare("F")) - { - state = false; - } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << - _handler.bool_to_string(state) << "] from client '" << + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/processing/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/port_name is."); - // update on transport state: "/update/transport/state, {T,F}, {true,false}" - _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg + // update on source position: "/update/source/position, iff, id, x, y" + _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/position iff."); + + // update on source position fixation: "/update/source/position_fixed, + // i{F,T}, id, false|true" + _handler.server().add_method("/update/source/position_fixed", NULL, + [this](lo_arg **argv, int, lo::Message message) { bool state; - (void) argv; - if(!message.types().compare("T")) + if(!message.types().compare("iT")) { state = true; } - else if(!message.types().compare("F")) + else if(!message.types().compare("iF")) { state = false; } - VERBOSE3("OscReceiver: Got [/update/transport/state, " << - _handler.bool_to_string(state) << "] from client '" << + VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(state) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /update/source/position_fixed \ +i{F,T}."); + + // update on source properties_file: "/update/source/properties_file, is, id, + // properties_file" + _handler.server().add_method("/update/source/properties_file", "is", + [](lo_arg **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); + VERBOSE("OscReceiver: Added callback for /update/source/properties_file is."); // update on transport seek: "/update/transport/seek, s, time" _handler.server().add_method("/update/transport/seek", "s", [](lo_arg **argv, @@ -470,10 +518,9 @@ ff."); ); VERBOSE("OscReceiver: Added callback for /update/transport/seek s."); - // update on scene source auto rotation: "/update/scene/auto_rotate_sources, - // {T,F}, {true,false}" - _handler.server().add_method("/update/scene/auto_rotate_sources", NULL, - [this](lo_arg **argv, int, lo::Message message) + // update on transport state: "/update/transport/state, {F,T}, false|true" + _handler.server().add_method("/update/transport/state", NULL, [this](lo_arg + **argv, int, lo::Message message) { bool state; (void) argv; @@ -485,60 +532,13 @@ ff."); { state = false; } - VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + VERBOSE3("OscReceiver: Got [/update/transport/state, " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/auto_rotate_sources \ -{F,T}."); - - // update on cpu_load: "/update/cpu_load, f, load" - _handler.server().add_method("/update/cpu_load", "f", [](lo_arg **argv, int, - lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/cpu_load, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/cpu_load f."); - - // update on scene sample rate: "/update/scene/sample_rate, i, sample_rate" - _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg - **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/scene/sample_rate i."); - - // update on scene master signal level: "/update/scene/master_signal_level, - // f, master_signal_level" - _handler.server().add_method("/update/scene/master_signal_level", "f", - [](lo_arg **argv, int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/scene/master_signal_level, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/scene/master_signal_level \ -f."); - - // update on source signal level: "/update/source/level, if, id, level" - _handler.server().add_method("/update/source/level", "if", [](lo_arg **argv, - int, lo::Message message) - { - VERBOSE3("OscReceiver: Got [/update/source/level, " << argv[0]->i << - ", "<< argv[1]->f << "] from client '" << message.source().hostname() - << ":" << message.source().port() << "'."); - } - ); - VERBOSE("OscReceiver: Added callback for /update/source/level if."); + VERBOSE("OscReceiver: Added callback for /update/transport/state {F,T}."); } /** @@ -584,53 +584,26 @@ void ssr::OscReceiver::add_poll_methods() */ void ssr::OscReceiver::add_source_methods() { - // set source position: "/source/position, iff, id, x, y" - _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + // delete source: "/source/delete, i, id" + // special case: i == 0 deletes all sources! + _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << - argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /source/position iff."); - - // set source fixed: "/source/position_fixed, i{T,F}, id, true|false" - _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg - **argv, int, lo::Message message) - { - if (!message.types().compare("iT")) + VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + if (argv[0]->i == 0) { - VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, true); + _controller.delete_all_sources(); } - else if (!message.types().compare("iF")) + else { - VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, false); + _controller.delete_source(argv[0]->i); } } ); - VERBOSE("OscReceiver: Added callback for /source/position_fixed i{T,F}."); - - // set source orientation: "/source/orientation, if, id, azimuth" - _handler.server().add_method("/source/orientation", "if", [this](lo_arg - **argv, int, lo::Message message) - { - VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /source/orientation if."); + VERBOSE("OscReceiver: Added callback for /source/delete i."); // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, int, lo::Message message) @@ -654,9 +627,27 @@ void ssr::OscReceiver::add_source_methods() apf::math::dB2linear(argv[1]->f)); } ); - VERBOSE("OscReceiver: Added callback for /source/gain if."); + VERBOSE("OscReceiver: Added callback for /source/gain if."); + + // set source model: "/source/model, is, id, model" + _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, + int, lo::Message message) + { + std::string name(&argv[1]->s); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(name, model)) + { + model = Source::point; + } + VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_model(argv[0]->i, model); + } + ); + VERBOSE("OscReceiver: Added callback for /source/model is."); - // set source mute: "/source/mute, i{T,F}, id, true|false" + // set source mute: "/source/mute, i{F,T}, id, true|false" _handler.server().add_method("/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -676,7 +667,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/mute i{T,F}."); + VERBOSE("OscReceiver: Added callback for /source/mute i{F,T}."); // set source name: "/source/name, is, id, name" _handler.server().add_method("/source/name", "is", [this](lo_arg **argv, int, @@ -692,54 +683,10 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/name is."); - // set source file: "/source/properties_file, is, id, properties_file" - _handler.server().add_method("/source/properties_file", "is", [this](lo_arg - **argv, int, lo::Message message) - { - std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_properties_file(argv[0]->i, name); - } - ); - VERBOSE("OscReceiver: Added callback for /source/properties_file is."); - - // set source model: "/source/model, is, id, model" - _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, - int, lo::Message message) - { - std::string name(&argv[1]->s); - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(name, model)) - { - model = Source::point; - } - VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_model(argv[0]->i, model); - } - ); - VERBOSE("OscReceiver: Added callback for /source/model is."); - - // set source port name: "/source/port_name, is, id, port_name" - _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, - int, lo::Message message) - { - std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_port_name(argv[0]->i, name); - } - ); - VERBOSE("OscReceiver: Added callback for /source/port_name is."); - - // create new source: "/source/new, sssffff{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffff{F,T}{F,T}{F,T}, name, model, // file_name_or_port_number, x, y, orientation, gain, position_fixed, // orientation_fixed, muted" - // create new source: "/source/new, sssffffis{T,F}{T,F}{T,F}, name, model, + // create new source: "/source/new, sssffffis{F,T}{F,T}{F,T}, name, model, // file_name_or_port_number, x, y, orientation, gain, file_channel, // properties_file, position_fixed, orientation_fixed, muted" _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, @@ -933,25 +880,79 @@ void ssr::OscReceiver::add_source_methods() VERBOSE("OscReceiver: Added callback for /source/new \ {sssffff,sssffffis}{F,T}{F,T}{F,T}."); - // delete source: "/source/delete, i, id" - // special case: i == 0 deletes all sources! - _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, + // set source orientation: "/source/orientation, if, id, azimuth" + _handler.server().add_method("/source/orientation", "if", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /source/orientation if."); + + // set source port name: "/source/port_name, is, id, port_name" + _handler.server().add_method("/source/port_name", "is", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << + name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - if (argv[0]->i == 0) + _controller.set_source_port_name(argv[0]->i, name); + } + ); + VERBOSE("OscReceiver: Added callback for /source/port_name is."); + + // set source position: "/source/position, iff, id, x, y" + _handler.server().add_method("/source/position", "iff", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << + argv[1]->f << ", " << argv[2]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /source/position iff."); + + // set source fixed: "/source/position_fixed, i{F,T}, id, true|false" + _handler.server().add_method("/source/position_fixed", NULL, [this](lo_arg + **argv, int, lo::Message message) + { + if (!message.types().compare("iT")) { - _controller.delete_all_sources(); + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", true] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, true); } - else + else if (!message.types().compare("iF")) { - _controller.delete_source(argv[0]->i); + VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << + ", false] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + _controller.set_source_position_fixed(argv[0]->i, false); } } ); - VERBOSE("OscReceiver: Added callback for /source/delete i."); + VERBOSE("OscReceiver: Added callback for /source/position_fixed i{F,T}."); + + // set source file: "/source/properties_file, is, id, properties_file" + _handler.server().add_method("/source/properties_file", "is", [this](lo_arg + **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << + ", " << name << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_source_properties_file(argv[0]->i, name); + } + ); + VERBOSE("OscReceiver: Added callback for /source/properties_file is."); + } /** @@ -966,18 +967,6 @@ void ssr::OscReceiver::add_source_methods() */ void ssr::OscReceiver::add_reference_methods() { - // set reference position: "/reference/position, ff, x, y" - _handler.server().add_method("/reference/position", "ff", [this](lo_arg - **argv, int, lo::Message message) - { - VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); - } - ); - VERBOSE("OscReceiver: Added callback for /reference/position ff."); - // set reference orientation: "/reference/orientation, f, azimuth" _handler.server().add_method("/reference/orientation", "f", [this](lo_arg **argv, int, lo::Message message) @@ -990,19 +979,17 @@ void ssr::OscReceiver::add_reference_methods() ); VERBOSE("OscReceiver: Added callback for /reference/orientation f."); - // set reference offset position: "/reference_offset/position, ff, x, y" - _handler.server().add_method("/reference_offset/position", "ff" , - [this](lo_arg **argv, int, lo::Message message) + // set reference position: "/reference/position, ff, x, y" + _handler.server().add_method("/reference/position", "ff", [this](lo_arg + **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/reference/offset_position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f)); + VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " + << argv[1]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); - VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); + VERBOSE("OscReceiver: Added callback for /reference/position ff."); // set reference offset orientation: "/reference_offset/orientation, f, // azimuth" @@ -1016,6 +1003,20 @@ void ssr::OscReceiver::add_reference_methods() } ); VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); + + // set reference offset position: "/reference_offset/position, ff, x, y" + _handler.server().add_method("/reference_offset/position", "ff" , + [this](lo_arg **argv, int, lo::Message message) + { + VERBOSE2("OscReceiver: Got [/reference_offset/position, " << argv[0]->f + << ", " << argv[1]->f << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f)); + } + ); + VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); } /** @@ -1029,19 +1030,19 @@ void ssr::OscReceiver::add_reference_methods() */ void ssr::OscReceiver::add_scene_methods() { - // save scene to file: "/scene/save, s, file" - _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, - lo::Message message) + // clear scene: "/scene/clear" + _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, + int, lo::Message message) { - std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << + (void) argv; + VERBOSE2("OscReceiver: [/scene/clear] from client '" << + message.source().hostname() << ":" << message.source().port() << "'."); - _controller.save_scene_as_XML(name); + _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added callback for /scene/save s."); + VERBOSE("OscReceiver: Added callback for /scene/clear."); // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) @@ -1055,6 +1056,19 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/load s."); + // save scene to file: "/scene/save, s, file" + _handler.server().add_method("/scene/save", "s" , [this](lo_arg **argv, int, + lo::Message message) + { + std::string name(&argv[0]->s); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" + << message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.save_scene_as_XML(name); + } + ); + VERBOSE("OscReceiver: Added callback for /scene/save s."); + // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) @@ -1066,19 +1080,6 @@ void ssr::OscReceiver::add_scene_methods() } ); VERBOSE("OscReceiver: Added callback for /scene/volume f."); - - // clear scene: "/scene/clear" - _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, - int, lo::Message message) - { - (void) argv; - VERBOSE2("OscReceiver: [/scene/clear] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.delete_all_sources(); - } - ); - VERBOSE("OscReceiver: Added callback for /scene/clear."); } /** @@ -1106,7 +1107,7 @@ void ssr::OscReceiver::add_processing_methods() "'."); _controller.start_processing(); } - else if(!message.types().compare("T")) + else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/processing/state, " << _handler.bool_to_string(false) << "] from client '" << @@ -1116,7 +1117,7 @@ void ssr::OscReceiver::add_processing_methods() } } ); - VERBOSE("OscReceiver: Added callback for /processing/state {T,F}."); + VERBOSE("OscReceiver: Added callback for /processing/state {F,T}."); } @@ -1132,31 +1133,6 @@ void ssr::OscReceiver::add_processing_methods() */ void ssr::OscReceiver::add_transport_methods() { - // set transport state: "transport/state, T, true" - _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, - int, lo::Message message) - { - (void) argv; - if(!message.types().compare("T")) - { - VERBOSE2("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_start(); - } - if(!message.types().compare("F")) - { - VERBOSE2("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_stop(); - } - } - ); - VERBOSE("OscReceiver: Added callback for /transport/state {T,F}."); - // rewind transport state: "/transport/rewind" _handler.server().add_method("/transport/rewind", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1191,6 +1167,31 @@ void ssr::OscReceiver::add_transport_methods() } ); VERBOSE("OscReceiver: Added callback for /transport/seek s."); + + // set transport state: "transport/state, T, true" + _handler.server().add_method("/transport/state", "T" , [this](lo_arg **argv, + int, lo::Message message) + { + (void) argv; + if(!message.types().compare("T")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_start(); + } + if(!message.types().compare("F")) + { + VERBOSE2("OscReceiver: Got [/transport/state, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + _controller.transport_stop(); + } + } + ); + VERBOSE("OscReceiver: Added callback for /transport/state {F,T}."); } /** From e2e041f5be5cdc6f057edb58405966ab56dd5c85 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 5 Jun 2017 23:39:06 +0200 Subject: [PATCH 324/363] src/networking/oscreceiver.cpp: Moving call to add_processing_methods() to alphabetical location. Changing VERBOSE messages in /subscribe and /message_level callbacks to adhere to style standard. Raising VERBOSE messages for /transport/seek and /transport/state messages to VERBOSE3. --- src/networking/oscreceiver.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e96a0027..4f2df46b 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -53,10 +53,10 @@ void ssr::OscReceiver::start() else if (_handler.is_client()) { add_poll_methods(); + add_processing_methods(); add_reference_methods(); add_scene_methods(); add_source_methods(); - add_processing_methods(); add_tracker_methods(); add_transport_methods(); } @@ -82,9 +82,9 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); - VERBOSE2("OscReceiver: Got request to set message level for client '" << - client.hostname() << ":" << client.port() << "' to: " << argv[0]->i); + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); set_message_level(_handler, client, static_cast(argv[0]->i)); } @@ -98,21 +98,24 @@ void ssr::OscReceiver::add_client_to_server_methods() lo::Address client(message.source()); if(!message.types().compare("T")) { - VERBOSE2("OscReceiver: Got subscribe request from '" << + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << "] from client '" << client.hostname() << ":" << client.port() << "'."); add_client(_handler, client, ssr::MessageLevel::CLIENT); } else if(!message.types().compare("F")) { - VERBOSE2("OscReceiver: Got unsubscribe request from '" << + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(false) << "] from client '" << client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); } else if(!message.types().compare("Ti")) { - VERBOSE2("OscReceiver: Got subscribe request from '" << - client.hostname() << ":" << client.port() << - "' for message level: " << argv[1]->i); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << ", " << argv[1]->i << + "] from client '" << client.hostname() << ":" << client.port() << + "'."); add_client(_handler, client, static_cast(argv[1]->i)); } @@ -1154,7 +1157,7 @@ void ssr::OscReceiver::add_transport_methods() std::string message_time(&argv[0]->s); if(apf::str::string2time(message_time, time)) { - VERBOSE2("OscReceiver: Got [/transport/seek, " << message_time << + VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.transport_locate(time); @@ -1175,7 +1178,7 @@ void ssr::OscReceiver::add_transport_methods() (void) argv; if(!message.types().compare("T")) { - VERBOSE2("OscReceiver: Got [/transport/state, " << + VERBOSE3("OscReceiver: Got [/transport/state, " << _handler.bool_to_string(true) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1183,7 +1186,7 @@ void ssr::OscReceiver::add_transport_methods() } if(!message.types().compare("F")) { - VERBOSE2("OscReceiver: Got [/transport/state, " << + VERBOSE3("OscReceiver: Got [/transport/state, " << _handler.bool_to_string(false) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); From ec48974ca350334d37acc72fb4ff887b83da9d56 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 6 Jun 2017 10:41:46 +0200 Subject: [PATCH 325/363] src/networking/oscreceiver.cpp: Adding various TODOs. Fixing errernous call to unitialized variable in /message_level callback handler. Adding First prototype of variable string for client/server VERBOSE message. --- src/networking/oscreceiver.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 4f2df46b..2e5d1436 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -85,7 +85,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, client, + set_message_level(_handler, message.source(), static_cast(argv[0]->i)); } ); @@ -110,6 +110,8 @@ void ssr::OscReceiver::add_client_to_server_methods() client.hostname() << ":" << client.port() << "'."); deactivate_client(_handler, client); } + //TODO: add /subscribe, Fss, host, port + //TODO: add /subscribe, Tiss, host, port else if(!message.types().compare("Ti")) { VERBOSE2("OscReceiver: Got [/subscribe, " << @@ -592,8 +594,9 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { + std::string from = (_handler.is_server())? "client": "server"; VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << + "] from " << from << " '" << message.source().hostname() << ":" << message.source().port() << "'."); if (argv[0]->i == 0) { @@ -605,8 +608,8 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/delete i."); + // set source file_channel: "/source/file_channel, ii, id, file_channel" _handler.server().add_method("/source/file_channel", "ii", [this](lo_arg **argv, int, lo::Message message) @@ -1033,6 +1036,13 @@ void ssr::OscReceiver::add_reference_methods() */ void ssr::OscReceiver::add_scene_methods() { + //TODO: add /scene/transfer ss, host, port (_controller.get_scene_as_XML()) + //_add_master_volume(node); + //_add_transport_state(node); + //_add_reference(node); + //_add_loudspeakers(node); + //_add_sources(node); + // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1044,8 +1054,8 @@ void ssr::OscReceiver::add_scene_methods() _controller.delete_all_sources(); } ); - VERBOSE("OscReceiver: Added callback for /scene/clear."); + // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) From 408cd902d3805104783fe8ccbcaf8f14149f4e6c Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 6 Jun 2017 16:37:35 +0200 Subject: [PATCH 326/363] src/networking/oscreceiver.h: Using std::strings for hostname and port in set_message_level(). src/networking/oscreceiver.cpp: Adding /message_level ssi callback handler. src/networking/oschandler.h: Changing definition of set_message_level friend function to use std::string types for hostname and port instead of a lo::Address. src/networking/oschandler.cpp: Changing OscReceiver::set_message_level() parameters to use std::strings for hostname and port instead of a lo::Address and updating documentation for the function. --- src/networking/oschandler.cpp | 11 ++++++----- src/networking/oschandler.h | 4 ++-- src/networking/oscreceiver.cpp | 29 ++++++++++++++++++++++------- src/networking/oscreceiver.h | 4 ++-- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index e0d4b375..6dae5aa0 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -202,13 +202,14 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) /** * OscHandler's friend function to set a client's message_level * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be deactivated + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel to be used for client */ -void ssr::OscReceiver::set_message_level(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level) +void ssr::OscReceiver::set_message_level(OscHandler& self, std::string + hostname, std::string port, ssr::MessageLevel message_level) { - self._osc_sender.set_client_message_level(client.hostname(), client.port(), - message_level); + self._osc_sender.set_client_message_level(hostname, port, message_level); } diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 0faaa5ee..0e5bec51 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -79,8 +79,8 @@ class OscHandler ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address client); - friend void OscReceiver::set_message_level(OscHandler& self, lo::Address - client, ssr::MessageLevel message_level); + friend void OscReceiver::set_message_level(OscHandler& self, std::string + hostname, std::string port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2e5d1436..d6928450 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -79,17 +79,32 @@ void ssr::OscReceiver::stop() void ssr::OscReceiver::add_client_to_server_methods() { // adding new subscribing client: "/message_level, i" - _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); - set_message_level(_handler, message.source(), - static_cast(argv[0]->i)); + if(!message.types().compare("i")) + { + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + set_message_level(_handler, message.source().hostname(), + message.source().port(), + static_cast(argv[0]->i)); + } + else if(!message.types().compare("ssi")) + { + std::string hostname(&argv[0]->s); + std::string port(&argv[1]->s); + VERBOSE2("OscReceiver: Got [/message_level, " << hostname << ", " << + port << ", " << argv[2]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + set_message_level(_handler, hostname, port, + static_cast(argv[2]->i)); + } } ); - VERBOSE("OscReceiver: Added callback for /message_level i."); + VERBOSE("OscReceiver: Added callback for /message_level {i,ssi}."); // adding new subscribing client: "/subscribe, {T,Ti,F}" _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 4011a46b..5f8d9b27 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -68,8 +68,8 @@ class OscReceiver void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, lo::Address client); - void set_message_level(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level); + void set_message_level(OscHandler& self, std::string hostname, std::string + port, ssr::MessageLevel message_level); }; } // namespace ssr From 394d79fbdbce63f9049c9c49e472946df6354678 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 7 Jun 2017 00:18:42 +0200 Subject: [PATCH 327/363] src/networking/*: Adding callback handlers for /subscribe {Fss,Tssi}. Rewriting add_client() and deactivate_client() to use std::string for hostname and port instead of a lo::Address object. --- src/networking/oschandler.cpp | 20 ++++++++----- src/networking/oschandler.h | 8 ++--- src/networking/oscreceiver.cpp | 53 ++++++++++++++++++++++++++-------- src/networking/oscreceiver.h | 7 +++-- 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 6dae5aa0..795278e1 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -180,23 +180,29 @@ void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) * OscHandler's friend function to add a client to the list of OscSender's * _client_addresses. * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be added + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel representing the client's message + * level */ -void ssr::OscReceiver::add_client(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level = ssr::MessageLevel::CLIENT) +void ssr::OscReceiver::add_client(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level = + ssr::MessageLevel::CLIENT) { - self._osc_sender.add_client(client.hostname(), client.port(), message_level); + self._osc_sender.add_client(hostname, port, message_level); } /** * OscHandler's friend function to deactivate a client from the list of * OscSender's _clients * @param self reference to OscHandler holding OscSender - * @param client lo::Address representing client to be deactivated + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port */ -void ssr::OscReceiver::deactivate_client(OscHandler& self, lo::Address client) +void ssr::OscReceiver::deactivate_client(OscHandler& self, std::string + hostname, std::string port) { - self._osc_sender.deactivate_client(client.hostname(), client.port()); + self._osc_sender.deactivate_client(hostname, port); } /** diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 0e5bec51..d5ea260a 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -75,10 +75,10 @@ class OscHandler lo::Message message); friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle); - friend void OscReceiver::add_client(OscHandler& self, lo::Address client, - ssr::MessageLevel message_level); - friend void OscReceiver::deactivate_client(OscHandler& self, lo::Address - client); + friend void OscReceiver::add_client(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level); + friend void OscReceiver::deactivate_client(OscHandler& self, std::string + hostname, std::string port); friend void OscReceiver::set_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index d6928450..c41cb8b0 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -106,39 +106,68 @@ void ssr::OscReceiver::add_client_to_server_methods() ); VERBOSE("OscReceiver: Added callback for /message_level {i,ssi}."); - // adding new subscribing client: "/subscribe, {T,Ti,F}" + // subscribing and unsubscribing clients _handler.server().add_method("/subscribe", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address client(message.source()); if(!message.types().compare("T")) { + // subscribing client: "/subscribe, T" VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(true) << "] from client '" << - client.hostname() << ":" << client.port() << "'."); - add_client(_handler, client, ssr::MessageLevel::CLIENT); + message.source().hostname() << ":" << message.source().port() << + "'."); + add_client(_handler, message.source().hostname(), + message.source().port(), ssr::MessageLevel::CLIENT); } + // unsubscribing client: "/subscribe, F" else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(false) << "] from client '" << - client.hostname() << ":" << client.port() << "'."); - deactivate_client(_handler, client); + message.source().hostname() << ":" << message.source().port() << + "'."); + deactivate_client(_handler, message.source().hostname(), + message.source().port()); } - //TODO: add /subscribe, Fss, host, port - //TODO: add /subscribe, Tiss, host, port + // unsubscribing client: "/subscribe, Fss, hostname, port" + else if(!message.types().compare("Fss")) + { + std::string hostname(&argv[1]->s); + std::string port(&argv[2]->s); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(false) << ", " << hostname << ", " << port + << "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + deactivate_client(_handler, hostname, port); + } + // subscribing client: "/subscribe, Tssi, hostname, port, message_level" + else if(!message.types().compare("Tssi")) + { + std::string hostname(&argv[1]->s); + std::string port(&argv[2]->s); + VERBOSE2("OscReceiver: Got [/subscribe, " << + _handler.bool_to_string(true) << ", " << hostname << ", " << port + << ", " << argv[3]->i << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + add_client(_handler, hostname, port, + static_cast(argv[3]->i)); + } + // subscribing client: "/subscribe, Ti, message_level" else if(!message.types().compare("Ti")) { VERBOSE2("OscReceiver: Got [/subscribe, " << _handler.bool_to_string(true) << ", " << argv[1]->i << - "] from client '" << client.hostname() << ":" << client.port() << - "'."); - add_client(_handler, client, + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + add_client(_handler, message.source().hostname(), + message.source().port(), static_cast(argv[1]->i)); } } ); - VERBOSE("OscReceiver: Added callback for /subscribe {F,T,Ti}."); + VERBOSE("OscReceiver: Added callback for /subscribe {F,Fss,T,Ti,Tssi}."); } /** diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 5f8d9b27..3a27d123 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -65,9 +65,10 @@ class OscReceiver void send_to_server(OscHandler& self, std::string path, lo::Message message); void send_to_server(OscHandler& self, lo::Bundle bundle); - void add_client(OscHandler& self, lo::Address client, ssr::MessageLevel - message_level); - void deactivate_client(OscHandler& self, lo::Address client); + void add_client(OscHandler& self, std::string hostname, std::string port, + ssr::MessageLevel message_level); + void deactivate_client(OscHandler& self, std::string hostname, std::string + port); void set_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; From 7a81d3c3bec426682869b2cb2db632a5b3e7e0e4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 00:01:54 +0200 Subject: [PATCH 328/363] src/networking/*: Changing OscSender's _server_address to _server of type OscClient, to have easier control over MessageLevel of the server for clients, using the same functionality. Refactoring all involved functions. Making all setters for the lo::Address fields use reference type parameters. --- src/networking/oscclient.cpp | 13 ++ src/networking/oscclient.h | 1 + src/networking/oschandler.cpp | 39 +++++- src/networking/oschandler.h | 7 +- src/networking/oscreceiver.cpp | 19 +-- src/networking/oscreceiver.h | 8 +- src/networking/oscsender.cpp | 217 ++++++++++++++++++--------------- src/networking/oscsender.h | 9 +- 8 files changed, 194 insertions(+), 119 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index f1030028..2206aede 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -71,6 +71,19 @@ lo::Address& ssr::OscClient::address() return _address; } +/** + * Function to set the OscClient's _address. + * @param hostname reference to a std::string representing the hostname to be + * used + * @param port reference to a std::string& representing the port to be used + **/ +void ssr::OscClient::set_address(std::string& hostname, std::string& port) +{ + _address = lo::Address(hostname, port); + VERBOSE3("OscClient: Address changed to: " << _address.hostname() << ":" << + _address.port() << "."); +} + /** * Function to set the OscClient's _message_level. * @param message_level a MessageLevel to be used for the OscClient diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index e975c94c..085a38a1 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -30,6 +30,7 @@ class OscClient bool active(); void activate(); void deactivate(); + void set_address(std::string& hostname, std::string& port); void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 795278e1..895e9681 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -85,16 +85,17 @@ void ssr::OscHandler::start() /** * OscHandler's friend function to set the OscSender's server_address * @param self reference to OscHandler holding OscSender - * @param server_address lo::Address object to be used for OscSender + * @param hostname reference to std::string representing hostname + * @param port reference to std::string representing port */ -void ssr::OscReceiver::set_server_for_client(ssr::OscHandler& self, lo::Address - server_address) +void ssr::OscReceiver::set_server_address(ssr::OscHandler& self, + std::string& hostname, std::string& port) { - self._osc_sender.set_server_address(server_address.hostname(), server_address.port()); + self._osc_sender.set_server_address(hostname, port); } /** - * OscHandler's friend function return OscSender's server_address + * OscHandler's friend function to return OscSender's server_address * @param self reference to OscHandler holding the OscSender * @return lo::Address server_address of OscSender */ @@ -103,6 +104,34 @@ lo::Address ssr::OscReceiver::server_address(ssr::OscHandler& self) return self._osc_sender.server_address(); } +/** + * OscHandler's friend function to check, if the current lo::Address of the + * server is the default + * @see ssr::OscSender::server_is_default() + * @param self reference to OscHandler holding the OscSender + * @return bool true, if OscSender's server address is the default, false + * otherwise + */ +bool ssr::OscReceiver::server_is_default(ssr::OscHandler& self) +{ + return self._osc_sender.server_is_default(); +} + +/** + * OscHandler's friend function to check, if the provided hostname and port + * match the OscSender's _server lo::Address + * @param self reference to OscHandler holding the OscSender + * @param hostname reference to std::string representing the hostname + * @param port reference to std::string representing the port + * @return bool true, if OscSender's server address matches the provided + * hostname and port + */ +bool ssr::OscReceiver::server_is(ssr::OscHandler& self, std::string& hostname, + std::string& port) +{ + return self._osc_sender.server_is(hostname, port); +} + /** * OscHandler's friend function to send an OSC message to a client, using * OscSender. diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index d5ea260a..212eb925 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -60,9 +60,12 @@ class OscHandler const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); // OscReceiver friend functions - friend void OscReceiver::set_server_for_client(OscHandler& self, - lo::Address server_address); + friend void OscReceiver::set_server_address(OscHandler& self, + std::string& hostname, std::string& port); friend lo::Address OscReceiver::server_address(OscHandler& self); + friend bool OscReceiver::server_is_default(OscHandler& self); + friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, + std::string& port); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c41cb8b0..21624d97 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -595,6 +595,8 @@ i{F,T}."); * server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. + * @todo rename to add_client_to_server_methods() and add /message_level, i + * callback, to set server's MessageLevel. */ void ssr::OscReceiver::add_poll_methods() { @@ -603,20 +605,23 @@ void ssr::OscReceiver::add_poll_methods() _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, lo::Message message) { - lo::Address server(server_address(_handler)); lo::Address from(message.source()); + std::string hostname(from.hostname()); + std::string port(from.port()); (void) argv; - if((server.hostname().compare(from.hostname()) != 0) && - (server.port().compare(from.port()) != 0) && - (from.port().compare("50001") != 0) && - (from.hostname().compare("none") != 0) - ) + if(!server_is(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Subscribing..."); - set_server_for_client(_handler, from); + set_server_address(_handler, hostname, port); from.send_from(_handler.server(), "/subscribe", "T"); } + else + { + VERBOSE3("OscReceiver: Got [/poll] from server " << from.hostname() << + ":" << from.port() << ". Sending alive signal."); + from.send_from(_handler.server(), "/alive", ""); + } } ); VERBOSE("OscReceiver: Added callback for /poll."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 3a27d123..85612d59 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -52,9 +52,11 @@ class OscReceiver ~OscReceiver(); void start(); void stop(); - void set_server_for_client(OscHandler& handler, lo::Address - server_address); - lo::Address server_address(OscHandler& handler); + void set_server_address(OscHandler& handler, std::string& hostname, + std::string& port); lo::Address server_address(OscHandler& handler); + bool server_is_default(OscHandler& handler); + bool server_is(OscHandler& handler, std::string& hostname, std::string& + port); void send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); void send_to_client(OscHandler& self, lo::Address client_address, diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 5d607887..9a6ac8c6 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -18,7 +18,7 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) - , _server_address("none", "50001") + , _server("none", "50001", MessageLevel::SERVER) , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); @@ -65,13 +65,34 @@ void ssr::OscSender::stop() } /** - * Returns true, if the _server_address is the default (setup at initialization) - * @return true, if _server_address is the default, false otherwise. + * Returns true, if the _server.address() is the default (setup at initialization) + * @return true, if _server.address() is the default, false otherwise. */ bool ssr::OscSender::server_is_default() { - if((_server_address.hostname().compare("none") == 0) && - (_server_address.port().compare("50001") == 0)) + if((_server.hostname().compare("none") == 0) && + (_server.port().compare("50001") == 0)) + { + return true; + } + else + { + return false; + } +} + +/** + * Returns true, if the _server.address()'s hostname and port are the same as + * the provided. + * @param hostname a reference to a std::string representing the hostname + * @param port a reference to a std::string representing the port + * @return true, if _server.address() has the same hostname and port, false + * otherwise. + */ +bool ssr::OscSender::server_is(std::string& hostname, std::string& port) +{ + if((_server.hostname().compare(hostname) == 0) && + (_server.port().compare(port) == 0)) { return true; } @@ -104,13 +125,12 @@ void ssr::OscSender::poll_all_clients() } /** - * Function to return OscSender's _server_address + * Function to return OscSender's _server.address() * @return a lo::Address object representing the current server for this client */ -lo::Address ssr::OscSender::server_address() +lo::Address& ssr::OscSender::server_address() { - lo::Address server(_server_address.hostname(), _server_address.port()); - return server; + return _server.address(); } /** @@ -124,14 +144,15 @@ void ssr::OscSender::set_message_level(const unsigned int& message_level) } /** - * Function to set OscSender's _server_address - * @param server_address a lo::Address to be used as _server_address + * Function to set OscSender's _server address + * @param hostname a std::string& to be used as hostname + * @param port a std::string& to be used as port */ -void ssr::OscSender::set_server_address(std::string hostname, std::string port) +void ssr::OscSender::set_server_address(std::string& hostname, std::string& port) { - _server_address = lo::Address(hostname, port); + _server.set_address(hostname, port); VERBOSE2("OscSender: Setting up new server address: "<< - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } /** @@ -142,13 +163,13 @@ void ssr::OscSender::set_server_address(std::string hostname, std::string port) */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server_address.hostname().compare("none") != 0) && - (_server_address.port().compare("50001") != 0)) + if((_server.hostname().compare("none") != 0) && + (_server.port().compare("50001") != 0)) { - _server_address.send_from(_handler.server(), path, message.types(), message); + _server.address().send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -158,10 +179,10 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server_address.send_from(_handler.server(), bundle); + _server.address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle (" << bundle.length() << - " messages) to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + " messages) to server " << _server.hostname() << ":" << + _server.port() << "."); } /** @@ -542,11 +563,11 @@ void ssr::OscSender::new_source(id_t id) else if(_handler.is_client()) { int32_t message_id = static_cast(id); - _server_address.send_from(_handler.server(), "/update/source/new", "i", + _server.address().send_from(_handler.server(), "/update/source/new", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -577,11 +598,11 @@ void ssr::OscSender::delete_source(id_t id) else if(_handler.is_client() && !server_is_default()) { _source_levels.erase(id); - _server_address.send_from(_handler.server(), "/update/source/delete", + _server.address().send_from(_handler.server(), "/update/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -608,10 +629,10 @@ void ssr::OscSender::delete_all_sources() } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/delete", + _server.address().send_from(_handler.server(), "/update/source/delete", "i", 0); VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } _source_levels.clear(); } @@ -658,11 +679,11 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/position", + _server.address().send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << ", " << position.x << ", " << position.y << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -710,12 +731,12 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/position_fixed", + _server.address().send_from(_handler.server(), "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -763,12 +784,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/orientation", + _server.address().send_from(_handler.server(), "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -813,12 +834,12 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/gain", + _server.address().send_from(_handler.server(), "/update/source/gain", "if", message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -865,12 +886,12 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/mute", + _server.address().send_from(_handler.server(), "/update/source/mute", "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << apf::str::A2S(message_id) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -917,11 +938,11 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/name", "is", + _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server_address.hostname() << ":" - << _server_address.port() << "."); + << message_name << "] to server " << _server.hostname() << ":" + << _server.port() << "."); } return true; } @@ -969,11 +990,11 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << message_id << ", " << file_name << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1004,11 +1025,11 @@ void ssr::OscSender::set_decay_exponent(float exponent) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1040,11 +1061,11 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " - << distance << "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + << distance << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1091,11 +1112,11 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/model", "is", + _server.address().send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + ", " << message_model << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1117,11 +1138,11 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& int32_t message_id = static_cast(id); if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/port_name", + _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + ", " << port_name << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1174,12 +1195,12 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1228,11 +1249,11 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1255,11 +1276,11 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) int32_t message_length = static_cast(length); if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/source/length", "ii", + _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", " << message_length << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -1293,11 +1314,11 @@ void ssr::OscSender::set_reference_position(const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/reference/position", + _server.address().send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server_address.hostname() - << ":" << _server_address.port() << "."); + << ", " << position.y << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } } @@ -1330,11 +1351,11 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1368,11 +1389,11 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << position.x << ", " << position.y << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } } @@ -1408,11 +1429,11 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), + _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server_address.hostname() << - ":" << _server_address.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1445,11 +1466,11 @@ void ssr::OscSender::set_master_volume(float volume) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/scene/volume", "f", + _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server_address.hostname() << ":" << - _server_address.port() << "."); + "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1499,11 +1520,11 @@ void ssr::OscSender::set_processing_state(bool state) } else if(_handler.is_client() && !server_is_default()) { - _server_address.send_from(_handler.server(), "/update/processing/state", + _server.address().send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << _handler.bool_to_message_type(state) << "] to server " << - _server_address.hostname() << ":" << _server_address.port() << "."); + _server.hostname() << ":" << _server.port() << "."); } } @@ -1546,16 +1567,16 @@ void ssr::OscSender::set_transport_state( const std::pair Date: Sat, 17 Jun 2017 01:20:40 +0200 Subject: [PATCH 329/363] src/networking/*: Removing _client_addresses from OscSender and replacing all calls to it by calls to _clients. Adding set_server_message_level(), to set the MessageLevel of a clients representation of a server. Minor fixes. --- src/networking/oschandler.cpp | 13 ++++++++ src/networking/oschandler.h | 2 ++ src/networking/oscreceiver.cpp | 21 ++++++++++++- src/networking/oscreceiver.h | 5 +++- src/networking/oscsender.cpp | 54 +++++++++++++++++++++------------- src/networking/oscsender.h | 5 ++-- 6 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 895e9681..b4ebf0bb 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -94,6 +94,19 @@ void ssr::OscReceiver::set_server_address(ssr::OscHandler& self, self._osc_sender.set_server_address(hostname, port); } +/** + * OscHandler's friend function to set a the OscSender _server's message_level + * @param self reference to OscHandler holding OscSender + * @param hostname reference to std::string representing the client's hostname + * @param port reference to std::string representing the client's port + * @param message_level ssr::MessageLevel to be used for server + */ +void ssr::OscReceiver::set_server_message_level(OscHandler& self, + ssr::MessageLevel message_level) +{ + self._osc_sender.set_server_message_level(message_level); +} + /** * OscHandler's friend function to return OscSender's server_address * @param self reference to OscHandler holding the OscSender diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 212eb925..f7610ecf 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -62,6 +62,8 @@ class OscHandler // OscReceiver friend functions friend void OscReceiver::set_server_address(OscHandler& self, std::string& hostname, std::string& port); + friend void OscReceiver::set_server_message_level(OscHandler& self, + MessageLevel message_level); friend lo::Address OscReceiver::server_address(OscHandler& self); friend bool OscReceiver::server_is_default(OscHandler& self); friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 21624d97..87fc7a01 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -78,7 +78,7 @@ void ssr::OscReceiver::stop() */ void ssr::OscReceiver::add_client_to_server_methods() { - // adding new subscribing client: "/message_level, i" + // setting MessageLevel of subscribed client: "/message_level, {i,ssi}" _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { @@ -600,6 +600,25 @@ i{F,T}."); */ void ssr::OscReceiver::add_poll_methods() { + + _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, + int, lo::Message message) + { +// lo::Address from(message.source()); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if(server_is(_handler, hostname, port)) + { + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); + set_server_message_level(_handler, + static_cast(argv[0]->i)); + } + } + ); + VERBOSE("OscReceiver: Added callback for /message_level i."); + // set _server_address for OscSender through OscHandler, depending on, if // polled from given server before _handler.server().add_method("/poll", NULL, [this](lo_arg **argv, int, diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 85612d59..5f237f2d 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -53,7 +53,10 @@ class OscReceiver void start(); void stop(); void set_server_address(OscHandler& handler, std::string& hostname, - std::string& port); lo::Address server_address(OscHandler& handler); + std::string& port); + lo::Address server_address(OscHandler& handler); + void set_server_message_level(OscHandler& handler, MessageLevel + message_level); bool server_is_default(OscHandler& handler); bool server_is(OscHandler& handler, std::string& hostname, std::string& port); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 9a6ac8c6..38ea2d6c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -135,7 +135,6 @@ lo::Address& ssr::OscSender::server_address() /** * Function to set OscSender's _message_level. - * If the message level is out of * @param MessageLevel enum representing the new message level */ void ssr::OscSender::set_message_level(const unsigned int& message_level) @@ -143,6 +142,15 @@ void ssr::OscSender::set_message_level(const unsigned int& message_level) _message_level = static_cast(message_level); } +/** + * Function to set OscSender server's _message_level (client). + * @param MessageLevel enum representing the new message level + */ +void ssr::OscSender::set_server_message_level(MessageLevel message_level) +{ + _server.set_message_level(message_level); +} + /** * Function to set OscSender's _server address * @param hostname a std::string& to be used as hostname @@ -163,8 +171,7 @@ void ssr::OscSender::set_server_address(std::string& hostname, std::string& port */ void ssr::OscSender::send_to_server(std::string path, lo::Message message) { - if((_server.hostname().compare("none") != 0) && - (_server.port().compare("50001") != 0)) + if(!server_is_default()) { _server.address().send_from(_handler.server(), path, message.types(), message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << @@ -179,28 +186,32 @@ void ssr::OscSender::send_to_server(std::string path, lo::Message message) */ void ssr::OscSender::send_to_server(lo::Bundle bundle) { - _server.address().send_from(_handler.server(), bundle); - VERBOSE3("OscSender: Sending bundle (" << bundle.length() << - " messages) to server " << _server.hostname() << ":" << - _server.port() << "."); + if(!server_is_default()) + { + _server.address().send_from(_handler.server(), bundle); + VERBOSE3("OscSender: Sending bundle (" << bundle.length() << + " messages) to server " << _server.hostname() << ":" << + _server.port() << "."); + } } /** * Function to send a lo::Message to a client. * @param address a lo:Address that will be sent to, when found in - * _client_addresses. + * _clients. * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ void ssr::OscSender::send_to_client(lo::Address address, std::string path, lo::Message message) { - for (const auto& client: _client_addresses) + for (const auto& client: _clients) { if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_handler.server(), path, message.types(), message); + client->address().send_from(_handler.server(), path, message.types(), + message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << "] to client " << address.hostname() << ":" << address.port() << "."); @@ -211,48 +222,49 @@ void ssr::OscSender::send_to_client(lo::Address address, std::string path, /** * Function to send a lo::Bundle to a client. * @param address a lo:Address that will be sent to, when found in - * _client_addresses. + * _clients. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) { - for (const auto& client: _client_addresses) + for (const auto& client: _clients) { if(client->hostname() == address.hostname() && client->port() == address.port()) { - client->send_from(_handler.server(), bundle); + client->address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << ":" << address.port() << "."); } } } /** - * Function to send a lo::Message to all clients setup in _client_addresses + * Function to send a lo::Message to all clients setup in _clients * vector. * @param path a std::string defining the path to send to * @param message a predefined lo::Messge object to be sent */ void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { + client->address().send_from(_handler.server(), path, message.types(), + message); VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << client_address->hostname() << ":" << - client_address->port() << "."); - client_address->send_from(_handler.server(), path, message.types(), message); + "] to client " << client->hostname() << ":" << + client->port() << "."); } } /** - * Sends a lo::Bundle to all clients setup in _client_addresses vector. + * Sends a lo::Bundle to all clients setup in _clients vector. * @param bundle a predefined lo::Bundle object to be sent */ void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) { - for (const auto& client_address: _client_addresses) + for (const auto& client: _clients) { - client_address->send_from(_handler.server(), bundle); + client->address().send_from(_handler.server(), bundle); VERBOSE3("OscSender: Sending bundle to all clients."); } } diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 29ae2022..2d50552f 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -40,12 +40,10 @@ class OscSender : public Subscriber // reference to handler OscHandler& _handler; bool _is_subscribed; - // address of server (client) + // server object (client) OscClient _server; // level of messages to send to server (client) MessageLevel _message_level; - // (obsolete) vector of pointers to client address objects (server) - std::vector _client_addresses; // vector of pointers to OscClient objects (server) std::vector _clients; // map of id/parameter_map pairs for new sources (server) @@ -72,6 +70,7 @@ class OscSender : public Subscriber void stop(); void set_server_address(std::string& hostname, std::string& port); lo::Address& server_address(); + void set_server_message_level(MessageLevel message_level); bool server_is_default(); bool server_is(std::string& hostname, std::string& port); void set_message_level(const unsigned int& message_level); From b917545ad8003c845424f7b74d7c4f7e433f78f4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 12:18:11 +0200 Subject: [PATCH 330/363] src/networking/*: Renaming set_message_level() to set_client_message_level() in OscHandler/OscReceiver in alignment with set_client_message_level() in OscSender for better readability. --- src/networking/oschandler.cpp | 2 +- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 6 +++--- src/networking/oscreceiver.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index b4ebf0bb..0effd7a4 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -254,7 +254,7 @@ void ssr::OscReceiver::deactivate_client(OscHandler& self, std::string * @param port std::string representing the client's port * @param message_level ssr::MessageLevel to be used for client */ -void ssr::OscReceiver::set_message_level(OscHandler& self, std::string +void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level) { self._osc_sender.set_client_message_level(hostname, port, message_level); diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index f7610ecf..5374c8fe 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -84,7 +84,7 @@ class OscHandler std::string port, ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, std::string hostname, std::string port); - friend void OscReceiver::set_message_level(OscHandler& self, std::string + friend void OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 87fc7a01..cf397542 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -87,7 +87,7 @@ void ssr::OscReceiver::add_client_to_server_methods() VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, message.source().hostname(), + set_client_message_level(_handler, message.source().hostname(), message.source().port(), static_cast(argv[0]->i)); } @@ -99,7 +99,7 @@ void ssr::OscReceiver::add_client_to_server_methods() port << ", " << argv[2]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - set_message_level(_handler, hostname, port, + set_client_message_level(_handler, hostname, port, static_cast(argv[2]->i)); } } @@ -1116,7 +1116,7 @@ void ssr::OscReceiver::add_scene_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: [/scene/clear] from client '" << + VERBOSE2("OscReceiver: Got [/scene/clear] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.delete_all_sources(); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 5f237f2d..323404da 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -74,7 +74,7 @@ class OscReceiver ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, std::string hostname, std::string port); - void set_message_level(OscHandler& self, std::string hostname, std::string + void set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); }; From fae6c396246b14920d00e736264afcb0ba1dee52 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 12:57:03 +0200 Subject: [PATCH 331/363] src/networking/oscsender.*: Using _server.message_level() instead of _message_level. --- src/networking/oscsender.cpp | 24 +++++++----------------- src/networking/oscsender.h | 5 ++--- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 38ea2d6c..b9ffb447 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -19,7 +19,6 @@ ssr::OscSender::OscSender(Publisher& controller, OscHandler& handler) : _controller(controller) , _handler(handler) , _server("none", "50001", MessageLevel::SERVER) - , _message_level(MessageLevel::THIN_CLIENT) { VERBOSE("OscSender: Initialized."); } @@ -133,15 +132,6 @@ lo::Address& ssr::OscSender::server_address() return _server.address(); } -/** - * Function to set OscSender's _message_level. - * @param MessageLevel enum representing the new message level - */ -void ssr::OscSender::set_message_level(const unsigned int& message_level) -{ - _message_level = static_cast(message_level); -} - /** * Function to set OscSender server's _message_level (client). * @param MessageLevel enum representing the new message level @@ -1576,8 +1566,8 @@ void ssr::OscSender::set_transport_state( const std::pair _clients; // map of id/parameter_map pairs for new sources (server) From 0d020e41b05ae718762576374f2ee31343bbd778 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 13:21:38 +0200 Subject: [PATCH 332/363] src/ssr_global.h: Adding GUI_SERVER to MessageLevel enum class for messages only meant for GUI updates. Making int representation implicit. --- src/ssr_global.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ssr_global.h b/src/ssr_global.h index efb117c4..726569c2 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -54,9 +54,10 @@ extern unsigned int usleeptime; enum class MessageLevel : id_t { SERVER = 0, - THIN_CLIENT = 1, - CLIENT = 2, - GUI_CLIENT = 3 + GUI_SERVER, + THIN_CLIENT, + CLIENT, + GUI_CLIENT }; } // namespace ssr From ee007905012466a18170b64f45b9b0ea267a2d22 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 13:22:32 +0200 Subject: [PATCH 333/363] src/networking/oscsender.cpp: Changing all MessageLevel checks for clients, when trying to send to server from GUI_CLIENT to GUI_SERVER. --- src/networking/oscsender.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b9ffb447..c517cf38 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1567,7 +1567,7 @@ void ssr::OscSender::set_transport_state( const std::pair Date: Sat, 17 Jun 2017 15:20:18 +0200 Subject: [PATCH 334/363] src/networking/*: Renaming OscSender::server_is(std::string& hostname, std::string& port) to OscSender::is_server(std::string& hostname, std::string& port) for better readability. Changing in all of its use-cases. --- src/networking/oschandler.cpp | 4 ++-- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 4 ++-- src/networking/oscreceiver.h | 2 +- src/networking/oscsender.cpp | 2 +- src/networking/oscsender.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0effd7a4..9ad2bf87 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -139,10 +139,10 @@ bool ssr::OscReceiver::server_is_default(ssr::OscHandler& self) * @return bool true, if OscSender's server address matches the provided * hostname and port */ -bool ssr::OscReceiver::server_is(ssr::OscHandler& self, std::string& hostname, +bool ssr::OscReceiver::is_server(ssr::OscHandler& self, std::string& hostname, std::string& port) { - return self._osc_sender.server_is(hostname, port); + return self._osc_sender.is_server(hostname, port); } /** diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 5374c8fe..88b0117f 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -66,7 +66,7 @@ class OscHandler MessageLevel message_level); friend lo::Address OscReceiver::server_address(OscHandler& self); friend bool OscReceiver::server_is_default(OscHandler& self); - friend bool OscReceiver::server_is(OscHandler& self, std::string& hostname, + friend bool OscReceiver::is_server(OscHandler& self, std::string& hostname, std::string& port); friend void OscReceiver::send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index cf397542..70c22e5f 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -607,7 +607,7 @@ void ssr::OscReceiver::add_poll_methods() // lo::Address from(message.source()); std::string hostname(message.source().hostname()); std::string port(message.source().port()); - if(server_is(_handler, hostname, port)) + if(is_server(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << @@ -628,7 +628,7 @@ void ssr::OscReceiver::add_poll_methods() std::string hostname(from.hostname()); std::string port(from.port()); (void) argv; - if(!server_is(_handler, hostname, port)) + if(!is_server(_handler, hostname, port)) { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Subscribing..."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 323404da..a23d41b3 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -58,7 +58,7 @@ class OscReceiver void set_server_message_level(OscHandler& handler, MessageLevel message_level); bool server_is_default(OscHandler& handler); - bool server_is(OscHandler& handler, std::string& hostname, std::string& + bool is_server(OscHandler& handler, std::string& hostname, std::string& port); void send_to_client(OscHandler& self, lo::Address client_address, std::string path, lo::Message message); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index c517cf38..68d71d7f 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -88,7 +88,7 @@ bool ssr::OscSender::server_is_default() * @return true, if _server.address() has the same hostname and port, false * otherwise. */ -bool ssr::OscSender::server_is(std::string& hostname, std::string& port) +bool ssr::OscSender::is_server(std::string& hostname, std::string& port) { if((_server.hostname().compare(hostname) == 0) && (_server.port().compare(port) == 0)) diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index f1c9e579..056650be 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -71,7 +71,7 @@ class OscSender : public Subscriber lo::Address& server_address(); void set_server_message_level(MessageLevel message_level); bool server_is_default(); - bool server_is(std::string& hostname, std::string& port); + bool is_server(std::string& hostname, std::string& port); void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port, ssr::MessageLevel message_level); From ab13fd94064013f177cff94265f7c1c02c4c4286 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 21:39:00 +0200 Subject: [PATCH 335/363] src/networking/oscreceiver.*: Renaming add_poll_methods() to add_server_to_client_methods(). Making /source/new callback more robust, by only initializing with OSC message types, once the understood type tags have been found. Minor line break fix. --- src/networking/oscreceiver.cpp | 68 ++++++++++++++++------------------ src/networking/oscreceiver.h | 6 +-- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 70c22e5f..20a14ba4 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -52,7 +52,7 @@ void ssr::OscReceiver::start() } else if (_handler.is_client()) { - add_poll_methods(); + add_server_to_client_methods(); add_processing_methods(); add_reference_methods(); add_scene_methods(); @@ -591,20 +591,17 @@ i{F,T}."); } /** - * Adds callback handlers (for clients) for poll messages received from a - * server. + * Adds callback handlers (for clients) for /poll and /message_level messages + * received from a server. * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo rename to add_client_to_server_methods() and add /message_level, i - * callback, to set server's MessageLevel. */ -void ssr::OscReceiver::add_poll_methods() +void ssr::OscReceiver::add_server_to_client_methods() { _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { -// lo::Address from(message.source()); std::string hostname(message.source().hostname()); std::string port(message.source().port()); if(is_server(_handler, hostname, port)) @@ -766,12 +763,6 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/new", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string name(&(argv[0]->s)); - std::string file_name_or_port_number(&(argv[2]->s)); - std::string types(message.types()); - float x(argv[3]->f); - float y(argv[4]->f); - float gain(argv[6]->f); int file_channel = 0; std::string properties_file = ""; std::string channel_and_properties = ""; @@ -779,70 +770,63 @@ void ssr::OscReceiver::add_source_methods() bool orientation_fixed; bool muted; bool setup = false; - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) - { - model = Source::point; - } - Position position(x, y); - Orientation orientation(argv[5]->f); - if (types.compare("sssffffTTT") == 0) + if (!message.types().compare("sssffffTTT")) { position_fixed = true; orientation_fixed = true; muted = true; setup = true; } - if (types.compare("sssffffTTF") == 0) + if (!message.types().compare("sssffffTTF")) { position_fixed = true; orientation_fixed = true; muted = false; setup = true; } - if (types.compare("sssffffTFF") == 0) + if (!message.types().compare("sssffffTFF")) { position_fixed = true; orientation_fixed = false; muted = false; setup = true; } - if (types.compare("sssffffFFF") == 0) + if (!message.types().compare("sssffffFFF")) { position_fixed = false; orientation_fixed = false; muted = false; setup = true; } - if (types.compare("sssffffTFT") == 0) + if (!message.types().compare("sssffffTFT")) { position_fixed = true; orientation_fixed = false; muted = true; setup = true; } - if (types.compare("sssffffFTF") == 0) + if (!message.types().compare("sssffffFTF")) { position_fixed = false; orientation_fixed = true; muted = false; setup = true; } - if (types.compare("sssffffFTT") == 0) + if (!message.types().compare("sssffffFTT")) { position_fixed = false; orientation_fixed = true; muted = true; setup = true; } - if (types.compare("sssffffFFT") == 0) + if (!message.types().compare("sssffffFFT")) { position_fixed = false; orientation_fixed = false; muted = true; setup = true; } - if (types.compare("sssffffisTTT") == 0) + if (!message.types().compare("sssffffisTTT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -852,7 +836,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisTTF") == 0) + if (!message.types().compare("sssffffisTTF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -862,7 +846,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisTFF") == 0) + if (!message.types().compare("sssffffisTFF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -872,7 +856,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisFFF") == 0) + if (!message.types().compare("sssffffisFFF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -882,7 +866,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisTFT") == 0) + if (!message.types().compare("sssffffisTFT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -892,7 +876,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisFTF") == 0) + if (!message.types().compare("sssffffisFTF")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -902,7 +886,7 @@ void ssr::OscReceiver::add_source_methods() muted = false; setup = true; } - if (types.compare("sssffffisFTT") == 0) + if (!message.types().compare("sssffffisFTT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -912,7 +896,7 @@ void ssr::OscReceiver::add_source_methods() muted = true; setup = true; } - if (types.compare("sssffffisFFT") == 0) + if (!message.types().compare("sssffffisFFT")) { file_channel = argv[7]->i; properties_file = &(argv[8]->s); @@ -924,6 +908,18 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); + float x(argv[3]->f); + float y(argv[4]->f); + float gain(argv[6]->f); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << ", " << orientation.azimuth << ", " << gain<< ", " << diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index a23d41b3..646b9dde 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -39,7 +39,7 @@ class OscReceiver ssr::OscHandler& _handler; void add_client_to_server_methods(); void add_update_notification_methods(); - void add_poll_methods(); + void add_server_to_client_methods(); void add_source_methods(); void add_reference_methods(); void add_scene_methods(); @@ -74,8 +74,8 @@ class OscReceiver ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, std::string hostname, std::string port); - void set_client_message_level(OscHandler& self, std::string hostname, std::string - port, ssr::MessageLevel message_level); + void set_client_message_level(OscHandler& self, std::string hostname, + std::string port, ssr::MessageLevel message_level); }; } // namespace ssr From c7562b955912243d737a7cc0ecff4e67b6c9245d Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 22:49:57 +0200 Subject: [PATCH 336/363] src/networking/oscsender.cpp: Fixing line breaks and indents. --- src/networking/oscsender.cpp | 186 +++++++++++++++++------------------ 1 file changed, 91 insertions(+), 95 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 68d71d7f..da8b0f8c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -493,7 +493,8 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) !(client->port().compare(port)) && client->active()) { client->deactivate(); - VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << "."); + VERBOSE2("OscSender: Deactivated client " << hostname << ":" << port << + "."); } } } @@ -622,10 +623,11 @@ void ssr::OscSender::delete_all_sources() { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/delete", "i", 0); + client->address().send_from(_handler.server(), "/source/delete", "i", + 0); VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -721,8 +723,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), - message_id); + "/source/position_fixed", + "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << _handler.bool_to_message_type(fixed) << ", " << message_id << "] to client " << client->address().hostname() << ":" << @@ -733,12 +735,12 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/position_fixed", + _server.address().send_from(_handler.server(), + "/update/source/position_fixed", "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -774,8 +776,8 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& { if(client && client->active()) { - client->address().send_from(_handler.server(), - "/source/orientation", "if", message_id, message_orientation); + client->address().send_from(_handler.server(), "/source/orientation", + "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id << ", " << message_orientation << "] to client " << client->address().hostname() << ":" << @@ -786,12 +788,12 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/orientation", - "if", message_id, message_orientation); + _server.address().send_from(_handler.server(), + "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << - apf::str::A2S(message_id) << ", " << - apf::str::A2S(message_orientation) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) + << "] to server " << _server.hostname() << ":" << _server.port() << + "."); } return true; } @@ -825,23 +827,22 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/gain", - "if", message_id, gain); - VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << - ", " << gain << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + client->address().send_from(_handler.server(), "/source/gain", "if", + message_id, gain); + VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " + << gain << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/gain", - "if", message_id, gain); + _server.address().send_from(_handler.server(), "/update/source/gain", "if", + message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } @@ -892,8 +893,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << - apf::str::A2S(message_id) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_id) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -928,12 +929,11 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/name", - "is", message_id, message_name); + client->address().send_from(_handler.server(), "/source/name", "is", + message_id, message_name); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << message_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + << message_name << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } @@ -943,8 +943,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, message_name); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server.hostname() << ":" - << _server.port() << "."); + << message_name << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -995,8 +995,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, file_name); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << file_name << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + message_id << ", " << file_name << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } return true; } @@ -1017,8 +1017,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) { if(client && client->active()) { - client->address().send_from(_handler.server(), - "/scene/decay_exponent", "f", exponent); + client->address().send_from(_handler.server(), "/scene/decay_exponent", + "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << "] to client " << client->address().hostname() << ":" << client->address().port() << "."); @@ -1030,8 +1030,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << "] to server " << _server.hostname() << ":" << _server.port() << + "."); } } @@ -1102,23 +1102,23 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) { if(client && client->active()) { - client->address().send_from(_handler.server(), "/source/model", - "is", message_id, message_model.c_str()); + client->address().send_from(_handler.server(), "/source/model", "is", + message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " << message_model << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/model", "is", - message_id, message_model.c_str()); + _server.address().send_from(_handler.server(), "/update/source/model", + "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + ", " << message_model << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1143,8 +1143,8 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + ", " << port_name << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1189,8 +1189,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << message_id << ", " << file_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1243,8 +1243,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id << ", " << message_file_channel << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1254,8 +1254,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + << ", " << message_file_channel << "] to server " << _server.hostname() + << ":" << _server.port() << "."); } return true; } @@ -1278,11 +1278,11 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) int32_t message_length = static_cast(length); if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/source/length", "ii", - message_id, message_length); - VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id - << ", " << message_length << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _server.address().send_from(_handler.server(), "/update/source/length", + "ii", message_id, message_length); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", + " << message_length << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } return true; } @@ -1308,19 +1308,18 @@ void ssr::OscSender::set_reference_position(const Position& position) client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + ", " << position.y << "] to client " << client->address().hostname() + << ":" << client->address().port() << "."); } } } else if(_handler.is_client() && !server_is_default()) { - _server.address().send_from(_handler.server(), "/update/reference/position", - "ff", position.x, position.y); + _server.address().send_from(_handler.server(), + "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + << ", " << position.y << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1346,8 +1345,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << orientation.azimuth << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1356,8 +1355,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1424,8 +1423,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << orientation.azimuth << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1434,8 +1433,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + orientation.azimuth << "] to server " << _server.hostname() << ":" << + _server.port() << "."); } } @@ -1471,8 +1470,7 @@ void ssr::OscSender::set_master_volume(float volume) _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } } @@ -1515,8 +1513,8 @@ void ssr::OscSender::set_processing_state(bool state) _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << _handler.bool_to_message_type(state) << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1574,11 +1572,11 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().hostname() << ":" << client->address().port() - << "."); + client->address().hostname() << ":" << client->address().port() << + "."); } } } @@ -1678,8 +1675,8 @@ void ssr::OscSender::set_sample_rate(int sr) _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_sr) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1718,8 +1715,8 @@ void ssr::OscSender::set_master_signal_level(float level) _server.address().send_from(_handler.server(), "/update/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + apf::str::A2S(message_level) << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } } @@ -1761,8 +1758,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) "if", message_id, message_level); VERBOSE3("OscSender: Sent [/update/source/level, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; } From d4f6f7da9759bf8c8eba38809773ab62d7041339 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 22:50:59 +0200 Subject: [PATCH 337/363] src/networking/oschandler.cpp: Removing obsolete TODO. --- src/networking/oschandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 9ad2bf87..14a7d96c 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -43,7 +43,6 @@ ssr::OscHandler::OscHandler(Publisher& controller, int port, std::string mode, ssr::OscHandler::~OscHandler() { stop(); - //TODO: delete members of _client_addresses VERBOSE("OscHandler: Destructing."); } From fbc285282e9b3634f914f5ae72538d7523cc25ad Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 23:01:53 +0200 Subject: [PATCH 338/363] src/networking/oscsender.cpp: Fixing broken string line wrap in VERBOSE. --- src/networking/oscsender.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index da8b0f8c..b5ea406c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -1280,9 +1280,9 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); - VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << ", - " << message_length << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << + ", " << message_length << "] to server " << _server.hostname() << ":" + << _server.port() << "."); } return true; } From cd3dcb933e094a2b4087bfb9621629cfef4fa157 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 17 Jun 2017 23:47:34 +0200 Subject: [PATCH 339/363] src/networking/*: Implementing from_is() functionality in OscHandler, returning a const std::string, depending on whether the handler is server or client. Implementing from_is() in all VERBOSE messages in client/server callbacks. --- src/networking/oschandler.cpp | 17 ++++ src/networking/oschandler.h | 3 + src/networking/oscreceiver.cpp | 150 ++++++++++++++++++--------------- 3 files changed, 101 insertions(+), 69 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 14a7d96c..1f8f9c24 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -343,3 +343,20 @@ const std::string ssr::OscHandler::bool_to_string(const bool& message) return _string_false; } } + +/** + * Returns a std::string representing from where messages where received from + * on this instance. Depends on whether this instance is a server or a client. + * @return 'client' if _mode is "server", 'server' otherwise + */ +const std::string ssr::OscHandler::from_is() +{ + if(is_server()) + { + return _string_client; + } + else + { + return _string_server; + } +} diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 88b0117f..3d231651 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -24,6 +24,8 @@ namespace const std::string _message_type_true{"T"}; const std::string _string_false{"false"}; const std::string _string_true{"true"}; + const std::string _string_server{"server"}; + const std::string _string_client{"client"}; } namespace ssr @@ -59,6 +61,7 @@ class OscHandler lo::ServerThread& server(); const std::string bool_to_message_type(const bool& message); const std::string bool_to_string(const bool& message); + const std::string from_is(); // OscReceiver friend functions friend void OscReceiver::set_server_address(OscHandler& self, std::string& hostname, std::string& port); diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 20a14ba4..2c1734fa 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -599,16 +599,17 @@ i{F,T}."); void ssr::OscReceiver::add_server_to_client_methods() { + // set OscSender's _server _message_level through OscHandler: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { std::string hostname(message.source().hostname()); std::string port(message.source().port()); + VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << + "] from server '" << message.source().hostname() << ":" << + message.source().port() << "'."); if(is_server(_handler, hostname, port)) { - VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); set_server_message_level(_handler, static_cast(argv[0]->i)); } @@ -659,10 +660,10 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { - std::string from = (_handler.is_server())? "client": "server"; VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << - "] from " << from << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); if (argv[0]->i == 0) { _controller.delete_all_sources(); @@ -680,8 +681,9 @@ void ssr::OscReceiver::add_source_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/file_channel, " << argv[0]->i << ", " - << argv[1]->i << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->i << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } ); @@ -692,8 +694,9 @@ void ssr::OscReceiver::add_source_methods() int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << - argv[1]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_gain(argv[0]->i, apf::math::dB2linear(argv[1]->f)); } @@ -711,8 +714,9 @@ void ssr::OscReceiver::add_source_methods() model = Source::point; } VERBOSE2("OscReceiver: Got [/source/model, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_model(argv[0]->i, model); } ); @@ -725,15 +729,16 @@ void ssr::OscReceiver::add_source_methods() if(!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", true] from client '"<< message.source().hostname() << ":" << + ", true] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_mute(argv[0]->i, true); } else if(!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", false] from client '"<< message.source().hostname() << ":" << - message.source().port() << "'."); + ", false] from " << _handler.from_is() << " '"<< + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_mute(argv[0]->i, false); } } @@ -745,9 +750,9 @@ void ssr::OscReceiver::add_source_methods() lo::Message message) { std::string name(&argv[1]->s); - VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << + VERBOSE2("OscReceiver: Got [/source/name, " << argv[0]->i << ", " << name + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_name(argv[0]->i, name); } @@ -926,9 +931,9 @@ void ssr::OscReceiver::add_source_methods() channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << - _handler.bool_to_string(muted) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(muted) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.new_source(name, model, file_name_or_port_number, file_channel, position, position_fixed, orientation, orientation_fixed, gain, muted, properties_file); @@ -955,8 +960,9 @@ void ssr::OscReceiver::add_source_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/orientation, " << argv[0]->i << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); } ); @@ -968,8 +974,9 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/port_name, " << argv[0]->i << ", " << - name << "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_source_port_name(argv[0]->i, name); } ); @@ -980,8 +987,9 @@ void ssr::OscReceiver::add_source_methods() int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/position, " << argv[0]->i << ", " << - argv[1]->f << ", " << argv[2]->f << "] from client '" << - message.source().hostname() << ":" << message.source().port() << "'."); + argv[1]->f << ", " << argv[2]->f << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); _controller.set_source_position(argv[0]->i, Position(argv[1]->f, argv[2]->f)); } @@ -995,14 +1003,14 @@ void ssr::OscReceiver::add_source_methods() if (!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from client '" << message.source().hostname() << ":" << + ", true] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position_fixed(argv[0]->i, true); } else if (!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from client '" << message.source().hostname() << ":" << + ", false] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_position_fixed(argv[0]->i, false); } @@ -1016,7 +1024,7 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from client '" << message.source().hostname() << + ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_source_properties_file(argv[0]->i, name); } @@ -1042,8 +1050,9 @@ void ssr::OscReceiver::add_reference_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/orientation, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_orientation(Orientation(argv[0]->f)); } ); @@ -1054,8 +1063,9 @@ void ssr::OscReceiver::add_reference_methods() **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference/position, " << argv[0]->f << ", " - << argv[1]->f << "] from client '" << message.source().hostname() << - ":" << message.source().port() << "'."); + << argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); } ); @@ -1067,8 +1077,9 @@ void ssr::OscReceiver::add_reference_methods() [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/orientation, " << - argv[0]->f << "] from client '" << message.source().hostname() << ":" - << message.source().port() << "'."); + argv[0]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); } ); @@ -1079,7 +1090,7 @@ void ssr::OscReceiver::add_reference_methods() [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/reference_offset/position, " << argv[0]->f - << ", " << argv[1]->f << "] from client '" << + << ", " << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); _controller.set_reference_offset_position(Position(argv[0]->f, @@ -1112,9 +1123,9 @@ void ssr::OscReceiver::add_scene_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/scene/clear] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/clear] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); _controller.delete_all_sources(); } ); @@ -1125,9 +1136,9 @@ void ssr::OscReceiver::add_scene_methods() lo::Message message) { std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.load_scene(name); } ); @@ -1138,9 +1149,9 @@ void ssr::OscReceiver::add_scene_methods() lo::Message message) { std::string name(&argv[0]->s); - VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from client '" - << message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.save_scene_as_XML(name); } ); @@ -1150,9 +1161,9 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) { - VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << "] from " + << _handler.from_is() << " '" << message.source().hostname() << ":" + << message.source().port() << "'."); _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); } ); @@ -1179,17 +1190,17 @@ void ssr::OscReceiver::add_processing_methods() if(!message.types().compare("T")) { VERBOSE2("OscReceiver: Got [/processing/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(true) << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.start_processing(); } else if(!message.types().compare("F")) { VERBOSE2("OscReceiver: Got [/processing/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(false) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.stop_processing(); } } @@ -1215,9 +1226,9 @@ void ssr::OscReceiver::add_transport_methods() **argv, int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/transport/rewind] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/transport/rewind] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_locate(0); } ); @@ -1232,8 +1243,9 @@ void ssr::OscReceiver::add_transport_methods() if(apf::str::string2time(message_time, time)) { VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); _controller.transport_locate(time); } else @@ -1253,17 +1265,17 @@ void ssr::OscReceiver::add_transport_methods() if(!message.types().compare("T")) { VERBOSE3("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(true) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(true) << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_start(); } if(!message.types().compare("F")) { VERBOSE3("OscReceiver: Got [/transport/state, " << - _handler.bool_to_string(false) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); + _handler.bool_to_string(false) << "] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.transport_stop(); } } @@ -1287,9 +1299,9 @@ void ssr::OscReceiver::add_tracker_methods() int, lo::Message message) { (void) argv; - VERBOSE2("OscReceiver: Got [/tracker/reset] from client " << - message.source().hostname() << ":" << message.source().port() << - "'."); + VERBOSE2("OscReceiver: Got [/tracker/reset] from " << _handler.from_is() + << " '" << message.source().hostname() << ":" << + message.source().port() << "'."); _controller.calibrate_client(); } ); From c5b06822f1720642f8458978fd02f71dd6e190cb Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 01:49:42 +0200 Subject: [PATCH 340/363] src/networking/*: Adding client_has_message_level() to OscSender (and to OscReceiver by OscHandler friend function) to check for MessageLevel of a client defined by hostname and port. Applying checks to whether caller of a message is the server currently setup (client mode) or if a client exists with a MessageLevel::SERVER (server mode) to be able to shut out unsolicited OSC messages to clients and servers. This way clients only listen to servers subscribed to and servers only to clients with a MessageLevel of SERVER. --- src/networking/oschandler.cpp | 16 ++ src/networking/oschandler.h | 2 + src/networking/oscreceiver.cpp | 414 ++++++++++++++++++++++++++------- src/networking/oscreceiver.h | 2 + src/networking/oscsender.cpp | 30 ++- src/networking/oscsender.h | 2 + 6 files changed, 376 insertions(+), 90 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 1f8f9c24..3e7433a2 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -259,6 +259,22 @@ void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string self._osc_sender.set_client_message_level(hostname, port, message_level); } +/** + * OscHandler's friend function to check if a client's message_level is greater + * or equal to one provided. + * @param self reference to OscHandler holding OscSender + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + * @param message_level ssr::MessageLevel to check for + * @return true, if the MessageLevel is equal or greater than the one + * requested, false otherwise + */ +bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& + hostname, std::string& port, ssr::MessageLevel message_level) +{ + self._osc_sender.client_has_message_level(hostname, port, message_level); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 3d231651..a49a8cfa 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -89,6 +89,8 @@ class OscHandler hostname, std::string port); friend void OscReceiver::set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); + friend bool OscReceiver::client_has_message_level(OscHandler& self, std::string& + hostname, std::string& port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 2c1734fa..b48892e7 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -660,17 +660,25 @@ void ssr::OscReceiver::add_source_methods() _handler.server().add_method("/source/delete", "i", [this](lo_arg **argv, int, lo::Message message) { + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); VERBOSE2("OscReceiver: Got [/source/delete, " << argv[0]->i << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - if (argv[0]->i == 0) - { - _controller.delete_all_sources(); - } - else + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) { - _controller.delete_source(argv[0]->i); + if (argv[0]->i == 0) + { + _controller.delete_all_sources(); + } + else + { + _controller.delete_source(argv[0]->i); + } } } ); @@ -684,7 +692,15 @@ void ssr::OscReceiver::add_source_methods() << argv[1]->i << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + } } ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); @@ -697,8 +713,16 @@ void ssr::OscReceiver::add_source_methods() argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/gain if."); @@ -717,7 +741,15 @@ void ssr::OscReceiver::add_source_methods() name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_model(argv[0]->i, model); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_model(argv[0]->i, model); + } } ); VERBOSE("OscReceiver: Added callback for /source/model is."); @@ -729,9 +761,18 @@ void ssr::OscReceiver::add_source_methods() if(!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/mute, " << argv[0]->i << - ", true] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_mute(argv[0]->i, true); + ", true] from " << _handler.from_is() << " '"<< + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_mute(argv[0]->i, true); + } } else if(!message.types().compare("iF")) { @@ -739,7 +780,15 @@ void ssr::OscReceiver::add_source_methods() ", false] from " << _handler.from_is() << " '"<< message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_mute(argv[0]->i, false); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_mute(argv[0]->i, false); + } } } ); @@ -754,7 +803,15 @@ void ssr::OscReceiver::add_source_methods() << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_name(argv[0]->i, name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_name(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/name is."); @@ -913,42 +970,50 @@ void ssr::OscReceiver::add_source_methods() } if (setup) { - std::string name(&(argv[0]->s)); - std::string file_name_or_port_number(&(argv[2]->s)); - float x(argv[3]->f); - float y(argv[4]->f); - float gain(argv[6]->f); - Source::model_t model = Source::model_t(); - if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) { - model = Source::point; + std::string name(&(argv[0]->s)); + std::string file_name_or_port_number(&(argv[2]->s)); + float x(argv[3]->f); + float y(argv[4]->f); + float gain(argv[6]->f); + Source::model_t model = Source::model_t(); + if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) + { + model = Source::point; + } + Position position(x, y); + Orientation orientation(argv[5]->f); + VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model + << ", " << file_name_or_port_number << ", " << x << ", " << y << + ", " << orientation.azimuth << ", " << gain<< ", " << + channel_and_properties << ", " << + _handler.bool_to_string(position_fixed) << ", " << + _handler.bool_to_string(orientation_fixed) << ", " << + _handler.bool_to_string(muted) << "] from " << + _handler.from_is() << " '" << message.source().hostname() << ":" + << message.source().port() << "'."); + _controller.new_source(name, model, file_name_or_port_number, + file_channel, position, position_fixed, orientation, + orientation_fixed, gain, muted, properties_file); + VERBOSE2("OscReceiver: Created source with following properties:" + "\nname: " << name << + "\nmodel: " << model << + "\nfile_name_or_port_number: " << file_name_or_port_number << + "\nfile_channel: " << file_channel << + "\nposition: " << position << + "\nposition_fixed: " << position_fixed << + "\norientation: " << orientation << + "\norientation_fixed: " << orientation_fixed << + "\ngain (linear): " << gain << + "\nmuted: " << muted << + "\nproperties_file: " << properties_file); } - Position position(x, y); - Orientation orientation(argv[5]->f); - VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model << - ", " << file_name_or_port_number << ", " << x << ", " << y << ", " - << orientation.azimuth << ", " << gain<< ", " << - channel_and_properties << ", " << - _handler.bool_to_string(position_fixed) << ", " << - _handler.bool_to_string(orientation_fixed) << ", " << - _handler.bool_to_string(muted) << "] from " << _handler.from_is() - << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.new_source(name, model, file_name_or_port_number, - file_channel, position, position_fixed, orientation, - orientation_fixed, gain, muted, properties_file); - VERBOSE2("OscReceiver: Created source with following properties:" - "\nname: " << name << - "\nmodel: " << model << - "\nfile_name_or_port_number: " << file_name_or_port_number << - "\nfile_channel: " << file_channel << - "\nposition: " << position << - "\nposition_fixed: " << position_fixed << - "\norientation: " << orientation << - "\norientation_fixed: " << orientation_fixed << - "\ngain (linear): " << gain << - "\nmuted: " << muted << - "\nproperties_file: " << properties_file); } } ); @@ -963,7 +1028,15 @@ void ssr::OscReceiver::add_source_methods() << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/orientation if."); @@ -977,7 +1050,15 @@ void ssr::OscReceiver::add_source_methods() name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_port_name(argv[0]->i, name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_port_name(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/port_name is."); @@ -990,8 +1071,16 @@ void ssr::OscReceiver::add_source_methods() argv[1]->f << ", " << argv[2]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /source/position iff."); @@ -1003,16 +1092,34 @@ void ssr::OscReceiver::add_source_methods() if (!message.types().compare("iT")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", true] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, true); + ", true] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_position_fixed(argv[0]->i, true); + } } else if (!message.types().compare("iF")) { VERBOSE2("OscReceiver: Got [/source/position_fixed, " << argv[0]->i << - ", false] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << - message.source().port() << "'."); - _controller.set_source_position_fixed(argv[0]->i, false); + ", false] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_source_position_fixed(argv[0]->i, false); + } } } ); @@ -1024,9 +1131,18 @@ void ssr::OscReceiver::add_source_methods() { std::string name(&argv[1]->s); VERBOSE2("OscReceiver: Got [/source/properties_file, " << argv[0]->i << - ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << - ":" << message.source().port() << "'."); - _controller.set_source_properties_file(argv[0]->i, name); + ", " << name << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_properties_file(argv[0]->i, name); + } } ); VERBOSE("OscReceiver: Added callback for /source/properties_file is."); @@ -1053,7 +1169,15 @@ void ssr::OscReceiver::add_reference_methods() "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_orientation(Orientation(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_orientation(Orientation(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference/orientation f."); @@ -1066,7 +1190,15 @@ void ssr::OscReceiver::add_reference_methods() << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_position(Position(argv[0]->f, argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference/position ff."); @@ -1080,7 +1212,15 @@ void ssr::OscReceiver::add_reference_methods() argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_offset_orientation(Orientation(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference_offset/orientation f."); @@ -1093,8 +1233,16 @@ void ssr::OscReceiver::add_reference_methods() << ", " << argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_reference_offset_position(Position(argv[0]->f, - argv[1]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_reference_offset_position(Position(argv[0]->f, + argv[1]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /reference_offset/position ff."); @@ -1126,7 +1274,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/clear] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.delete_all_sources(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.delete_all_sources(); + } } ); VERBOSE("OscReceiver: Added callback for /scene/clear."); @@ -1139,7 +1295,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/load, " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.load_scene(name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.load_scene(name); + } } ); VERBOSE("OscReceiver: Added callback for /scene/load s."); @@ -1152,7 +1316,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/save, " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.save_scene_as_XML(name); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.save_scene_as_XML(name); + } } ); VERBOSE("OscReceiver: Added callback for /scene/save s."); @@ -1164,7 +1336,15 @@ void ssr::OscReceiver::add_scene_methods() VERBOSE2("OscReceiver: Got [/scene/volume, " << argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_master_volume(apf::math::dB2linear(argv[0]->f)); + } } ); VERBOSE("OscReceiver: Added callback for /scene/volume f."); @@ -1193,7 +1373,15 @@ void ssr::OscReceiver::add_processing_methods() _handler.bool_to_string(true) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.start_processing(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.start_processing(); + } } else if(!message.types().compare("F")) { @@ -1201,7 +1389,15 @@ void ssr::OscReceiver::add_processing_methods() _handler.bool_to_string(false) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.stop_processing(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.stop_processing(); + } } } ); @@ -1229,7 +1425,15 @@ void ssr::OscReceiver::add_transport_methods() VERBOSE2("OscReceiver: Got [/transport/rewind] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_locate(0); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.transport_locate(0); + } } ); VERBOSE("OscReceiver: Added callback for /transport/rewind."); @@ -1238,20 +1442,28 @@ void ssr::OscReceiver::add_transport_methods() _handler.server().add_method("/transport/seek", "s" , [this](lo_arg **argv, int, lo::Message message) { - float time; std::string message_time(&argv[0]->s); - if(apf::str::string2time(message_time, time)) - { - VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << - "] from " << _handler.from_is() << " '" << - message.source().hostname() << ":" << message.source().port() << - "'."); - _controller.transport_locate(time); - } - else + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + VERBOSE3("OscReceiver: Got [/transport/seek, " << message_time << + "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) { - ERROR("Couldn't get the time out of the \"seek\" attribute (\"" - << message_time << "\")."); + float time; + if(apf::str::string2time(message_time, time)) + { + _controller.transport_locate(time); + } + else + { + ERROR("Couldn't get the time out of the \"seek\" attribute (\"" + << message_time << "\")."); + } } } ); @@ -1268,7 +1480,15 @@ void ssr::OscReceiver::add_transport_methods() _handler.bool_to_string(true) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_start(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.transport_start(); + } } if(!message.types().compare("F")) { @@ -1276,7 +1496,15 @@ void ssr::OscReceiver::add_transport_methods() _handler.bool_to_string(false) << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.transport_stop(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.transport_stop(); + } } } ); @@ -1302,7 +1530,15 @@ void ssr::OscReceiver::add_tracker_methods() VERBOSE2("OscReceiver: Got [/tracker/reset] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); - _controller.calibrate_client(); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.calibrate_client(); + } } ); VERBOSE("OscReceiver: Added callback for /tracker/reset."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 646b9dde..9a1fba6f 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -76,6 +76,8 @@ class OscReceiver port); void set_client_message_level(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); + bool client_has_message_level(OscHandler& self, std::string& hostname, + std::string& port, ssr::MessageLevel message_level); }; } // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index b5ea406c..85545338 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -500,7 +500,7 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) } /** - * Set message level of a client + * Set MessageLevel of a client * @param hostname std::string representing the hostname of a client * @param port std::string representing the port of a client * @param message_level ssr::MessageLevel enum representing the message level @@ -521,6 +521,34 @@ void ssr::OscSender::set_client_message_level(std::string hostname, std::string } } +/** + * Compare MessageLevel of a client with one provided + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + * @param message_level ssr::MessageLevel enum representing the message level + * to use + * @return true, if @s message_level is equal or less of what the client, + * defined by @s hostname and @s port has set, false otherwise (also if client + * is not found). + */ +bool ssr::OscSender::client_has_message_level(std::string& hostname, + std::string& port, ssr::MessageLevel message_level) +{ + bool has_level = false; + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->message_level() >= + message_level) + { + has_level = true; + break; + } + } + return has_level; +} + + /** * Removes all clients from the vector of clients. */ diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 056650be..148ec100 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -77,6 +77,8 @@ class OscSender : public Subscriber message_level); void set_client_message_level(std::string hostname, std::string port, ssr::MessageLevel message_level); + bool client_has_message_level(std::string& hostname, std::string& port, + ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); From 34df06e8e5cf1458dda17ed8737b2a75d7975287 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 11:34:41 +0200 Subject: [PATCH 341/363] src/networking/oscreceiver.cpp: Removing obsolete TODOs. --- src/networking/oscreceiver.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index b48892e7..440c7e8c 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -15,7 +15,6 @@ using namespace apf::str; * Constructor * @param controller reference to a Publisher object * @param port_in integer representing a port to used for incoming OSC messages - * @todo add error handler for ServerThread */ ssr::OscReceiver::OscReceiver(Publisher& controller, OscHandler& handler) : _controller(controller) @@ -649,9 +648,6 @@ void ssr::OscReceiver::add_server_to_client_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * set source related settings). */ void ssr::OscReceiver::add_source_methods() { @@ -1155,9 +1151,6 @@ void ssr::OscReceiver::add_source_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_reference_methods() { @@ -1253,9 +1246,6 @@ void ssr::OscReceiver::add_reference_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_scene_methods() { @@ -1356,9 +1346,6 @@ void ssr::OscReceiver::add_scene_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_processing_methods() { @@ -1411,9 +1398,6 @@ void ssr::OscReceiver::add_processing_methods() * (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_transport_methods() { @@ -1516,9 +1500,6 @@ void ssr::OscReceiver::add_transport_methods() * received from a server or a client with MessageLevel::SERVER (respectively). * This function uses C++11 lambda functions to define the behavior for every * callback, that interface with the Publisher's functionality. - * @todo add checks for client MessageLevel when this is used for a server - * (only clients with message_level MessageLevel::SERVER ought to be able to - * interact) */ void ssr::OscReceiver::add_tracker_methods() { From 26ba4eaa5ab51938d65603b2d941a7103f638279 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:15:16 +0200 Subject: [PATCH 342/363] src/publisher.h: Adding set_source_file_name() to public Publisher interface. --- src/publisher.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/publisher.h b/src/publisher.h index 3f4c1739..be4c67b0 100644 --- a/src/publisher.h +++ b/src/publisher.h @@ -114,6 +114,7 @@ struct Publisher virtual void set_source_position_fixed(id_t id, const bool fix) = 0; virtual void set_source_file_channel(id_t id, const int& channel) = 0; + virtual void set_source_file_name(id_t id, const std::string& file_name) = 0; /// set position of the reference /// @param position well, the position From 17b813a6fc0e5ddc4c6cc58624351a7af90e0cd3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:16:07 +0200 Subject: [PATCH 343/363] src/networking/oschandler.cpp: Fix missing return statement in ssr::OscReceiver::client_has_message_level() friend function implementation. --- src/networking/oschandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 3e7433a2..688f3811 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -272,7 +272,7 @@ void ssr::OscReceiver::set_client_message_level(OscHandler& self, std::string bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level) { - self._osc_sender.client_has_message_level(hostname, port, message_level); + return self._osc_sender.client_has_message_level(hostname, port, message_level); } From d6b90d16e24c25bcb2434c00c1d3a6ab0bd4d4b1 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 14:33:39 +0200 Subject: [PATCH 344/363] src/networking/oscreceiver.cpp: Adding client callbacks for /cpu_load with MessageLevel GUI_CLIENT. Adding callback for /source/file_name_or_port_number. Adding callback for /source/level. Adding callback for /scene/amplitude_reference_distance, /scene/auto_rotate_sources, /scene/decay_exponent. Adding callback for /update/scene/master_signal_level. src/networking/oscsender.cpp: Updating check for MessageLevel in ssr:OscSender::client_has_message_level() to check if client is active. Adding server-side implementation to ssr::OscSender::set_cpu_load(). Removing server-side implementation from ssr::OscSender::set_sample_rate(). Sending messages only to GUI_CLIENT clients in set_source_signal_level(), set_master_signal_level(). Removing obsolete TODOs. Minor fixes. --- src/networking/oscreceiver.cpp | 148 ++++++++++++++++++++++++++++++++- src/networking/oscsender.cpp | 96 +++++++-------------- 2 files changed, 177 insertions(+), 67 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 440c7e8c..a79dbbd4 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -311,7 +311,7 @@ ff."); message.source().port() << "'."); } ); - VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent."); + VERBOSE("OscReceiver: Added callback for /update/scene/decay_exponent f."); // update on scene master signal level: "/update/scene/master_signal_level, // f, master_signal_level" @@ -597,6 +597,16 @@ i{F,T}."); */ void ssr::OscReceiver::add_server_to_client_methods() { + // set cpu_load: "/cpu_load, f, load" + _handler.server().add_method("/cpu_load", "f", [](lo_arg **argv, int, + lo::Message message) + { + VERBOSE3("OscReceiver: Got [/cpu_load, " << argv[0]->f << + "] from server '" << message.source().hostname() << ":" << + message.source().port() << "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /cpu_load f."); // set OscSender's _server _message_level through OscHandler: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, @@ -701,12 +711,36 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); + // set source file_name_or_port_number: + // "/source/file_name_or_port_number, is, id, file_name_or_port_number" + _handler.server().add_method("/source/file_name_or_port_number", "is", + [this](lo_arg **argv, int, lo::Message message) + { + std::string name(&argv[1]->s); + VERBOSE3("OscReceiver: Got [/source/file_name_or_port_number, " << + argv[0]->i << ", " << name << "] from " << _handler.from_is() << + " '" << message.source().hostname() << ":" << message.source().port() + << "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_source_file_name(argv[0]->i, name); + } + } + ); + VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number" + "is."); + // set source gain: "/source/gain, if, id, gain" _handler.server().add_method("/source/gain", "if", [this](lo_arg **argv, int, lo::Message message) { VERBOSE2("OscReceiver: Got [/source/gain, " << argv[0]->i << ", " << - argv[1]->f << "] from " << _handler.from_is() << " '" << + argv[1]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); std::string hostname(message.source().hostname()); @@ -723,6 +757,18 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/gain if."); + // set source signal level (GUI_CLIENT only): "/source/level, if, id, level" + _handler.server().add_method("/source/level", "if", [this](lo_arg **argv, + int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/source/level, " << argv[0]->i << ", "<< + argv[1]->f << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /source/level if."); + // set source model: "/source/model, is, id, model" _handler.server().add_method("/source/model", "is", [this](lo_arg **argv, int, lo::Message message) @@ -1256,6 +1302,70 @@ void ssr::OscReceiver::add_scene_methods() //_add_loudspeakers(node); //_add_sources(node); + // set scene's amplitude reference distance: + // "/scene/amplitude_reference_distance, f, amplitude_reference_distance" + _handler.server().add_method("/scene/amplitude_reference_distance", "f", + [this](lo_arg **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/amplitude_reference_distance, " << + argv[0]->f << "] from client '" << message.source().hostname() << + ":" << message.source().port() << "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_amplitude_reference_distance(argv[0]->f); + } + } + ); + VERBOSE("OscReceiver: Added callback for \ +/scene/amplitude_reference_distance f."); + + // set scene source auto rotation: "/scene/auto_rotate_sources, {F,T}, + // false|true" + _handler.server().add_method("/scene/auto_rotate_sources", NULL, + [this](lo_arg **argv, int, lo::Message message) + { + (void) argv; + if(!message.types().compare("T")) + { + VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_auto_rotation(true); + } + } + else if(!message.types().compare("F")) + { + VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, + hostname, port, + MessageLevel::SERVER))) + { + _controller.set_auto_rotation(false); + } + } + } + ); + VERBOSE("OscReceiver: Added callback for /scene/auto_rotate_sources {F,T}."); + // clear scene: "/scene/clear" _handler.server().add_method("/scene/clear", NULL , [this](lo_arg **argv, int, lo::Message message) @@ -1277,6 +1387,27 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/clear."); + // set scene decay exponent: "/scene/decay_exponent, f, decay_exponent" + _handler.server().add_method("/scene/decay_exponent", "f", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + std::string hostname(message.source().hostname()); + std::string port(message.source().port()); + if ((_handler.is_client() && is_server(_handler, hostname, port)) || + (_handler.is_server() && client_has_message_level(_handler, hostname, + port, + MessageLevel::SERVER))) + { + _controller.set_decay_exponent(argv[0]->f); + } + } + ); + VERBOSE("OscReceiver: Added callback for /scene/decay_exponent f."); + // load scene from file: "/scene/load, s, file" _handler.server().add_method("/scene/load", "s" , [this](lo_arg **argv, int, lo::Message message) @@ -1319,6 +1450,19 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/save s."); + // update on scene master signal level: "/update/scene/master_signal_level, + // f, master_signal_level" + _handler.server().add_method("/scene/master_signal_level", "f", [this](lo_arg + **argv, int, lo::Message message) + { + VERBOSE3("OscReceiver: Got [/scene/master_signal_level, " << argv[0]->f + << "] from " << _handler.from_is() << " '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + } + ); + VERBOSE("OscReceiver: Added callback for /scene/master_signal_level f."); + // set master volume: "/scene/volume, f, volume" _handler.server().add_method("/scene/volume", "f" , [this](lo_arg **argv, int, lo::Message message) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 85545338..60abb83d 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -538,8 +538,8 @@ bool ssr::OscSender::client_has_message_level(std::string& hostname, for (auto& client: _clients) { if(!(client->hostname().compare(hostname)) && - !(client->port().compare(port)) && client->message_level() >= - message_level) + !(client->port().compare(port)) && client->active() && + client->message_level() >= message_level) { has_level = true; break; @@ -1035,7 +1035,6 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& * On client: Sends out OSC message to server about the updating of decay_exponent * @param exponentn float representing the decay exponent * @param name a std::string representing the properties_file of source - * @todo implement receiving in OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_decay_exponent(float exponent) { @@ -1071,7 +1070,6 @@ void ssr::OscSender::set_decay_exponent(float exponent) * On client: Sends out OSC message to server about the updating of the * amplitude reference distance. * @param distance a float representing the amplitude reference distance - * @todo implement receiving in OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_amplitude_reference_distance(float distance) { @@ -1083,9 +1081,9 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) { client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); - VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << distance << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + VERBOSE3("OscSender: Sent [/scene/amplitude_reference_distance, f, " << + distance << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } @@ -1190,8 +1188,6 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& * @param file_name a std::string representing the file name or * port number of source * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& file_name) @@ -1246,8 +1242,6 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& * @param id id_t representing the source * @param file_channel an int representing the channel in use for source * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) { @@ -1297,8 +1291,6 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) * @param id id_t representing the source * @param length an int representing the source file's length * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) { @@ -1322,8 +1314,6 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) * On client: Sends out OSC message to server about the updating of the * reference position. * @param position a Position representing the new reference position - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_position(const Position& position) { @@ -1358,8 +1348,6 @@ void ssr::OscSender::set_reference_position(const Position& position) * On client: Sends out OSC message to server about the updating of the * reference orientation. * @param orientation an Orientation representing the new reference orientation - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) { @@ -1396,8 +1384,6 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) * On client: Sends out OSC message to server about the updating of the * reference offset position. * @param position a Position representing the new reference offset position - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_offset_position(const Position& position) { @@ -1435,8 +1421,6 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) * reference offset orientation. * @param orientation an Orientation representing the new reference offset * orientation - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_reference_offset_orientation(const Orientation& orientation) @@ -1473,8 +1457,6 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& * On client: Sends out OSC message to server about the updating of the master * volume (submits in dB!). * @param volume float representing the new volume (linear scale) - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_master_volume(float volume) { @@ -1526,8 +1508,6 @@ void ssr::OscSender::set_source_output_levels(id_t id, float* first , float* * On client: Sends out OSC message to server about the update of its * processing state. * @param state bool representing the processing state - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_processing_state(bool state) { @@ -1564,8 +1544,6 @@ void ssr::OscSender::set_processing_state(bool state) * processing state. * @param state a std::pair of a bool representing the processing state and * jack_nframes_t, representing the current location in the transport - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_transport_state( const std::pair& state) @@ -1617,8 +1595,6 @@ void ssr::OscSender::set_transport_state( const std::pairactive() && client->message_level() == + MessageLevel::GUI_CLIENT) + { + client->address().send_from(_handler.server(), "/cpu_load", "f", load); + VERBOSE3("OscSender: Sent [/cpu_load, f, " << apf::str::A2S(load) << + "] to client " << client->hostname() << ":" << client->port() << + "."); + } + } + } + else if(_handler.is_client() && !server_is_default() && _server.message_level() == MessageLevel::GUI_SERVER) { _server.address().send_from(_handler.server(), "/update/cpu_load", "f", @@ -1672,33 +1660,16 @@ void ssr::OscSender::set_cpu_load(float load) /** * Subscriber function called, when Publisher set sample rate. - * On server: Sends out OSC message to all clients to update their - * sample rate. - * On client: Sends out OSC message to server about the update of its - * sample rate. + * On server: Does nothing, as the sample rate is set during SSR startup and + * can not be changed during runtime. + * On client: Sends out OSC message to server about the update of its sample + * rate. * @param sr an integer representing the current sample rate. - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_sample_rate(int sr) { int32_t message_sr = static_cast(sr); - if(_handler.is_server()) - { - for (const auto& client: _clients) - { - if(client && client->active()) - { - client->address().send_from(_handler.server(), "/scene/sample_rate", - "i", message_sr); - VERBOSE3("OscSender: Sent [/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to client " << - client->address().hostname() << ":" << client->address().port() << - "."); - } - } - } - else if(_handler.is_client() && !server_is_default()) + if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); @@ -1710,13 +1681,10 @@ void ssr::OscSender::set_sample_rate(int sr) /** * Subscriber function called, when Publisher set the master signal level. - * On server: Sends out OSC message to all clients to update their master - * signal level. - * On client: Sends out OSC message to server about the update of its signal - * level. + * On server: Sends out OSC message to clients with MessageLevel GUI_CLIENT + * On client: Sends out OSC message to server with MessageLevel GUI_SERVER + * about the update of its signal level. * @param level a float representing the current master signal level. - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ void ssr::OscSender::set_master_signal_level(float level) { @@ -1725,8 +1693,8 @@ void ssr::OscSender::set_master_signal_level(float level) { for (const auto& client: _clients) { - if(client && client->active() && client->message_level() >= - MessageLevel::CLIENT) + if(client && client->active() && client->message_level() == + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); @@ -1757,8 +1725,6 @@ void ssr::OscSender::set_master_signal_level(float level) * @param id an id_t representing the source. * @param level a float representing the signal level of the source. * @return true - * @todo implement receiver callback in - * OscReceiver::add_server_to_client_methods() */ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { @@ -1769,7 +1735,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) for (const auto& client: _clients) { if(client && client->active() && client->message_level() >= - MessageLevel::CLIENT) + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); From a4650247d1015ce5a9d32ed647cd84b7ed243405 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Jun 2017 18:42:41 +0200 Subject: [PATCH 345/363] src/networking/oscreceiver.h: Remove obsolete todo. --- src/networking/oscreceiver.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 9a1fba6f..9250cf8a 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -30,7 +30,6 @@ class OscHandler; * This class holds a Publisher and an OscHandler reference. * It is responsible for all incoming OSC messages and using callback functions * to trigger functionality in the Publisher. - * @todo add functionality to only process a subset of incoming client messages */ class OscReceiver { From 66e8bd5b9835240ecf40694d04d81e6fc54fe6f3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 01:01:40 +0200 Subject: [PATCH 346/363] src/ssr_global.h: Removing unused field THIN_CLIENT from enum class MessageLevel. Moving SERVER and GUI_SERVER to the top values. --- src/ssr_global.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ssr_global.h b/src/ssr_global.h index 726569c2..eefb266d 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -53,11 +53,10 @@ extern float c_inverse; ///< reciprocal value of c extern unsigned int usleeptime; enum class MessageLevel : id_t { - SERVER = 0, - GUI_SERVER, - THIN_CLIENT, - CLIENT, - GUI_CLIENT + CLIENT = 0, + GUI_CLIENT, + SERVER, + GUI_SERVER }; } // namespace ssr From aa39998742ec82a7e5851d96f5ed7fc9857a0eda Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 10:02:26 +0200 Subject: [PATCH 347/363] src/networking/oscreceiver.cpp: Making callback for /update/source/mute and /update/source/position_fixed more robust. Switching to VERBOSE2 (from VERBOSE3) in callback handlers for all non-rapid messages. --- src/networking/oscreceiver.cpp | 98 +++++++++++++++++----------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index a79dbbd4..e6927fca 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -216,7 +216,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/orientation, " << + VERBOSE2("OscReceiver: Got [/update/reference/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -227,7 +227,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference/position", "ff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference/position, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/update/reference/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -240,7 +240,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference_offset/orientation", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/orientation, " << + VERBOSE2("OscReceiver: Got [/update/reference_offset/orientation, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -254,7 +254,7 @@ void ssr::OscReceiver::add_update_notification_methods() _handler.server().add_method("/update/reference_offset/position", "ff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/reference_offset/position, " << + VERBOSE2("OscReceiver: Got [/update/reference_offset/position, " << argv[0]->f << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -269,7 +269,7 @@ ff."); _handler.server().add_method("/update/scene/amplitude_reference_distance", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/amplitude_reference_distance, " + VERBOSE2("OscReceiver: Got [/update/scene/amplitude_reference_distance, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -292,7 +292,7 @@ ff."); { state = false; } - VERBOSE3("OscReceiver: Got [/update/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/update/scene/auto_rotate_sources, " << _handler.bool_to_string(state) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -306,7 +306,7 @@ ff."); _handler.server().add_method("/update/scene/decay_exponent", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/update/scene/decay_exponent, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -330,7 +330,7 @@ f."); _handler.server().add_method("/update/scene/sample_rate", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << + VERBOSE2("OscReceiver: Got [/update/scene/sample_rate, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -341,7 +341,7 @@ f."); _handler.server().add_method("/update/scene/volume", "f", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << + VERBOSE2("OscReceiver: Got [/update/scene/volume, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -352,7 +352,7 @@ f."); _handler.server().add_method("/update/source/delete", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/delete, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/delete, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -364,7 +364,7 @@ f."); _handler.server().add_method("/update/source/file_channel", "ii", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/file_channel, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -378,7 +378,7 @@ f."); [](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/file_name_or_port_number, " << + VERBOSE2("OscReceiver: Got [/update/source/file_name_or_port_number, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -391,7 +391,7 @@ f."); _handler.server().add_method("/update/source/gain", "if", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/gain, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/gain, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -403,7 +403,7 @@ f."); _handler.server().add_method("/update/source/length", "ii", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/length, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/length, " << argv[0]->i << ", " << argv[1]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -427,7 +427,7 @@ f."); int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " + VERBOSE2("OscReceiver: Got [/update/source/model, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -439,19 +439,20 @@ f."); _handler.server().add_method("/update/source/mute", NULL, [this](lo_arg **argv, int, lo::Message message) { - bool state; if(!message.types().compare("iT")) { - state = true; + VERBOSE2("OscReceiver: Got [/update/source/mute, " << argv[0]->i << + ", " << _handler.bool_to_string(true) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } else if(!message.types().compare("iF")) { - state = false; + VERBOSE2("OscReceiver: Got [/update/source/mute, " << argv[0]->i << + ", " << _handler.bool_to_string(false) << "] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); } - VERBOSE3("OscReceiver: Got [/update/processing/state, " << argv[0]->i << - ", " << _handler.bool_to_string(state) << "] from client '" << - message.source().hostname() << ":" << message.source().port() << - "'."); } ); VERBOSE("OscReceiver: Added callback for /update/source/mute i{F,T}."); @@ -461,7 +462,7 @@ f."); int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " + VERBOSE2("OscReceiver: Got [/update/source/name, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -473,7 +474,7 @@ f."); _handler.server().add_method("/update/source/orientation", "if", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/orientation, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/orientation, " << argv[0]->i << ", " << argv[1]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -485,7 +486,7 @@ f."); _handler.server().add_method("/update/source/new", "i", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/new, " << argv[0]->i + VERBOSE2("OscReceiver: Got [/update/source/new, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); } @@ -497,7 +498,7 @@ f."); **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/port_name, " << + VERBOSE2("OscReceiver: Got [/update/source/port_name, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -509,7 +510,7 @@ f."); _handler.server().add_method("/update/source/position", "iff", [](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/update/source/position, " << argv[0]->i << + VERBOSE2("OscReceiver: Got [/update/source/position, " << argv[0]->i << ", " << argv[1]->f << ", " << argv[2]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -522,19 +523,20 @@ f."); _handler.server().add_method("/update/source/position_fixed", NULL, [this](lo_arg **argv, int, lo::Message message) { - bool state; if(!message.types().compare("iT")) { - state = true; + VERBOSE2("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(true) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } else if(!message.types().compare("iF")) { - state = false; + VERBOSE2("OscReceiver: Got [/update/source/position_fixed, " << + argv[0]->i << ", " << _handler.bool_to_string(false) << + "] from client '" << message.source().hostname() << ":" << + message.source().port() << "'."); } - VERBOSE3("OscReceiver: Got [/update/source/position_fixed, " << - argv[0]->i << ", " << _handler.bool_to_string(state) << - "] from client '" << message.source().hostname() << ":" << - message.source().port() << "'."); } ); VERBOSE("OscReceiver: Added callback for /update/source/position_fixed \ @@ -546,7 +548,7 @@ i{F,T}."); [](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/update/source/properties_file, " << + VERBOSE2("OscReceiver: Got [/update/source/properties_file, " << argv[0]->i << ", " << name << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -644,7 +646,7 @@ void ssr::OscReceiver::add_server_to_client_methods() } else { - VERBOSE3("OscReceiver: Got [/poll] from server " << from.hostname() << + VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << ":" << from.port() << ". Sending alive signal."); from.send_from(_handler.server(), "/alive", ""); } @@ -711,13 +713,13 @@ void ssr::OscReceiver::add_source_methods() ); VERBOSE("OscReceiver: Added callback for /source/file_channel ii."); - // set source file_name_or_port_number: - // "/source/file_name_or_port_number, is, id, file_name_or_port_number" + // set source file_name_or_port_number: "/source/file_name_or_port_number, + // is, id, file_name_or_port_number" _handler.server().add_method("/source/file_name_or_port_number", "is", [this](lo_arg **argv, int, lo::Message message) { std::string name(&argv[1]->s); - VERBOSE3("OscReceiver: Got [/source/file_name_or_port_number, " << + VERBOSE2("OscReceiver: Got [/source/file_name_or_port_number, " << argv[0]->i << ", " << name << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -732,7 +734,7 @@ void ssr::OscReceiver::add_source_methods() } } ); - VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number" + VERBOSE("OscReceiver: Added callback for /source/file_name_or_port_number " "is."); // set source gain: "/source/gain, if, id, gain" @@ -1031,9 +1033,9 @@ void ssr::OscReceiver::add_source_methods() } Position position(x, y); Orientation orientation(argv[5]->f); - VERBOSE3("OscReceiver: Got [/source/new, " << name << ", " << model + VERBOSE2("OscReceiver: Got [/source/new, " << name << ", " << model << ", " << file_name_or_port_number << ", " << x << ", " << y << - ", " << orientation.azimuth << ", " << gain<< ", " << + ", " << orientation.azimuth << ", " << gain << channel_and_properties << ", " << _handler.bool_to_string(position_fixed) << ", " << _handler.bool_to_string(orientation_fixed) << ", " << @@ -1307,7 +1309,7 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/amplitude_reference_distance", "f", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/scene/amplitude_reference_distance, " << + VERBOSE2("OscReceiver: Got [/scene/amplitude_reference_distance, " << argv[0]->f << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); std::string hostname(message.source().hostname()); @@ -1332,7 +1334,7 @@ void ssr::OscReceiver::add_scene_methods() (void) argv; if(!message.types().compare("T")) { - VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/scene/auto_rotate_sources, " << _handler.bool_to_string(true) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1348,7 +1350,7 @@ void ssr::OscReceiver::add_scene_methods() } else if(!message.types().compare("F")) { - VERBOSE3("OscReceiver: Got [/scene/auto_rotate_sources, " << + VERBOSE2("OscReceiver: Got [/scene/auto_rotate_sources, " << _handler.bool_to_string(false) << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1391,7 +1393,7 @@ void ssr::OscReceiver::add_scene_methods() _handler.server().add_method("/scene/decay_exponent", "f", [this](lo_arg **argv, int, lo::Message message) { - VERBOSE3("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f + VERBOSE2("OscReceiver: Got [/scene/decay_exponent, " << argv[0]->f << "] from " << _handler.from_is() << " '" << message.source().hostname() << ":" << message.source().port() << "'."); @@ -1450,8 +1452,8 @@ void ssr::OscReceiver::add_scene_methods() ); VERBOSE("OscReceiver: Added callback for /scene/save s."); - // update on scene master signal level: "/update/scene/master_signal_level, - // f, master_signal_level" + // set scene master signal level: "/scene/master_signal_level, f, + // master_signal_level" _handler.server().add_method("/scene/master_signal_level", "f", [this](lo_arg **argv, int, lo::Message message) { From 46dd7c2dcc5d6d4ff25535f036106d2cfff528af Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Jun 2017 10:13:33 +0200 Subject: [PATCH 348/363] src/networking/oscsender.cpp: Moving check for file_name_or_port_number property to within statement checking for new_source in OscSender::set_source_mute (preventing accidental sending on server, before source is created). Moving check for file_channel property to within statement checking for new source in OscSender::set_source_properties_file (preventing accidental sending on server, before source is created). Moving check for file_channel > 0 to within statement checking for new source in OscSender::set_source_file_channel to prevent an unfinished source in _new_sources. Setting client check to <= GUI_CLIENT for OscSender::set_transport_state and to == GUI_CLIENT for OscSender::set_source_signal_level. Using std::string reference directly in VERBOSE messages of functions having string parameters and c_str() representation for sending OSC messages to not initialize an unneeded variable every time. --- src/networking/oscsender.cpp | 57 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 60abb83d..80627b42 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -417,7 +417,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("gain", 0.0)); VERBOSE2("OscSender: Sent [/source/new, sssffff" << _handler.bool_to_message_type( - _new_sources.at(id).get( "position_fixed", false)) << + _new_sources.at(id).get("position_fixed", false)) << _handler.bool_to_message_type( _new_sources.at(id).get("orientation_fixed", false)) << _handler.bool_to_message_type( @@ -892,10 +892,11 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) int32_t message_id = static_cast(id); if(_handler.is_server()) { - if(is_new_source(id) && - _new_sources.at(id).has_key("file_name_or_port_number")) + if(is_new_source(id)) { - _new_sources.at(id).set("mute", mute); + if(_new_sources.at(id).has_key("file_name_or_port_number")) + _new_sources.at(id).set("mute", mute); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -942,7 +943,6 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) bool ssr::OscSender::set_source_name(id_t id, const std::string& name) { int32_t message_id = static_cast(id); - const char * message_name = name.c_str(); if(_handler.is_server()) { if(is_new_source(id)) @@ -958,10 +958,10 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) if(client && client->active()) { client->address().send_from(_handler.server(), "/source/name", "is", - message_id, message_name); + message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << message_name << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + << name << "] to client " << client->address().hostname() << ":" + << client->address().port() << "."); } } } @@ -969,9 +969,9 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) else if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), "/update/source/name", "is", - message_id, message_name); + message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << message_name << "] to server " << _server.hostname() << ":" << + << name << "] to server " << _server.hostname() << ":" << _server.port() << "."); } return true; @@ -993,12 +993,13 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& name) { int32_t message_id = static_cast(id); - const char * file_name = name.c_str(); if(_handler.is_server()) { - if(is_new_source(id) && !name.empty()) + if(is_new_source(id)) { - _new_sources.at(id).set("properties_file", file_name); + if(name.compare("") && _new_sources.at(id).has_key("file_channel")) + _new_sources.at(id).set("properties_file", name); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1009,11 +1010,11 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& if(client && client->active()) { client->address().send_from(_handler.server(), - "/source/properties_file", "is", message_id, file_name); + "/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << - message_id << ", " << file_name << "] to client " << - client->address().hostname() << ":" << - client->address().port() << "."); + message_id << ", " << name << "] to client " << + client->address().hostname() << ":" << client->address().port() + << "."); } } } @@ -1021,10 +1022,10 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& else if(_handler.is_client() && !server_is_default()) { _server.address().send_from(_handler.server(), - "/update/source/properties_file", "is", message_id, file_name); + "/update/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << file_name << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + message_id << ", " << name << "] to server " << _server.hostname() << + ":" << _server.port() << "."); } return true; } @@ -1150,8 +1151,8 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) } /** - * Subscriber function called, when Publisher set a source's port_name. - * On server: Does nothing, as port_name is local and depends on prefix + * Subscriber function called, when Publisher set a source's port_name. On + * server: Does nothing, as port_name is local and depends on prefix * On client: Sends out OSC message to server about the successful updating of * the source's port_name. * @param id id_t representing the source @@ -1249,9 +1250,11 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) int32_t message_file_channel = static_cast(file_channel); if(_handler.is_server()) { - if(is_new_source(id) && file_channel > 0) + if(is_new_source(id)) { - _new_sources.at(id).set("file_channel", file_channel); + if(file_channel > 0) + _new_sources.at(id).set("file_channel", file_channel); + if(is_complete_source(id)) send_new_source_message_from_id(id); } @@ -1553,8 +1556,8 @@ void ssr::OscSender::set_transport_state( const std::pairactive() && client->message_level() >= - MessageLevel::CLIENT) + if(client && client->active() && client->message_level() <= + MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/transport/state", _handler.bool_to_message_type(state.first)); @@ -1734,7 +1737,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) { for (const auto& client: _clients) { - if(client && client->active() && client->message_level() >= + if(client && client->active() && client->message_level() == MessageLevel::GUI_CLIENT) { client->address().send_from(_handler.server(), "/source/level", "if", From 7add4071298ab8eaaf83f1b6bc88913256645829 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 28 Jun 2017 16:34:48 +0200 Subject: [PATCH 349/363] src/networking/oscreceiver.cpp: Switching to setting initial gain of a source on the logarithmic scale (to be coherent with the IP interface and how /source/gain handles things). --- src/networking/oscreceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e6927fca..6299a816 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -1025,7 +1025,7 @@ void ssr::OscReceiver::add_source_methods() std::string file_name_or_port_number(&(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); - float gain(argv[6]->f); + float gain(apf::math::dB2linear(argv[6]->f)); Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) { From 1b9358524717677fd6158b41b5abd2cfdf1b0f84 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 29 Jun 2017 10:26:57 +0200 Subject: [PATCH 350/363] src/networking/oscsender.cpp: Wrapping all VERBOSE output information about hostname:port in ''. Minor linewrap fixes. --- src/networking/oscsender.cpp | 231 ++++++++++++++++++----------------- 1 file changed, 117 insertions(+), 114 deletions(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 80627b42..dba68803 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -377,9 +377,9 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("gain", 0.0) << ", " << _new_sources.at(id).get("file_channel", 1) << ", " << _new_sources.at(id).get("properties_file", "") - << "] to client " << + << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } _new_sources.erase(id); @@ -430,9 +430,9 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("y", 0.0) << ", " << _new_sources.at(id).get("orientation", 0.0) << ", " << _new_sources.at(id).get("gain", 0.0) - << "] to client " << + << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } _new_sources.erase(id); @@ -597,8 +597,8 @@ void ssr::OscSender::new_source(id_t id) _server.address().send_from(_handler.server(), "/update/source/new", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/new, i, " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -621,8 +621,8 @@ void ssr::OscSender::delete_source(id_t id) client->address().send_from(_handler.server(), "/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/source/delete, i," << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -632,8 +632,8 @@ void ssr::OscSender::delete_source(id_t id) _server.address().send_from(_handler.server(), "/update/source/delete", "i", message_id); VERBOSE3("OscSender: Sent [/update/source/delete, i, " << message_id << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); + "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -653,9 +653,9 @@ void ssr::OscSender::delete_all_sources() { client->address().send_from(_handler.server(), "/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client " << + VERBOSE3("OscSender: Sent [/source/delete, i, 0] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -663,8 +663,8 @@ void ssr::OscSender::delete_all_sources() { _server.address().send_from(_handler.server(), "/update/source/delete", "i", 0); - VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server " << - _server.hostname() << ":" << _server.port() << "."); + VERBOSE3("OscSender: Sent [/update/source/delete, i, 0] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } _source_levels.clear(); } @@ -702,9 +702,9 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) client->address().send_from(_handler.server(), "/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/source/position, iff, " << message_id << - position.x << ", " << position.y << "] to client " << + position.x << ", " << position.y << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } } @@ -714,8 +714,8 @@ bool ssr::OscSender::set_source_position(id_t id, const Position& position) _server.address().send_from(_handler.server(), "/update/source/position", "iff", message_id, position.x, position.y); VERBOSE3("OscSender: Sent [/update/source/position, iff, " << message_id << - ", " << position.x << ", " << position.y << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + ", " << position.x << ", " << position.y << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } return true; } @@ -755,8 +755,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/source/position_fixed, i" << _handler.bool_to_message_type(fixed) << ", " << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -768,7 +768,8 @@ bool ssr::OscSender::set_source_position_fixed(id_t id, const bool& fixed) "i"+_handler.bool_to_message_type(fixed), message_id); VERBOSE3("OscSender: Sent [/update/source/position_fixed, i" +_handler.bool_to_message_type(fixed) << ", " << message_id << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -807,9 +808,9 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& client->address().send_from(_handler.server(), "/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/source/orientation, if, " << message_id - << ", " << message_orientation << "] to client " << + << ", " << message_orientation << "] to client '" << client->address().hostname() << ":" << - client->address().port() << "."); + client->address().port() << "'."); } } } @@ -820,8 +821,8 @@ bool ssr::OscSender::set_source_orientation(id_t id , const Orientation& "/update/source/orientation", "if", message_id, message_orientation); VERBOSE3("OscSender: Sent [/update/source/orientation, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_orientation) - << "] to server " << _server.hostname() << ":" << _server.port() << - "."); + << "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -858,8 +859,8 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) client->address().send_from(_handler.server(), "/source/gain", "if", message_id, gain); VERBOSE3("OscSender: Sent [/source/gain, if, " << message_id << ", " - << gain << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + << gain << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -870,7 +871,8 @@ bool ssr::OscSender::set_source_gain(id_t id, const float& gain) message_id, gain); VERBOSE3("OscSender: Sent [/update/source/gain, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(gain) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } return true; } @@ -910,8 +912,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << message_id << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -922,8 +924,8 @@ bool ssr::OscSender::set_source_mute(id_t id, const bool& mute) "i"+_handler.bool_to_message_type(mute), message_id); VERBOSE3("OscSender: Sent [/update/source/mute, i" << _handler.bool_to_message_type(mute) << ", " << - apf::str::A2S(message_id) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_id) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } return true; } @@ -960,8 +962,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) client->address().send_from(_handler.server(), "/source/name", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/name, is, " << message_id << ", " - << name << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + << name << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -971,8 +973,8 @@ bool ssr::OscSender::set_source_name(id_t id, const std::string& name) _server.address().send_from(_handler.server(), "/update/source/name", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/name, is, " << message_id << ", " - << name << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << name << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1012,9 +1014,9 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& client->address().send_from(_handler.server(), "/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/source/properties_file, is, " << - message_id << ", " << name << "] to client " << + message_id << ", " << name << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1024,8 +1026,8 @@ bool ssr::OscSender::set_source_properties_file(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/properties_file", "is", message_id, name.c_str()); VERBOSE3("OscSender: Sent [/update/source/properties_file, is, " << - message_id << ", " << name << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + message_id << ", " << name << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } return true; } @@ -1048,8 +1050,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) client->address().send_from(_handler.server(), "/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/scene/decay_exponent, f, " << exponent << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1058,8 +1060,8 @@ void ssr::OscSender::set_decay_exponent(float exponent) _server.address().send_from(_handler.server(), "/update/scene/decay_exponent", "f", exponent); VERBOSE3("OscSender: Sent [/update/scene/decay_exponent, f, " << exponent - << "] to server " << _server.hostname() << ":" << _server.port() << - "."); + << "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } } @@ -1083,8 +1085,8 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) client->address().send_from(_handler.server(), "/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/scene/amplitude_reference_distance, f, " << - distance << "] to client " << client->address().hostname() << ":" - << client->address().port() << "."); + distance << "] to client '" << client->address().hostname() << ":" + << client->address().port() << "'."); } } } @@ -1093,8 +1095,8 @@ void ssr::OscSender::set_amplitude_reference_distance(float distance) _server.address().send_from(_handler.server(), "/update/scene/amplitude_reference_distance", "f", distance); VERBOSE3("OscSender: Sent [/update/scene/amplitude_reference_distance, f, " - << distance << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << distance << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1132,9 +1134,9 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) client->address().send_from(_handler.server(), "/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/source/model, is, " << message_id << ", " - << message_model << "] to client " << + << message_model << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1144,8 +1146,8 @@ bool ssr::OscSender::set_source_model(id_t id, const Source::model_t& model) _server.address().send_from(_handler.server(), "/update/source/model", "is", message_id, message_model.c_str()); VERBOSE3("OscSender: Sent [/update/source/model, is, " << message_id << - ", " << message_model << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + ", " << message_model << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1170,8 +1172,8 @@ bool ssr::OscSender::set_source_port_name(id_t id, const std::string& _server.address().send_from(_handler.server(), "/update/source/port_name", "is", message_id, port_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/port_name, is, " << message_id << - ", " << port_name << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + ", " << port_name << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } return true; } @@ -1213,9 +1215,9 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& "/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/source/file_name_or_port_number, is, " << - message_id << ", " << file_name << "] to client " << + message_id << ", " << file_name << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1226,8 +1228,8 @@ bool ssr::OscSender::set_source_file_name(id_t id, const std::string& "/update/source/file_name_or_port_number", "is", message_id, file_name.c_str()); VERBOSE3("OscSender: Sent [/update/source/file_name_or_port_number, is, " - << message_id << ", " << file_name << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + << message_id << ", " << file_name << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } return true; } @@ -1267,9 +1269,9 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) client->address().send_from(_handler.server(), "/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to client " << + << ", " << message_file_channel << "] to client '" << client->address().hostname() << ":" << client->address().port() - << "."); + << "'."); } } } @@ -1279,8 +1281,8 @@ bool ssr::OscSender::set_source_file_channel(id_t id, const int& file_channel) _server.address().send_from(_handler.server(), "/update/source/file_channel", "ii", message_id, message_file_channel); VERBOSE3("OscSender: Sent [/update/source/file_channel, ii, " << message_id - << ", " << message_file_channel << "] to server " << _server.hostname() - << ":" << _server.port() << "."); + << ", " << message_file_channel << "] to server '" << _server.hostname() + << ":" << _server.port() << "'."); } return true; } @@ -1304,8 +1306,8 @@ bool ssr::OscSender::set_source_file_length(id_t id, const long int& length) _server.address().send_from(_handler.server(), "/update/source/length", "ii", message_id, message_length); VERBOSE3("OscSender: Sent [/update/source/length, ii, " << message_id << - ", " << message_length << "] to server " << _server.hostname() << ":" - << _server.port() << "."); + ", " << message_length << "] to server '" << _server.hostname() << ":" + << _server.port() << "'."); } return true; } @@ -1329,8 +1331,8 @@ void ssr::OscSender::set_reference_position(const Position& position) client->address().send_from(_handler.server(), "/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference/position, ff, " << position.x << - ", " << position.y << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + ", " << position.y << "] to client '" << client->address().hostname() + << ":" << client->address().port() << "'."); } } } @@ -1339,8 +1341,8 @@ void ssr::OscSender::set_reference_position(const Position& position) _server.address().send_from(_handler.server(), "/update/reference/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference/position, ff, " << position.x - << ", " << position.y << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + << ", " << position.y << "] to server '" << _server.hostname() << ":" + << _server.port() << "'."); } } @@ -1363,9 +1365,9 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) client->address().send_from(_handler.server(), "/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference/orientation, f, " << - orientation.azimuth << "] to client " << + orientation.azimuth << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1374,8 +1376,8 @@ void ssr::OscSender::set_reference_orientation(const Orientation& orientation) _server.address().send_from(_handler.server(), "/update/reference/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + orientation.azimuth << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1399,9 +1401,9 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) client->address().send_from(_handler.server(), "/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to client " << - client->address().hostname() << ":" << client->address().port() - << "."); + position.x << ", " << position.y << "] to client '" << + client->address().hostname() << ":" << client->address().port() << + "'."); } } } @@ -1410,8 +1412,8 @@ void ssr::OscSender::set_reference_offset_position(const Position& position) _server.address().send_from(_handler.server(), "/update/reference_offset/position", "ff", position.x, position.y); VERBOSE3("OscSender: Sent [/update/reference_offset/position, ff, " << - position.x << ", " << position.y << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + position.x << ", " << position.y << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } } @@ -1437,9 +1439,9 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& client->address().send_from(_handler.server(), "/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/reference_offset/orientation, f, " << - orientation.azimuth << "] to client " << + orientation.azimuth << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1448,8 +1450,8 @@ void ssr::OscSender::set_reference_offset_orientation(const Orientation& _server.address().send_from(_handler.server(), "/update/reference_offset/orientation", "f", orientation.azimuth); VERBOSE3("OscSender: Sent [/update/reference_offset/orientation, f, " << - orientation.azimuth << "] to server " << _server.hostname() << ":" << - _server.port() << "."); + orientation.azimuth << "] to server '" << _server.hostname() << ":" << + _server.port() << "'."); } } @@ -1473,8 +1475,8 @@ void ssr::OscSender::set_master_volume(float volume) client->address().send_from(_handler.server(), "/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/scene/volume, f, " << message_volume << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1483,7 +1485,8 @@ void ssr::OscSender::set_master_volume(float volume) _server.address().send_from(_handler.server(), "/update/scene/volume", "f", message_volume); VERBOSE3("OscSender: Sent [/update/scene/volume, f, " << message_volume << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << + "'."); } } @@ -1523,9 +1526,9 @@ void ssr::OscSender::set_processing_state(bool state) client->address().send_from(_handler.server(), "/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/processing/state, " << - _handler.bool_to_message_type(state) << "] to client " << + _handler.bool_to_message_type(state) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1534,8 +1537,8 @@ void ssr::OscSender::set_processing_state(bool state) _server.address().send_from(_handler.server(), "/update/processing/state", _handler.bool_to_message_type(state)); VERBOSE3("OscSender: Sent [/update/processing/state, " << - _handler.bool_to_message_type(state) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _handler.bool_to_message_type(state) << "] to server '" << + _server.hostname() << ":" << _server.port() << "'."); } } @@ -1562,14 +1565,14 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().send_from(_handler.server(), "/transport/state", _handler.bool_to_message_type(state.first)); VERBOSE3("OscSender: Sent [/transport/state, " << - _handler.bool_to_message_type(state.first) << "] to client " << + _handler.bool_to_message_type(state.first) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); client->address().send_from(_handler.server(), "/transport/seek", "i", message_nframes); VERBOSE3("OscSender: Sent [/transport/seek, i, " << message_nframes << - "] to client " << client->address().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1579,13 +1582,13 @@ void ssr::OscSender::set_transport_state( const std::pairaddress().hostname() << ":" << - client->address().port() << "."); + "] to client '" << client->address().hostname() << ":" << + client->address().port() << "'."); } } } @@ -1623,8 +1626,8 @@ void ssr::OscSender::set_auto_rotation(bool auto_rotate_sources) "/update/scene/auto_rotate_sources", _handler.bool_to_message_type(auto_rotate_sources)); VERBOSE3("OscSender: Sent [/update/scene/auto_rotate_sources, " << - _handler.bool_to_message_type(auto_rotate_sources) << "] to server " << - _server.hostname() << ":" << _server.port() << "."); + _handler.bool_to_message_type(auto_rotate_sources) << "] to server '" + << _server.hostname() << ":" << _server.port() << "'."); } } @@ -1646,18 +1649,18 @@ void ssr::OscSender::set_cpu_load(float load) { client->address().send_from(_handler.server(), "/cpu_load", "f", load); VERBOSE3("OscSender: Sent [/cpu_load, f, " << apf::str::A2S(load) << - "] to client " << client->hostname() << ":" << client->port() << - "."); + "] to client '" << client->hostname() << ":" << client->port() << + "'."); } } } - else if(_handler.is_client() && !server_is_default() && _server.message_level() == - MessageLevel::GUI_SERVER) + else if(_handler.is_client() && !server_is_default() && + _server.message_level() == MessageLevel::GUI_SERVER) { _server.address().send_from(_handler.server(), "/update/cpu_load", "f", load); VERBOSE3("OscSender: Sent [/update/cpu_load, f, " << apf::str::A2S(load) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << "'."); } } @@ -1677,8 +1680,8 @@ void ssr::OscSender::set_sample_rate(int sr) _server.address().send_from(_handler.server(), "/update/scene/sample_rate", "i", message_sr); VERBOSE3("OscSender: Sent [/update/scene/sample_rate, i, " << - apf::str::A2S(message_sr) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_sr) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } } @@ -1702,9 +1705,9 @@ void ssr::OscSender::set_master_signal_level(float level) client->address().send_from(_handler.server(), "/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to client " << + apf::str::A2S(message_level) << "] to client '" << client->address().hostname() << ":" << client->address().port() << - "."); + "'."); } } } @@ -1714,8 +1717,8 @@ void ssr::OscSender::set_master_signal_level(float level) _server.address().send_from(_handler.server(), "/update/scene/master_signal_level", "f", message_level); VERBOSE3("OscSender: Sent [/update/scene/master_signal_level, f, " << - apf::str::A2S(message_level) << "] to server " << _server.hostname() << - ":" << _server.port() << "."); + apf::str::A2S(message_level) << "] to server '" << _server.hostname() << + ":" << _server.port() << "'."); } } @@ -1743,8 +1746,8 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) client->address().send_from(_handler.server(), "/source/level", "if", message_id, message_level); VERBOSE3("OscSender: Sent [/source/level, if, " << message_id << ", " - << message_level << "] to client " << client->address().hostname() - << ":" << client->address().port() << "."); + << message_level << "] to client '" << client->address().hostname() + << ":" << client->address().port() << "'."); } } } @@ -1755,7 +1758,7 @@ bool ssr::OscSender::set_source_signal_level(const id_t id, const float& level) "if", message_id, message_level); VERBOSE3("OscSender: Sent [/update/source/level, if, " << apf::str::A2S(message_id) << ", " << apf::str::A2S(message_level) << - "] to server " << _server.hostname() << ":" << _server.port() << "."); + "] to server '" << _server.hostname() << ":" << _server.port() << "'."); } return true; } From eb98369a6423bb1682dd96a4db22c2fa6b6f43e2 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 10 Jul 2017 17:57:34 +0200 Subject: [PATCH 351/363] src/networking/*: Adding functionality to discard inactive clients automatically after 10 seconds. No more messages will be sent to them, as long as they don't subscribe again. --- src/networking/oscclient.cpp | 36 ++++++++++++++++++++++++++++++++-- src/networking/oscclient.h | 4 ++++ src/networking/oschandler.cpp | 12 ++++++++++++ src/networking/oschandler.h | 12 ++++++++---- src/networking/oscreceiver.cpp | 22 ++++++++++++++++++--- src/networking/oscreceiver.h | 2 ++ src/networking/oscsender.cpp | 29 +++++++++++++++++++++++---- src/networking/oscsender.h | 4 +++- 8 files changed, 107 insertions(+), 14 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 2206aede..47fa4795 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -15,10 +15,11 @@ ssr::OscClient::OscClient(std::string hostname, std::string port, MessageLevel message_level) : _address(hostname, port) , _message_level(message_level) + , _alive_counter(10) { _active = true; - VERBOSE("OscClient: Initialized as " << _address.hostname() << ":" << - _address.port() << "."); + VERBOSE("OscClient: Initialized as '" << _address.hostname() << ":" << + _address.port() << "'."); } /** @@ -110,3 +111,34 @@ const std::string ssr::OscClient::port() { return _address.port(); } + +/** + * Function to increment the OscClient's _alive_counter + **/ +void ssr::OscClient::increment_alive_counter() +{ + _alive_counter++; +} + +/** + * Function to decrement the OscClient's _alive_counter. + * Deactivates the OscClient, in the case where _alive_counter <= 0 + **/ +void ssr::OscClient::decrement_alive_counter() +{ + _alive_counter--; + if(_alive_counter < 0) + { + deactivate(); + VERBOSE("OscClient: Deactivated '" << _address.hostname() << ":" << + _address.port() << "' due to inactivity."); + } +} + +/** + * Function to reset the OscClient's _alive counter + **/ +void ssr::OscClient::reset_alive_counter() +{ + _alive_counter=10; +} diff --git a/src/networking/oscclient.h b/src/networking/oscclient.h index 085a38a1..fa0a1628 100644 --- a/src/networking/oscclient.h +++ b/src/networking/oscclient.h @@ -19,6 +19,7 @@ class OscClient lo::Address _address; MessageLevel _message_level; bool _active = false; + int _alive_counter; public: OscClient(std::string hostname, std::string port, MessageLevel @@ -34,6 +35,9 @@ class OscClient void set_message_level(MessageLevel message_level); const std::string hostname(); const std::string port(); + void increment_alive_counter(); + void decrement_alive_counter(); + void reset_alive_counter(); }; } diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 688f3811..97630302 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -275,6 +275,18 @@ bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& return self._osc_sender.client_has_message_level(hostname, port, message_level); } +/** + * OscHandler's friend function to increment an active client's alive counter. + * @param self reference to OscHandler holding OscSender + * @param hostname std::string representing the client's hostname + * @param port std::string representing the client's port + */ +void ssr::OscReceiver::increment_client_alive_counter(OscHandler& self, + std::string& hostname, std::string& port) +{ + self._osc_sender.increment_client_alive_counter(hostname, port); +} + /** * This function returns the OscHandler's mode diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index a49a8cfa..71d5840d 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -87,10 +87,14 @@ class OscHandler std::string port, ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, std::string hostname, std::string port); - friend void OscReceiver::set_client_message_level(OscHandler& self, std::string - hostname, std::string port, ssr::MessageLevel message_level); - friend bool OscReceiver::client_has_message_level(OscHandler& self, std::string& - hostname, std::string& port, ssr::MessageLevel message_level); + friend void OscReceiver::set_client_message_level(OscHandler& self, + std::string hostname, std::string port, ssr::MessageLevel + message_level); + friend bool OscReceiver::client_has_message_level(OscHandler& self, + std::string& hostname, std::string& port, ssr::MessageLevel + message_level); + friend void OscReceiver::increment_client_alive_counter(OscHandler& self, + std::string& hostname, std::string& port); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6299a816..6dc688a1 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -70,13 +70,27 @@ void ssr::OscReceiver::stop() } /** - * Adds callback handlers (for server) for subscribe and message level messages - * received from clients. + * Adds callback handlers (for server) for alive, subscribe and message level + * messages received from clients. * This function uses C++11 lambda functions to define the behavior for every * callback. */ void ssr::OscReceiver::add_client_to_server_methods() { + // incrementing alive_counter of subscribed client: "/alive" + _handler.server().add_method("/alive", NULL, [this](lo_arg **argv, + int, lo::Message message) + { + std::string hostname = message.source().hostname(); + std::string port = message.source().port(); + VERBOSE2("OscReceiver: Got [/alive] from client '" << + message.source().hostname() << ":" << message.source().port() << + "'."); + increment_client_alive_counter(_handler, hostname, port); + } + ); + VERBOSE("OscReceiver: Added callback for /alive."); + // setting MessageLevel of subscribed client: "/message_level, {i,ssi}" _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) @@ -647,8 +661,10 @@ void ssr::OscReceiver::add_server_to_client_methods() else { VERBOSE2("OscReceiver: Got [/poll] from server " << from.hostname() << - ":" << from.port() << ". Sending alive signal."); + ":" << from.port() << "."); from.send_from(_handler.server(), "/alive", ""); + VERBOSE2("OscReceiver: Sent [/alive] to server " << from.hostname() << + ":" << from.port() << "."); } } ); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 9250cf8a..acc371b4 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -77,6 +77,8 @@ class OscReceiver std::string port, ssr::MessageLevel message_level); bool client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level); + void increment_client_alive_counter(OscHandler& self, std::string& + hostname, std::string& port); }; } // namespace ssr diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index dba68803..6da5a15c 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -115,6 +115,7 @@ void ssr::OscSender::poll_all_clients() if(client && client->active()) { client->address().send_from(_handler.server(), "/poll", ""); + client->decrement_alive_counter(); } } //TODO find better solution to compensate for execution time @@ -457,6 +458,7 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, if(client->message_level() != message_level) client->set_message_level(message_level); client->activate(); + client->reset_alive_counter(); setup = true; VERBOSE2("OscSender: Recycled client " << hostname << ":" << port << "."); @@ -474,8 +476,8 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, if (!setup) { _clients.push_back(new OscClient(hostname, port, message_level)); - VERBOSE2("OscSender: Added new client " << hostname << ":" << port << - " using message level " << static_cast(message_level) << + VERBOSE2("OscSender: Added new client '" << hostname << ":" << port << + "' using message level " << static_cast(message_level) << "."); } } @@ -506,8 +508,8 @@ void ssr::OscSender::deactivate_client(std::string hostname, std::string port) * @param message_level ssr::MessageLevel enum representing the message level * to use */ -void ssr::OscSender::set_client_message_level(std::string hostname, std::string - port, ssr::MessageLevel message_level) +void ssr::OscSender::set_client_message_level(std::string& hostname, + std::string& port, ssr::MessageLevel message_level) { for (auto& client: _clients) { @@ -521,6 +523,25 @@ void ssr::OscSender::set_client_message_level(std::string hostname, std::string } } +/** + * Increment the _alive_counter of an active client + * @param hostname std::string representing the hostname of a client + * @param port std::string representing the port of a client + */ +void ssr::OscSender::increment_client_alive_counter(std::string& hostname, + std::string& port) +{ + for (auto& client: _clients) + { + if(!(client->hostname().compare(hostname)) && + !(client->port().compare(port)) && client->active()) + { + client->increment_alive_counter(); + break; + } + } +} + /** * Compare MessageLevel of a client with one provided * @param hostname std::string representing the hostname of a client diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 148ec100..56918f99 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -75,11 +75,13 @@ class OscSender : public Subscriber void set_message_level(const unsigned int& message_level); void add_client(std::string hostname, std::string port, ssr::MessageLevel message_level); - void set_client_message_level(std::string hostname, std::string port, + void set_client_message_level(std::string& hostname, std::string& port, ssr::MessageLevel message_level); bool client_has_message_level(std::string& hostname, std::string& port, ssr::MessageLevel message_level); void deactivate_client(std::string hostname, std::string port); + void increment_client_alive_counter(std::string& hostname, std::string& + port); void send_to_server(std::string path, lo::Message message); void send_to_server(lo::Bundle bundle); void send_to_client(lo::Address address, std::string path, lo::Message From cbefee9a0f8382ac43caaee15e8fe2315444d76c Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Jul 2017 13:35:49 +0200 Subject: [PATCH 352/363] src/networking/*: Let calls to increment_client_alive_counter in OSCReceiver implicitely copy by value. --- src/networking/oschandler.cpp | 2 +- src/networking/oschandler.h | 2 +- src/networking/oscreceiver.cpp | 5 ++--- src/networking/oscreceiver.h | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 97630302..0227caae 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -282,7 +282,7 @@ bool ssr::OscReceiver::client_has_message_level(OscHandler& self, std::string& * @param port std::string representing the client's port */ void ssr::OscReceiver::increment_client_alive_counter(OscHandler& self, - std::string& hostname, std::string& port) + std::string hostname, std::string port) { self._osc_sender.increment_client_alive_counter(hostname, port); } diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 71d5840d..6de5a15e 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -94,7 +94,7 @@ class OscHandler std::string& hostname, std::string& port, ssr::MessageLevel message_level); friend void OscReceiver::increment_client_alive_counter(OscHandler& self, - std::string& hostname, std::string& port); + std::string hostname, std::string port); }; } // namespace ssr diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 6dc688a1..5e73edd3 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -81,12 +81,11 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/alive", NULL, [this](lo_arg **argv, int, lo::Message message) { - std::string hostname = message.source().hostname(); - std::string port = message.source().port(); VERBOSE2("OscReceiver: Got [/alive] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); - increment_client_alive_counter(_handler, hostname, port); + increment_client_alive_counter(_handler, message.source().hostname(), + message.source().port()); } ); VERBOSE("OscReceiver: Added callback for /alive."); diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index acc371b4..8b271e3b 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -77,8 +77,8 @@ class OscReceiver std::string port, ssr::MessageLevel message_level); bool client_has_message_level(OscHandler& self, std::string& hostname, std::string& port, ssr::MessageLevel message_level); - void increment_client_alive_counter(OscHandler& self, std::string& - hostname, std::string& port); + void increment_client_alive_counter(OscHandler& self, std::string hostname, + std::string port); }; } // namespace ssr From a76e69053a083baedee689dd3b4867c06bbe1a0a Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 11 Jul 2017 16:41:30 +0200 Subject: [PATCH 353/363] src/ssr_global.h: Extending MessageLevel by MAX_VALUE. src/networking/*: Making assignment of client/server MessageLevel sane. --- src/networking/oscclient.cpp | 3 +++ src/networking/oscreceiver.cpp | 38 ++++++++++++++++++++++++---------- src/networking/oscreceiver.h | 1 + src/networking/oscsender.cpp | 3 +-- src/ssr_global.h | 3 ++- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/networking/oscclient.cpp b/src/networking/oscclient.cpp index 47fa4795..e8c2267d 100644 --- a/src/networking/oscclient.cpp +++ b/src/networking/oscclient.cpp @@ -92,6 +92,9 @@ void ssr::OscClient::set_address(std::string& hostname, std::string& port) void ssr::OscClient::set_message_level(MessageLevel message_level) { _message_level = message_level; + VERBOSE("OscClient: Message level of '" << _address.hostname() << ":" << + _address.port() << "' changed to " << static_cast(_message_level) + << "."); } /** diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index 5e73edd3..c9f17af8 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -94,14 +94,14 @@ void ssr::OscReceiver::add_client_to_server_methods() _handler.server().add_method("/message_level", NULL, [this](lo_arg **argv, int, lo::Message message) { + (void) argv; if(!message.types().compare("i")) { VERBOSE2("OscReceiver: Got [/message_level, " << argv[0]->i << "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); set_client_message_level(_handler, message.source().hostname(), - message.source().port(), - static_cast(argv[0]->i)); + message.source().port(), get_sane_message_level(argv[0]->i)); } else if(!message.types().compare("ssi")) { @@ -112,7 +112,7 @@ void ssr::OscReceiver::add_client_to_server_methods() message.source().hostname() << ":" << message.source().port() << "'."); set_client_message_level(_handler, hostname, port, - static_cast(argv[2]->i)); + get_sane_message_level(argv[2]->i)); } } ); @@ -164,7 +164,7 @@ void ssr::OscReceiver::add_client_to_server_methods() message.source().hostname() << ":" << message.source().port() << "'."); add_client(_handler, hostname, port, - static_cast(argv[3]->i)); + get_sane_message_level(argv[3]->i)); } // subscribing client: "/subscribe, Ti, message_level" else if(!message.types().compare("Ti")) @@ -174,8 +174,7 @@ void ssr::OscReceiver::add_client_to_server_methods() "] from client '" << message.source().hostname() << ":" << message.source().port() << "'."); add_client(_handler, message.source().hostname(), - message.source().port(), - static_cast(argv[1]->i)); + message.source().port(), get_sane_message_level(argv[1]->i)); } } ); @@ -623,7 +622,7 @@ void ssr::OscReceiver::add_server_to_client_methods() ); VERBOSE("OscReceiver: Added callback for /cpu_load f."); - // set OscSender's _server _message_level through OscHandler: /message_level, i + // set OscSender's _server _message_level: /message_level, i _handler.server().add_method("/message_level", "i", [this](lo_arg **argv, int, lo::Message message) { @@ -633,10 +632,7 @@ void ssr::OscReceiver::add_server_to_client_methods() "] from server '" << message.source().hostname() << ":" << message.source().port() << "'."); if(is_server(_handler, hostname, port)) - { - set_server_message_level(_handler, - static_cast(argv[0]->i)); - } + set_server_message_level(_handler, get_sane_message_level(argv[0]->i)); } ); VERBOSE("OscReceiver: Added callback for /message_level i."); @@ -1686,3 +1682,23 @@ void ssr::OscReceiver::add_tracker_methods() VERBOSE("OscReceiver: Added callback for /tracker/reset."); } +/** + * Creates a sane MessageLevel from an int32_t + * @param message_level An int32_t + * @return a MessageLevel + */ +ssr::MessageLevel ssr::OscReceiver::get_sane_message_level(int32_t message_level) +{ + if(message_level <= 0){ + return ssr::MessageLevel::CLIENT; + } + else if(ssr::MessageLevel::MAX_VALUE < + static_cast(message_level)) + { + return ssr::MessageLevel::GUI_SERVER; + } + else + { + return static_cast(message_level); + } +} diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index 8b271e3b..b3433fdf 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -45,6 +45,7 @@ class OscReceiver void add_processing_methods(); void add_transport_methods(); void add_tracker_methods(); + ssr::MessageLevel get_sane_message_level(int32_t message_level); public: OscReceiver(Publisher& controller, OscHandler& handler); diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 6da5a15c..1c9b56b0 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -477,8 +477,7 @@ void ssr::OscSender::add_client(std::string hostname, std::string port, { _clients.push_back(new OscClient(hostname, port, message_level)); VERBOSE2("OscSender: Added new client '" << hostname << ":" << port << - "' using message level " << static_cast(message_level) << - "."); + "' using message level " << static_cast(message_level) << "."); } } diff --git a/src/ssr_global.h b/src/ssr_global.h index eefb266d..e8dbdc63 100644 --- a/src/ssr_global.h +++ b/src/ssr_global.h @@ -56,7 +56,8 @@ enum class MessageLevel : id_t CLIENT = 0, GUI_CLIENT, SERVER, - GUI_SERVER + GUI_SERVER, + MAX_VALUE = GUI_SERVER }; } // namespace ssr From 34669e65fe3c31a5acfc250664c2eeadc7752e78 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 12 Jul 2017 13:05:35 +0200 Subject: [PATCH 354/363] src/networking/oschandler.cpp: Adding exit with EXIT_FAILURE, in case the ServerThread could not be initialized (most likely due to port already being in use). --- src/networking/oschandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 0227caae..8951c9f5 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -64,7 +64,9 @@ void ssr::OscHandler::start() VERBOSE("OscHandler: Starting"); // check if lo::ServerThread is valid if (!_server.is_valid()) { - ERROR("OscHandler: ServerThread could not be started!"); + ERROR("OscHandler: The liblo ServerThread could not be started!" << + " Is the port already in use?"); + exit(EXIT_FAILURE); } _server.set_callbacks([this]() { From 3bb0b96301cabc33e163c82a7812baf136ab6284 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 13 Jul 2017 13:43:59 +0200 Subject: [PATCH 355/363] src/networking/oscreceiver.cpp: Adding check, if id > 0 to all source related callbacks. --- src/networking/oscreceiver.cpp | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index c9f17af8..e002bd70 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -694,7 +694,7 @@ void ssr::OscReceiver::add_source_methods() { _controller.delete_all_sources(); } - else + else if (argv[0]->i > 0) { _controller.delete_source(argv[0]->i); } @@ -718,7 +718,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_file_channel(argv[0]->i, argv[1]->i); + if (argv[0]->i > 0) + _controller.set_source_file_channel(argv[0]->i, argv[1]->i); } } ); @@ -741,7 +742,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_file_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_file_name(argv[0]->i, name); } } ); @@ -763,8 +765,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + if (argv[0]->i > 0) + _controller.set_source_gain(argv[0]->i, + apf::math::dB2linear(argv[1]->f)); } } ); @@ -803,7 +806,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_model(argv[0]->i, model); + if (argv[0]->i > 0) + _controller.set_source_model(argv[0]->i, model); } } ); @@ -826,7 +830,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_mute(argv[0]->i, true); + if (argv[0]->i > 0) + _controller.set_source_mute(argv[0]->i, true); } } else if(!message.types().compare("iF")) @@ -842,7 +847,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_mute(argv[0]->i, false); + if (argv[0]->i > 0) + _controller.set_source_mute(argv[0]->i, false); } } } @@ -865,7 +871,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_name(argv[0]->i, name); } } ); @@ -1090,7 +1097,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_orientation(argv[0]->i, Orientation(argv[1]->f)); + if (argv[0]->i > 0) + _controller.set_source_orientation(argv[0]->i, + Orientation(argv[1]->f)); } } ); @@ -1112,7 +1121,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_port_name(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_port_name(argv[0]->i, name); } } ); @@ -1133,8 +1143,9 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_position(argv[0]->i, Position(argv[1]->f, - argv[2]->f)); + if (argv[0]->i > 0) + _controller.set_source_position(argv[0]->i, Position(argv[1]->f, + argv[2]->f)); } } ); @@ -1157,7 +1168,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_position_fixed(argv[0]->i, true); + if (argv[0]->i > 0) + _controller.set_source_position_fixed(argv[0]->i, true); } } else if (!message.types().compare("iF")) @@ -1173,7 +1185,8 @@ void ssr::OscReceiver::add_source_methods() hostname, port, MessageLevel::SERVER))) { - _controller.set_source_position_fixed(argv[0]->i, false); + if (argv[0]->i > 0) + _controller.set_source_position_fixed(argv[0]->i, false); } } } @@ -1196,7 +1209,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - _controller.set_source_properties_file(argv[0]->i, name); + if (argv[0]->i > 0) + _controller.set_source_properties_file(argv[0]->i, name); } } ); From 9fd8b0244903f1ea8c72022db6a840af2f986f88 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 25 Jul 2017 18:51:31 +0200 Subject: [PATCH 356/363] src/networking/oscreceiver.cpp: Using the linear scale, instead of logarithmic scale for setting source gain. A range form 0.0 - inf is used, where 1.0 signifies 100% source level. --- src/networking/oscreceiver.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/networking/oscreceiver.cpp b/src/networking/oscreceiver.cpp index e002bd70..6b280049 100644 --- a/src/networking/oscreceiver.cpp +++ b/src/networking/oscreceiver.cpp @@ -765,9 +765,8 @@ void ssr::OscReceiver::add_source_methods() port, MessageLevel::SERVER))) { - if (argv[0]->i > 0) - _controller.set_source_gain(argv[0]->i, - apf::math::dB2linear(argv[1]->f)); + if (argv[0]->i > 0 && argv[1]->f >= 0.0) + _controller.set_source_gain(argv[0]->i, argv[1]->f); } } ); @@ -1043,7 +1042,9 @@ void ssr::OscReceiver::add_source_methods() std::string file_name_or_port_number(&(argv[2]->s)); float x(argv[3]->f); float y(argv[4]->f); - float gain(apf::math::dB2linear(argv[6]->f)); + float gain(argv[6]->f); + if (gain < 0.0) + gain = 0.0; Source::model_t model = Source::model_t(); if (!apf::str::S2A(apf::str::A2S(argv[1]->s), model)) { From af9c2c97ba0b2a0ee899a01ce1a9f40ccd6324db Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 21 Jun 2017 17:41:09 +0200 Subject: [PATCH 357/363] supercollider/workflows.scd: Adding workflow example for 'sclang is a client controlling the server' and 'sclang mimics a server, controls a client'. --- supercollider/workflows.scd | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 supercollider/workflows.scd diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd new file mode 100644 index 00000000..2dfac3c5 --- /dev/null +++ b/supercollider/workflows.scd @@ -0,0 +1,62 @@ +// workflows + +// sclang is a client, controlling a SSR server instance +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // move source 1 to -2.0/2.0 + ~address.sendMsg("/source/position", 1, -2.0, 2.0); + // move source 2 to 2.0/2.0 + ~address.sendMsg("/source/position", 2, 2.0, 2.0); + // remove all sources + ~address.sendMsg("/scene/clear"); + // unsubscribe from server + ~address.sendMsg("/subscribe", $F); +) + +// sclang is a server, controlling a SSR client instance +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // poll client instance to make it subscribe + ~address.sendMsg("/poll"); + // subsequent poll makes client emit /alive message + ~address.sendMsg("/poll"); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // set message level to GUI_SERVER (a lot of messages!) + ~address.sendMsg("/message_level", 3); + // move source 1 to -2.0/2.0 + ~address.sendMsg("/source/position", 1, -2.0, 2.0); + // move source 2 to 2.0/2.0 + ~address.sendMsg("/source/position", 2, 2.0, 2.0); + // set message level back to SERVER + ~address.sendMsg("/message_level", 1); + // remove all sources + ~address.sendMsg("/scene/clear"); +) + From 74d944a040173d01e0e6a89a2f18a41ab7dbda91 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 27 Jul 2017 23:19:23 +0200 Subject: [PATCH 358/363] supercollider/workflows.scd: Adding Sensors2OSC example, setting reference orientation through orientation sensor and two sources through multi-touch interface. --- supercollider/workflows.scd | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd index 2dfac3c5..d3c2e1f5 100644 --- a/supercollider/workflows.scd +++ b/supercollider/workflows.scd @@ -60,3 +60,108 @@ ~address.sendMsg("/scene/clear"); ) +// sclang is a client, controlling a SSR server instance, while forwarding OSC +// commands from a smartphone, that uses Sensors2OSC (https://sensors2.org/osc/) +( + // set address of the client instance + ~address = NetAddr("localhost", 50001); + // print all OSC messages sent to sclang +// OSCFunc.trace(true, true); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // add new source with standard input at -1.0/1.0 + ~address.sendMsg("/source/new", "in_1", "point", "1", + -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // add new source with standard input at 1.0/1.0 + ~address.sendMsg("/source/new", "in_2", "point", "2", + 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + // unmute source 1 + ~address.sendMsg("/source/mute", 1, $F); + // unmute source 2 + ~address.sendMsg("/source/mute", 2, $F); + // vectors for holding source position + ~source1 = [-1.0, -1.0]; + ~source2 = [-1.0, -1.0]; + // OSC functions to receive from Sensors2OSC and send to SSR + OSCFunc( + { + arg msg, time, addr, recvPort; + [msg, time, addr, recvPort].postln; + ~address.sendMsg("/reference/orientation", msg[1]); + }, + '/orientation/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source1[0] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 1, + ~source1[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source1[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch1/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source1[1] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 1, + ~source1[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source1[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch1/Y' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source2[0] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 2, + ~source2[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source2[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch2/X' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + if(msg[1]>=0.0, { + ~source2[1] = msg[1]; + [msg, time, addr, recvPort].postln; + }); + if(msg[0] != (-1.0) && msg[1] != (-1.0), { + ~address.sendMsg("/source/position", 2, + ~source2[0].linlin(0.0, 1.0, -10.0, 10.0), + ~source2[1].linlin(0.0, 1.0, -10.0, 10.0) + ); + }); + }, + '/touch2/Y' + ); +) + +// clear scene and unsubscribe from server instance +( + // remove all sources + ~address.sendMsg("/scene/clear"); + // unsubscribe from server + ~address.sendMsg("/subscribe", $F); +) + From ebc1eb493fd5c7ed587aec3feacd1ab2b3a53a25 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 18 Aug 2017 19:20:30 +0200 Subject: [PATCH 359/363] supercollider/workflows.scd: Fixing input creation and source volume. Introducing /alive message on receiving /poll from server. Controlling /reference/orientation with /orientation/X from Sensors2OSC. Deactivating verbose printout on each received message. --- supercollider/workflows.scd | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/supercollider/workflows.scd b/supercollider/workflows.scd index d3c2e1f5..cf7a92e3 100644 --- a/supercollider/workflows.scd +++ b/supercollider/workflows.scd @@ -66,19 +66,14 @@ // set address of the client instance ~address = NetAddr("localhost", 50001); // print all OSC messages sent to sclang -// OSCFunc.trace(true, true); // subscribe to server with MessageLevel::SERVER ~address.sendMsg("/subscribe", $T, 2); // add new source with standard input at -1.0/1.0 - ~address.sendMsg("/source/new", "in_1", "point", "1", - -1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); + ~address.sendMsg("/source/new", "in_1", "point", "1", -1.0, 1.0, 0.0, 0.99, + $F, $F, $F); // add new source with standard input at 1.0/1.0 - ~address.sendMsg("/source/new", "in_2", "point", "2", - 1.0, 1.0, 0.1, 0.1, 0, "1", $F, $F, $T); - // unmute source 1 - ~address.sendMsg("/source/mute", 1, $F); - // unmute source 2 - ~address.sendMsg("/source/mute", 2, $F); + ~address.sendMsg("/source/new", "in_2", "point", "2", 1.0, 1.0, 0.0, 0.99, + $F, $F, $F); // vectors for holding source position ~source1 = [-1.0, -1.0]; ~source2 = [-1.0, -1.0]; @@ -86,8 +81,14 @@ OSCFunc( { arg msg, time, addr, recvPort; - [msg, time, addr, recvPort].postln; - ~address.sendMsg("/reference/orientation", msg[1]); + ~address.sendMsg("/alive"); + }, + '/poll' + ); + OSCFunc( + { + arg msg, time, addr, recvPort; + ~address.sendMsg("/reference/orientation", msg[1]+90); }, '/orientation/X' ); @@ -96,7 +97,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source1[0] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 1, @@ -112,7 +112,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source1[1] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 1, @@ -128,7 +127,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source2[0] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 2, @@ -144,7 +142,6 @@ arg msg, time, addr, recvPort; if(msg[1]>=0.0, { ~source2[1] = msg[1]; - [msg, time, addr, recvPort].postln; }); if(msg[0] != (-1.0) && msg[1] != (-1.0), { ~address.sendMsg("/source/position", 2, From 965bf524f209a51375e2fabc6dcec69228b6a1a7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 24 Jun 2017 17:03:44 +0200 Subject: [PATCH 360/363] supercollider/tests.scd: Adding tests for server and client (subscribed and not subscribed). --- supercollider/tests.scd | 226 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 supercollider/tests.scd diff --git a/supercollider/tests.scd b/supercollider/tests.scd new file mode 100644 index 00000000..8f9398ed --- /dev/null +++ b/supercollider/tests.scd @@ -0,0 +1,226 @@ +// tests + +// evaluate block to add the test functions +( + +~processingTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/processing/state", [$F, $T].choose)}); +}; + +~referenceTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/reference/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/reference/position", 10.0.rand2, 10.0.rand2)}); + 100.do({address.sendMsg("/reference_offset/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/reference_offset/position", 10.0.rand2, 10.0.rand2)}); +}; + +~sceneTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/scene/amplitude_reference_distance", 10.0.rand2)}); + 10.do({address.sendMsg("/scene/auto_rotate_sources", [$F, $T].choose)}); + address.sendMsg("/scene/clear"); + 20.do({address.sendMsg("/scene/decay_exponent", rrand(-1, 10))}); + address.sendMsg("/scene/load", "some_file.asdf"); + address.sendMsg("/scene/save", "some_file.asdf"); + 100.do({address.sendMsg("/scene/master_signal_level", rrand(-100.0, 40.0))}); + 100.do({address.sendMsg("/scene/volume", rrand(-100.0, 40.0))}); +}; + +~sourceTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/source/delete", 10.rand2)}); + 20.do({address.sendMsg("/source/file_channel", 10.rand2, 10.rand)}); + 20.do({address.sendMsg("/source/file_name_or_port_number", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/source/gain", 10.rand2, rrand(-100.0, 40.0))}); + 100.do({address.sendMsg("/source/level", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/source/model", 10.rand2, ["unknown", "point", "plane", "line", "directional", "extended"].choose)}); + 20.do({address.sendMsg("/source/mute", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/source/name", 10.rand2, ("source_"++10.rand2.asString))}); + 20.do({address.sendMsg("/source/new", ("source_"++10.rand2.asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + 10.rand2.asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), rrand(-100.0, 40.0), + [$F, $T].choose, [$F, $T].choose, [$F, $T].choose) + }); + 20.do({address.sendMsg("/source/new", ("source_"++10.rand2.asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + 10.rand2.asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), rrand(-100.0, 40.0), + 10.rand2, ("file_"++10.rand2.asString), [$F, $T].choose, [$F, $T].choose, + [$F, $T].choose) + }); + 20.do({address.sendMsg("/source/orientation", 10.rand2, 360.0.rand2)}); + 20.do({address.sendMsg("/source/port_name", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/source/position", 10.rand2, 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/source/position_fixed", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/source/properties_file", 10.rand2, 10.rand2.asString)}); +}; + +~trackerTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 10.do({address.sendMsg("/tracker/reset")}); +}; + +~transportTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/transport/rewind")}); + 100.do({address.sendMsg("/transport/seek", (10.rand2.asString++":"++59.rand2.asString++":"++59.0.rand2.asString))}); + 100.do({address.sendMsg("/transport/state", [$F, $T].choose)}); +}; + +~updateTestRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/update/cpu_load", 100.0.rand)}); + 100.do({address.sendMsg("/update/processing/state", [$F, $T].choose)}); + 100.do({address.sendMsg("/update/reference/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/update/reference/position", 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/reference_offset/orientation", 360.0.rand2)}); + 20.do({address.sendMsg("/update/reference_offset/position", 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/scene/amplitude_reference_distance", 10.0.rand2)}); + 20.do({address.sendMsg("/update/scene/auto_rotate_sources", [$F, $T].choose)}); + 20.do({address.sendMsg("/update/scene/decay_exponent", rrand(-1.0, 10.0))}); + 20.do({address.sendMsg("/update/scene/master_signal_level", rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/scene/sample_rate", [22050, 44100, 48000, 88200, 96000].choose)}); + 20.do({address.sendMsg("/update/scene/volume", rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/delete", 10.rand2)}); + 20.do({address.sendMsg("/update/source/file_channel", 10.rand2, 10.rand2)}); + 20.do({address.sendMsg("/update/source/file_name_or_port_number", 10.rand2, 10.rand2.asString)}); + 20.do({address.sendMsg("/update/source/gain", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/level", 10.rand2, rrand(-100.0, 40.0))}); + 20.do({address.sendMsg("/update/source/model", 10.rand2, ["unknown", "point", "plane", "line", "directional", "extended"].choose)}); + 20.do({address.sendMsg("/update/source/mute", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/update/source/name", 10.rand2, ("source_"++10.rand2.asString))}); + 20.do({address.sendMsg("/update/source/new", 10.rand2)}); + 20.do({address.sendMsg("/update/source/orientation", 10.rand2, 360.0.rand2)}); + 20.do({address.sendMsg("/update/source/port_name", 10.rand2, ("in_"++10.rand2))}); + 20.do({address.sendMsg("/update/source/position", 10.rand2, 10.0.rand2, 10.0.rand2)}); + 20.do({address.sendMsg("/update/source/position_fixed", 10.rand2, [$F, $T].choose)}); + 20.do({address.sendMsg("/update/source/properties_file", 10.rand2, ("file_"++10.rand2.asString))}); + 20.do({address.sendMsg("/update/transport/seek", (10.rand2.asString++":"++59.rand2.asString++":"++59.0.rand2.asString))}); + 100.do({address.sendMsg("/update/transport/state", [$F, $T].choose)}); +}; + +~messageLevelTestServerRandomAll = { arg address = NetAddr("127.0.0.1", 50001), otherClient = NetAddr("127.0.0.1", 50002); + 20.do({address.sendMsg("/message_level", 10.rand2)}); + 20.do({address.sendMsg("/message_level", otherClient.ip.asString, otherClient.port.asString, 10.rand2)}); +}; + +~subscribeTestOtherClient = { arg address = NetAddr("127.0.0.1", 50001), otherClient = NetAddr("127.0.0.1", 50002); + 10.do({ + address.sendMsg("/subscribe", [$F, $T].choose, otherClient.ip, otherClient.port); + address.sendMsg("/subscribe", $T, otherClient.ip, otherClient.port, 10.rand2); + address.sendMsg("/subscribe", [$F, $T].choose); + address.sendMsg("/subscribe", $T, 10.rand2); + address.sendMsg("/subscribe", $F); + }); +}; + +~cpuLoadTestClient = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/cpu_load", 100.0.rand)}); +}; + +~messageLevelTestClientRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 20.do({address.sendMsg("/message_level", 10.rand2)}); +}; + +~pollTestClientRandomAll = { arg address = NetAddr("127.0.0.1", 50001); + 100.do({address.sendMsg("/poll")}); +}; + +~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; + amountOfSources.do({|item,i| + address.sendMsg("/source/new", ("source_"++(i+1).asString), ["unknown", + "point", "plane", "line", "directional", "extended"].choose, + (i+1).asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), + rrand(-100.0, 40.0), [$F, $T].choose, [$F, $T].choose, [$F, + $T].choose); + }); + amountOfSources.do({ |item, i| + address.sendMsg("/source/position_fixed", i+1, $F); + address.sendMsg("/source/mute", i+1, $F); + }); + 100.do({ + amountOfSources.do({|item, i| + address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); + }); + }); +}; + +) + + +// sclang tries to control/send to server (not subscribed) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + ~messageLevelTestServerRandomAll.value; + ~sourceTestRandomAll.value; + ~updateTestRandomAll.value; + ~subscribeTestOtherClient.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang controls server (subscribed) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + // subscribe to server with MessageLevel::SERVER + ~address.sendMsg("/subscribe", $T, 2); + // send alive message on subsequent poll + ~responder_poll = OSCFunc( + { |msg, time, addr, recvPort| + ~address.sendMsg("/alive"); + }, '/poll' + , ~address + ); + ~messageLevelTestServerRandomAll.value; + ~sourceTestRandomAll.value; + ~updateTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang tries to control client (not polled) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + ~messageLevelTestClientRandomAll.value; + ~cpuLoadTestClient.value; + ~sourceTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang tries to control client (polled) +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + ~pollTestClientRandomAll.value; + ~messageLevelTestClientRandomAll.value; + ~cpuLoadTestClient.value; + ~sourceTestRandomAll.value; + ~processingTestRandomAll.value; + ~transportTestRandomAll.value; + ~trackerTestRandomAll.value; + ~referenceTestRandomAll.value; + ~sceneTestRandomAll.value; +) + +// sclang controls a client (polled), adds sources and moves them +( + // print all OSC messages sent to sclang + OSCFunc.trace(true, true); + // set address of the server instance + ~address = NetAddr("127.0.0.1", 50001); + // poll client instance to make it subscribe + ~address.sendMsg("/poll"); + ~sourceTestMoving.value(amountOfSources: 20); +) + From 406a06b494a0170706186648672e56eee1603037 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 28 Jun 2017 16:09:02 +0200 Subject: [PATCH 361/363] supercollider/tests.scd: Adding separate function to add n sources. Adding sourceTestAdding to source movement test. Making sourceTestMoving function use a Routine to move n sources randomly for 100 seconds, each 100ms. --- supercollider/tests.scd | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/supercollider/tests.scd b/supercollider/tests.scd index 8f9398ed..61c8099d 100644 --- a/supercollider/tests.scd +++ b/supercollider/tests.scd @@ -120,23 +120,23 @@ 100.do({address.sendMsg("/poll")}); }; -~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; +~sourceTestAdding = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; amountOfSources.do({|item,i| - address.sendMsg("/source/new", ("source_"++(i+1).asString), ["unknown", - "point", "plane", "line", "directional", "extended"].choose, - (i+1).asString, 10.0.rand2, 10.0.rand2, rrand(-100.0, 40.0), - rrand(-100.0, 40.0), [$F, $T].choose, [$F, $T].choose, [$F, - $T].choose); - }); - amountOfSources.do({ |item, i| - address.sendMsg("/source/position_fixed", i+1, $F); - address.sendMsg("/source/mute", i+1, $F); + address.sendMsg("/source/new", ("source_"++(i+1).asString), "point", + (i+1).asString, 10.0.rand2, 10.0.rand2, -6.0, -6.0, $F, $T, $F); }); - 100.do({ - amountOfSources.do({|item, i| - address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); +}; + +~sourceTestMoving = { arg address = NetAddr("127.0.0.1", 50001), amountOfSources = 2; + Routine{ + 1.wait; + 1000.do({ + amountOfSources.do({|item, i| + address.sendMsg("/source/position", i+1, 10.0.rand2, 10.0.rand2); + }); + 0.1.wait; }); - }); + }.play; }; ) @@ -221,6 +221,7 @@ ~address = NetAddr("127.0.0.1", 50001); // poll client instance to make it subscribe ~address.sendMsg("/poll"); + ~sourceTestAdding.value(amountOfSources: 20); ~sourceTestMoving.value(amountOfSources: 20); ) From 2c9ec30676a71045f4d1d7ff2023bfbc8395d95f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 16 Dec 2018 12:28:40 +0100 Subject: [PATCH 362/363] src/networking/*: Removing dead code (which also fails to compile). --- src/networking/oschandler.cpp | 73 ----------------------- src/networking/oschandler.h | 12 ---- src/networking/oscreceiver.h | 10 ---- src/networking/oscsender.cpp | 106 ---------------------------------- src/networking/oscsender.h | 8 --- 5 files changed, 209 deletions(-) diff --git a/src/networking/oschandler.cpp b/src/networking/oschandler.cpp index 8951c9f5..d4a8ac70 100644 --- a/src/networking/oschandler.cpp +++ b/src/networking/oschandler.cpp @@ -146,79 +146,6 @@ bool ssr::OscReceiver::is_server(ssr::OscHandler& self, std::string& hostname, return self._osc_sender.is_server(hostname, port); } -/** - * OscHandler's friend function to send an OSC message to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param client_address lo::Address of client to send to (must be in _client_addresses) - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address - client_address, std::string path, lo::Message message) -{ - self._osc_sender.send_to_client(client_address, path, message); -} - -/** - * OscHandler's friend function to send an OSC bundle to a client, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param client_address lo::Address of client to send to (must be in _client_addresses) - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_client(OscHandler& self, lo::Address - client_address, lo::Bundle bundle) -{ - self._osc_sender.send_to_client(client_address, bundle); -} - -/** - * OscHandler's friend function to send an OSC message to all clients, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Message to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, std::string path, - lo::Message message) -{ - self._osc_sender.send_to_all_clients(path, message); -} - -/** - * OscHandler's friend function to send an OSC bundle to all clients, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle bundle) -{ - self._osc_sender.send_to_all_clients(bundle); -} - -/** - * OscHandler's friend function to send an OSC message to the server, using - * OscSender and a designated path. - * @param self reference to OscHandler holding OscSender - * @param path std::string defining the path to send on - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_server(OscHandler& self, std::string path, - lo::Message message) -{ - self._osc_sender.send_to_server(path, message); -} - -/** - * OscHandler's friend function to send an OSC bundle to the server, using - * OscSender. - * @param self reference to OscHandler holding OscSender - * @param message lo::Bundle to be sent - */ -void ssr::OscReceiver::send_to_server(OscHandler& self, lo::Bundle bundle) -{ - self._osc_sender.send_to_server(bundle); -} - /** * OscHandler's friend function to add a client to the list of OscSender's * _client_addresses. diff --git a/src/networking/oschandler.h b/src/networking/oschandler.h index 6de5a15e..306c3db3 100644 --- a/src/networking/oschandler.h +++ b/src/networking/oschandler.h @@ -71,18 +71,6 @@ class OscHandler friend bool OscReceiver::server_is_default(OscHandler& self); friend bool OscReceiver::is_server(OscHandler& self, std::string& hostname, std::string& port); - friend void OscReceiver::send_to_client(OscHandler& self, lo::Address - client_address, std::string path, lo::Message message); - friend void OscReceiver::send_to_client(OscHandler& self, lo::Address - client_address, lo::Bundle bundle); - friend void OscReceiver::send_to_all_clients(OscHandler& self, std::string - path, lo::Message message); - friend void OscReceiver::send_to_all_clients(OscHandler& self, lo::Bundle - bundle); - friend void OscReceiver::send_to_server(OscHandler& self, std::string path, - lo::Message message); - friend void OscReceiver::send_to_server(OscHandler& self, lo::Bundle - bundle); friend void OscReceiver::add_client(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); friend void OscReceiver::deactivate_client(OscHandler& self, std::string diff --git a/src/networking/oscreceiver.h b/src/networking/oscreceiver.h index b3433fdf..c050e0ca 100644 --- a/src/networking/oscreceiver.h +++ b/src/networking/oscreceiver.h @@ -60,16 +60,6 @@ class OscReceiver bool server_is_default(OscHandler& handler); bool is_server(OscHandler& handler, std::string& hostname, std::string& port); - void send_to_client(OscHandler& self, lo::Address client_address, - std::string path, lo::Message message); - void send_to_client(OscHandler& self, lo::Address client_address, - lo::Bundle bundle); - void send_to_all_clients(OscHandler& self, std::string path, lo::Message - message); - void send_to_all_clients(OscHandler& self, lo::Bundle bundle); - void send_to_server(OscHandler& self, std::string path, lo::Message - message); - void send_to_server(OscHandler& self, lo::Bundle bundle); void add_client(OscHandler& self, std::string hostname, std::string port, ssr::MessageLevel message_level); void deactivate_client(OscHandler& self, std::string hostname, std::string diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 1c9b56b0..6ef7f904 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -154,112 +154,6 @@ void ssr::OscSender::set_server_address(std::string& hostname, std::string& port _server.hostname() << ":" << _server.port() << "."); } -/** - * Function to send a lo::Message to the lo:Address setup as server using a - * predefined path - * @param path a std::string defining the path to send to - * @param message a predefined lo::Messge object to be sent - */ -void ssr::OscSender::send_to_server(std::string path, lo::Message message) -{ - if(!server_is_default()) - { - _server.address().send_from(_handler.server(), path, message.types(), message); - VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to server " << _server.hostname() << ":" << - _server.port() << "."); - } -} - -/** - * Function to send a lo::Bundle to the lo:Address setup as server - * @param bundle a predefined lo::Bundle object to be sent - */ -void ssr::OscSender::send_to_server(lo::Bundle bundle) -{ - if(!server_is_default()) - { - _server.address().send_from(_handler.server(), bundle); - VERBOSE3("OscSender: Sending bundle (" << bundle.length() << - " messages) to server " << _server.hostname() << ":" << - _server.port() << "."); - } -} - -/** - * Function to send a lo::Message to a client. - * @param address a lo:Address that will be sent to, when found in - * _clients. - * @param path a std::string defining the path to send to - * @param message a predefined lo::Messge object to be sent - */ -void ssr::OscSender::send_to_client(lo::Address address, std::string path, - lo::Message message) -{ - for (const auto& client: _clients) - { - if(client->hostname() == address.hostname() && client->port() == - address.port()) - { - client->address().send_from(_handler.server(), path, message.types(), - message); - VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << address.hostname() << ":" << address.port() << - "."); - } - } -} - -/** - * Function to send a lo::Bundle to a client. - * @param address a lo:Address that will be sent to, when found in - * _clients. - * @param bundle a predefined lo::Bundle object to be sent - */ -void ssr::OscSender::send_to_client(lo::Address address, lo::Bundle bundle) -{ - for (const auto& client: _clients) - { - if(client->hostname() == address.hostname() && client->port() == - address.port()) - { - client->address().send_from(_handler.server(), bundle); - VERBOSE3("OscSender: Sending bundle to client " << address.hostname() << - ":" << address.port() << "."); } - } -} - -/** - * Function to send a lo::Message to all clients setup in _clients - * vector. - * @param path a std::string defining the path to send to - * @param message a predefined lo::Messge object to be sent - */ -void ssr::OscSender::send_to_all_clients(std::string path, lo::Message message) -{ - for (const auto& client: _clients) - { - client->address().send_from(_handler.server(), path, message.types(), - message); - VERBOSE3("OscSender: Sending ["<< path << ", " << message.types() << - "] to client " << client->hostname() << ":" << - client->port() << "."); - } -} - -/** - * Sends a lo::Bundle to all clients setup in _clients vector. - * @param bundle a predefined lo::Bundle object to be sent - */ -void ssr::OscSender::send_to_all_clients(lo::Bundle bundle) -{ - for (const auto& client: _clients) - { - client->address().send_from(_handler.server(), bundle); - VERBOSE3("OscSender: Sending bundle to all clients."); - } -} - /** * Checks keys of _new_sources map against provided source id * @return true, if source id is found in _new_sources, false otherwise diff --git a/src/networking/oscsender.h b/src/networking/oscsender.h index 56918f99..338a9a7c 100644 --- a/src/networking/oscsender.h +++ b/src/networking/oscsender.h @@ -82,14 +82,6 @@ class OscSender : public Subscriber void deactivate_client(std::string hostname, std::string port); void increment_client_alive_counter(std::string& hostname, std::string& port); - void send_to_server(std::string path, lo::Message message); - void send_to_server(lo::Bundle bundle); - void send_to_client(lo::Address address, std::string path, lo::Message - message); - void send_to_client(lo::Address address, lo::Bundle bundle); - void send_to_all_clients(std::string path, lo::Message message); - void send_to_all_clients(lo::Bundle bundle); - void send_levels(); // Subscriber Interface From 541052112915b0f95660217618fbcdc2422e755b Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 16 Dec 2018 13:59:54 +0100 Subject: [PATCH 363/363] src/networking/oscsender.cpp: Turning std::string into C-string for send_from(). --- src/networking/oscsender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking/oscsender.cpp b/src/networking/oscsender.cpp index 6ef7f904..412f3b14 100644 --- a/src/networking/oscsender.cpp +++ b/src/networking/oscsender.cpp @@ -254,7 +254,7 @@ void ssr::OscSender::send_new_source_message_from_id(id_t id) _new_sources.at(id).get("orientation", 0.0), _new_sources.at(id).get("gain", 0.0), _new_sources.at(id).get("file_channel", 1), - _new_sources.at(id).get("properties_file", "")); + _new_sources.at(id).get("properties_file", "").c_str()); VERBOSE2("OscSender: Sent [/source/new, sssffffis" << _handler.bool_to_message_type(_new_sources.at(id).get( "position_fixed", false)) <<