Skip to content

Commit

Permalink
cvOSCcv update
Browse files Browse the repository at this point in the history
Allow empty OSC namespace and longer paths (i.e. to use with Resolume). Fix crash with empty namespace.
  • Loading branch information
chichian committed Apr 4, 2019
1 parent 39abe39 commit 299f7d7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
30 changes: 18 additions & 12 deletions src/Module_oscCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void oscCV::step()
this->cleanupOSC(); // Try to clean up OSC
break;
case OSCAction::Enable:
this->cleanupOSC(); // Try to clean up OSC if we already have something
this->cleanupOSC(); // Try to clean up OSC if we already have something
this->initOSC(this->oscNewSettings.oscTxIpAddress.c_str(), this->oscNewSettings.oscTxPort, this->oscNewSettings.oscRxPort);
//oscStarted = this->oscInitialized;
break;
Expand Down Expand Up @@ -433,7 +433,14 @@ void oscCV::step()
oscStream << osc::BeginBundleImmediate;
packetOpened = true;
}
sprintf(addressBuffer, "/%s%s", oscNamespace.c_str(), inputChannels[c].getPath().c_str());
if (oscNamespace.empty()) // Allow empty namespaces
{
sprintf(addressBuffer, "%s", inputChannels[c].getPath().c_str());
}
else
{
sprintf(addressBuffer, "/%s%s", oscNamespace.c_str(), inputChannels[c].getPath().c_str());
}
oscStream << osc::BeginMessage(addressBuffer);
if (inputChannels[c].convertVals)
{
Expand All @@ -460,9 +467,7 @@ void oscCV::step()
oscStream << inputChannels[c].val;
}
oscStream << osc::EndMessage;
//oscStream << osc::BeginMessage(addressBuffer)
// << ((inputChannels[c].convertVals) ? inputChannels[c].translatedVal : inputChannels[c].val)
// << osc::EndMessage;

#if TROWA_DEBUG_MSGS >= TROWA_DEBUG_LVL_MED
debug("SEND OSC[%d]: %s %7.3f", c, addressBuffer, inputChannels[c].getValCV2OSC());
#endif
Expand Down Expand Up @@ -498,6 +503,7 @@ void oscCV::step()
}
oscMutex.unlock();
} // end if packet opened (close it)

} // end Rack Input Ports ==> OSC Output

//--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--
Expand Down Expand Up @@ -547,18 +553,17 @@ void oscCV::step()
// @oscNamespace : (IN) The namespace (without /).
// Set the OSC namespace (thread safe-ish).
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
void oscCV::setOscNamespace(std::string oscNamespace)
void oscCV::setOscNamespace(std::string oscNs)
{
std::lock_guard<std::mutex> lock(oscMutex);
if (oscNamespace[0] == '/')
this->oscNamespace = oscNamespace.substr(1);
if (!oscNs.empty() && oscNs.at(0) == '/')
this->oscNamespace = oscNs.substr(1);
else
this->oscNamespace = oscNamespace;
this->oscNamespace = oscNs;
if (this->oscListener != NULL)
{
try
{
//debug("Setting listener's namespace: %s", oscNamespace.c_str());
this->oscListener->setNamespace(oscNamespace);
}
catch (const std::exception& e)
Expand Down Expand Up @@ -589,8 +594,9 @@ void TSOSCCVSimpleMsgListener::ProcessMessage(const osc::ReceivedMessage& rxMsg,
const char* ns = this->oscNamespace.c_str();
mutExNamespace.unlock();
std::string addr = rxMsg.AddressPattern();
int len = strlen(ns);
if (std::strcmp(addr.substr(0, len).c_str(), ns) != 0) // Message is not for us
int len = (oscNamespace.empty()) ? 0 : oscNamespace.length();
// [2019-04-03] Allow empty namespaces
if (!oscNamespace.empty() && std::strcmp(addr.substr(0, len).c_str(), ns) != 0) // Message is not for us
{
#if TROWA_DEBUG_MSGS >= TROWA_DEBUG_LVL_LOW
debug("Message is not for our namespace (%s).", ns);
Expand Down
9 changes: 5 additions & 4 deletions src/Module_oscCV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ struct TSOSCCVChannel {
}
void setPath(std::string path)
{
std::lock_guard<std::mutex> lock(mutPath);
if (path[0] != '/')
std::lock_guard<std::mutex> lock(mutPath);
if (path.length() > 0 && path.at(0) != '/')
this->path = "/" + path;
else
this->path = path;
Expand Down Expand Up @@ -475,16 +475,17 @@ class TSOSCCVSimpleMsgListener : public osc::OscPacketListener {
TSOSCCVSimpleMsgListener(std::string oscNs, oscCV* oscModule)
{
this->oscModule = oscModule;
if (oscNs.length() > 0 && oscNs.at(0) != '/')
if (!oscNs.empty() && oscNs.at(0) != '/')
this->oscNamespace = "/" + oscNs;
else
this->oscNamespace = oscNs;
return;
}
void setNamespace(std::string oscNs)
{
//debug("Listener.setNamespace(): %s, first char is %c.", oscNs.c_str(), oscNs.at(0));
std::lock_guard<std::mutex> lock(mutExNamespace);
if (oscNs.length() > 0 && oscNs.at(0) != '/')
if (!oscNs.empty() && oscNs.at(0) != '/')
this->oscNamespace = "/" + oscNs;
else
this->oscNamespace = oscNs;
Expand Down
13 changes: 8 additions & 5 deletions src/Widget_oscCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ oscCVWidget::oscCVWidget(oscCV* oscModule) : TSSModuleWidgetBase(oscModule)
// OSC Input Path (this is OSC outgoing message, our input)
x += dx + tbXOffset;
std::string path = (isPreview) ? "/ch/" + std::to_string(r + 1) : oscModule->inputChannels[r].path;
TSTextField* txtField = new TSTextField(TSTextField::TextType::Any, 50);
TSTextField* txtField = new TSTextField(TSTextField::TextType::Any, TROWA_OSCCV_OSC_PATH_SIZE);
txtField->box.size = tbPathSize;
txtField->box.pos = Vec(x, y + tbYOffset);
txtField->text = path;
Expand Down Expand Up @@ -220,7 +220,7 @@ oscCVWidget::oscCVWidget(oscCV* oscModule) : TSSModuleWidgetBase(oscModule)
// OSC Output Path (this is OSC incoming message, our output)
x = xStart - tbXOffset - tbPathSize.x;
std::string path = (isPreview) ? "/ch/" + std::to_string(r + 1) : oscModule->outputChannels[r].path;
TSTextField* txtField = new TSTextField(TSTextField::TextType::Any, 50);
TSTextField* txtField = new TSTextField(TSTextField::TextType::Any, TROWA_OSCCV_OSC_PATH_SIZE);
txtField->box.size = tbPathSize;
txtField->box.pos = Vec(x, y + tbYOffset);
txtField->text = path;
Expand Down Expand Up @@ -655,10 +655,13 @@ void TSOscCVTopDisplay::step() {
thisModule = dynamic_cast<oscCV*>(parentWidget->module);
connected = thisModule->oscInitialized;
if (connected)
{
thisIp = thisModule->currentOSCSettings.oscTxIpAddress
+ std::string(" Tx:") + std::to_string(thisModule->currentOSCSettings.oscTxPort)
+ std::string(" Rx:") + std::to_string(thisModule->currentOSCSettings.oscRxPort)
+ ((thisModule->oscNamespace.at(0) == '/') ? " " : " /") + thisModule->oscNamespace + " ";
+ std::string(" Tx:") + std::to_string(thisModule->currentOSCSettings.oscTxPort)
+ std::string(" Rx:") + std::to_string(thisModule->currentOSCSettings.oscRxPort);
if (!thisModule->oscNamespace.empty())
thisIp = thisIp + ((thisModule->oscNamespace.at(0) == '/') ? " " : " /") + thisModule->oscNamespace + " ";
}
}


Expand Down
1 change: 1 addition & 0 deletions src/Widget_oscCV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace rack;

#define TROWA_SCROLLING_MSG_TOTAL_SIZE 256
#define TROWA_OSCCV_NUM_COLORS 8
#define TROWA_OSCCV_OSC_PATH_SIZE 256 // Max path size (was hard coded for TSTextBoxes to 50)

struct oscCV;
struct TSOscCVTopDisplay;
Expand Down
3 changes: 2 additions & 1 deletion src/trowaSoft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ using namespace rack;
extern Plugin *plugin;

// An internal version number (integer) value. Simple int value for quick/dirty easy comparison.
#define TROWA_INTERNAL_VERSION_INT 12 // 12: 0.6.4
#define TROWA_INTERNAL_VERSION_INT 13 // 13: 0.6.5

// 7: 0.5.5.2
// 8: 0.6.5.2dev - For Rack 0.6.0dev
// 9: 0.6.1
//10: 0.6.2
//11: 0.6.3
//12: 0.6.4
//13: 0.6.5

//#include "TSSModuleWidgetBase.hpp"
#include "TSSequencerWidgetBase.hpp"
Expand Down

0 comments on commit 299f7d7

Please sign in to comment.