New OSC Target for Alias and renaming source

Allow creating temporary OSC aliases to link to a target by ID or name. Allow renaming a source from OSC.
This commit is contained in:
Bruno Herbelin
2024-03-09 00:05:56 +01:00
parent e20261fa66
commit f280d3b64c
2 changed files with 62 additions and 22 deletions

View File

@@ -81,8 +81,8 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
if (address.size() > 2 && address.front().compare(OSC_PREFIX) == 0 ){ if (address.size() > 2 && address.front().compare(OSC_PREFIX) == 0 ){
// done with the first part of the OSC address // done with the first part of the OSC address
address.pop_front(); address.pop_front();
// next part of the OSC message is the target // next part of the OSC message is the target, after alias correction
std::string target = address.front(); std::string target = Control::manager().alias( address.front() );
// next part of the OSC message is the attribute // next part of the OSC message is the attribute
address.pop_front(); address.pop_front();
std::string attribute = address.front(); std::string attribute = address.front();
@@ -201,6 +201,16 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
int i = 0; int i = 0;
std::string num = target.substr( target.find("#") == std::string::npos ? 1 : 2 ); std::string num = target.substr( target.find("#") == std::string::npos ? 1 : 2 );
if ( BaseToolkit::is_a_number(num, &i)){ if ( BaseToolkit::is_a_number(num, &i)){
// special case of creating an alias for given source target
if (attribute.compare(OSC_SOURCE_ALIAS) == 0) {
const char *label = nullptr;
m.ArgumentStream() >> label >> osc::EndMessage;
Control::manager().aliases_[std::string("/").append(label)] = target;
Log::Info(CONTROL_OSC_MSG "New alias /%s for target %s.", label, target.c_str());
}
// usual case, addressing the source by '#n'
else {
Source *s = Mixer::manager().sourceAtIndex(i); Source *s = Mixer::manager().sourceAtIndex(i);
if (s) { if (s) {
// apply attributes to source // apply attributes to source
@@ -212,11 +222,20 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
Log::Info(CONTROL_OSC_MSG "No source at ID %s targetted by %s.", num.c_str(), sender); Log::Info(CONTROL_OSC_MSG "No source at ID %s targetted by %s.", num.c_str(), sender);
} }
} }
}
// General case: try to identify the target by name // General case: try to identify the target by name
else {
// special case of creating an alias for given source target
if (attribute.compare(OSC_SOURCE_ALIAS) == 0) {
const char *label = nullptr;
m.ArgumentStream() >> label >> osc::EndMessage;
Control::manager().aliases_[std::string("/").append(label)] = target;
Log::Info(CONTROL_OSC_MSG "New alias /%s for target %s.", label, target.c_str());
}
// usual case, addressing the source by its name
else { else {
// try to find source by given name // try to find source by given name
Source *s = Mixer::manager().findSource(target.substr(1)); Source *s = Mixer::manager().findSource(target.substr(1));
// if a source with the given target name or index was found // if a source with the given target name or index was found
if (s) { if (s) {
// apply attributes to source // apply attributes to source
@@ -228,6 +247,7 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
Log::Info(CONTROL_OSC_MSG "Unknown target '%s' requested by %s.", target.c_str(), sender); Log::Info(CONTROL_OSC_MSG "Unknown target '%s' requested by %s.", target.c_str(), sender);
} }
} }
}
else { else {
Log::Info(CONTROL_OSC_MSG "Unknown osc message '%s' sent by %s.", m.AddressPattern(), sender); Log::Info(CONTROL_OSC_MSG "Unknown osc message '%s' sent by %s.", m.AddressPattern(), sender);
} }
@@ -309,6 +329,15 @@ Control::~Control()
terminate(); terminate();
} }
std::string Control::alias (std::string target)
{
auto it_alias = aliases_.find(target);
if ( it_alias != aliases_.end() )
return it_alias->second;
else
return target;
}
std::string Control::translate (std::string addresspattern) std::string Control::translate (std::string addresspattern)
{ {
auto it_translation = translation_.find(addresspattern); auto it_translation = translation_.find(addresspattern);
@@ -597,8 +626,14 @@ bool Control::receiveSourceAttribute(Source *target, const std::string &attribut
return send_feedback; return send_feedback;
try { try {
/// e.g. '/vimix/#0/rename s toto'
if (attribute.compare(OSC_SOURCE_RENAME) == 0) {
const char *label = nullptr;
arguments >> label >> osc::EndMessage;
Mixer::manager().renameSource(target, label);
}
/// e.g. '/vimix/current/play' or '/vimix/current/play T' or '/vimix/current/play F' /// e.g. '/vimix/current/play' or '/vimix/current/play T' or '/vimix/current/play F'
if ( attribute.compare(OSC_SOURCE_PLAY) == 0) { else if ( attribute.compare(OSC_SOURCE_PLAY) == 0) {
float on = 1.f; float on = 1.f;
if ( !arguments.Eos()) { if ( !arguments.Eos()) {
arguments >> on >> osc::EndMessage; arguments >> on >> osc::EndMessage;

View File

@@ -34,6 +34,8 @@
#define OSC_PREVIOUS "/previous" #define OSC_PREVIOUS "/previous"
#define OSC_SOURCE_NAME "/name" #define OSC_SOURCE_NAME "/name"
#define OSC_SOURCE_RENAME "/rename"
#define OSC_SOURCE_ALIAS "/alias"
#define OSC_SOURCE_LOCK "/lock" #define OSC_SOURCE_LOCK "/lock"
#define OSC_SOURCE_PLAY "/play" #define OSC_SOURCE_PLAY "/play"
#define OSC_SOURCE_PAUSE "/pause" #define OSC_SOURCE_PAUSE "/pause"
@@ -129,8 +131,6 @@ public:
void update(); void update();
void terminate(); void terminate();
// OSC translation
std::string translate (std::string addresspqattern);
bool inputActive (uint id); bool inputActive (uint id);
float inputValue (uint id); float inputValue (uint id);
@@ -170,6 +170,10 @@ protected:
static void keyboardCalback(GLFWwindow*, int, int, int, int); static void keyboardCalback(GLFWwindow*, int, int, int, int);
// OSC translation
std::string translate (std::string addresspqattern);
std::string alias (std::string target);
private: private:
static void listen(); static void listen();
@@ -177,6 +181,7 @@ private:
std::condition_variable receiver_end_; std::condition_variable receiver_end_;
UdpListeningReceiveSocket *receiver_; UdpListeningReceiveSocket *receiver_;
std::map<std::string, std::string> aliases_;
std::map<std::string, std::string> translation_; std::map<std::string, std::string> translation_;
void loadOscConfig(); void loadOscConfig();
void resetOscConfig(); void resetOscConfig();