mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2026-06-03 21:41:38 +00:00
made the 3 osc ports configurable via (cross-platform) config scripts and move them outside of well used ranges for UDP
This commit is contained in:
@@ -31,117 +31,105 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
OSC_server::OSC_server(const string &port) :
|
||||
m_port(port),
|
||||
m_exit(false),
|
||||
m_command_ring_buffer(262144)
|
||||
{
|
||||
//cerr<<"using port: ["<<port<<"]"<<endl;
|
||||
m_server = lo_server_thread_new(port.c_str(), error_handler);
|
||||
m_port(port),
|
||||
m_exit(false),
|
||||
m_command_ring_buffer(262144) {
|
||||
//cerr<<"using port: ["<<port<<"]"<<endl;
|
||||
m_server = lo_server_thread_new(port.c_str(), error_handler);
|
||||
if (m_server) {
|
||||
cerr<<m_server<<endl;
|
||||
lo_server_thread_add_method(m_server, NULL, NULL, default_handler, this);
|
||||
}
|
||||
}
|
||||
|
||||
OSC_server::~OSC_server()
|
||||
{
|
||||
m_exit=true;
|
||||
lo_server_thread_stop(m_server);
|
||||
OSC_server::~OSC_server() {
|
||||
m_exit=true;
|
||||
lo_server_thread_stop(m_server);
|
||||
}
|
||||
|
||||
void OSC_server::run()
|
||||
{
|
||||
lo_server_thread_start(m_server);
|
||||
// while (!m_exit) usleep(1000);
|
||||
void OSC_server::run() {
|
||||
if (!m_server) return;
|
||||
lo_server_thread_start(m_server);
|
||||
// while (!m_exit) usleep(1000);
|
||||
}
|
||||
|
||||
void OSC_server::error_handler(int num, const char *msg, const char *path)
|
||||
{
|
||||
//cerr<<"liblo server error "<<num<<" in path "<<path<<": "<<msg<<endl;
|
||||
cerr<<"liblo server error "<<num<<endl;
|
||||
void OSC_server::error_handler(int num, const char *msg, const char *path) {
|
||||
//cerr<<"liblo server error "<<num<<" in path "<<path<<": "<<msg<<endl;
|
||||
cerr<<"liblo server error "<<num<<endl;
|
||||
}
|
||||
|
||||
int OSC_server::default_handler(const char *path, const char *types, lo_arg **argv,
|
||||
int argc, void *data, void *user_data)
|
||||
{
|
||||
OSC_server *server = (OSC_server*)user_data;
|
||||
int argc, void *data, void *user_data) {
|
||||
OSC_server *server = (OSC_server*)user_data;
|
||||
if (!server) return -1;
|
||||
|
||||
unsigned int size = 0;
|
||||
for (int i=0; i<argc; i++)
|
||||
{
|
||||
size+=lo_arg_size((lo_type)types[i],argv[i]);
|
||||
// add one for the null terminator
|
||||
if (types[i]=='s') size++;
|
||||
}
|
||||
|
||||
char *newdata=new char[size];
|
||||
unsigned int pos=0;
|
||||
for (int i=0; i<argc; i++)
|
||||
{
|
||||
switch (types[i])
|
||||
{
|
||||
case LO_INT32:
|
||||
{
|
||||
if (pos+4>COMMAND_DATA_SIZE)
|
||||
{
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,(char*)argv[i],4);
|
||||
pos+=4;
|
||||
}
|
||||
break;
|
||||
case LO_FLOAT:
|
||||
{
|
||||
if (pos+4>COMMAND_DATA_SIZE)
|
||||
{
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,(char*)argv[i],4);
|
||||
pos+=4;
|
||||
}
|
||||
break;
|
||||
case LO_STRING:
|
||||
{
|
||||
int size=strlen(&argv[i]->s);
|
||||
|
||||
if (pos+size+1>COMMAND_DATA_SIZE)
|
||||
{
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,&argv[i]->s,size);
|
||||
newdata[pos+size]='\0';
|
||||
pos+=size+1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
cerr<<"unsupported type: "<<types[i]<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (1)//pos==size) hmm
|
||||
{
|
||||
command_ring_buffer::command command(path,types,newdata,pos);
|
||||
if (!server->m_command_ring_buffer.send(command))
|
||||
{
|
||||
//cerr<<"OSC_server - ringbuffer full!"<<endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr<<"OSC_server::default_handler: size mismatch ["<<pos<<":"<<size<<"], not sending message"<<endl;
|
||||
}
|
||||
unsigned int size = 0;
|
||||
for (int i=0; i<argc; i++) {
|
||||
size+=lo_arg_size((lo_type)types[i],argv[i]);
|
||||
// add one for the null terminator
|
||||
if (types[i]=='s') size++;
|
||||
}
|
||||
|
||||
char *newdata=new char[size];
|
||||
unsigned int pos=0;
|
||||
for (int i=0; i<argc; i++) {
|
||||
switch (types[i]) {
|
||||
case LO_INT32: {
|
||||
if (pos+4>COMMAND_DATA_SIZE) {
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,(char*)argv[i],4);
|
||||
pos+=4;
|
||||
}
|
||||
break;
|
||||
case LO_FLOAT: {
|
||||
if (pos+4>COMMAND_DATA_SIZE) {
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,(char*)argv[i],4);
|
||||
pos+=4;
|
||||
}
|
||||
break;
|
||||
case LO_STRING: {
|
||||
int size=strlen(&argv[i]->s);
|
||||
|
||||
if (pos+size+1>COMMAND_DATA_SIZE) {
|
||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(newdata+pos,&argv[i]->s,size);
|
||||
newdata[pos+size]='\0';
|
||||
pos+=size+1;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
cerr<<"unsupported type: "<<types[i]<<endl;
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (1) { //pos==size) hmm
|
||||
|
||||
command_ring_buffer::command command(path,types,newdata,pos);
|
||||
if (!server->m_command_ring_buffer.send(command)) {
|
||||
//cerr<<"OSC_server - ringbuffer full!"<<endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cerr<<"OSC_server::default_handler: size mismatch ["<<pos<<":"<<size<<"], not sending message"<<endl;
|
||||
}
|
||||
|
||||
delete[] newdata;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -24,20 +24,21 @@
|
||||
class OSC_server
|
||||
{
|
||||
public:
|
||||
OSC_server(const std::string &port);
|
||||
~OSC_server();
|
||||
|
||||
void run();
|
||||
bool get(command_ring_buffer::command& command) { return m_command_ring_buffer.get(command);}
|
||||
|
||||
OSC_server(const std::string &port);
|
||||
~OSC_server();
|
||||
|
||||
void run();
|
||||
bool get(command_ring_buffer::command& command) { return m_command_ring_buffer.get(command);}
|
||||
bool ok() { return m_server!=NULL; }
|
||||
|
||||
private:
|
||||
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
|
||||
static void error_handler(int num, const char *m, const char *path);
|
||||
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
|
||||
static void error_handler(int num, const char *m, const char *path);
|
||||
|
||||
lo_server_thread m_server;
|
||||
std::string m_port;
|
||||
bool m_exit;
|
||||
command_ring_buffer m_command_ring_buffer;
|
||||
lo_server_thread m_server;
|
||||
std::string m_port;
|
||||
bool m_exit;
|
||||
command_ring_buffer m_command_ring_buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,10 @@ using namespace std;
|
||||
|
||||
lo_address status::m_address = lo_address_new_from_url("osc.udp://localhost:8890");
|
||||
|
||||
void status::set_port(const std::string &port) {
|
||||
status::m_address = lo_address_new_from_url(string("osc.udp://localhost:"+port).c_str());
|
||||
}
|
||||
|
||||
void status::_update(const std::string &msg) {
|
||||
lo_send(m_address,"/report","s",msg.c_str());
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace spiralcore {
|
||||
|
||||
class status {
|
||||
public:
|
||||
static void set_port(const std::string &port);
|
||||
static void _update(const std::string &msg);
|
||||
static void update(const char *msg, ...);
|
||||
static void sound_item(const std::string &name, const std::string &colour);
|
||||
|
||||
Reference in New Issue
Block a user